Skip to content

[compiler-rt] Propagate sysroot from CMake to msan tests #132299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

zeroomega
Copy link
Contributor

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.

@llvmbot
Copy link
Member

llvmbot commented Mar 20, 2025

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Haowei (zeroomega)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/132299.diff

2 Files Affected:

  • (modified) compiler-rt/test/msan/lit.cfg.py (+4)
  • (modified) compiler-rt/test/msan/lit.site.cfg.py.in (+1)
diff --git a/compiler-rt/test/msan/lit.cfg.py b/compiler-rt/test/msan/lit.cfg.py
index 361be79e2557e..7282d29340201 100644
--- a/compiler-rt/test/msan/lit.cfg.py
+++ b/compiler-rt/test/msan/lit.cfg.py
@@ -17,6 +17,10 @@
         "-fno-optimize-sibling-calls",
     ]
     + [config.target_cflags]
+    + [
+        "--sysroot",
+        config.cmake_sysroot
+    ] if config.cmake_sysroot and config.host_os == "Linux" else []
     + config.debug_info_flags
 )
 # Some Msan tests leverage backtrace() which requires libexecinfo on 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")

Copy link

github-actions bot commented Mar 20, 2025

✅ With the latest revision this PR passed the Python code formatter.

@zeroomega zeroomega force-pushed the compiler-rt-sysroot branch from 5c8a61c to 83b012a Compare March 20, 2025 23:13
@@ -17,7 +17,9 @@
"-fno-optimize-sibling-calls",
]
+ [config.target_cflags]
+ config.debug_info_flags
+ ["--sysroot", config.cmake_sysroot]
if config.cmake_sysroot and config.host_os == "Linux"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried but ran into some further issues as some rtsan unit tests are not compatible with older glibc as memfd_create was not defined in glibc 2.19, it still can be invoked through syscall wrappers but that probably needs a separate patch. Therefore, I current limit the change to msan on Linux only to avoid other unwanted breakages.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's seems like incremental which which does not lead us to desired direction.
Could you try to figure out rtsan issue instead?

@zeroomega zeroomega force-pushed the compiler-rt-sysroot branch 3 times, most recently from 74d3fd4 to 9637a8a Compare March 28, 2025 22:47
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.
@zeroomega zeroomega requested a review from petrhosek March 28, 2025 22:56
@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be included in MSAN_UNITTEST_COMMON_CFLAGS as well.

[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.
@zeroomega zeroomega force-pushed the compiler-rt-sysroot branch from 9637a8a to 215d995 Compare April 4, 2025 22:45
[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.
@vitalybuka vitalybuka requested a review from petrhosek April 8, 2025 18:11
@@ -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@"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a nit, but I'd suggest calling it just sysroot, the fact that it comes from CMake isn't relevant.

Suggested change
config.cmake_sysroot = "@CMAKE_SYSROOT@"
config.sysroot = "@CMAKE_SYSROOT@"

Copy link
Collaborator

@vitalybuka vitalybuka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's good enough @petrhosek, then it's good enough for me. LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants