File tree 10 files changed +15
-30
lines changed 10 files changed +15
-30
lines changed Original file line number Diff line number Diff line change @@ -57,8 +57,6 @@ void AsanCheckDynamicRTPrereqs() {}
57
57
void AsanCheckIncompatibleRT () {}
58
58
void InitializeAsanInterceptors () {}
59
59
60
- void *AsanDoesNotSupportStaticLinkage () { return nullptr ; }
61
-
62
60
void InitializePlatformExceptionHandlers () {}
63
61
void AsanOnDeadlySignal (int signo, void *siginfo, void *context) {
64
62
UNIMPLEMENTED ();
Original file line number Diff line number Diff line change @@ -80,7 +80,6 @@ void ReplaceSystemMalloc();
80
80
81
81
// asan_linux.cpp / asan_mac.cpp / asan_win.cpp
82
82
uptr FindDynamicShadowStart ();
83
- void *AsanDoesNotSupportStaticLinkage ();
84
83
void AsanCheckDynamicRTPrereqs ();
85
84
void AsanCheckIncompatibleRT ();
86
85
Original file line number Diff line number Diff line change 47
47
48
48
# if SANITIZER_ANDROID || SANITIZER_FREEBSD || SANITIZER_SOLARIS
49
49
# include < ucontext.h>
50
- extern " C" void *_DYNAMIC;
51
50
# elif SANITIZER_NETBSD
52
51
# include < link_elf.h>
53
52
# include < ucontext.h>
54
- extern Elf_Dyn _DYNAMIC;
55
53
# else
56
54
# include < link.h>
57
55
# include < sys/ucontext.h>
58
- extern ElfW (Dyn) _DYNAMIC[];
59
56
# endif
60
57
61
58
typedef enum {
@@ -76,11 +73,6 @@ void InitializePlatformInterceptors() {}
76
73
void InitializePlatformExceptionHandlers () {}
77
74
bool IsSystemHeapAddress (uptr addr) { return false ; }
78
75
79
- void *AsanDoesNotSupportStaticLinkage () {
80
- // This will fail to link with -static.
81
- return &_DYNAMIC;
82
- }
83
-
84
76
# if ASAN_PREMAP_SHADOW
85
77
uptr FindPremappedShadowStart (uptr shadow_size_bytes) {
86
78
uptr granularity = GetMmapGranularity ();
Original file line number Diff line number Diff line change @@ -49,11 +49,6 @@ void InitializePlatformInterceptors() {}
49
49
void InitializePlatformExceptionHandlers () {}
50
50
bool IsSystemHeapAddress (uptr addr) { return false ; }
51
51
52
- // No-op. Mac does not support static linkage anyway.
53
- void *AsanDoesNotSupportStaticLinkage () {
54
- return 0 ;
55
- }
56
-
57
52
uptr FindDynamicShadowStart () {
58
53
return MapDynamicShadow (MemToShadowSize (kHighMemEnd ), ASAN_SHADOW_SCALE,
59
54
/* min_shadow_base_alignment*/ 0 , kHighMemEnd );
Original file line number Diff line number Diff line change @@ -410,6 +410,8 @@ static bool AsanInitInternal() {
410
410
return false ;
411
411
}
412
412
413
+ // Make sure we are not statically linked.
414
+ __interception::DoesNotSupportStaticLinking ();
413
415
AsanCheckIncompatibleRT ();
414
416
AsanCheckDynamicRTPrereqs ();
415
417
AvoidCVE_2016_2143 ();
@@ -421,9 +423,6 @@ static bool AsanInitInternal() {
421
423
422
424
InitializeHighMemEnd ();
423
425
424
- // Make sure we are not statically linked.
425
- AsanDoesNotSupportStaticLinkage ();
426
-
427
426
// Install tool-specific callbacks in sanitizer_common.
428
427
AddDieCallback (AsanDie);
429
428
SetCheckUnwindCallback (CheckUnwind);
Original file line number Diff line number Diff line change @@ -266,8 +266,6 @@ void PlatformTSDDtor(void *tsd) { AsanThread::TSDDtor(tsd); }
266
266
// }}}
267
267
268
268
// ---------------------- Various stuff ---------------- {{{
269
- void *AsanDoesNotSupportStaticLinkage () { return 0 ; }
270
-
271
269
uptr FindDynamicShadowStart () {
272
270
return MapDynamicShadow (MemToShadowSize (kHighMemEnd ), ASAN_SHADOW_SCALE,
273
271
/* min_shadow_base_alignment*/ 0 , kHighMemEnd );
Original file line number Diff line number Diff line change @@ -348,6 +348,18 @@ typedef unsigned long long uptr;
348
348
#else
349
349
typedef unsigned long uptr;
350
350
#endif // _WIN64
351
+
352
+ #if defined(__ELF__) && !SANITIZER_FUCHSIA
353
+ // The use of interceptors makes many sanitizers unusable for static linking.
354
+ // Define a function, if called, will cause a linker error (undefined _DYNAMIC).
355
+ // However, -static-pie (which is not common) cannot be detected at link time.
356
+ extern uptr kDynamic [] asm (" _DYNAMIC" );
357
+ inline void DoesNotSupportStaticLinking () {
358
+ [[maybe_unused]] volatile auto x = &kDynamic ;
359
+ }
360
+ #else
361
+ inline void DoesNotSupportStaticLinking () {}
362
+ #endif
351
363
} // namespace __interception
352
364
353
365
#define INCLUDED_FROM_INTERCEPTION_LIB
Original file line number Diff line number Diff line change @@ -57,7 +57,6 @@ void ReplaceSystemMalloc();
57
57
58
58
// memprof_linux.cpp
59
59
uptr FindDynamicShadowStart ();
60
- void *MemprofDoesNotSupportStaticLinkage ();
61
60
62
61
// memprof_thread.cpp
63
62
MemprofThread *CreateMainThread ();
Original file line number Diff line number Diff line change 38
38
#include < unistd.h>
39
39
#include < unwind.h>
40
40
41
- extern ElfW (Dyn) _DYNAMIC[];
42
-
43
41
typedef enum {
44
42
MEMPROF_RT_VERSION_UNDEFINED = 0 ,
45
43
MEMPROF_RT_VERSION_DYNAMIC,
@@ -57,11 +55,6 @@ namespace __memprof {
57
55
void InitializePlatformInterceptors () {}
58
56
void InitializePlatformExceptionHandlers () {}
59
57
60
- void *MemprofDoesNotSupportStaticLinkage () {
61
- // This will fail to link with -static.
62
- return &_DYNAMIC;
63
- }
64
-
65
58
uptr FindDynamicShadowStart () {
66
59
uptr shadow_size_bytes = MemToShadowSize (kHighMemEnd );
67
60
return MapDynamicShadow (shadow_size_bytes, SHADOW_SCALE,
Original file line number Diff line number Diff line change @@ -162,7 +162,7 @@ static void MemprofInitInternal() {
162
162
InitializeHighMemEnd ();
163
163
164
164
// Make sure we are not statically linked.
165
- MemprofDoesNotSupportStaticLinkage ();
165
+ __interception::DoesNotSupportStaticLinking ();
166
166
167
167
// Install tool-specific callbacks in sanitizer_common.
168
168
AddDieCallback (MemprofDie);
You can’t perform that action at this time.
0 commit comments