OSDN Git Service

[asan] Reduce binary size by using unnamed private aliases
authorVitaly Buka <vitalybuka@google.com>
Tue, 4 Dec 2018 00:36:14 +0000 (00:36 +0000)
committerVitaly Buka <vitalybuka@google.com>
Tue, 4 Dec 2018 00:36:14 +0000 (00:36 +0000)
Summary:
--asan-use-private-alias increases binary sizes by 10% or more.
Most of this space was long names of aliases and new symbols.
These symbols are not needed for the ODC check at all.

Reviewers: eugenis

Subscribers: hiraditya, llvm-commits

Differential Revision: https://reviews.llvm.org/D55146

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348221 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Instrumentation/AddressSanitizer.cpp
test/Instrumentation/AddressSanitizer/local_alias.ll

index 42b8179..1cbdf4a 100644 (file)
@@ -746,7 +746,7 @@ public:
               ClRecover : Recover;
           this->CompileKernel = ClEnableKasan.getNumOccurrences() > 0 ?
               ClEnableKasan : CompileKernel;
-       }
+  }
 
   bool runOnModule(Module &M) override;
   StringRef getPassName() const override { return "AddressSanitizerModule"; }
@@ -2176,8 +2176,8 @@ bool AddressSanitizerModule::InstrumentGlobals(IRBuilder<> &IRB, Module &M, bool
     if (CanUsePrivateAliases && ClUsePrivateAliasForGlobals) {
       // Create local alias for NewGlobal to avoid crash on ODR between
       // instrumented and non-instrumented libraries.
-      auto *GA = GlobalAlias::create(GlobalValue::InternalLinkage,
-                                     NameForGlobal + M.getName(), NewGlobal);
+      auto *GA =
+          GlobalAlias::create(GlobalValue::PrivateLinkage, "", NewGlobal);
 
       // With local aliases, we need to provide another externally visible
       // symbol __odr_asan_XXX to detect ODR violation.
index 3db241d..0ac3981 100644 (file)
@@ -7,7 +7,7 @@ target triple = "x86_64-unknown-linux-gnu"
 
 ; Check that we generate internal alias and odr indicator symbols for global to be protected.
 ; CHECK: @__odr_asan_gen_a = internal global i8 0, align 1
-; CHECK: @"a<stdin>" = internal alias { [2 x i32], [56 x i8] }, { [2 x i32], [56 x i8] }* @a
+; CHECK: @0 = private alias { [2 x i32], [56 x i8] }, { [2 x i32], [56 x i8] }* @a
 
 ; Function Attrs: nounwind sanitize_address uwtable
 define i32 @foo(i32 %M) #0 {