Skip to content

Commit 96da982

Browse files
authored
[sanitizers] COMPILER_RT_ASAN_UNIT_TESTS_USE_HOST_RUNTIME to build only unit tests (#161455)
When COMPILER_RT_TEST_STANDALONE_BUILD_LIBS=OFF, none of the asan unit tests depend on a just-built asan runtime, and instead use the host runtime. However, some unit tests currently explicitly depend on the `asan` target which builds an asan runtime. COMPILER_RT_ASAN_UNIT_TESTS_USE_HOST_RUNTIME removes this erroneous dependency when set to ON. rdar://99760364
1 parent 30e323b commit 96da982

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

compiler-rt/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ mark_as_advanced(COMPILER_RT_BUILD_ORC)
8383
option(COMPILER_RT_BUILD_GWP_ASAN "Build GWP-ASan, and link it into SCUDO" ON)
8484
mark_as_advanced(COMPILER_RT_BUILD_GWP_ASAN)
8585
option(COMPILER_RT_ENABLE_CET "Build Compiler RT with CET enabled" OFF)
86+
option(COMPILER_RT_ASAN_UNIT_TESTS_USE_HOST_RUNTIME "Build asan unit tests without depending upon a just-built asan runtime" OFF)
87+
mark_as_advanced(COMPILER_RT_ASAN_UNIT_TESTS_USE_HOST_RUNTIME)
8688

8789
option(COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH "Set custom sysroot for building SCUDO standalone" OFF)
8890
mark_as_advanced(COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH)

compiler-rt/lib/asan/tests/CMakeLists.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,21 @@ function(add_asan_tests arch test_runtime)
170170
set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)
171171
set(CONFIG_NAME_DYNAMIC ${ARCH_UPPER_CASE}${OS_NAME}DynamicConfig)
172172

173+
# On some platforms, unit tests can be run against the runtime that shipped
174+
# with the host compiler with COMPILER_RT_TEST_STANDALONE_BUILD_LIBS=OFF.
175+
# COMPILER_RT_ASAN_UNIT_TESTS_USE_HOST_RUNTIME=ON removes the dependency
176+
# on `asan`, allowing the tests to be run independently without
177+
# a newly built asan runtime.
178+
set(ASAN_UNIT_TEST_DEPS asan)
179+
if(COMPILER_RT_ASAN_UNIT_TESTS_USE_HOST_RUNTIME)
180+
set(ASAN_UNIT_TEST_DEPS)
181+
endif()
182+
173183
# Closure to keep the values.
174184
function(generate_asan_tests test_objects test_suite testname)
175185
generate_compiler_rt_tests(${test_objects} ${test_suite} ${testname} ${arch}
176186
COMPILE_DEPS ${ASAN_UNITTEST_HEADERS} ${ASAN_IGNORELIST_FILE}
177-
DEPS asan
187+
DEPS ${ASAN_UNIT_TEST_DEPS}
178188
KIND ${TEST_KIND}
179189
${ARGN}
180190
)
@@ -215,7 +225,7 @@ function(add_asan_tests arch test_runtime)
215225
add_compiler_rt_test(AsanDynamicUnitTests "${dynamic_test_name}" "${arch}"
216226
SUBDIR "${CONFIG_NAME_DYNAMIC}"
217227
OBJECTS ${ASAN_INST_TEST_OBJECTS}
218-
DEPS asan ${ASAN_INST_TEST_OBJECTS}
228+
DEPS ${ASAN_UNIT_TEST_DEPS} ${ASAN_INST_TEST_OBJECTS}
219229
LINK_FLAGS ${ASAN_DYNAMIC_UNITTEST_INSTRUMENTED_LINK_FLAGS} ${TARGET_LINK_FLAGS} ${DYNAMIC_LINK_FLAGS}
220230
)
221231
endif()

0 commit comments

Comments
 (0)