Skip to content

Commit

Permalink
Always emit symbol table when dwarf section exists in COFF
Browse files Browse the repository at this point in the history
This also fixes check prefix NO which is pointless in symtab.test

Reviewed By: mstorsjo

Differential Revision: https://reviews.llvm.org/D149235
  • Loading branch information
HaohaiWen committed Apr 27, 2023
1 parent 05551c6 commit 44363f2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lld/COFF/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,9 @@ void Writer::createSymbolAndStringTable() {
// solution where discardable sections have long names preserved and
// non-discardable sections have their names truncated, to ensure that any
// section which is mapped at runtime also has its name mapped at runtime.
bool HasDwarfSection = false;
for (OutputSection *sec : ctx.outputSections) {
HasDwarfSection |= sec->name.startswith(".debug_");
if (sec->name.size() <= COFF::NameSize)
continue;
if ((sec->header.Characteristics & IMAGE_SCN_MEM_DISCARDABLE) == 0)
Expand All @@ -1279,7 +1281,7 @@ void Writer::createSymbolAndStringTable() {
sec->setStringTableOff(addEntryToStringTable(sec->name));
}

if (ctx.config.debugDwarf || ctx.config.debugSymtab) {
if (ctx.config.debugDwarf || ctx.config.debugSymtab || HasDwarfSection) {
for (ObjFile *file : ctx.objFileInstances) {
for (Symbol *b : file->getSymbols()) {
auto *d = dyn_cast_or_null<Defined>(b);
Expand Down
9 changes: 8 additions & 1 deletion lld/test/COFF/symtab.test
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

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

# CHECK: Symbols [
# CHECK-NEXT: Symbol {
Expand Down Expand Up @@ -84,7 +86,8 @@
# CHECK-NEXT: }
# CHECK-NEXT: ]

# NO: Symbols [
# NO: Symbols [
# NO-NEXT: ]

--- !COFF
header:
Expand Down Expand Up @@ -141,6 +144,10 @@ sections:
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
Alignment: 4
SectionData: 48656C6C6F0048656C6C6F20576F726C6400
- Name: .blank
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
Alignment: 1
SectionData: 0000
symbols:
- Name: "@comp.id"
Value: 10394907
Expand Down

0 comments on commit 44363f2

Please sign in to comment.