Skip to content

Commit 9c307cd

Browse files
cjacektru
authored andcommitted
[LLD][COFF] Allow symbols with empty chunks to have no associated output section in the PDB writer (#149523)
If a chunk is empty and there are no other non-empty chunks in the same section, `removeEmptySections()` will remove the entire section. In this case, use a section index of 0, as the MSVC linker does, instead of asserting. (cherry picked from commit 1ab04fc)
1 parent 431af6d commit 9c307cd

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

lld/COFF/PDB.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,9 +1135,12 @@ static pdb::BulkPublic createPublic(COFFLinkerContext &ctx, Defined *def) {
11351135
pub.setFlags(flags);
11361136

11371137
OutputSection *os = ctx.getOutputSection(def->getChunk());
1138-
assert(os && "all publics should be in final image");
1139-
pub.Offset = def->getRVA() - os->getRVA();
1140-
pub.Segment = os->sectionIndex;
1138+
assert((os || !def->getChunk()->getSize()) &&
1139+
"all publics should be in final image");
1140+
if (os) {
1141+
pub.Offset = def->getRVA() - os->getRVA();
1142+
pub.Segment = os->sectionIndex;
1143+
}
11411144
return pub;
11421145
}
11431146

lld/test/COFF/pdb-empty-sec.s

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// REQUIRES: x86
2+
3+
// RUN: llvm-mc -filetype=obj -triple=x86_64-windows %s -o %t.obj
4+
// RUN: lld-link -dll -noentry -debug %t.obj -out:%t.dll
5+
// RUN: llvm-pdbutil dump -publics %t.pdb | FileCheck %s
6+
7+
// CHECK: Records
8+
// CHECK-NEXT: 0 | S_PUB32 [size = 20] `func`
9+
// CHECK-NEXT: flags = none, addr = 0001:0000
10+
// CHECK-NEXT: 20 | S_PUB32 [size = 20] `sym`
11+
// CHECK-NEXT: flags = none, addr = 0000:0000
12+
13+
.globl sym
14+
.data
15+
sym:
16+
.text
17+
.globl func
18+
func:
19+
ret

0 commit comments

Comments
 (0)