Skip to content

Commit 2d5fb27

Browse files
authored
[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.
1 parent 6d4ffbd commit 2d5fb27

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

compiler-rt/lib/ubsan/ubsan_signals_standalone.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ void InitializeDeadlySignals() {
6666
return;
6767
is_initialized = true;
6868
InitializeSignalInterceptors();
69+
#if SANITIZER_INTERCEPT_SIGNAL_AND_SIGACTION
70+
// REAL(sigaction_symname) is nullptr in a static link. Bail out.
71+
if (!REAL(sigaction_symname))
72+
return;
73+
#endif
6974
InstallDeadlySignalHandlers(&UBsanOnDeadlySignal);
7075
}
7176

compiler-rt/test/ubsan/TestCases/Misc/Linux/static-link.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// REQUIRES: ubsan-standalone
22
// REQUIRES: target={{x86_64.*}}
3-
// REQUIRES: librt_has_multf3
43
// 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
4+
// RUN: %run %t 2>&1 | FileCheck %s
55
#include <signal.h>
66
#include <stdio.h>
77

0 commit comments

Comments
 (0)