From d7b6449512ea9a65ffc20f66ca53f0befa9bd349 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 6 Nov 2014 20:01:34 +0000 Subject: [PATCH] Base check on the section name, not the variable name. The variable is private, so the name should not be relied on. Also, the linker uses the sections, so asan should too when trying to avoid causing the linker problems. llvm-svn: 221480 --- .../Instrumentation/AddressSanitizer.cpp | 15 +++++---------- .../AddressSanitizer/do-not-instrument-cstring.ll | 7 +++++++ 2 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 test/Instrumentation/AddressSanitizer/do-not-instrument-cstring.ll diff --git a/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/lib/Transforms/Instrumentation/AddressSanitizer.cpp index 906de7e4fda..49eccad1d97 100644 --- a/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -971,16 +971,6 @@ bool AddressSanitizerModule::ShouldInstrumentGlobal(GlobalVariable *G) { // For now, just ignore this Global if the alignment is large. if (G->getAlignment() > MinRedzoneSizeForGlobal()) return false; - // Ignore all the globals with the names starting with "\01L_OBJC_". - // Many of those are put into the .cstring section. The linker compresses - // that section by removing the spare \0s after the string terminator, so - // our redzones get broken. - if ((G->getName().find("\01L_OBJC_") == 0) || - (G->getName().find("\01l_OBJC_") == 0)) { - DEBUG(dbgs() << "Ignoring \\01L_OBJC_* global: " << *G << "\n"); - return false; - } - if (G->hasSection()) { StringRef Section(G->getSection()); // Ignore the globals from the __OBJC section. The ObjC runtime assumes @@ -1009,6 +999,11 @@ bool AddressSanitizerModule::ShouldInstrumentGlobal(GlobalVariable *G) { DEBUG(dbgs() << "Ignoring a cstring literal: " << *G << "\n"); return false; } + if (Section.startswith("__TEXT,__objc_methname,cstring_literals")) { + DEBUG(dbgs() << "Ignoring objc_methname cstring global: " << *G << "\n"); + return false; + } + // Callbacks put into the CRT initializer/terminator sections // should not be instrumented. diff --git a/test/Instrumentation/AddressSanitizer/do-not-instrument-cstring.ll b/test/Instrumentation/AddressSanitizer/do-not-instrument-cstring.ll new file mode 100644 index 00000000000..de6a4decdbb --- /dev/null +++ b/test/Instrumentation/AddressSanitizer/do-not-instrument-cstring.ll @@ -0,0 +1,7 @@ +; RUN: opt < %s -asan -asan-module -S | FileCheck %s + +target datalayout = "e" + +@foo = private global [19 x i8] c"scannerWithString:\00", section "__TEXT,__objc_methname,cstring_literals" + +; CHECK: @foo = private global [19 x i8] c"scannerWithString:\00", section "__TEXT,__objc_methname,cstring_literals" \ No newline at end of file