[llvm] [ASan] AddressSanitizerPass constructor should honor the AsanCtorKind argument (PR #72330)

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 14 16:41:26 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Usama Hameed (usama54321)

<details>
<summary>Changes</summary>

Currently, the ConstructorKind member variable in AddressSanitizerPass gets overriden by the ClConstructorKind whether the option is passed from the command line or not.  This override should only happen if the ClConstructorKind argument is passed from the command line.  Otherwise, the constructor should honor the argument passed to it. This patch makes this fix.

rdar://118423755

---
Full diff: https://github.com/llvm/llvm-project/pull/72330.diff


2 Files Affected:

- (modified) llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerOptions.h (+2-1) 
- (modified) llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp (+5-2) 


``````````diff
diff --git a/llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerOptions.h b/llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerOptions.h
index d697b72cde05e95..48da3c99d645edc 100644
--- a/llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerOptions.h
+++ b/llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerOptions.h
@@ -22,7 +22,8 @@ enum class AsanDtorKind {
 /// Types of ASan module constructors supported
 enum class AsanCtorKind {
   None,
-  Global
+  Global,
+  Invalid
 };
 
 /// Mode of ASan detect stack use after return
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index 5c2763850ac6540..0e1fa6a2bc2c20d 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -355,7 +355,7 @@ static cl::opt<AsanCtorKind> ClConstructorKind(
     cl::values(clEnumValN(AsanCtorKind::None, "none", "No constructors"),
                clEnumValN(AsanCtorKind::Global, "global",
                           "Use global constructors")),
-    cl::init(AsanCtorKind::Global), cl::Hidden);
+    cl::init(AsanCtorKind::Invalid), cl::Hidden);
 // These flags allow to change the shadow mapping.
 // The shadow mapping looks like
 //    Shadow = (Mem >> scale) + offset
@@ -813,6 +813,9 @@ class ModuleAddressSanitizer {
     if (ClOverrideDestructorKind != AsanDtorKind::Invalid)
       this->DestructorKind = ClOverrideDestructorKind;
     assert(this->DestructorKind != AsanDtorKind::Invalid);
+
+    if (ClConstructorKind != AsanCtorKind::Invalid)
+      this->ConstructorKind = ClConstructorKind;
   }
 
   bool instrumentModule(Module &);
@@ -1149,7 +1152,7 @@ AddressSanitizerPass::AddressSanitizerPass(
     AsanCtorKind ConstructorKind)
     : Options(Options), UseGlobalGC(UseGlobalGC),
       UseOdrIndicator(UseOdrIndicator), DestructorKind(DestructorKind),
-      ConstructorKind(ClConstructorKind) {}
+      ConstructorKind(ConstructorKind) {}
 
 PreservedAnalyses AddressSanitizerPass::run(Module &M,
                                             ModuleAnalysisManager &MAM) {

``````````

</details>


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


More information about the llvm-commits mailing list