[llvm] Disable santizers on constructors. (PR #111960)

via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 11 00:35:29 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Daniel Kiss (DanielKristofKiss)

<details>
<summary>Changes</summary>

Sanitizers 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:

- (modified) llvm/lib/Transforms/Utils/ModuleUtils.cpp (+4) 
- (modified) llvm/test/tools/llvm-reduce/ifunc-alias.ll (+2-1) 
- (modified) llvm/test/tools/llvm-reduce/remove-ifunc-program-addrspace.ll (+2-1) 
- (modified) llvm/test/tools/llvm-reduce/remove-ifunc.ll (+2-1) 


``````````diff
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

``````````

</details>


https://github.com/llvm/llvm-project/pull/111960


More information about the llvm-commits mailing list