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

Usama Hameed via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 14 16:40:59 PST 2023


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

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

>From 41e51898676b1a44331febe4427f3580ed30f15f Mon Sep 17 00:00:00 2001
From: usama <u_hameed at apple.com>
Date: Tue, 14 Nov 2023 16:37:34 -0800
Subject: [PATCH] [ASan] AddressSanitizerPass constructor should honor the
 AsanCtorKind argument.

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
---
 .../Transforms/Instrumentation/AddressSanitizerOptions.h   | 3 ++-
 llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp   | 7 +++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

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) {



More information about the llvm-commits mailing list