-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Disable santizers on constructors. #111960
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
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-llvm-transforms Author: Daniel Kiss (DanielKristofKiss) ChangesSanitizers are initialised later then constructors run which could lead to runtime problems. Full diff: https://github.com/llvm/llvm-project/pull/111960.diff 4 Files Affected:
diff --git a/llvm/lib/Transforms/Utils/ModuleUtils.cpp b/llvm/lib/Transforms/Utils/ModuleUtils.cpp
index 7249571f344938..5358fc2c77f28c 100644
--- a/llvm/lib/Transforms/Utils/ModuleUtils.cpp
+++ b/llvm/lib/Transforms/Utils/ModuleUtils.cpp
@@ -433,6 +433,10 @@ bool llvm::lowerGlobalIFuncUsersAsGlobalCtor(
FunctionType::get(Type::getVoidTy(Ctx), false), Function::InternalLinkage,
DL.getProgramAddressSpace(), "", &M);
+ // Disable Sanitizers as they might not yet initilised when the contructor
+ // runs.
+ NewCtor->addFnAttr(llvm::Attribute::DisableSanitizerInstrumentation);
+
BasicBlock *BB = BasicBlock::Create(Ctx, "", NewCtor);
IRBuilder<> InitBuilder(BB);
diff --git a/llvm/test/tools/llvm-reduce/ifunc-alias.ll b/llvm/test/tools/llvm-reduce/ifunc-alias.ll
index 258eb00383f7e6..01337a7abc0f1b 100644
--- a/llvm/test/tools/llvm-reduce/ifunc-alias.ll
+++ b/llvm/test/tools/llvm-reduce/ifunc-alias.ll
@@ -60,9 +60,10 @@ define float @call_alias_of_ifunc(i64 %arg) {
ret float %call
}
-; CHECK-FINAL-BOTH: define internal void [[CONSTRUCTOR]]() {
+; CHECK-FINAL-BOTH: define internal void [[CONSTRUCTOR]]() #[[#CONSTRUCTOR_ATTR:]] {
; CHECK-FINAL-BOTH-NEXT: %1 = call ptr @resolver()
; CHECK-FINAL-BOTH-NEXT: store ptr %1, ptr [[TABLE]], align 8
; CHECK-FINAL-BOTH-NEXT: %2 = call ptr @resolver()
; CHECK-FINAL-BOTH-NEXT: store ptr %2, ptr getelementptr inbounds ([2 x ptr], ptr [[TABLE]], i32 0, i32 1), align 8
; CHECK-FINAL-BOTH-NEXT: ret void
+; CHECK-FINAL-DAG: attributes #[[#CONSTRUCTOR_ATTR]] = {{{.*}} disable_sanitizer_instrumentation {{.*}}
diff --git a/llvm/test/tools/llvm-reduce/remove-ifunc-program-addrspace.ll b/llvm/test/tools/llvm-reduce/remove-ifunc-program-addrspace.ll
index e275d61764b216..c76fa10f393297 100644
--- a/llvm/test/tools/llvm-reduce/remove-ifunc-program-addrspace.ll
+++ b/llvm/test/tools/llvm-reduce/remove-ifunc-program-addrspace.ll
@@ -90,7 +90,7 @@ define void @load_removed() addrspace(0) {
ret void
}
-; CHECK-FINAL: define internal void [[TABLE_CTOR]]() addrspace(1) {
+; CHECK-FINAL: define internal void [[TABLE_CTOR]]() addrspace(1) #[[#CONSTRUCTOR_ATTR:]] {
; CHECK-FINAL-NEXT: %1 = call addrspace(1) ptr addrspace(1) @resolver1_in_1()
; CHECK-FINAL-NEXT: store ptr addrspace(1) %1, ptr addrspace(2) [[TABLE]], align 8
; CHECK-FINAL-NEXT: %2 = call addrspace(0) ptr addrspace(1) @resolver1_in_0()
@@ -105,3 +105,4 @@ define void @load_removed() addrspace(0) {
; CHECK-FINAL-NEXT: %7 = call addrspace(0) ptr addrspace(1) @resolver1_in_0()
; CHECK-FINAL-NEXT: store ptr addrspace(1) %7, ptr addrspace(2) getelementptr inbounds ([6 x ptr addrspace(1)], ptr addrspace(2) [[TABLE]], i32 0, i32 5), align 8
; CHECK-FINAL-NEXT: ret void
+; CHECK-FINAL-DAG: attributes #[[#CONSTRUCTOR_ATTR]] = {{{.*}} disable_sanitizer_instrumentation {{.*}}
\ No newline at end of file
diff --git a/llvm/test/tools/llvm-reduce/remove-ifunc.ll b/llvm/test/tools/llvm-reduce/remove-ifunc.ll
index a7853d937d9a65..62e2e2b5af771a 100644
--- a/llvm/test/tools/llvm-reduce/remove-ifunc.ll
+++ b/llvm/test/tools/llvm-reduce/remove-ifunc.ll
@@ -177,7 +177,7 @@ define i32 @call_used_in_initializer(double %arg) {
ret i32 %ret
}
-; CHECK-FINAL-LABEL: define internal void @1() {
+; CHECK-FINAL-LABEL: define internal void @1() #[[#CONSTRUCTOR_ATTR:]] {
; CHECK-FINAL-NEXT: %1 = call ptr @resolver1()
; CHECK-FINAL-NEXT: store ptr %1, ptr @0, align 8
; CHECK-FINAL-NEXT: %2 = call ptr @resolver2()
@@ -196,3 +196,4 @@ define i32 @call_used_in_initializer(double %arg) {
; CHECK-FINAL-NEXT: store ptr %8, ptr getelementptr inbounds ([8 x ptr], ptr @0, i32 0, i32 7), align 8
; CHECK-FINAL-NEXT: ret void
; CHECK-FINAL-NEXT: }
+; CHECK-FINAL-DAG: attributes #[[#CONSTRUCTOR_ATTR]] = {{{.*}} disable_sanitizer_instrumentation {{.*}}
\ No newline at end of file
|
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.
Are you actually using this for codegen? The only test changes are in llvm-reduce
@@ -433,6 +433,10 @@ bool llvm::lowerGlobalIFuncUsersAsGlobalCtor( | |||
FunctionType::get(Type::getVoidTy(Ctx), false), Function::InternalLinkage, | |||
DL.getProgramAddressSpace(), "", &M); | |||
|
|||
// Disable Sanitizers as they might not yet initilised when the contructor |
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.
// Disable Sanitizers as they might not yet initilised when the contructor | |
// Disable Sanitizers as they might not yet initialized when the contructor |
@@ -105,3 +105,4 @@ define void @load_removed() addrspace(0) { | |||
; CHECK-FINAL-NEXT: %7 = call addrspace(0) ptr addrspace(1) @resolver1_in_0() | |||
; CHECK-FINAL-NEXT: store ptr addrspace(1) %7, ptr addrspace(2) getelementptr inbounds ([6 x ptr addrspace(1)], ptr addrspace(2) [[TABLE]], i32 0, i32 5), align 8 | |||
; CHECK-FINAL-NEXT: ret void | |||
; CHECK-FINAL-DAG: attributes #[[#CONSTRUCTOR_ATTR]] = {{{.*}} disable_sanitizer_instrumentation {{.*}} |
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.
Missing newline at end of file
@@ -196,3 +196,4 @@ define i32 @call_used_in_initializer(double %arg) { | |||
; CHECK-FINAL-NEXT: store ptr %8, ptr getelementptr inbounds ([8 x ptr], ptr @0, i32 0, i32 7), align 8 | |||
; CHECK-FINAL-NEXT: ret void | |||
; CHECK-FINAL-NEXT: } | |||
; CHECK-FINAL-DAG: attributes #[[#CONSTRUCTOR_ATTR]] = {{{.*}} disable_sanitizer_instrumentation {{.*}} |
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.
Missing newline at end of file
That is the plan, see #111962 |
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'm surprised we can't sanitize constructors
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.
Can you show example of what you are trying to fix.
On most platforms sanitizers initialized from .preinit_array exactly to be ready to check constructors.
Asan features rely constructor instrumentations.
Trying to sort out the initialisation order for ifuncs/santizers on Windows. (https://reviews.llvm.org/D150262) |
Sanitizers are initialised later then constructors run which could lead to runtime problems.