Author: Fangrui Song Date: 2020-08-29T18:27:34-07:00 New Revision: 6ae7b403c3e1aebcb825d3dd4777d3c1149d6d67
URL: https://github.com/llvm/llvm-project/commit/6ae7b403c3e1aebcb825d3dd4777d3c1149d6d67 DIFF: https://github.com/llvm/llvm-project/commit/6ae7b403c3e1aebcb825d3dd4777d3c1149d6d67.diff LOG: Set alignment of .llvmbc and .llvmcmd to 1 Otherwise their alignment is dependent on the size of the section. If the size is large than 16, the alignment will be 16. 16 is a bad choice for both .llvmbc and .llvmcmd because the padding between two contributions from input sections is of a variable size. A bitstream is actually guaranteed to be 4-byte aligned, but consumers don't need this property. Added: Modified: clang/test/Frontend/embed-bitcode.ll clang/test/Frontend/x86-embed-bitcode.ll llvm/lib/Bitcode/Writer/BitcodeWriter.cpp llvm/test/CodeGen/X86/embed-bitcode.ll Removed: ################################################################################ diff --git a/clang/test/Frontend/embed-bitcode.ll b/clang/test/Frontend/embed-bitcode.ll index 75cdc5f657fc..defb2d12f2f0 100644 --- a/clang/test/Frontend/embed-bitcode.ll +++ b/clang/test/Frontend/embed-bitcode.ll @@ -43,9 +43,9 @@ ; RUN: | FileCheck %s -check-prefix=CHECK-WARNING ; CHECK-ELF: @llvm.embedded.module -; CHECK-ELF: section ".llvmbc" +; CHECK-ELF-SAME: section ".llvmbc", align 1 ; CHECK-ELF: @llvm.cmdline -; CHECK-ELF: section ".llvmcmd" +; CHECK-ELF-SAME: section ".llvmcmd", align 1 ; CHECK-ONLY-BITCODE: @llvm.embedded.module = private constant ; CHECK-ONLY-BITCODE: c"\DE\C0\17\0B diff --git a/clang/test/Frontend/x86-embed-bitcode.ll b/clang/test/Frontend/x86-embed-bitcode.ll index 709f56bdfe81..b49fa6247c16 100644 --- a/clang/test/Frontend/x86-embed-bitcode.ll +++ b/clang/test/Frontend/x86-embed-bitcode.ll @@ -43,17 +43,17 @@ ; CHECK: section "__LLVM,__cmdline" ; CHECK-ELF: @llvm.embedded.module -; CHECK-ELF: section ".llvmbc" +; CHECK-ELF-SAME: section ".llvmbc", align 1 ; CHECK-ELF: @llvm.cmdline -; CHECK-ELF: section ".llvmcmd" +; CHECK-ELF-SAME: section ".llvmcmd", align 1 ; CHECK-ELF-MARKER: @llvm.embedded.module ; CHECK-ELF-MARKER: constant [0 x i8] zeroinitializer ; CHECK-ELF-MARKER: @llvm.cmdline -; CHECK-ELF-MARKER: section ".llvmcmd" +; CHECK-ELF-MARKER: section ".llvmcmd", align 1 ; CHECK-ELF-ONLY-BITCODE: @llvm.embedded.module -; CHECK-ELF-ONLY-BITCODE: section ".llvmbc" +; CHECK-ELF-ONLY-BITCODE-SAME: section ".llvmbc", align 1 ; CHECK-ELF-ONLY-BITCODE-NOT: @llvm.cmdline ; CHECK-ELF-ONLY-BITCODE-NOT: section ".llvmcmd" diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index f2630903dba1..eaea026681b1 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -4852,6 +4852,9 @@ void llvm::EmbedBitcodeInModule(llvm::Module &M, llvm::MemoryBufferRef Buf, M, ModuleConstant->getType(), true, llvm::GlobalValue::PrivateLinkage, ModuleConstant); GV->setSection(getSectionNameForBitcode(T)); + // Set alignment to 1 to prevent padding between two contributions from input + // sections after linking. + GV->setAlignment(Align(1)); UsedArray.push_back( ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, UsedElementType)); if (llvm::GlobalVariable *Old = @@ -4875,6 +4878,7 @@ void llvm::EmbedBitcodeInModule(llvm::Module &M, llvm::MemoryBufferRef Buf, llvm::GlobalValue::PrivateLinkage, CmdConstant); GV->setSection(getSectionNameForCommandline(T)); + GV->setAlignment(Align(1)); UsedArray.push_back( ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, UsedElementType)); if (llvm::GlobalVariable *Old = M.getGlobalVariable("llvm.cmdline", true)) { diff --git a/llvm/test/CodeGen/X86/embed-bitcode.ll b/llvm/test/CodeGen/X86/embed-bitcode.ll index 00dd7ef17d56..8c56dfe2168f 100644 --- a/llvm/test/CodeGen/X86/embed-bitcode.ll +++ b/llvm/test/CodeGen/X86/embed-bitcode.ll @@ -5,6 +5,6 @@ ; CHECK-NEXT: .llvmbc PROGBITS 0000000000000000 [[#%x,OFF:]] 000004 00 0 ; CHECK-NEXT: .llvmcmd PROGBITS 0000000000000000 [[#%x,OFF:]] 000005 00 0 -@llvm.embedded.module = private constant [4 x i8] c"BC\C0\DE", section ".llvmbc" -@llvm.cmdline = private constant [5 x i8] c"-cc1\00", section ".llvmcmd" +@llvm.embedded.module = private constant [4 x i8] c"BC\C0\DE", section ".llvmbc", align 1 +@llvm.cmdline = private constant [5 x i8] c"-cc1\00", section ".llvmcmd", align 1 @llvm.compiler.used = appending global [2 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @llvm.embedded.module, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @llvm.cmdline, i32 0, i32 0)], section "llvm.metadata" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits