llvm.org GIT mirror llvm / cfd8739
[asan] Set alignment of __asan_global_* globals to sizeof(GlobalStruct) When using profiling and ASan together (-fprofile-instr-generate -fcoverage-mapping -fsanitize=address), at least on Darwin, the section of globals that ASan emits (__asan_globals) is misaligned and starts at an odd offset. This really doesn't have anything to do with profiling, but it triggers the issue because profiling emits a string section, which can have arbitrary size. This patch changes the alignment to sizeof(GlobalStruct). Differential Revision: https://reviews.llvm.org/D28573 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291715 91177308-0d34-0410-b5e6-96231b3b80d8 Kuba Mracek 3 years ago
2 changed file(s) with 4 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
15971597 StructType::get(IntptrTy, IntptrTy, IntptrTy, IntptrTy, IntptrTy,
15981598 IntptrTy, IntptrTy, IntptrTy, nullptr);
15991599 unsigned SizeOfGlobalStruct = DL.getTypeAllocSize(GlobalStructTy);
1600 assert((isPowerOf2_32(SizeOfGlobalStruct) ||
1601 !TargetTriple.isOSBinFormatCOFF()) &&
1600 assert(isPowerOf2_32(SizeOfGlobalStruct) &&
16021601 "global metadata will not be padded appropriately");
16031602 SmallVector Initializers(UseMetadataArray ? n : 0);
16041603
17651764 GlobalValue::getRealLinkageName(G->getName()));
17661765 Metadata->setSection(getGlobalMetadataSection());
17671766
1767 // We don't want any padding, but we also need a reasonable alignment.
17681768 // The MSVC linker always inserts padding when linking incrementally. We
17691769 // cope with that by aligning each struct to its size, which must be a power
17701770 // of two.
1771 if (TargetTriple.isOSBinFormatCOFF())
1772 Metadata->setAlignment(SizeOfGlobalStruct);
1773 else
1774 Metadata->setAlignment(1); // Don't leave padding in between.
1771 Metadata->setAlignment(SizeOfGlobalStruct);
17751772
17761773 // On platforms that support comdats, put the metadata and the
17771774 // instrumented global in the same group. This ensures that the metadata
1515
1616
1717 ; Find the metadata for @global:
18 ; CHECK: [[METADATA:@.+]] = internal global {{.*}} @global {{.*}} section "__DATA,__asan_globals,regular", align 1
18 ; CHECK: [[METADATA:@.+]] = internal global {{.*}} @global {{.*}} section "__DATA,__asan_globals,regular", align 64
1919
2020 ; Find the liveness binder for @global and its metadata:
2121 ; CHECK: @__asan_binder_global = internal global {{.*}} @global {{.*}} [[METADATA]] {{.*}} section "__DATA,__asan_liveness,regular,live_support"