Skip to content
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

[WIP][ASan][test] Enable ASan tests on SPARC #107405

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

Conversation

rorth
Copy link
Collaborator

@rorth rorth commented Sep 5, 2024

With PR #107223 and PR #107403, ASan testing can be enabled on SPARC. This patch does so, 32-bit only on Solaris (there is no 64-bit support even in GCC), and both 32 and 64-bit on Linux (although GCC only supports 32-bit here).

Apart from the obvious CMake changes, this patch includes a couple of testcase adjustments necessary for SPARC:

  • In asan_oob_test.cpp, the OOB_int subtest needs to be disabled: it performs unaligned accesses that cannot work on a strict-alignment target like SPARC.
  • asan_test.cpp needs to disable subtests that depend on support for __builtin_setjmp and __builtin_longjmp.
  • zero_page_pc.cpp reports 0x5 as the faulting address on access to 0x4. I don't really know why, but it's consistent between Solaris and Linux.

Tested on sparcv9-sun-solaris2.11 and sparc64-unknown-linux-gnu.

Solaris results are not too bad (36 FAILs) while the Linux ones are quite bad, in particular because quite a number of tests just hang.

For those reasons, I'm just posting the patch for reference in case someone else wants to try this on Linux.

With PR llvm#107223 and PR llvm#107403, ASan testing can be enabled on SPARC.  This
patch does so, 32-bit only on Solaris (there is no 64-bit support even in
GCC), and both 32 and 64-bit on Linux (although GCC only support 32-bit
here).

Apart from the obvious CMake changes, this patch includes a couple of
testcase adjustments necessary for SPARC:
- In `asan_oob_test.cpp`, the `OOB_int` subtest needs to be disabled: it
  performs unaligned accesses that cannot work on a strict-alignment target
  like SPARC.
- `asan_test.cpp` needs to disable subtests that depend on support for
  `__builtin_setjmp` and `__builtin_longjmp`.
- `zero_page_pc.cpp` reports `0x5` as the faulting address on access to
  `0x4`.  I don't really know why, but it's consistent between Solaris and
  Linux.

Tested on `sparcv9-sun-solaris2.11` and `sparc64-unknown-linux-gnu`.

Solaris results are not too bad (36 `FAIL`s) while the Linux ones are quite
bad, in particular because quite a number of tests just hang.

For those reasons, I'm just posting the patch for reference in case someone
else wants to try this on Linux.
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 5, 2024

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

Author: Rainer Orth (rorth)

Changes

With PR #107223 and PR #107403, ASan testing can be enabled on SPARC. This patch does so, 32-bit only on Solaris (there is no 64-bit support even in GCC), and both 32 and 64-bit on Linux (although GCC only supports 32-bit here).

Apart from the obvious CMake changes, this patch includes a couple of testcase adjustments necessary for SPARC:

  • In asan_oob_test.cpp, the OOB_int subtest needs to be disabled: it performs unaligned accesses that cannot work on a strict-alignment target like SPARC.
  • asan_test.cpp needs to disable subtests that depend on support for __builtin_setjmp and __builtin_longjmp.
  • zero_page_pc.cpp reports 0x5 as the faulting address on access to 0x4. I don't really know why, but it's consistent between Solaris and Linux.

Tested on sparcv9-sun-solaris2.11 and sparc64-unknown-linux-gnu.

Solaris results are not too bad (36 FAILs) while the Linux ones are quite bad, in particular because quite a number of tests just hang.

For those reasons, I'm just posting the patch for reference in case someone else wants to try this on Linux.


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

7 Files Affected:

  • (modified) compiler-rt/lib/asan/tests/CMakeLists.txt (+1-1)
  • (modified) compiler-rt/lib/asan/tests/asan_oob_test.cpp (+8-1)
  • (modified) compiler-rt/lib/asan/tests/asan_test.cpp (+1-1)
  • (modified) compiler-rt/test/asan/CMakeLists.txt (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/zero_page_pc.cpp (+1-1)
  • (modified) compiler-rt/test/sanitizer_common/CMakeLists.txt (+1-3)
  • (modified) compiler-rt/test/ubsan/CMakeLists.txt (+3-3)
diff --git a/compiler-rt/lib/asan/tests/CMakeLists.txt b/compiler-rt/lib/asan/tests/CMakeLists.txt
index b489bb99aeff3a..f103243e2549df 100644
--- a/compiler-rt/lib/asan/tests/CMakeLists.txt
+++ b/compiler-rt/lib/asan/tests/CMakeLists.txt
@@ -243,8 +243,8 @@ if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT ANDROID)
   if(APPLE)
     darwin_filter_host_archs(ASAN_SUPPORTED_ARCH ASAN_TEST_ARCH)
   endif()
-  list(REMOVE_ITEM ASAN_TEST_ARCH sparc sparcv9)
   if(OS_NAME MATCHES "SunOS")
+    list(REMOVE_ITEM ASAN_TEST_ARCH sparcv9)
     list(REMOVE_ITEM ASAN_TEST_ARCH x86_64)
   endif()
 
diff --git a/compiler-rt/lib/asan/tests/asan_oob_test.cpp b/compiler-rt/lib/asan/tests/asan_oob_test.cpp
index 56f573c1fc4820..ce4c90c23e84b6 100644
--- a/compiler-rt/lib/asan/tests/asan_oob_test.cpp
+++ b/compiler-rt/lib/asan/tests/asan_oob_test.cpp
@@ -11,6 +11,13 @@
 //===----------------------------------------------------------------------===//
 #include "asan_test_utils.h"
 
+#ifdef __sparc__
+// Tests using unaligned accesses cannot work on strict-alignment targets.
+#define SKIP_ON_STRICT_ALIGNMENT(x) DISABLED_##x
+#else
+#define SKIP_ON_STRICT_ALIGNMENT(x) x
+#endif
+
 NOINLINE void asan_write_sized_aligned(uint8_t *p, size_t size) {
   EXPECT_EQ(0U, ((uintptr_t)p % size));
   if      (size == 1) asan_write((uint8_t*)p);
@@ -79,7 +86,7 @@ TEST(AddressSanitizer, OOB_char) {
   OOBTest<U1>();
 }
 
-TEST(AddressSanitizer, OOB_int) {
+TEST(AddressSanitizer, SKIP_ON_STRICT_ALIGNMENT(OOB_int)) {
   OOBTest<U4>();
 }
 
diff --git a/compiler-rt/lib/asan/tests/asan_test.cpp b/compiler-rt/lib/asan/tests/asan_test.cpp
index 827c2ae3a9cdc8..09d71569f89bba 100644
--- a/compiler-rt/lib/asan/tests/asan_test.cpp
+++ b/compiler-rt/lib/asan/tests/asan_test.cpp
@@ -631,7 +631,7 @@ NOINLINE void SigLongJmpFunc1(sigjmp_buf buf) {
 
 #if !defined(__ANDROID__) && !defined(__arm__) && !defined(__aarch64__) && \
     !defined(__mips__) && !defined(__mips64) && !defined(__s390__) &&      \
-    !defined(__riscv) && !defined(__loongarch__)
+    !defined(__riscv) && !defined(__loongarch__) && !defined(__sparc__)
 NOINLINE void BuiltinLongJmpFunc1(jmp_buf buf) {
   // create three red zones for these two stack objects.
   int a;
diff --git a/compiler-rt/test/asan/CMakeLists.txt b/compiler-rt/test/asan/CMakeLists.txt
index fb9e81bbe8082d..423491e54a37a3 100644
--- a/compiler-rt/test/asan/CMakeLists.txt
+++ b/compiler-rt/test/asan/CMakeLists.txt
@@ -36,8 +36,8 @@ set(ASAN_TEST_ARCH ${ASAN_SUPPORTED_ARCH})
 if(APPLE)
   darwin_filter_host_archs(ASAN_SUPPORTED_ARCH ASAN_TEST_ARCH)
 endif()
-list(REMOVE_ITEM ASAN_TEST_ARCH sparc sparcv9)
 if(OS_NAME MATCHES "SunOS")
+  list(REMOVE_ITEM ASAN_TEST_ARCH sparcv9)
   list(REMOVE_ITEM ASAN_TEST_ARCH x86_64)
 endif()
 
diff --git a/compiler-rt/test/asan/TestCases/zero_page_pc.cpp b/compiler-rt/test/asan/TestCases/zero_page_pc.cpp
index 9a395ecdf37c82..a7d00ce9b69886 100644
--- a/compiler-rt/test/asan/TestCases/zero_page_pc.cpp
+++ b/compiler-rt/test/asan/TestCases/zero_page_pc.cpp
@@ -19,6 +19,6 @@ int main() {
   // the compiler is free to choose the order. As a result, the address is
   // either 0x4, 0xc or 0x14. The pc is still in main() because it has not
   // actually made the call when the faulting access occurs.
-  // CHECK: {{AddressSanitizer: (SEGV|access-violation).*(address|pc) 0x0*[4c]}}
+  // CHECK: {{AddressSanitizer: (SEGV|access-violation).*(address|pc) 0x0*[45c]}}
   return 0;
 }
diff --git a/compiler-rt/test/sanitizer_common/CMakeLists.txt b/compiler-rt/test/sanitizer_common/CMakeLists.txt
index fa06b82acebd94..cad94df136a73c 100644
--- a/compiler-rt/test/sanitizer_common/CMakeLists.txt
+++ b/compiler-rt/test/sanitizer_common/CMakeLists.txt
@@ -58,10 +58,8 @@ foreach(tool ${SUPPORTED_TOOLS})
   if(APPLE)
     darwin_filter_host_archs(${tool_toupper}_SUPPORTED_ARCH TEST_ARCH)
   endif()
-  if(${tool} STREQUAL "asan")
-    list(REMOVE_ITEM TEST_ARCH sparc sparcv9)
-  endif()
   if(OS_NAME MATCHES "SunOS" AND ${tool} STREQUAL "asan")
+    list(REMOVE_ITEM TEST_ARCH sparcv9)
     list(REMOVE_ITEM TEST_ARCH x86_64)
   endif()
 
diff --git a/compiler-rt/test/ubsan/CMakeLists.txt b/compiler-rt/test/ubsan/CMakeLists.txt
index d95f9ad649ebf8..4fda2e9ec27af1 100644
--- a/compiler-rt/test/ubsan/CMakeLists.txt
+++ b/compiler-rt/test/ubsan/CMakeLists.txt
@@ -51,10 +51,10 @@ foreach(arch ${UBSAN_TEST_ARCH})
   if(COMPILER_RT_HAS_ASAN AND ";${ASAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
     # TODO(wwchrome): Re-enable ubsan for asan win 64-bit when ready.
     # Disable ubsan with AddressSanitizer tests for Windows 64-bit,
-    # 64-bit Solaris/x86, and SPARC.
+    # 64-bit Solaris/SPARC and Solaris/x86.
     if((NOT (OS_NAME MATCHES "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 8)) AND
-       (NOT (OS_NAME MATCHES "SunOS" AND ${arch} MATCHES x86_64)) AND
-       (NOT ${arch} MATCHES sparc))
+       (NOT (OS_NAME MATCHES "SunOS" AND ${arch} MATCHES sparcv9)) AND
+       (NOT (OS_NAME MATCHES "SunOS" AND ${arch} MATCHES x86_64)))
       add_ubsan_testsuites("AddressSanitizer" asan ${arch})
     endif()
   endif()

Copy link

github-actions bot commented Sep 5, 2024

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff 0797c184c636889f2897746dc71390ae28005c7c 7b8142d20ed27dbd6d4d6771eaf0a0b5cb18ebed --extensions cpp -- compiler-rt/lib/asan/tests/asan_oob_test.cpp compiler-rt/lib/asan/tests/asan_test.cpp compiler-rt/test/asan/TestCases/zero_page_pc.cpp
View the diff from clang-format here.
diff --git a/compiler-rt/lib/asan/tests/asan_oob_test.cpp b/compiler-rt/lib/asan/tests/asan_oob_test.cpp
index ce4c90c23e..0203662433 100644
--- a/compiler-rt/lib/asan/tests/asan_oob_test.cpp
+++ b/compiler-rt/lib/asan/tests/asan_oob_test.cpp
@@ -13,9 +13,9 @@
 
 #ifdef __sparc__
 // Tests using unaligned accesses cannot work on strict-alignment targets.
-#define SKIP_ON_STRICT_ALIGNMENT(x) DISABLED_##x
+#  define SKIP_ON_STRICT_ALIGNMENT(x) DISABLED_##x
 #else
-#define SKIP_ON_STRICT_ALIGNMENT(x) x
+#  define SKIP_ON_STRICT_ALIGNMENT(x) x
 #endif
 
 NOINLINE void asan_write_sized_aligned(uint8_t *p, size_t size) {
@@ -86,9 +86,7 @@ TEST(AddressSanitizer, OOB_char) {
   OOBTest<U1>();
 }
 
-TEST(AddressSanitizer, SKIP_ON_STRICT_ALIGNMENT(OOB_int)) {
-  OOBTest<U4>();
-}
+TEST(AddressSanitizer, SKIP_ON_STRICT_ALIGNMENT(OOB_int)) { OOBTest<U4>(); }
 
 TEST(AddressSanitizer, OOBRightTest) {
   size_t max_access_size = SANITIZER_WORDSIZE == 64 ? 8 : 4;
diff --git a/compiler-rt/lib/asan/tests/asan_test.cpp b/compiler-rt/lib/asan/tests/asan_test.cpp
index 09d71569f8..9cc4118dbd 100644
--- a/compiler-rt/lib/asan/tests/asan_test.cpp
+++ b/compiler-rt/lib/asan/tests/asan_test.cpp
@@ -629,9 +629,9 @@ NOINLINE void SigLongJmpFunc1(sigjmp_buf buf) {
   siglongjmp(buf, 1);
 }
 
-#if !defined(__ANDROID__) && !defined(__arm__) && !defined(__aarch64__) && \
-    !defined(__mips__) && !defined(__mips64) && !defined(__s390__) &&      \
-    !defined(__riscv) && !defined(__loongarch__) && !defined(__sparc__)
+#  if !defined(__ANDROID__) && !defined(__arm__) && !defined(__aarch64__) && \
+      !defined(__mips__) && !defined(__mips64) && !defined(__s390__) &&      \
+      !defined(__riscv) && !defined(__loongarch__) && !defined(__sparc__)
 NOINLINE void BuiltinLongJmpFunc1(jmp_buf buf) {
   // create three red zones for these two stack objects.
   int a;

@rorth rorth changed the title [ASan][test] Enable ASan tests on SPARC [WIP][ASan][test] Enable ASan tests on SPARC Sep 5, 2024
@rorth
Copy link
Collaborator Author

rorth commented Sep 5, 2024

TBH, I'm wary of the suggested clang-format changes, at least some of which are inconsistent with the rest of files.

rorth added a commit to rorth/llvm-project that referenced this pull request Sep 11, 2024
When enabling ASan testing on SPARC as per PR llvm#107405, two tests `FAIL` in
similar ways as detailed in Issue llvm#108194: at `-O1` and above, one line of
the stacktrace lacks the line number info, causing the tests to `FAIL`.  I
could trace this to `clang` generating incomplete line number info; `g++`
gets this right.

To avoid this, this patch `XFAIL`s the affected tests on SPARC.

Tested on `sparcv9-sun-solaris2.11`.
rorth added a commit to rorth/llvm-project that referenced this pull request Sep 11, 2024
…p etc. on SPARC

When enabling ASan testing on SPARC as per PR llvm#107405, two tests `FAIL`:
```
  SanitizerCommon-asan-sparc-SunOS :: sanitizer_coverage_trace_pc_guard-dso.cpp
  SanitizerCommon-asan-sparc-SunOS :: sanitizer_coverage_trace_pc_guard.cpp

```
The issue is the same in both cases:
```
WARNING: No coverage file for projects/compiler-rt/test/sanitizer_common/asan-sparc-SunOS/Output/sanitizer_coverage_trace_pc_guard.cpp.tmp
WARNING: No coverage file for sanitizer_coverage_trace_pc_guard.cpp.tmp.22766.sancov
ERROR: No valid coverage files given.

```
Checking the file with `sancov -print` reveals `Wrong magic: 4294967090`.
There seems to be an endianess bug somewhere, since the tests are already
disabled on other big-endian targets.

This patch matches this.

Tested on `sparcv9-sun-solaris2.11`.
…AIL`.

In hindsight this is no wonder: while
`compiler-rt/lib/asan/asan_mapping_sparc64.h` has support for the
Linux/sparc64 VA hole,
```
commit 9df0754
Author: Vitaly Buka <vitalybuka@google.com>
Date:   Tue Mar 12 21:02:24 2019 +0000

    AddressSanitizer: 64-bit SPARC/Linux port
```
there's nothing corresponding in `clang`.  Also, `gcc` disables 64-bit ASan
on Linux/sparc64, too.

So this patch disables `sparcv9` ASan testing in general.

Tested on `sparcv9-sun-solaris2.11` and `sparc64-unknown-linux-gnu`
rorth added a commit to rorth/llvm-project that referenced this pull request Sep 13, 2024
When SPARC Asan testing is enabled by PR llvm#107405, many Linux/sparc64 tests
just hang like
```
#0  0xf7ae8e90 in syscall () from /usr/lib32/libc.so.6
#1  0x701065e8 in __sanitizer::FutexWait(__sanitizer::atomic_uint32_t*, unsigned int) ()
    at compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:766
llvm#2  0x70107c90 in Wait ()
    at compiler-rt/lib/sanitizer_common/sanitizer_mutex.cpp:35
llvm#3  0x700f7cac in Lock ()
    at compiler-rt/lib/asan/../sanitizer_common/sanitizer_mutex.h:196
llvm#4  Lock ()
    at compiler-rt/lib/asan/../sanitizer_common/sanitizer_thread_registry.h:98
llvm#5  LockThreads ()
    at compiler-rt/lib/asan/asan_thread.cpp:489
llvm#6  0x700e9c8c in __asan::BeforeFork() ()
    at compiler-rt/lib/asan/asan_posix.cpp:157
llvm#7  0xf7ac83f4 in ?? () from /usr/lib32/libc.so.6
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
```
It turns out that this happens in tests using `internal_fork`
(e.g. invoking `llvm-symbolizer`): unlike most other Linux targets, which
use `clone`, Linux/sparc64 has to use `__fork` instead.  While `clone`
doesn't trigger `pthread_atfork` handlers, `__fork` obviously does, causing
the hang.

To avoid this, this patch disables `InstallAtForkHandler` and lets the ASan
tests run to completion.

Tested on `sparc64-unknown-linux-gnu`.
@rorth
Copy link
Collaborator Author

rorth commented Sep 13, 2024

@ebotcazou, any insight on the stage of 64-bit SPARC ASan support in clang and gcc?

@ebotcazou
Copy link

I think that my last try was https://gcc.gnu.org/legacy-ml/gcc-patches/2019-03/msg00478.html

rorth added a commit that referenced this pull request Sep 16, 2024
When SPARC Asan testing is enabled by PR #107405, many Linux/sparc64
tests just hang like
```
#0  0xf7ae8e90 in syscall () from /usr/lib32/libc.so.6
#1  0x701065e8 in __sanitizer::FutexWait(__sanitizer::atomic_uint32_t*, unsigned int) ()
    at compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:766
#2  0x70107c90 in Wait ()
    at compiler-rt/lib/sanitizer_common/sanitizer_mutex.cpp:35
#3  0x700f7cac in Lock ()
    at compiler-rt/lib/asan/../sanitizer_common/sanitizer_mutex.h:196
#4  Lock ()
    at compiler-rt/lib/asan/../sanitizer_common/sanitizer_thread_registry.h:98
#5  LockThreads ()
    at compiler-rt/lib/asan/asan_thread.cpp:489
#6  0x700e9c8c in __asan::BeforeFork() ()
    at compiler-rt/lib/asan/asan_posix.cpp:157
#7  0xf7ac83f4 in ?? () from /usr/lib32/libc.so.6
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
```
It turns out that this happens in tests using `internal_fork` (e.g.
invoking `llvm-symbolizer`): unlike most other Linux targets, which use
`clone`, Linux/sparc64 has to use `__fork` instead. While `clone`
doesn't trigger `pthread_atfork` handlers, `__fork` obviously does,
causing the hang.

To avoid this, this patch disables `InstallAtForkHandler` and lets the
ASan tests run to completion.

Tested on `sparc64-unknown-linux-gnu`.
rorth added a commit that referenced this pull request Sep 16, 2024
#108206)

…p etc. on SPARC

When enabling ASan testing on SPARC as per PR #107405, two tests `FAIL`:
```
  SanitizerCommon-asan-sparc-SunOS :: sanitizer_coverage_trace_pc_guard-dso.cpp
  SanitizerCommon-asan-sparc-SunOS :: sanitizer_coverage_trace_pc_guard.cpp

```
The issue is the same in both cases:
```
WARNING: No coverage file for projects/compiler-rt/test/sanitizer_common/asan-sparc-SunOS/Output/sanitizer_coverage_trace_pc_guard.cpp.tmp
WARNING: No coverage file for sanitizer_coverage_trace_pc_guard.cpp.tmp.22766.sancov
ERROR: No valid coverage files given.

```
Checking the file with `sancov -print` reveals `Wrong magic:
4294967090`. There seems to be an endianess bug somewhere, since the
tests are already disabled on other big-endian targets.

This patch matches this.

Tested on `sparcv9-sun-solaris2.11`.
rorth added a commit that referenced this pull request Sep 16, 2024
When enabling ASan testing on SPARC as per PR #107405, two tests `FAIL`
in similar ways as detailed in Issue #108194: at `-O1` and above, one
line of the stacktrace lacks the line number info, causing the tests to
`FAIL`. I could trace this to `clang` generating incomplete line number
info; `g++` gets this right.

To avoid this, this patch `XFAIL`s the affected tests on SPARC.

Tested on `sparcv9-sun-solaris2.11`.
rorth added a commit to rorth/llvm-project that referenced this pull request Sep 18, 2024
When ASan testing is enabled on SPARC as per PR llvm#107405, the
```
  AddressSanitizer-sparc-sunos :: TestCases/Posix/stack-overflow.cpp
```
test `FAIL`s:
```
compiler-rt/test/asan/TestCases/Posix/stack-overflow.cpp:80:12: error: CHECK: expected string not found in input
 // CHECK: {{stack-overflow on address 0x.* \(pc 0x.* bp 0x.* sp 0x.* T.*\)}}
           ^
AddressSanitizer:DEADLYSIGNAL
AddressSanitizer:DEADLYSIGNAL
=================================================================
==11358==ERROR: AddressSanitizer: SEGV on unknown address 0xff3fff90 (pc 0x000db0c0 bp 0xfeed59f8 sp 0xfeed5978 T0)
==11358==The signal is caused by a READ memory access.
AddressSanitizer:DEADLYSIGNAL
AddressSanitizer: nested bug in the same thread, aborting.
```
It turns out that `sanitizer_linux.cpp` (`GetPcSpBp`) tries to dereference
the stack pointer to get at the saved frame pointer, which cannot work since
`sp` has been invalidated by the stack overflow in the test.  The access
attempt thus leads to a second `SEGV`.

Solaris `walkcontext(3C)` doesn't have that problem: in the original
OpenSolaris sources (`$SRC/lib/libc/port/gen/walkstack.c`) they used
`/proc/self/as` to avoid the fault, which is quite heavy-handed.  Solaris
11.4 uses a non-faulting load instead (`load_no_fault_uint32`, which just
uses the `lduwa` insn).

This patch follows this lead, returning a `NULL` `bp` in the failure case.
Unfortunately, this leads to `SEGV`s in the depth of the unwinder, so this
patch avoids printing a stack trace in this case.

Tested on `sparcv9-sun-solaris2.11` and `sparc64-unknown-linux-gnu`.
rorth added a commit to rorth/llvm-project that referenced this pull request Sep 18, 2024
…ceptors

When ASan testing is enabled on SPARC as per PR llvm#107405, a couple of tests
`FAIL` on Linux/sparc64:
```
  AddressSanitizer-sparc-linux :: TestCases/printf-2.c
  AddressSanitizer-sparc-linux :: TestCases/printf-3.c
  AddressSanitizer-sparc-linux :: TestCases/printf-4.c
  AddressSanitizer-sparc-linux :: TestCases/printf-5.c

  SanitizerCommon-asan-sparc-Linux :: Linux/unexpected_format_specifier_test.cpp
```
It turns out the interceptors aren't used since on Linux/sparc64 `double`
and `long double` are the same, and a couple of `stdio` functions are
prefixed with `__nldbl_` (no long double) accordingly.

This patch handles this.

Tested on `sparc64-unknown-linux-gnu`.
rorth added a commit to rorth/llvm-project that referenced this pull request Sep 18, 2024
When ASan testing is enabled on SPARC as per PR llvm#107405, the
```
  AddressSanitizer-sparc-linux :: TestCases/Posix/print_cmdline.cpp
```
test `FAIL`s.  Either `ASAN_OPTIONS=print_cmdline=true` yielded binary
garbage in the `Command:` output or just an empty string.

It turns out one needs to apply an offset to `__libc_stack_end` to get at
the actual `argc`/`argv`, as described in `glibc`'s
`sysdeps/sparc/sparc{32,64}/dl-machine.h` (`DL_STACK_END`).

This patch does this, fixing the test.

Tested on `sparc64-unknown-linux-gnu`.
rorth added a commit to rorth/llvm-project that referenced this pull request Sep 18, 2024
When ASan testing is enabled on SPARC as per PR llvm#107405, the
```
  AddressSanitizer-sparc-linux :: TestCases/Linux/odr_c_test.c

```
`FAIL`s on Linux/sparc64:
```
+ projects/compiler-rt/test/asan/SPARCLinuxConfig/TestCases/Linux/Output/odr_c_test.c.tmp
+ count 0
Expected 0 lines, got 13.

AddressSanitizer:DEADLYSIGNAL
=================================================================
==4165420==ERROR: AddressSanitizer: BUS on unknown address (pc 0x7012d5b4 bp 0xffa3b938 sp 0xffa3b8d0 T0)
==4165420==The signal is caused by a READ memory access.
==4165420==Hint: this fault was caused by a dereference of a high value address (see register values below).  Disassemble the provided pc to learn which register was used.
```
The test relies on an unaligned access, which cannot work on a
strict-alignment target like SPARC.

Thus this patch skips the test.

Tested on `sparc64-unknown-linux-gnu`.
rorth added a commit that referenced this pull request Sep 19, 2024
When ASan testing is enabled on SPARC as per PR #107405, the
```
  AddressSanitizer-sparc-linux :: TestCases/Linux/odr_c_test.c

```
test `FAIL`s on Linux/sparc64:
```
+ projects/compiler-rt/test/asan/SPARCLinuxConfig/TestCases/Linux/Output/odr_c_test.c.tmp
+ count 0
Expected 0 lines, got 13.

AddressSanitizer:DEADLYSIGNAL
=================================================================
==4165420==ERROR: AddressSanitizer: BUS on unknown address (pc 0x7012d5b4 bp 0xffa3b938 sp 0xffa3b8d0 T0)
==4165420==The signal is caused by a READ memory access.
==4165420==Hint: this fault was caused by a dereference of a high value address (see register values below).  Disassemble the provided pc to learn which register was used.
```
The test relies on an unaligned access, which cannot work on a
strict-alignment target like SPARC.

Thus this patch skips the test.

Tested on `sparc64-unknown-linux-gnu`.
rorth added a commit to rorth/llvm-project that referenced this pull request Sep 19, 2024
When ASan testing is enabled on SPARC as per PR llvm#107405, the
```
  AddressSanitizer-sparc-linux :: TestCases/Linux/ptrace.cpp
```
`FAIL`s on Linux/sparc64.  This happens because the `ptrace` interceptor
has no support for that target at all.

This patch adds the missing parts and accounts for a couple of issues
specific to this target:
- In some cases, SPARC just needs to be included in the list of supported
  targets.
- Besides, the Linux/sparc64 types used by the `PTRACE_GETREGS` and
  `PTRACE_GETFPREGS` need to be filled in.
- `ptrace` has a weird quirk on this target: for a couple of requests, the
  meaning of the `data` and `addr` args is reversed.  All of the
  `Linux/ptrace.cpp` test and the interceptor, pre-syscall and post-syscall
  hooks need to account for that swap in their checks.

Tested on `sparc64-unknown-linux-gnu` and `x86_64-pc-linux-gnu`.
tmsri pushed a commit to tmsri/llvm-project that referenced this pull request Sep 19, 2024
When ASan testing is enabled on SPARC as per PR llvm#107405, the
```
  AddressSanitizer-sparc-linux :: TestCases/Linux/odr_c_test.c

```
test `FAIL`s on Linux/sparc64:
```
+ projects/compiler-rt/test/asan/SPARCLinuxConfig/TestCases/Linux/Output/odr_c_test.c.tmp
+ count 0
Expected 0 lines, got 13.

AddressSanitizer:DEADLYSIGNAL
=================================================================
==4165420==ERROR: AddressSanitizer: BUS on unknown address (pc 0x7012d5b4 bp 0xffa3b938 sp 0xffa3b8d0 T0)
==4165420==The signal is caused by a READ memory access.
==4165420==Hint: this fault was caused by a dereference of a high value address (see register values below).  Disassemble the provided pc to learn which register was used.
```
The test relies on an unaligned access, which cannot work on a
strict-alignment target like SPARC.

Thus this patch skips the test.

Tested on `sparc64-unknown-linux-gnu`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants