diff options
author | Kuba Brecka <kuba.brecka@gmail.com> | 2016-10-31 18:51:58 +0000 |
---|---|---|
committer | Kuba Brecka <kuba.brecka@gmail.com> | 2016-10-31 18:51:58 +0000 |
commit | 588bf7bf31fc3a89d95ba381136d78d79100b929 (patch) | |
tree | 8f0ad97b806eb02b2e731a2145ff956082c983af /lib | |
parent | 30e34b0f1a64c95936acbab2b2677169de83c843 (diff) |
[asan] Move instrumented null-terminated strings to a special section, LLVM part
On Darwin, simple C null-terminated constant strings normally end up in the __TEXT,__cstring section of the resulting Mach-O binary. When instrumented with ASan, these strings are transformed in a way that they cannot be in __cstring (the linker unifies the content of this section and strips extra NUL bytes, which would break instrumentation), and are put into a generic __const section. This breaks some of the tools that we have: Some tools need to scan all C null-terminated strings in Mach-O binaries, and scanning all the contents of __const has a large performance penalty. This patch instead introduces a special section, __asan_cstring which will now hold the instrumented null-terminated strings.
Differential Revision: https://reviews.llvm.org/D25026
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285619 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/Instrumentation/AddressSanitizer.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/lib/Transforms/Instrumentation/AddressSanitizer.cpp index d77a0ae31b7..df068e88090 100644 --- a/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -1535,6 +1535,14 @@ bool AddressSanitizerModule::InstrumentGlobals(IRBuilder<> &IRB, Module &M) { NewGlobal->copyAttributesFrom(G); NewGlobal->setAlignment(MinRZ); + // Move null-terminated C strings to "__asan_cstring" section on Darwin. + if (TargetTriple.isOSBinFormatMachO() && !G->hasSection() && + G->isConstant()) { + auto Seq = dyn_cast<ConstantDataSequential>(G->getInitializer()); + if (Seq && Seq->isCString()) + NewGlobal->setSection("__TEXT,__asan_cstring,regular"); + } + // Transfer the debug info. The payload starts at offset zero so we can // copy the debug info over as is. SmallVector<DIGlobalVariable *, 1> GVs; |