Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[compiler-rt][test] Apply CFLAGS from sanitizer_common to all tests #120798

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 1 commit into
base: main
Choose a base branch
from

Conversation

aaronpuchert
Copy link
Member

Sanitizer-specific tests don't use the sanitizer_common flags, but the issues they address probably also apply to the individual sanitizers.

This was observed in #119071: moving a test from sanitizer_common to msan broke it in builds with CMAKE_SYSROOT set, because the --sysroot argument was no longer applied to the test.

@llvmbot
Copy link
Member

llvmbot commented Dec 20, 2024

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

Author: Aaron Puchert (aaronpuchert)

Changes

Sanitizer-specific tests don't use the sanitizer_common flags, but the issues they address probably also apply to the individual sanitizers.

This was observed in #119071: moving a test from sanitizer_common to msan broke it in builds with CMAKE_SYSROOT set, because the --sysroot argument was no longer applied to the test.


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

2 Files Affected:

  • (modified) compiler-rt/cmake/config-ix.cmake (+8)
  • (modified) compiler-rt/test/sanitizer_common/CMakeLists.txt (-11)
diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
index 6d52eecc9a91fe..09c15fdabfd09c 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -307,6 +307,14 @@ macro(get_test_cc_for_arch arch cc_out cflags_out)
     if(APPLE)
       list(APPEND ${cflags_out} ${DARWIN_osx_CFLAGS})
     endif()
+    if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+      # ARM on Linux might use the slow unwinder as default and the unwind table
+      # is required to get a complete stacktrace.
+      list(APPEND ${cflags_out} -funwind-tables)
+      if(CMAKE_SYSROOT)
+        list(APPEND ${cflags_out} "--sysroot=${CMAKE_SYSROOT}")
+      endif()
+    endif()
     string(REPLACE ";" " " ${cflags_out} "${${cflags_out}}")
   endif()
 endmacro()
diff --git a/compiler-rt/test/sanitizer_common/CMakeLists.txt b/compiler-rt/test/sanitizer_common/CMakeLists.txt
index 615666676f57ac..b044b9c6c3e088 100644
--- a/compiler-rt/test/sanitizer_common/CMakeLists.txt
+++ b/compiler-rt/test/sanitizer_common/CMakeLists.txt
@@ -73,17 +73,6 @@ foreach(tool ${SUPPORTED_TOOLS})
     get_test_cc_for_arch(${arch} SANITIZER_COMMON_TEST_TARGET_CC SANITIZER_COMMON_TEST_TARGET_CFLAGS)
     set(CONFIG_NAME ${tool}-${arch}-${OS_NAME})
 
-    # ARM on Linux might use the slow unwinder as default and the unwind table is
-    # required to get a complete stacktrace.
-    if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" AND NOT ANDROID)
-      list(APPEND SANITIZER_COMMON_TEST_TARGET_CFLAGS -funwind-tables)
-      if(CMAKE_SYSROOT)
-        list(APPEND SANITIZER_COMMON_TEST_TARGET_CFLAGS "--sysroot=${CMAKE_SYSROOT}")
-      endif()
-      string(REPLACE ";" " " SANITIZER_COMMON_TEST_TARGET_CFLAGS
-                             "${SANITIZER_COMMON_TEST_TARGET_CFLAGS}")
-    endif()
-
     configure_lit_site_cfg(
       ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
       ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py)

@aaronpuchert
Copy link
Member Author

@nico or @alanzhao1: could you test this together with #119071 relanded? Does that solve the issue (and not create new issues)?

@aaronpuchert
Copy link
Member Author

Ping @nico / @alanzhao1. Since you reverted #119071 and you were the only ones to run into this issue, I'd appreciate if you could test this. Otherwise I'll have to land both changes and then see you revert them again if something doesn't work.

I've managed to somewhat reproduce this with a different sysroot, but the problem here arises due to the combination of sysroot and base image, and I can't exactly produce the setting that you have.

I'll also discuss offering both symbol versions, but I don't have a good idea for that yet.

@aaronpuchert aaronpuchert requested a review from vitalybuka March 4, 2025 22:45
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.

I suspect new code needs to be outside of
"if(ANDROID OR (NOT APPLE AND ${arch} MATCHES "arm|aarch64|riscv32|riscv64"))"

@vitalybuka vitalybuka requested review from petrhosek and vitalybuka May 6, 2025 23:26
Sanitizer-specific tests don't use the sanitizer_common flags, but the
issues they address probably also apply to the individual sanitizers.

This was observed in llvm#119071: moving a test from sanitizer_common to
msan broke it in builds with CMAKE_SYSROOT set, because the --sysroot
argument was no longer applied to the test.
@aaronpuchert aaronpuchert force-pushed the sanitizer-common-test-flags branch from 288b004 to faea58a Compare May 7, 2025 09:26
@aaronpuchert
Copy link
Member Author

I've not changed anything about when -funwind-tables is applied, this is just moving the flags to apply to all tests. (All that use this function.)

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.

3 participants