Skip to content

Commit 44363f2

Browse files
committed
Always emit symbol table when dwarf section exists in COFF
This also fixes check prefix NO which is pointless in symtab.test Reviewed By: mstorsjo Differential Revision: https://reviews.llvm.org/D149235
1 parent 05551c6 commit 44363f2

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lld/COFF/Writer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,9 @@ void Writer::createSymbolAndStringTable() {
12661266
// solution where discardable sections have long names preserved and
12671267
// non-discardable sections have their names truncated, to ensure that any
12681268
// section which is mapped at runtime also has its name mapped at runtime.
1269+
bool HasDwarfSection = false;
12691270
for (OutputSection *sec : ctx.outputSections) {
1271+
HasDwarfSection |= sec->name.startswith(".debug_");
12701272
if (sec->name.size() <= COFF::NameSize)
12711273
continue;
12721274
if ((sec->header.Characteristics & IMAGE_SCN_MEM_DISCARDABLE) == 0)
@@ -1279,7 +1281,7 @@ void Writer::createSymbolAndStringTable() {
12791281
sec->setStringTableOff(addEntryToStringTable(sec->name));
12801282
}
12811283

1282-
if (ctx.config.debugDwarf || ctx.config.debugSymtab) {
1284+
if (ctx.config.debugDwarf || ctx.config.debugSymtab || HasDwarfSection) {
12831285
for (ObjFile *file : ctx.objFileInstances) {
12841286
for (Symbol *b : file->getSymbols()) {
12851287
auto *d = dyn_cast_or_null<Defined>(b);

lld/test/COFF/symtab.test

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
# RUN: lld-link /debug /out:%t.exe /entry:main %t.obj %p/Inputs/std64.lib
1010
# RUN: llvm-readobj --symbols %t.exe | FileCheck -check-prefix=NO %s
11+
# RUN: lld-link /debug /merge:.blank=.debug_info /out:%t.exe /entry:main %t.obj %p/Inputs/std64.lib
12+
# RUN: llvm-readobj --symbols %t.exe | FileCheck %s
1113

1214
# CHECK: Symbols [
1315
# CHECK-NEXT: Symbol {
@@ -84,7 +86,8 @@
8486
# CHECK-NEXT: }
8587
# CHECK-NEXT: ]
8688

87-
# NO: Symbols [
89+
# NO: Symbols [
90+
# NO-NEXT: ]
8891

8992
--- !COFF
9093
header:
@@ -141,6 +144,10 @@ sections:
141144
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
142145
Alignment: 4
143146
SectionData: 48656C6C6F0048656C6C6F20576F726C6400
147+
- Name: .blank
148+
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
149+
Alignment: 1
150+
SectionData: 0000
144151
symbols:
145152
- Name: "@comp.id"
146153
Value: 10394907

0 commit comments

Comments
 (0)