summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorAlexey Samsonov <vonosmas@gmail.com>2014-07-12 00:42:52 +0000
committerAlexey Samsonov <vonosmas@gmail.com>2014-07-12 00:42:52 +0000
commit15c96696150cc76a28e4aa51a109ef68476c3b5a (patch)
tree3b7d919d22ad549c245c88ad1f2d0b176a4c2068 /llvm/lib/Transforms
parentfc31efe95a9a220fb1a3f7a7dd8109fd2441d196 (diff)
downloadbcm5719-llvm-15c96696150cc76a28e4aa51a109ef68476c3b5a.tar.gz
bcm5719-llvm-15c96696150cc76a28e4aa51a109ef68476c3b5a.zip
[ASan] Collect unmangled names of global variables in Clang to print them in error reports.
Currently ASan instrumentation pass creates a string with global name for each instrumented global (to include global names in the error report). Global name is already mangled at this point, and we may not be able to demangle it at runtime (e.g. there is no __cxa_demangle on Android). Instead, create a string with fully qualified global name in Clang, and pass it to ASan instrumentation pass in llvm.asan.globals metadata. If there is no metadata for some global, ASan will use the original algorithm. This fixes https://code.google.com/p/address-sanitizer/issues/detail?id=264. llvm-svn: 212872
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp29
1 files changed, 20 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index 17cfd92ff27..e42839c9c6b 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -216,8 +216,11 @@ namespace {
class GlobalsMetadata {
public:
struct Entry {
- Entry() : SourceLoc(nullptr), IsDynInit(false), IsBlacklisted(false) {}
+ Entry()
+ : SourceLoc(nullptr), Name(nullptr), IsDynInit(false),
+ IsBlacklisted(false) {}
GlobalVariable *SourceLoc;
+ GlobalVariable *Name;
bool IsDynInit;
bool IsBlacklisted;
};
@@ -232,7 +235,7 @@ class GlobalsMetadata {
return;
for (auto MDN : Globals->operands()) {
// Metadata node contains the global and the fields of "Entry".
- assert(MDN->getNumOperands() == 4);
+ assert(MDN->getNumOperands() == 5);
Value *V = MDN->getOperand(0);
// The optimizer may optimize away a global entirely.
if (!V)
@@ -246,9 +249,14 @@ class GlobalsMetadata {
E.SourceLoc = GVLoc;
addSourceLocationGlobal(GVLoc);
}
- ConstantInt *IsDynInit = cast<ConstantInt>(MDN->getOperand(2));
+ if (Value *Name = MDN->getOperand(2)) {
+ GlobalVariable *GVName = cast<GlobalVariable>(Name);
+ E.Name = GVName;
+ InstrumentationGlobals.insert(GVName);
+ }
+ ConstantInt *IsDynInit = cast<ConstantInt>(MDN->getOperand(3));
E.IsDynInit |= IsDynInit->isOne();
- ConstantInt *IsBlacklisted = cast<ConstantInt>(MDN->getOperand(3));
+ ConstantInt *IsBlacklisted = cast<ConstantInt>(MDN->getOperand(4));
E.IsBlacklisted |= IsBlacklisted->isOne();
}
}
@@ -1049,6 +1057,14 @@ bool AddressSanitizerModule::InstrumentGlobals(IRBuilder<> &IRB, Module &M) {
for (size_t i = 0; i < n; i++) {
static const uint64_t kMaxGlobalRedzone = 1 << 18;
GlobalVariable *G = GlobalsToChange[i];
+
+ auto MD = GlobalsMD.get(G);
+ // Create string holding the global name unless it was provided by
+ // the metadata.
+ GlobalVariable *Name =
+ MD.Name ? MD.Name : createPrivateGlobalForString(M, G->getName(),
+ /*AllowMerging*/ true);
+
PointerType *PtrTy = cast<PointerType>(G->getType());
Type *Ty = PtrTy->getElementType();
uint64_t SizeInBytes = DL->getTypeAllocSize(Ty);
@@ -1070,9 +1086,6 @@ bool AddressSanitizerModule::InstrumentGlobals(IRBuilder<> &IRB, Module &M) {
NewTy, G->getInitializer(),
Constant::getNullValue(RightRedZoneTy), NULL);
- GlobalVariable *Name =
- createPrivateGlobalForString(M, G->getName(), /*AllowMerging*/true);
-
// Create a new global variable with enough space for a redzone.
GlobalValue::LinkageTypes Linkage = G->getLinkage();
if (G->isConstant() && Linkage == GlobalValue::PrivateLinkage)
@@ -1092,8 +1105,6 @@ bool AddressSanitizerModule::InstrumentGlobals(IRBuilder<> &IRB, Module &M) {
NewGlobal->takeName(G);
G->eraseFromParent();
- auto MD = GlobalsMD.get(G);
-
Initializers[i] = ConstantStruct::get(
GlobalStructTy, ConstantExpr::getPointerCast(NewGlobal, IntptrTy),
ConstantInt::get(IntptrTy, SizeInBytes),
OpenPOWER on IntegriCloud