[compiler-rt] [ubsan] Support static linking with standalone runtime (PR #80943)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 6 22:33:26 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-compiler-rt-sanitizer
Author: Fangrui Song (MaskRay)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/80943.diff
2 Files Affected:
- (modified) compiler-rt/lib/ubsan/ubsan_signals_standalone.cpp (+5)
- (modified) compiler-rt/test/ubsan/TestCases/Misc/Linux/static-link.cpp (+1-1)
``````````diff
diff --git a/compiler-rt/lib/ubsan/ubsan_signals_standalone.cpp b/compiler-rt/lib/ubsan/ubsan_signals_standalone.cpp
index 354f847fab7138..68edd3a1b2062e 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 cd185049567f79..f26b7b868cad62 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>
``````````
</details>
https://github.com/llvm/llvm-project/pull/80943
More information about the llvm-commits
mailing list