[llvm] r291859 - [asan] Don't overalign global metadata.

Kuba Mracek via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 19 16:18:56 PST 2017


Please merge this (along with r291858 which this depends on) into release_40.

Thanks,
Kuba

> On 12 Jan 2017, at 15:26, Evgeniy Stepanov via llvm-commits <llvm-commits at lists.llvm.org> wrote:
> 
> Author: eugenis
> Date: Thu Jan 12 17:26:20 2017
> New Revision: 291859
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=291859&view=rev
> Log:
> [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
> 
> Modified:
>    llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
>    llvm/trunk/test/Instrumentation/AddressSanitizer/global_metadata_darwin.ll
> 
> Modified: llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp?rev=291859&r1=291858&r2=291859&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp (original)
> +++ llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp Thu Jan 12 17:26:20 2017
> @@ -1609,22 +1609,12 @@ void AddressSanitizerModule::SetComdatFo
> 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::InstrumentG
>     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);
>   }
> }
> 
> Modified: llvm/trunk/test/Instrumentation/AddressSanitizer/global_metadata_darwin.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/AddressSanitizer/global_metadata_darwin.ll?rev=291859&r1=291858&r2=291859&view=diff
> ==============================================================================
> --- llvm/trunk/test/Instrumentation/AddressSanitizer/global_metadata_darwin.ll (original)
> +++ llvm/trunk/test/Instrumentation/AddressSanitizer/global_metadata_darwin.ll Thu Jan 12 17:26:20 2017
> @@ -16,7 +16,7 @@ target triple = "x86_64-apple-macosx10.1
> 
> 
> ; Find the metadata for @global:
> -; CHECK: [[METADATA:@.+]] = internal global {{.*}} @global {{.*}} section "__DATA,__asan_globals,regular", align 64
> +; CHECK: [[METADATA:@.+]] = internal global {{.*}} @global {{.*}} section "__DATA,__asan_globals,regular"
> 
> ; Find the liveness binder for @global and its metadata:
> ; CHECK: @__asan_binder_global = internal global {{.*}} @global {{.*}} [[METADATA]] {{.*}} section "__DATA,__asan_liveness,regular,live_support"
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list