From 986276bbec1b1ea3a094dd05c92b3e971b15d975 Mon Sep 17 00:00:00 2001 From: Haowei Wu Date: Thu, 20 Mar 2025 15:14:10 -0700 Subject: [PATCH 1/3] [compiler-rt] Propagate sysroot from CMake to msan tests Some msan tests requires rpc/xdr.h, which is no longer available in some newer glibc. In build systems with hermetic sysroot set through CMake, this issue can be solved by setting the sysroot to CMAKE_SYSROOT for these tests. This patch implements it. --- compiler-rt/lib/msan/tests/CMakeLists.txt | 6 +++++- compiler-rt/test/msan/lit.cfg.py | 5 +++++ compiler-rt/test/msan/lit.site.cfg.py.in | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/compiler-rt/lib/msan/tests/CMakeLists.txt b/compiler-rt/lib/msan/tests/CMakeLists.txt index a8500225337e6..6b1dc2bad6962 100644 --- a/compiler-rt/lib/msan/tests/CMakeLists.txt +++ b/compiler-rt/lib/msan/tests/CMakeLists.txt @@ -63,7 +63,11 @@ set(MSAN_UNITTEST_LINK_FLAGS # inputs. ) -append_list_if(COMPILER_RT_HAS_LIBDL -ldl MSAN_UNITTEST_LINK_FLAGS) +if (LINUX) + append_list_if(CMAKE_SYSROOT "--sysroot=${CMAKE_SYSROOT}" MSAN_UNITTEST_LINK_FLAGS) +endif() + + append_list_if(COMPILER_RT_HAS_LIBDL -ldl MSAN_UNITTEST_LINK_FLAGS) macro(msan_compile obj_list source arch kind cflags) sanitizer_test_compile( diff --git a/compiler-rt/test/msan/lit.cfg.py b/compiler-rt/test/msan/lit.cfg.py index 361be79e2557e..ab1fc667d97e0 100644 --- a/compiler-rt/test/msan/lit.cfg.py +++ b/compiler-rt/test/msan/lit.cfg.py @@ -18,6 +18,11 @@ ] + [config.target_cflags] + config.debug_info_flags + + ( + ["--sysroot", config.cmake_sysroot] + if config.cmake_sysroot and config.host_os == "Linux" + else [] + ) ) # Some Msan tests leverage backtrace() which requires libexecinfo on FreeBSD. if config.host_os == "FreeBSD": diff --git a/compiler-rt/test/msan/lit.site.cfg.py.in b/compiler-rt/test/msan/lit.site.cfg.py.in index 47264d0986946..41231359692ed 100644 --- a/compiler-rt/test/msan/lit.site.cfg.py.in +++ b/compiler-rt/test/msan/lit.site.cfg.py.in @@ -6,6 +6,7 @@ config.target_cflags = "@MSAN_TEST_TARGET_CFLAGS@" config.target_arch = "@MSAN_TEST_TARGET_ARCH@" config.use_lld = @MSAN_TEST_USE_LLD@ config.use_thinlto = @MSAN_TEST_USE_THINLTO@ +config.cmake_sysroot = "@CMAKE_SYSROOT@" # Load common config for all compiler-rt lit tests. lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured") From 215d9958b7cf0b4e4308b2071ca30a5ad696071c Mon Sep 17 00:00:00 2001 From: Haowei Wu Date: Fri, 4 Apr 2025 15:42:58 -0700 Subject: [PATCH 2/3] amend! [compiler-rt] Propagate sysroot from CMake to msan tests [compiler-rt] Propagate sysroot from CMake to msan tests Some msan tests requires rpc/xdr.h, which is no longer available in some newer glibc. In build systems with hermetic sysroot set through CMake, this issue can be solved by setting the sysroot to CMAKE_SYSROOT for these tests. This patch implements it. From c7cf3c43969d7ec0a7437af2e60aca87f4366a39 Mon Sep 17 00:00:00 2001 From: Haowei Wu Date: Fri, 4 Apr 2025 15:46:03 -0700 Subject: [PATCH 3/3] amend! amend! [compiler-rt] Propagate sysroot from CMake to msan tests [compiler-rt] Propagate sysroot from CMake to msan tests Some msan tests requires rpc/xdr.h, which is no longer available in some newer glibc. In build systems with hermetic sysroot set through CMake, this issue can be solved by setting the sysroot to CMAKE_SYSROOT for these tests. This patch implements it. --- compiler-rt/lib/msan/tests/CMakeLists.txt | 7 +++---- compiler-rt/test/msan/lit.cfg.py | 7 ++----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/compiler-rt/lib/msan/tests/CMakeLists.txt b/compiler-rt/lib/msan/tests/CMakeLists.txt index 6b1dc2bad6962..26a86afd4674f 100644 --- a/compiler-rt/lib/msan/tests/CMakeLists.txt +++ b/compiler-rt/lib/msan/tests/CMakeLists.txt @@ -63,11 +63,10 @@ set(MSAN_UNITTEST_LINK_FLAGS # inputs. ) -if (LINUX) - append_list_if(CMAKE_SYSROOT "--sysroot=${CMAKE_SYSROOT}" MSAN_UNITTEST_LINK_FLAGS) -endif() +append_list_if(CMAKE_SYSROOT "--sysroot=${CMAKE_SYSROOT}" MSAN_UNITTEST_COMMON_CFLAGS) +append_list_if(CMAKE_SYSROOT "--sysroot=${CMAKE_SYSROOT}" MSAN_UNITTEST_LINK_FLAGS) - append_list_if(COMPILER_RT_HAS_LIBDL -ldl MSAN_UNITTEST_LINK_FLAGS) +append_list_if(COMPILER_RT_HAS_LIBDL -ldl MSAN_UNITTEST_LINK_FLAGS) macro(msan_compile obj_list source arch kind cflags) sanitizer_test_compile( diff --git a/compiler-rt/test/msan/lit.cfg.py b/compiler-rt/test/msan/lit.cfg.py index ab1fc667d97e0..bcc6d693022ee 100644 --- a/compiler-rt/test/msan/lit.cfg.py +++ b/compiler-rt/test/msan/lit.cfg.py @@ -18,12 +18,9 @@ ] + [config.target_cflags] + config.debug_info_flags - + ( - ["--sysroot", config.cmake_sysroot] - if config.cmake_sysroot and config.host_os == "Linux" - else [] - ) ) +if config.cmake_sysroot: + clang_msan_cflags += [f"--sysroot={config.cmake_sysroot}"] # Some Msan tests leverage backtrace() which requires libexecinfo on FreeBSD. if config.host_os == "FreeBSD": clang_msan_cflags += ["-lexecinfo", "-fPIC"]