llvm.org GIT mirror llvm / f317b6e
[asan] Do not instrument accesses to profiling globals It's only useful to asan-itize profiling globals while debugging llvm's profiling instrumentation passes. Enabling asan along with instrprof or gcov instrumentation shouldn't incur extra overhead. This patch is in the same spirit as r264805 and r273202, which disabled tsan instrumentation of instrprof/gcov globals. Differential Revision: http://reviews.llvm.org/D21541 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273444 91177308-0d34-0410-b5e6-96231b3b80d8 Vedant Kumar 4 years ago
2 changed file(s) with 23 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
856856 return GV;
857857 }
858858
859 static bool GlobalWasGeneratedByAsan(GlobalVariable *G) {
860 return G->getName().startswith(kAsanGenPrefix) ||
861 G->getName().startswith(kSanCovGenPrefix) ||
862 G->getName().startswith(kODRGenPrefix);
859 /// \brief Check if \p G has been created by a trusted compiler pass.
860 static bool GlobalWasGeneratedByCompiler(GlobalVariable *G) {
861 // Do not instrument asan globals.
862 if (G->getName().startswith(kAsanGenPrefix) ||
863 G->getName().startswith(kSanCovGenPrefix) ||
864 G->getName().startswith(kODRGenPrefix))
865 return true;
866
867 // Do not instrument gcov counter arrays.
868 if (G->getName() == "__llvm_gcov_ctr")
869 return true;
870
871 return false;
863872 }
864873
865874 Value *AddressSanitizer::memToShadow(Value *Shadow, IRBuilder<> &IRB) {
12421251 if (GlobalsMD.get(G).IsBlacklisted) return false;
12431252 if (!Ty->isSized()) return false;
12441253 if (!G->hasInitializer()) return false;
1245 if (GlobalWasGeneratedByAsan(G)) return false; // Our own global.
1254 if (GlobalWasGeneratedByCompiler(G)) return false; // Our own globals.
12461255 // Touch only those globals that will not be defined in other modules.
12471256 // Don't handle ODR linkage types and COMDATs since other modules may be built
12481257 // without ASan.
0 ; This test checks that we don't instrument globals created by profiling passes.
1 ; RUN: opt < %s -asan -asan-module -S | FileCheck %s
2
3 @__profc_test = private global [1 x i64] zeroinitializer, section "__DATA,__llvm_prf_cnts", align 8
4 @__llvm_gcov_ctr = internal global [1 x i64] zeroinitializer
5
6 ; CHECK-DAG: @asan.module_ctor
7 ; CHECK-NOT: @__asan_gen{{.*}}__llvm_gcov_ctr
8 ; CHECK-NOT: @__asan_gen{{.*}}__profc_test