This is an archive of the discontinued LLVM Phabricator instance.

[Sanitizers] Disable SANITIZER_CAN_FAST_UNWIND on all SPARC targets
ClosedPublic

Authored by ro on Nov 5 2018, 4:26 AM.

Details

Summary

While testing my to-be-submitted Solaris sanitizer support on gcc mainline, I ran into
an issue on Solaris/SPARC (sparc-sun-solaris2.11). Initially libasan.so failed to link:

Undefined                       first referenced
 symbol                             in file
__sanitizer::BufferedStackTrace::FastUnwindStack(unsigned long, unsigned long, unsigned long, unsigned long, unsigned int) /var/gcc/gcc-9.0.0-20181024/11.5-gcc-gas/sparc-sun-solaris2.11/./libsanitizer/asan/.libs/libasan.so

This happens because SANITIZER_CAN_FAST_UNWIND is enabled on non-Linux
SPARC targets (cf. sanitizer_stacktrace.h), but the guard around the SPARCv8-only
definition in sanitizer_stacktrace_sparc.cc only works with clang:

clang predefines sparcv8 on non-Solaris, and sparcv8 only on Solaris
gcc predefines
sparcv8 on Solaris, but sparc_v8 on non-Solaris

The attached patch allows for all three variants.

However, disabling SANITIZER_CAN_FAST_UNWIND on all SPARC targets
fixes a couple of testsuite failures in the Solaris asan testsuite, so for now it's better
to keep it disabled everywhere.

This allowed the libsanitizer build to complete and gave reasonable (though slightly
worse than on Solaris/x86) testsuite results.

I'd like to get this into GCC 9, which requires that this patch be accepted upstream
first.

Diff Detail

Event Timeline

ro created this revision.Nov 5 2018, 4:26 AM
Herald added subscribers: Restricted Project, chrib, fedor.sergeev and 2 others. · View Herald TranscriptNov 5 2018, 4:26 AM
vitalybuka accepted this revision.Nov 5 2018, 9:20 AM
This revision is now accepted and ready to land.Nov 5 2018, 9:20 AM
This revision was automatically updated to reflect the committed changes.

There is also sparc and sparc64 support in sanitizers on NetBSD... but I cannot say for now how well it works. For sure we run UBSan and ASan for both of them.

ro added a comment.Nov 13 2018, 6:23 AM

There is also sparc and sparc64 support in sanitizers on NetBSD... but I cannot say for now how well it works. For sure we run UBSan and ASan for both of them.

I still wonder how this works, though: I've just refreshed my patch for SPARC support in compiler-rt (https://reviews.llvm.org/D40900) and tried
again with patches on top to enable asan on 32-bit sparc in clang and the 32-bit asan tests in compiler-rt (trivial, but not submitted as pointless).

I immediately ran again into build failures of the compiler-rt asan tests:

fatal error: error in backend: Function "main": over-aligned dynamic alloca not supported.
clang-8: error: clang frontend command failed with exit code 70 (use -v to see invocation)

just the same as when I initially had submitted D40900. If you have a way around this, I'm all ears ;-)

I cannot reasonably try sparcv9 on Solaris, though, due to the particular address space layout used there.

However, as I mentioned since about a week an implementation of the TARGET_ASAN_SHADOW_OFFSET hook for sparc has landed in
gcc mainline, where asan works reasonably well.

ubsan should be no problem, admittedly.

krytarowski added a comment.EditedNov 15 2018, 5:06 AM
In D54099#1296841, @ro wrote:

There is also sparc and sparc64 support in sanitizers on NetBSD... but I cannot say for now how well it works. For sure we run UBSan and ASan for both of them.

I still wonder how this works, though: I've just refreshed my patch for SPARC support in compiler-rt (https://reviews.llvm.org/D40900) and tried
again with patches on top to enable asan on 32-bit sparc in clang and the 32-bit asan tests in compiler-rt (trivial, but not submitted as pointless).

I immediately ran again into build failures of the compiler-rt asan tests:

fatal error: error in backend: Function "main": over-aligned dynamic alloca not supported.
clang-8: error: clang frontend command failed with exit code 70 (use -v to see invocation)

just the same as when I initially had submitted D40900. If you have a way around this, I'm all ears ;-)

I cannot reasonably try sparcv9 on Solaris, though, due to the particular address space layout used there.

However, as I mentioned since about a week an implementation of the TARGET_ASAN_SHADOW_OFFSET hook for sparc has landed in
gcc mainline, where asan works reasonably well.

ubsan should be no problem, admittedly.

This works with GCC and manually patched libsanitizer (GCC 6.x/7.x) by other developers (mainly Christos Zoulas). The LLVM version is as of now much more advanced, beyond basic support for UBSan and ASan.

I'm personally short on time to work on the GCC part myself.