summaryrefslogtreecommitdiffstats
path: root/lib/Transforms/Instrumentation/AddressSanitizer.cpp
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2013-08-06 22:52:42 +0000
committerBill Wendling <isanbard@gmail.com>2013-08-06 22:52:42 +0000
commit55a1a590bf0cadf88dfbef2aab6948ffec35c1c3 (patch)
treec8d7a3fb9a7689831f8851c4675f675417e9dbd8 /lib/Transforms/Instrumentation/AddressSanitizer.cpp
parent47cfec02842f885b46ea0d3c812793e660691640 (diff)
downloadexternal_llvm-55a1a590bf0cadf88dfbef2aab6948ffec35c1c3.zip
external_llvm-55a1a590bf0cadf88dfbef2aab6948ffec35c1c3.tar.gz
external_llvm-55a1a590bf0cadf88dfbef2aab6948ffec35c1c3.tar.bz2
Change the linkage of these global values to 'internal'.
The globals being generated here were given the 'private' linkage type. However, this caused them to end up in different sections with the wrong prefix. E.g., they would be in the __TEXT,__const section with an 'L' prefix instead of an 'l' (lowercase ell) prefix. The problem is that the linker will eat a literal label with 'L'. If a weak symbol is then placed into the __TEXT,__const section near that literal, then it cannot distinguish between the literal and the weak symbol. Part of the problems here was introduced because the address sanitizer converted some C strings into constant initializers with trailing nuls. (Thus putting them in the __const section with the wrong prefix.) The others were variables that the address sanitizer created but simply had the wrong linkage type. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187827 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Instrumentation/AddressSanitizer.cpp')
-rw-r--r--lib/Transforms/Instrumentation/AddressSanitizer.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index a954fa2..d77e20b 100644
--- a/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -547,11 +547,11 @@ static size_t TypeSizeToSizeIndex(uint32_t TypeSize) {
return Res;
}
-// Create a constant for Str so that we can pass it to the run-time lib.
+// \brief Create a constant for Str so that we can pass it to the run-time lib.
static GlobalVariable *createPrivateGlobalForString(Module &M, StringRef Str) {
Constant *StrConst = ConstantDataArray::getString(M.getContext(), Str);
GlobalVariable *GV = new GlobalVariable(M, StrConst->getType(), true,
- GlobalValue::PrivateLinkage, StrConst,
+ GlobalValue::InternalLinkage, StrConst,
kAsanGenPrefix);
GV->setUnnamedAddr(true); // Ok to merge these.
GV->setAlignment(1); // Strings may not be merged w/o setting align 1.
@@ -961,8 +961,11 @@ bool AddressSanitizerModule::runOnModule(Module &M) {
GlobalVariable *Name = createPrivateGlobalForString(M, G->getName());
// Create a new global variable with enough space for a redzone.
+ GlobalValue::LinkageTypes Linkage = G->getLinkage();
+ if (G->isConstant() && Linkage == GlobalValue::PrivateLinkage)
+ Linkage = GlobalValue::InternalLinkage;
GlobalVariable *NewGlobal = new GlobalVariable(
- M, NewTy, G->isConstant(), G->getLinkage(),
+ M, NewTy, G->isConstant(), Linkage,
NewInitializer, "", G, G->getThreadLocalMode());
NewGlobal->copyAttributesFrom(G);
NewGlobal->setAlignment(MinRZ);
@@ -995,7 +998,7 @@ bool AddressSanitizerModule::runOnModule(Module &M) {
ArrayType *ArrayOfGlobalStructTy = ArrayType::get(GlobalStructTy, n);
GlobalVariable *AllGlobals = new GlobalVariable(
- M, ArrayOfGlobalStructTy, false, GlobalVariable::PrivateLinkage,
+ M, ArrayOfGlobalStructTy, false, GlobalVariable::InternalLinkage,
ConstantArray::get(ArrayOfGlobalStructTy, Initializers), "");
// Create calls for poisoning before initializers run and unpoisoning after.