-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[sanitizer] Reject unsupported -static at link time #83524
[sanitizer] Reject unsupported -static at link time #83524
Conversation
Created using spr 1.3.4
@llvm/pr-subscribers-compiler-rt-sanitizer Author: Fangrui Song (MaskRay) ChangesMost sanitizers don't support static linking. One primary reason is the Full diff: https://github.com/llvm/llvm-project/pull/83524.diff 5 Files Affected:
diff --git a/compiler-rt/lib/hwasan/hwasan_interceptors.cpp b/compiler-rt/lib/hwasan/hwasan_interceptors.cpp
index 96df4dd0c24d7d..d519ac3a459b67 100644
--- a/compiler-rt/lib/hwasan/hwasan_interceptors.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_interceptors.cpp
@@ -520,6 +520,7 @@ void InitializeInterceptors() {
CHECK_EQ(inited, 0);
# if HWASAN_WITH_INTERCEPTORS
+ __interception::DoesNotSupportStaticLinking();
InitializeCommonInterceptors();
(void)(read_iovec);
diff --git a/compiler-rt/lib/lsan/lsan_interceptors.cpp b/compiler-rt/lib/lsan/lsan_interceptors.cpp
index 885f7ad5ddba96..1fd0010f9ea936 100644
--- a/compiler-rt/lib/lsan/lsan_interceptors.cpp
+++ b/compiler-rt/lib/lsan/lsan_interceptors.cpp
@@ -543,6 +543,7 @@ namespace __lsan {
void InitializeInterceptors() {
// Fuchsia doesn't use interceptors that require any setup.
#if !SANITIZER_FUCHSIA
+ __interception::DoesNotSupportStaticLinking();
InitializeSignalInterceptors();
INTERCEPT_FUNCTION(malloc);
diff --git a/compiler-rt/lib/msan/msan_interceptors.cpp b/compiler-rt/lib/msan/msan_interceptors.cpp
index 2c9f2c01e14b06..6e0b2bf2ef5b6f 100644
--- a/compiler-rt/lib/msan/msan_interceptors.cpp
+++ b/compiler-rt/lib/msan/msan_interceptors.cpp
@@ -1762,6 +1762,8 @@ void InitializeInterceptors() {
static int inited = 0;
CHECK_EQ(inited, 0);
+ __interception::DoesNotSupportStaticLinking();
+
new(interceptor_ctx()) InterceptorContext();
InitializeCommonInterceptors();
diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
index a9f6673ac44e90..dd8550d642cce8 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
@@ -2861,6 +2861,8 @@ void InitializeInterceptors() {
REAL(memcpy) = internal_memcpy;
#endif
+ __interception::DoesNotSupportStaticLinking();
+
new(interceptor_ctx()) InterceptorContext();
InitializeCommonInterceptors();
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/static-link.c b/compiler-rt/test/sanitizer_common/TestCases/Linux/static-link.c
new file mode 100644
index 00000000000000..f45f718cb08d34
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/static-link.c
@@ -0,0 +1,2 @@
+// UNSUPPORTED: hwasan, ubsan
+// RUN: not %clangxx -static %s -o /dev/null
|
@@ -0,0 +1,2 @@ | |||
// UNSUPPORTED: hwasan, ubsan |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is special about these two sanitizers (why doesn't it also apply to lsan/msan/tsan)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess hwasan, ubsan
can be with or without interceptors
hwasan on non-android linux will be with interceptors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. The test is only for sanitizers that are guaranteed to use interceptors that are incompatible with -static
links. I unsupport hwasan/ubsan because they may not use interceptors.
(hwasan has other incompatibility with static linking, but that's not as fundamental as interceptors).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks for explaining!
@@ -0,0 +1,2 @@ | |||
// UNSUPPORTED: hwasan, ubsan |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks for explaining!
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 thisdetector to other sanitizers. dfsan actually supports -static for
certain cases. Don't touch dfsan.