[PATCH] D86374: [TargetLoweringObjectFileImpl] Make .llvmbc and .llvmcmd non-SHF_ALLOC

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 21 14:49:34 PDT 2020


MaskRay created this revision.
MaskRay added reviewers: mtrofin, tejohnson.
Herald added subscribers: llvm-commits, dexonsmith, steven_wu, hiraditya.
Herald added a project: LLVM.
MaskRay requested review of this revision.

There are two ways .llvmbc can be produced:

- clang -c -fembed-bitcode=all (which also produces .llvmcmd)
- LTO backend: ld.lld -mllvm -lto-embed-bitcode or -plugin-opt=-lto-embed-bitcode

.llvmbc and .llvmcmd have the SHF_ALLOC flag, so they can be dropped by
--gc-sections.

This patch sets SectionKind::Metadata to drop the SHF_ALLOC flag. This
is conceptually correct: the two sections are not part of the process
image, so SHF_ALLOC is not appropriate.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86374

Files:
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/test/CodeGen/X86/embed-bitcode.ll
  llvm/test/LTO/X86/embed-bitcode.ll


Index: llvm/test/LTO/X86/embed-bitcode.ll
===================================================================
--- llvm/test/LTO/X86/embed-bitcode.ll
+++ llvm/test/LTO/X86/embed-bitcode.ll
@@ -13,8 +13,8 @@
 ; RUN: llvm-objcopy -O binary -j .llvmbc %t3.0 %t-embedded.bc
 ; RUN: llvm-dis %t-embedded.bc -o - | FileCheck %s --check-prefix=CHECK-LL
 
-; CHECK-ELF: .text
-; CHECK-ELF: .llvmbc
+; CHECK-ELF:      .text   PROGBITS 0000000000000000 [[#%x,OFF:]] [[#%x,SIZE:]] 00 AX 0
+; CHECK-ELF-NEXT: .llvmbc PROGBITS 0000000000000000 [[#%x,OFF:]] [[#%x,SIZE:]] 00    0
 
 ; CHECK-LL: @_start
 ; CHECK-LL: @foo
Index: llvm/test/CodeGen/X86/embed-bitcode.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/X86/embed-bitcode.ll
@@ -0,0 +1,10 @@
+; RUN: llc -filetype=obj -mtriple=x86_64 %s -o %t
+; RUN: llvm-readelf -S %t | FileCheck %s
+
+; CHECK:      .text    PROGBITS 0000000000000000 [[#%x,OFF:]] 000000 00 AX 0
+; CHECK-NEXT: .llvmbc  PROGBITS 0000000000000000 [[#%x,OFF:]] 000004 00    0
+; CHECK-NEXT: .llvmcmd PROGBITS 0000000000000000 [[#%x,OFF:]] 000005 00    0
+
+ at llvm.embedded.module = private constant [4 x i8] c"BC\C0\DE", section ".llvmbc"
+ at llvm.cmdline = private constant [5 x i8] c"-cc1\00", section ".llvmcmd"
+ at 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"
Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
===================================================================
--- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -436,7 +436,8 @@
   if (Name == getInstrProfSectionName(IPSK_covmap, Triple::ELF,
                                       /*AddSegmentInfo=*/false) ||
       Name == getInstrProfSectionName(IPSK_covfun, Triple::ELF,
-                                      /*AddSegmentInfo=*/false))
+                                      /*AddSegmentInfo=*/false) ||
+      Name == ".llvmbc" || Name == ".llvmcmd")
     return SectionKind::getMetadata();
 
   if (Name.empty() || Name[0] != '.') return K;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86374.287115.patch
Type: text/x-patch
Size: 2245 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200821/150ffbf2/attachment.bin>


More information about the llvm-commits mailing list