diff options
author | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2017-01-12 23:26:20 +0000 |
---|---|---|
committer | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2017-01-12 23:26:20 +0000 |
commit | f01c70fec02ea2c709daa55494f56ea54669dc7b (patch) | |
tree | a789af1b68824cce5ea823206932802c487a061c /llvm/lib | |
parent | 5d31d08a210e8883ddb6837a11636d1af0bd6c12 (diff) | |
download | bcm5719-llvm-f01c70fec02ea2c709daa55494f56ea54669dc7b.tar.gz bcm5719-llvm-f01c70fec02ea2c709daa55494f56ea54669dc7b.zip |
[asan] Don't overalign global metadata.
Other than on COFF with incremental linking, global metadata should
not need any extra alignment.
Differential Revision: https://reviews.llvm.org/D28628
llvm-svn: 291859
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp index 5f7e67033d4..ffd518e5296 100644 --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -1609,22 +1609,12 @@ void AddressSanitizerModule::SetComdatForGlobalMetadata( GlobalVariable * AddressSanitizerModule::CreateMetadataGlobal(Module &M, Constant *Initializer, StringRef OriginalName) { - auto &DL = M.getDataLayout(); GlobalVariable *Metadata = new GlobalVariable(M, Initializer->getType(), false, GlobalVariable::InternalLinkage, Initializer, Twine("__asan_global_") + GlobalValue::getRealLinkageName(OriginalName)); Metadata->setSection(getGlobalMetadataSection()); - - // We don't want any padding, but we also need a reasonable alignment. - // The MSVC linker always inserts padding when linking incrementally. We - // cope with that by aligning each struct to its size, which must be a power - // of two. - unsigned SizeOfGlobalStruct = DL.getTypeAllocSize(Initializer->getType()); - assert(isPowerOf2_32(SizeOfGlobalStruct) && - "global metadata will not be padded appropriately"); - Metadata->setAlignment(SizeOfGlobalStruct); return Metadata; } @@ -1642,11 +1632,22 @@ void AddressSanitizerModule::InstrumentGlobalsCOFF( IRBuilder<> &IRB, Module &M, ArrayRef<GlobalVariable *> ExtendedGlobals, ArrayRef<Constant *> MetadataInitializers) { assert(ExtendedGlobals.size() == MetadataInitializers.size()); + auto &DL = M.getDataLayout(); for (size_t i = 0; i < ExtendedGlobals.size(); i++) { + Constant *Initializer = MetadataInitializers[i]; GlobalVariable *G = ExtendedGlobals[i]; GlobalVariable *Metadata = - CreateMetadataGlobal(M, MetadataInitializers[i], G->getName()); + CreateMetadataGlobal(M, Initializer, G->getName()); + + // The MSVC linker always inserts padding when linking incrementally. We + // cope with that by aligning each struct to its size, which must be a power + // of two. + unsigned SizeOfGlobalStruct = DL.getTypeAllocSize(Initializer->getType()); + assert(isPowerOf2_32(SizeOfGlobalStruct) && + "global metadata will not be padded appropriately"); + Metadata->setAlignment(SizeOfGlobalStruct); + SetComdatForGlobalMetadata(G, Metadata); } } |