Skip to content

Commit 430c495

Browse files
mstorsjotru
authored andcommitted
[compiler-rt] [test] Fix using toolchains that rely on Clang default configs (llvm#113491)
The use of CLANG_NO_DEFAULT_CONFIG in the tests was added because some Linux distributions had a global default config file, that added flags relating to hardening, which interfere with the sanitizer tests. By setting CLANG_NO_DEFAULT_CONFIG, the global default config files that are found are ignored, and the sanitizers get the expected default compiler behaviour. (This was llvm#60394, which was fixed in 8ab7625.) However, some toolchains may rely on default config files for mandatory parts required for functioning at all - setting things like sysroots, -rtlib, -unwindlib, -stdlib, -fuse-ld etc. In such a case we can't forcibly disable any default config, because it will break the otherwise working toolchain. Add a test for whether the compiler works while passing --no-default-config to it. If the option is accepted and the toolchain still works while that is set, set CLANG_NO_DEFAULT_CONFIG while running tests. (This adds a little bit of inconsistency, as we're testing for the command line option, while using the environment variable. However doing compile testing with an environment variable isn't quite as easily doable, and passing an extra command line flag to all compile commands while testing, is a bit clumsy - therefore this inconsistency.) (cherry picked from commit a14a83d)
1 parent 2d8ee3a commit 430c495

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

compiler-rt/CMakeLists.txt

+16
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ include(CompilerRTUtils)
3939
include(CMakeDependentOption)
4040
include(GetDarwinLinkerVersion)
4141

42+
include(CheckCXXCompilerFlag)
43+
44+
# Check if we can compile with --no-default-config, or if that omits a config
45+
# file that is essential for the toolchain to work properly.
46+
#
47+
# Using CMAKE_REQUIRED_FLAGS to make sure the flag is used both for compilation
48+
# and for linking.
49+
#
50+
# Doing this test early on, to see if the flag works on the toolchain
51+
# out of the box. Later on, we end up adding -nostdlib and similar flags
52+
# to all test compiles, which easily can give false positives on this test.
53+
set(OLD_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
54+
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} --no-default-config")
55+
check_cxx_compiler_flag("" COMPILER_RT_HAS_NO_DEFAULT_CONFIG_FLAG)
56+
set(CMAKE_REQUIRED_FLAGS "${OLD_CMAKE_REQUIRED_FLAGS}")
57+
4258
option(COMPILER_RT_BUILD_BUILTINS "Build builtins" ON)
4359
mark_as_advanced(COMPILER_RT_BUILD_BUILTINS)
4460
option(COMPILER_RT_DISABLE_AARCH64_FMV "Disable AArch64 Function Multi Versioning support" OFF)

compiler-rt/test/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ pythonize_bool(COMPILER_RT_ENABLE_INTERNAL_SYMBOLIZER)
1212

1313
pythonize_bool(COMPILER_RT_HAS_AARCH64_SME)
1414

15+
pythonize_bool(COMPILER_RT_HAS_NO_DEFAULT_CONFIG_FLAG)
16+
1517
configure_compiler_rt_lit_site_cfg(
1618
${CMAKE_CURRENT_SOURCE_DIR}/lit.common.configured.in
1719
${CMAKE_CURRENT_BINARY_DIR}/lit.common.configured)

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,11 @@ def is_windows_lto_supported():
980980
# default configs for the test runs. In particular, anything hardening
981981
# related is likely to cause issues with sanitizer tests, because it may
982982
# preempt something we're looking to trap (e.g. _FORTIFY_SOURCE vs our ASAN).
983-
config.environment["CLANG_NO_DEFAULT_CONFIG"] = "1"
983+
#
984+
# Only set this if we know we can still build for the target while disabling
985+
# default configs.
986+
if config.has_no_default_config_flag:
987+
config.environment["CLANG_NO_DEFAULT_CONFIG"] = "1"
984988

985989
if config.has_compiler_rt_libatomic:
986990
base_lib = os.path.join(config.compiler_rt_libdir, "libclang_rt.atomic%s.so"

compiler-rt/test/lit.common.configured.in

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ set_default("test_standalone_build_libs", @COMPILER_RT_TEST_STANDALONE_BUILD_LIB
5353
set_default("has_compiler_rt_libatomic", @COMPILER_RT_BUILD_STANDALONE_LIBATOMIC_PYBOOL@)
5454
set_default("aarch64_sme", @COMPILER_RT_HAS_AARCH64_SME_PYBOOL@)
5555
set_default("darwin_linker_version", "@COMPILER_RT_DARWIN_LINKER_VERSION@")
56+
set_default("has_no_default_config_flag", @COMPILER_RT_HAS_NO_DEFAULT_CONFIG_FLAG_PYBOOL@)
5657
# True iff the test suite supports ignoring the test compiler's runtime library path
5758
# and using `config.compiler_rt_libdir` instead. This only matters when the runtime
5859
# library paths differ.

0 commit comments

Comments
 (0)