Skip to content

Commit 41f3332

Browse files
authored
[LLD][COFF] Discard .llvmbc and .llvmcmd sections (#150897)
Those sections are generated by -fembed-bitcode and do not need to be kept in executable files.
1 parent 72b77c1 commit 41f3332

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

lld/COFF/InputFiles.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,11 @@ SectionChunk *ObjFile::readSection(uint32_t sectionNumber,
403403
return nullptr;
404404
}
405405

406+
// Those sections are generated by -fembed-bitcode and do not need to be kept
407+
// in executable files.
408+
if (name == ".llvmbc" || name == ".llvmcmd")
409+
return nullptr;
410+
406411
// Object files may have DWARF debug info or MS CodeView debug info
407412
// (or both).
408413
//

lld/test/COFF/embed-bitcode.test

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# RUN: yaml2obj %s -o %t.obj
2+
# RUN: lld-link /entry:main /subsystem:console /out:%t.exe %t.obj
3+
# RUN: llvm-readobj -S %t.exe | FileCheck %s
4+
5+
# CHECK-NOT: Name: .llvmbc
6+
# CHECK-NOT: Name: .llvmcmd
7+
8+
--- !COFF
9+
header:
10+
Machine: IMAGE_FILE_MACHINE_AMD64
11+
12+
sections:
13+
- Name: .text
14+
Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
15+
SectionData: "C3"
16+
- Name: .llvmbc
17+
Characteristics: [ IMAGE_SCN_MEM_DISCARDABLE ]
18+
SectionData: "4243C0DE"
19+
- Name: .llvmcmd
20+
Characteristics: [ IMAGE_SCN_MEM_DISCARDABLE ]
21+
SectionData: "2D63633100"
22+
23+
symbols:
24+
- Name: main
25+
Value: 0
26+
SectionNumber: 1
27+
SimpleType: IMAGE_SYM_TYPE_NULL
28+
ComplexType: IMAGE_SYM_DTYPE_FUNCTION
29+
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
30+
...

0 commit comments

Comments
 (0)