diff options
author | Fangrui Song <i@maskray.me> | 2024-02-14 10:50:24 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-14 10:50:24 -0800 |
commit | 2d5fb27db71b57f299793160181ef28fea5573e7 (patch) | |
tree | ee4e5c082503ed3dfb8a55d543a10b50763aefbd | |
parent | 6d4ffbdfa8ff90e4ee6081ad8dbb8ec24e982a02 (diff) |
[ubsan] Support static linking with standalone runtime (#80943)
The standalone runtime (not
-fsanitize-minimal-runtime/-fsanitize-trap=undefined) installs some
signal handlers using `real_sigaction`. With static linking
(-static/-static-pie), the called `REAL(sigaction)` is null, leading to
an immediate segfault, which is confusing (#51538).
Fix #51538 by bailing out.
`// REQUIRES: librt_has_multf3` from https://reviews.llvm.org/D109709
actually disabled the test because `librt_has_*` features are only for
`compiler-rt/test/builtins`. The test does not reproduce for me:
libclang_rt.builtins.a or libgcc. Revert the REQUIRES.
-rw-r--r-- | compiler-rt/lib/ubsan/ubsan_signals_standalone.cpp | 5 | ||||
-rw-r--r-- | compiler-rt/test/ubsan/TestCases/Misc/Linux/static-link.cpp | 2 |
2 files changed, 6 insertions, 1 deletions
diff --git a/compiler-rt/lib/ubsan/ubsan_signals_standalone.cpp b/compiler-rt/lib/ubsan/ubsan_signals_standalone.cpp index 354f847fab71..68edd3a1b206 100644 --- a/compiler-rt/lib/ubsan/ubsan_signals_standalone.cpp +++ b/compiler-rt/lib/ubsan/ubsan_signals_standalone.cpp @@ -66,6 +66,11 @@ void InitializeDeadlySignals() { return; is_initialized = true; InitializeSignalInterceptors(); +#if SANITIZER_INTERCEPT_SIGNAL_AND_SIGACTION + // REAL(sigaction_symname) is nullptr in a static link. Bail out. + if (!REAL(sigaction_symname)) + return; +#endif InstallDeadlySignalHandlers(&UBsanOnDeadlySignal); } diff --git a/compiler-rt/test/ubsan/TestCases/Misc/Linux/static-link.cpp b/compiler-rt/test/ubsan/TestCases/Misc/Linux/static-link.cpp index cd185049567f..f26b7b868cad 100644 --- a/compiler-rt/test/ubsan/TestCases/Misc/Linux/static-link.cpp +++ b/compiler-rt/test/ubsan/TestCases/Misc/Linux/static-link.cpp @@ -1,7 +1,7 @@ // REQUIRES: ubsan-standalone // REQUIRES: target={{x86_64.*}} -// REQUIRES: librt_has_multf3 // RUN: %clangxx -fsanitize=bool -static %s -o %t && UBSAN_OPTIONS=handle_segv=0:handle_sigbus=0:handle_sigfpe=0 %run %t 2>&1 | FileCheck %s +// RUN: %run %t 2>&1 | FileCheck %s #include <signal.h> #include <stdio.h> |