Skip to content

Commit 3a7c187

Browse files
authored
[safestack] Support multilib testing (#98002)
While working on my safestack patches, I noticed that only the default multilib was tested even though all multilib versions of `libclang_rt.safestack.a` were built. This patch fixes this, patterned after the ubsan testing support. Tested on `amd64-pc-solaris2.11` (`amd64` and `i386`), `sparcv9-sun-solaris2.11` (`sparcv9` and `sparc`), `x86_64-pc-linux-gnu` (`x86_64` and `i386`), and `sparc64-unknown-linux-gnu` (`sparcv9` and `sparc`).
1 parent 25f4bd8 commit 3a7c187

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed
Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,40 @@
11
set(SAFESTACK_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
22
set(SAFESTACK_LIT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
33

4+
set(SAFESTACK_TESTSUITES)
45
set(SAFESTACK_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
56
list(APPEND SAFESTACK_TEST_DEPS safestack)
6-
if(NOT COMPILER_RT_STANDALONE_BUILD)
7-
# Some tests require LTO, so add a dependency on the relevant LTO plugin.
8-
if(LLVM_ENABLE_PIC)
9-
if(LLVM_BINUTILS_INCDIR)
10-
list(APPEND SAFESTACK_TEST_DEPS
11-
LLVMgold
12-
)
13-
endif()
14-
if(APPLE)
15-
list(APPEND SAFESTACK_TEST_DEPS
16-
LTO
17-
)
7+
8+
macro(add_safestack_testsuite test_mode sanitizer arch)
9+
set(SAFESTACK_LIT_TEST_MODE "${test_mode}")
10+
set(CONFIG_NAME ${SAFESTACK_LIT_TEST_MODE})
11+
12+
if(NOT COMPILER_RT_STANDALONE_BUILD)
13+
# Some tests require LTO, so add a dependency on the relevant LTO plugin.
14+
if(LLVM_ENABLE_PIC)
15+
if(LLVM_BINUTILS_INCDIR)
16+
list(APPEND SAFESTACK_TEST_DEPS LLVMgold)
17+
endif()
18+
if(APPLE)
19+
list(APPEND SAFESTACK_TEST_DEPS LTO)
20+
endif()
1821
endif()
1922
endif()
20-
endif()
23+
set(CONFIG_NAME ${CONFIG_NAME}-${arch})
24+
configure_lit_site_cfg(
25+
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
26+
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py)
27+
list(APPEND SAFESTACK_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
28+
endmacro()
29+
30+
set(SAFESTACK_TEST_ARCH ${SAFESTACK_SUPPORTED_ARCH})
2131

22-
configure_lit_site_cfg(
23-
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
24-
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
25-
)
32+
foreach(arch ${SAFESTACK_TEST_ARCH})
33+
set(SAFESTACK_TEST_TARGET_ARCH ${arch})
34+
get_test_cc_for_arch(${arch} SAFESTACK_TEST_TARGET_CC SAFESTACK_TEST_TARGET_CFLAGS)
35+
add_safestack_testsuite("Standalone" safestack ${arch})
36+
endforeach()
2637

2738
add_lit_testsuite(check-safestack "Running the SafeStack tests"
28-
${CMAKE_CURRENT_BINARY_DIR}
39+
${SAFESTACK_TESTSUITES}
2940
DEPENDS ${SAFESTACK_TEST_DEPS})

compiler-rt/test/safestack/lit.cfg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44

55
# Setup config name.
6-
config.name = "SafeStack"
6+
config.name = "SafeStack-" + config.name_suffix
77

88
# Setup source root.
99
config.test_source_root = os.path.dirname(__file__)

compiler-rt/test/safestack/lit.site.cfg.py.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
@LIT_SITE_CFG_IN_HEADER@
22

3+
# Tool-specific config options.
4+
config.name_suffix = "@CONFIG_NAME@"
5+
config.safestack_lit_test_mode = "@SAFESTACK_LIT_TEST_MODE@"
6+
config.target_cflags = "@SAFESTACK_TEST_TARGET_CFLAGS@"
7+
config.target_arch = "@SAFESTACK_TEST_TARGET_ARCH@"
8+
39
# Load common config for all compiler-rt lit tests.
410
lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
511

0 commit comments

Comments
 (0)