Skip to content

Commit fe1d02b

Browse files
authored
[sanitizer] Reject unsupported -static at link time (#83524)
Most sanitizers don't support static linking. One primary reason is the incompatibility with interceptors. `GetTlsSize` is another reason. asan/memprof use `__interception::DoesNotSupportStaticLinking` (`_DYNAMIC` reference) to reject -static at link time. Port this detector to other sanitizers. dfsan actually supports -static for certain cases. Don't touch dfsan.
1 parent 4d62929 commit fe1d02b

File tree

5 files changed

+8
-0
lines changed

5 files changed

+8
-0
lines changed

compiler-rt/lib/hwasan/hwasan_interceptors.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ void InitializeInterceptors() {
520520
CHECK_EQ(inited, 0);
521521

522522
# if HWASAN_WITH_INTERCEPTORS
523+
__interception::DoesNotSupportStaticLinking();
523524
InitializeCommonInterceptors();
524525

525526
(void)(read_iovec);

compiler-rt/lib/lsan/lsan_interceptors.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ namespace __lsan {
543543
void InitializeInterceptors() {
544544
// Fuchsia doesn't use interceptors that require any setup.
545545
#if !SANITIZER_FUCHSIA
546+
__interception::DoesNotSupportStaticLinking();
546547
InitializeSignalInterceptors();
547548

548549
INTERCEPT_FUNCTION(malloc);

compiler-rt/lib/msan/msan_interceptors.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,8 @@ void InitializeInterceptors() {
17621762
static int inited = 0;
17631763
CHECK_EQ(inited, 0);
17641764

1765+
__interception::DoesNotSupportStaticLinking();
1766+
17651767
new(interceptor_ctx()) InterceptorContext();
17661768

17671769
InitializeCommonInterceptors();

compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2861,6 +2861,8 @@ void InitializeInterceptors() {
28612861
REAL(memcpy) = internal_memcpy;
28622862
#endif
28632863

2864+
__interception::DoesNotSupportStaticLinking();
2865+
28642866
new(interceptor_ctx()) InterceptorContext();
28652867

28662868
// Interpose __tls_get_addr before the common interposers. This is needed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// UNSUPPORTED: hwasan, ubsan
2+
// RUN: not %clangxx -static %s -o /dev/null

0 commit comments

Comments
 (0)