Skip to content

[safestack] Support multilib testing #98002

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

Merged
merged 1 commit into from
Jul 19, 2024

Conversation

rorth
Copy link
Collaborator

@rorth rorth commented Jul 8, 2024

While working on my safestack patches, I noticed that only the default multilib was tested even though all multilib versions of libclang_rt.safestack.a were built.

This patch fixes this, patterned after the ubsan testing support.

Tested on amd64-pc-solaris2.11 (amd64 and i386), sparcv9-sun-solaris2.11 (sparcv9 and sparc), x86_64-pc-linux-gnu (x86_64 and i386), and sparc64-unknown-linux-gnu (sparcv9 and sparc).

While working on my safestack patches, I noticed that only the default
multilib was tested even though all multilib versions of
`libclang_rt.safestack.a` were built.

This patch fixes this, patterned after the ubsan testing support.

Tested on `amd64-pc-solaris2.11` (`amd64` and `i386`),
`sparcv9-sun-solaris2.11` (`sparcv9` and `sparc`), `x86_64-pc-linux-gnu`
(`x86_64` and `i386`), and `sparc64-unknown-linux-gnu` (`sparcv9`).

Linux/i386 testing requires the patch switching safestack to
`sanitizer_common` functions, otherwise all tests `FAIL`.

Linux/sparc testing doesn't work (only 64-bit) since `clang` doesn't find
the 32-bit runtime.
@llvmbot
Copy link
Member

llvmbot commented Jul 8, 2024

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

Author: Rainer Orth (rorth)

Changes

While working on my safestack patches, I noticed that only the default multilib was tested even though all multilib versions of libclang_rt.safestack.a were built.

This patch fixes this, patterned after the ubsan testing support.

Tested on amd64-pc-solaris2.11 (amd64 and i386), sparcv9-sun-solaris2.11 (sparcv9 and sparc), x86_64-pc-linux-gnu (x86_64 and i386), and sparc64-unknown-linux-gnu (sparcv9).

Linux/i386 testing requires the patch switching safestack to sanitizer_common functions, otherwise all tests FAIL.

Linux/sparc testing doesn't work (only 64-bit) since clang doesn't find the 32-bit runtime.


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

3 Files Affected:

  • (modified) compiler-rt/test/safestack/CMakeLists.txt (+29-18)
  • (modified) compiler-rt/test/safestack/lit.cfg.py (+1-1)
  • (modified) compiler-rt/test/safestack/lit.site.cfg.py.in (+6)
diff --git a/compiler-rt/test/safestack/CMakeLists.txt b/compiler-rt/test/safestack/CMakeLists.txt
index 89ba6e74884b1..fca06024c9856 100644
--- a/compiler-rt/test/safestack/CMakeLists.txt
+++ b/compiler-rt/test/safestack/CMakeLists.txt
@@ -1,29 +1,40 @@
 set(SAFESTACK_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
 set(SAFESTACK_LIT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
 
+set(SAFESTACK_TESTSUITES)
 set(SAFESTACK_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
 list(APPEND SAFESTACK_TEST_DEPS safestack)
-if(NOT COMPILER_RT_STANDALONE_BUILD)
-  # Some tests require LTO, so add a dependency on the relevant LTO plugin.
-  if(LLVM_ENABLE_PIC)
-    if(LLVM_BINUTILS_INCDIR)
-      list(APPEND SAFESTACK_TEST_DEPS
-        LLVMgold
-      )
-    endif()
-    if(APPLE)
-      list(APPEND SAFESTACK_TEST_DEPS
-        LTO
-      )
+
+macro(add_safestack_testsuite test_mode sanitizer arch)
+  set(SAFESTACK_LIT_TEST_MODE "${test_mode}")
+  set(CONFIG_NAME ${SAFESTACK_LIT_TEST_MODE})
+
+  if(NOT COMPILER_RT_STANDALONE_BUILD)
+    # Some tests require LTO, so add a dependency on the relevant LTO plugin.
+    if(LLVM_ENABLE_PIC)
+      if(LLVM_BINUTILS_INCDIR)
+        list(APPEND SAFESTACK_TEST_DEPS LLVMgold)
+      endif()
+      if(APPLE)
+        list(APPEND SAFESTACK_TEST_DEPS LTO)
+      endif()
     endif()
   endif()
-endif()
+  set(CONFIG_NAME ${CONFIG_NAME}-${arch})
+  configure_lit_site_cfg(
+    ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
+    ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py)
+  list(APPEND SAFESTACK_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
+endmacro()
+
+set(SAFESTACK_TEST_ARCH ${SAFESTACK_SUPPORTED_ARCH})
 
-configure_lit_site_cfg(
-  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
-  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
-  )
+foreach(arch ${SAFESTACK_TEST_ARCH})
+  set(SAFESTACK_TEST_TARGET_ARCH ${arch})
+  get_test_cc_for_arch(${arch} SAFESTACK_TEST_TARGET_CC SAFESTACK_TEST_TARGET_CFLAGS)
+  add_safestack_testsuite("Standalone" safestack ${arch})
+endforeach()
 
 add_lit_testsuite(check-safestack "Running the SafeStack tests"
-  ${CMAKE_CURRENT_BINARY_DIR}
+  ${SAFESTACK_TESTSUITES}
   DEPENDS ${SAFESTACK_TEST_DEPS})
diff --git a/compiler-rt/test/safestack/lit.cfg.py b/compiler-rt/test/safestack/lit.cfg.py
index aadb8bf0d5c77..c266fe3e7b6bb 100644
--- a/compiler-rt/test/safestack/lit.cfg.py
+++ b/compiler-rt/test/safestack/lit.cfg.py
@@ -3,7 +3,7 @@
 import os
 
 # Setup config name.
-config.name = "SafeStack"
+config.name = "SafeStack-" + config.name_suffix
 
 # Setup source root.
 config.test_source_root = os.path.dirname(__file__)
diff --git a/compiler-rt/test/safestack/lit.site.cfg.py.in b/compiler-rt/test/safestack/lit.site.cfg.py.in
index 3c8bf41b283b8..ee866bca2bad3 100644
--- a/compiler-rt/test/safestack/lit.site.cfg.py.in
+++ b/compiler-rt/test/safestack/lit.site.cfg.py.in
@@ -1,5 +1,11 @@
 @LIT_SITE_CFG_IN_HEADER@
 
+# Tool-specific config options.
+config.name_suffix = "@CONFIG_NAME@"
+config.safestack_lit_test_mode = "@SAFESTACK_LIT_TEST_MODE@"
+config.target_cflags = "@SAFESTACK_TEST_TARGET_CFLAGS@"
+config.target_arch = "@SAFESTACK_TEST_TARGET_ARCH@"
+
 # Load common config for all compiler-rt lit tests.
 lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
 

@rorth rorth merged commit 3a7c187 into llvm:main Jul 19, 2024
9 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 19, 2024

LLVM Buildbot has detected a new failure on builder sanitizer-ppc64le-linux running on ppc64le-sanitizer while building compiler-rt at step 2 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/72/builds/1378

Here is the relevant piece of the build log for the reference:

Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure)
...
PASS: ThreadSanitizer-powerpc64le :: simple_race.c (2347 of 2465)
PASS: MemorySanitizer-POWERPC64LE :: dtor-vtable-multiple-inheritance.cpp (2348 of 2465)
PASS: ThreadSanitizer-powerpc64le :: mmap_stress2.cpp (2349 of 2465)
PASS: ScudoStandalone-Unit :: ./ScudoUnitTest-powerpc64le-Test/80/274 (2350 of 2465)
PASS: ScudoStandalone-Unit :: ./ScudoUnitTest-powerpc64le-Test/85/274 (2351 of 2465)
PASS: ThreadSanitizer-powerpc64le :: ignored-interceptors-mmap.cpp (2352 of 2465)
PASS: SanitizerCommon-msan-powerpc64le-Linux :: get_module_and_offset_for_pc.cpp (2353 of 2465)
PASS: SanitizerCommon-lsan-powerpc64le-Linux :: Linux/signal_name.c (2354 of 2465)
PASS: ThreadSanitizer-powerpc64le :: simple_race.cpp (2355 of 2465)
PASS: ThreadSanitizer-powerpc64le :: race_on_barrier.c (2356 of 2465)
FAIL: ThreadSanitizer-powerpc64le :: signal_block.cpp (2357 of 2465)
******************** TEST 'ThreadSanitizer-powerpc64le :: signal_block.cpp' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/./bin/clang  -fsanitize=thread -Wall  -m64 -fno-function-sections   -gline-tables-only -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/../ -O1 /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp -o /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/runtimes/runtimes-bins/compiler-rt/test/tsan/POWERPC64LEConfig/Output/signal_block.cpp.tmp &&  /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/runtimes/runtimes-bins/compiler-rt/test/tsan/POWERPC64LEConfig/Output/signal_block.cpp.tmp 2>&1 | FileCheck /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp
+ /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/./bin/clang -fsanitize=thread -Wall -m64 -fno-function-sections -gline-tables-only -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/../ -O1 /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp -o /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/runtimes/runtimes-bins/compiler-rt/test/tsan/POWERPC64LEConfig/Output/signal_block.cpp.tmp
+ /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/runtimes/runtimes-bins/compiler-rt/test/tsan/POWERPC64LEConfig/Output/signal_block.cpp.tmp
+ FileCheck /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp:59:15: error: CHECK-NOT: excluded string found in input
// CHECK-NOT: WARNING: ThreadSanitizer:
              ^
<stdin>:2:1: note: found here
WARNING: ThreadSanitizer: signal handler spoils errno (pid=606483)
^~~~~~~~~~~~~~~~~~~~~~~~~

Input file: <stdin>
Check file: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp

-dump-input=help explains the following input dump.

Input was:
<<<<<<
        1: ================== 
        2: WARNING: ThreadSanitizer: signal handler spoils errno (pid=606483) 
not:59     !~~~~~~~~~~~~~~~~~~~~~~~~                                           error: no match expected
        3:  Signal 10 handler invoked at: 
        4:  #0 handler(int) /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp:13 (signal_block.cpp.tmp+0xff160) 
        5:  #1 thread(void*) /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp:25:5 (signal_block.cpp.tmp+0xff2b0) 
        6:  
        7: SUMMARY: ThreadSanitizer: signal handler spoils errno /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp:13 in handler(int) 
        8: ================== 
        9: DONE 
       10: ThreadSanitizer: reported 1 warnings 
>>>>>>

--

Step 9 (test compiler-rt debug) failure: test compiler-rt debug (failure)
...
PASS: ThreadSanitizer-powerpc64le :: simple_race.c (2347 of 2465)
PASS: MemorySanitizer-POWERPC64LE :: dtor-vtable-multiple-inheritance.cpp (2348 of 2465)
PASS: ThreadSanitizer-powerpc64le :: mmap_stress2.cpp (2349 of 2465)
PASS: ScudoStandalone-Unit :: ./ScudoUnitTest-powerpc64le-Test/80/274 (2350 of 2465)
PASS: ScudoStandalone-Unit :: ./ScudoUnitTest-powerpc64le-Test/85/274 (2351 of 2465)
PASS: ThreadSanitizer-powerpc64le :: ignored-interceptors-mmap.cpp (2352 of 2465)
PASS: SanitizerCommon-msan-powerpc64le-Linux :: get_module_and_offset_for_pc.cpp (2353 of 2465)
PASS: SanitizerCommon-lsan-powerpc64le-Linux :: Linux/signal_name.c (2354 of 2465)
PASS: ThreadSanitizer-powerpc64le :: simple_race.cpp (2355 of 2465)
PASS: ThreadSanitizer-powerpc64le :: race_on_barrier.c (2356 of 2465)
FAIL: ThreadSanitizer-powerpc64le :: signal_block.cpp (2357 of 2465)
******************** TEST 'ThreadSanitizer-powerpc64le :: signal_block.cpp' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/./bin/clang  -fsanitize=thread -Wall  -m64 -fno-function-sections   -gline-tables-only -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/../ -O1 /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp -o /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/runtimes/runtimes-bins/compiler-rt/test/tsan/POWERPC64LEConfig/Output/signal_block.cpp.tmp &&  /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/runtimes/runtimes-bins/compiler-rt/test/tsan/POWERPC64LEConfig/Output/signal_block.cpp.tmp 2>&1 | FileCheck /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp
+ /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/./bin/clang -fsanitize=thread -Wall -m64 -fno-function-sections -gline-tables-only -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/../ -O1 /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp -o /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/runtimes/runtimes-bins/compiler-rt/test/tsan/POWERPC64LEConfig/Output/signal_block.cpp.tmp
+ /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/runtimes/runtimes-bins/compiler-rt/test/tsan/POWERPC64LEConfig/Output/signal_block.cpp.tmp
+ FileCheck /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp:59:15: error: CHECK-NOT: excluded string found in input
// CHECK-NOT: WARNING: ThreadSanitizer:
              ^
<stdin>:2:1: note: found here
WARNING: ThreadSanitizer: signal handler spoils errno (pid=606483)
^~~~~~~~~~~~~~~~~~~~~~~~~

Input file: <stdin>
Check file: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp

-dump-input=help explains the following input dump.

Input was:
<<<<<<
        1: ================== 
        2: WARNING: ThreadSanitizer: signal handler spoils errno (pid=606483) 
not:59     !~~~~~~~~~~~~~~~~~~~~~~~~                                           error: no match expected
        3:  Signal 10 handler invoked at: 
        4:  #0 handler(int) /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp:13 (signal_block.cpp.tmp+0xff160) 
        5:  #1 thread(void*) /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp:25:5 (signal_block.cpp.tmp+0xff2b0) 
        6:  
        7: SUMMARY: ThreadSanitizer: signal handler spoils errno /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp:13 in handler(int) 
        8: ================== 
        9: DONE 
       10: ThreadSanitizer: reported 1 warnings 
>>>>>>

--


yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
While working on my safestack patches, I noticed that only the default
multilib was tested even though all multilib versions of
`libclang_rt.safestack.a` were built.

This patch fixes this, patterned after the ubsan testing support.

Tested on `amd64-pc-solaris2.11` (`amd64` and `i386`),
`sparcv9-sun-solaris2.11` (`sparcv9` and `sparc`), `x86_64-pc-linux-gnu`
(`x86_64` and `i386`), and `sparc64-unknown-linux-gnu` (`sparcv9` and
`sparc`).
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