[PATCH] D28628: [asan] Don't overalign global metadata.

Evgeniy Stepanov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 12 15:21:27 PST 2017


eugenis created this revision.
eugenis added reviewers: kubabrecka, rgov, pcc.
eugenis added a subscriber: llvm-commits.
eugenis set the repository for this revision to rL LLVM.

Other than on COFF with incremental linking, global metadata should not need any extra alignment.


Repository:
  rL LLVM

https://reviews.llvm.org/D28628

Files:
  lib/Transforms/Instrumentation/AddressSanitizer.cpp
  test/Instrumentation/AddressSanitizer/global_metadata_darwin.ll


Index: test/Instrumentation/AddressSanitizer/global_metadata_darwin.ll
===================================================================
--- test/Instrumentation/AddressSanitizer/global_metadata_darwin.ll
+++ test/Instrumentation/AddressSanitizer/global_metadata_darwin.ll
@@ -16,7 +16,7 @@
 
 
 ; 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"
Index: lib/Transforms/Instrumentation/AddressSanitizer.cpp
===================================================================
--- lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -1617,14 +1617,15 @@
                              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);
+  if (TargetTriple.isOSBinFormatCOFF()) {
+    unsigned SizeOfGlobalStruct = DL.getTypeAllocSize(Initializer->getType());
+    assert(isPowerOf2_32(SizeOfGlobalStruct) &&
+           "global metadata will not be padded appropriately");
+    Metadata->setAlignment(SizeOfGlobalStruct);
+  }
   return Metadata;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28628.84181.patch
Type: text/x-patch
Size: 1952 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170112/839249ca/attachment.bin>


More information about the llvm-commits mailing list