llvm.org GIT mirror llvm / c2ee6e2
[asan/win] Align global registration metadata to its size This way, when the linker adds padding between globals, we can skip over the zero padding bytes and reliably find the start of the next metadata global. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288096 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 4 years ago
2 changed file(s) with 14 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
15601560 size_t n = GlobalsToChange.size();
15611561 if (n == 0) return false;
15621562
1563 auto &DL = M.getDataLayout();
15631564 bool UseComdatMetadata = TargetTriple.isOSBinFormatCOFF();
15641565 bool UseMachOGlobalsSection = ShouldUseMachOGlobalsSection();
15651566 bool UseMetadataArray = !(UseComdatMetadata || UseMachOGlobalsSection);
15771578 StructType *GlobalStructTy =
15781579 StructType::get(IntptrTy, IntptrTy, IntptrTy, IntptrTy, IntptrTy,
15791580 IntptrTy, IntptrTy, IntptrTy, nullptr);
1581 unsigned SizeOfGlobalStruct = DL.getTypeAllocSize(GlobalStructTy);
1582 assert((isPowerOf2_32(SizeOfGlobalStruct) ||
1583 !TargetTriple.isOSBinFormatCOFF()) &&
1584 "global metadata will not be padded appropriately");
15801585 SmallVector Initializers(UseMetadataArray ? n : 0);
15811586
15821587 // On recent Mach-O platforms, use a structure which binds the liveness of
15951600 GlobalVariable *ModuleName = createPrivateGlobalForString(
15961601 M, M.getModuleIdentifier(), /*AllowMerging*/ false);
15971602
1598 auto &DL = M.getDataLayout();
15991603 for (size_t i = 0; i < n; i++) {
16001604 static const uint64_t kMaxGlobalRedzone = 1 << 18;
16011605 GlobalVariable *G = GlobalsToChange[i];
17421746 Initializer, Twine("__asan_global_") +
17431747 GlobalValue::getRealLinkageName(G->getName()));
17441748 Metadata->setSection(getGlobalMetadataSection());
1745 Metadata->setAlignment(1); // Don't leave padding in between.
1749
1750 // The MSVC linker always inserts padding when linking incrementally. We
1751 // cope with that by aligning each struct to its size, which must be a power
1752 // of two.
1753 if (TargetTriple.isOSBinFormatCOFF())
1754 Metadata->setAlignment(SizeOfGlobalStruct);
1755 else
1756 Metadata->setAlignment(1); // Don't leave padding in between.
17461757
17471758 // On platforms that support comdats, put the metadata and the
17481759 // instrumented global in the same group. This ensures that the metadata
1212
1313 ; CHECK: $dead_global = comdat noduplicates
1414 ; CHECK: @dead_global = local_unnamed_addr global { i32, [60 x i8] } { i32 42, [60 x i8] zeroinitializer }, comdat, align 32
15 ; CHECK: @__asan_global_dead_global = internal global { {{.*}} }, section ".ASAN$GL", comdat($dead_global), align 1
15 ; CHECK: @__asan_global_dead_global = internal global { {{.*}} }, section ".ASAN$GL", comdat($dead_global), align 64
1616
1717 @dead_global = local_unnamed_addr global i32 42, align 4
1818 @mystr = linkonce_odr unnamed_addr constant [5 x i8] c"main\00", comdat, align 1