Skip to content

Commit deaf121

Browse files
committed
Warn when an output section name is longer than 8 characters
Recent versions of Microsoft's dumpbin tool cannot handle such PE files. LLVM tools and GNU tools can, and use this to encode long section names like ".debug_info", which is commonly used for DWARF. Don't do this in mingw mode or when -debug:dwarf is passed, since the user probably wants long section names for DWARF sections. PR43754 Reviewers: ruiu, mstorsjo Differential Revision: https://reviews.llvm.org/D69594
1 parent a264e85 commit deaf121

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

lld/COFF/Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ struct Configuration {
218218
bool warnMissingOrderSymbol = true;
219219
bool warnLocallyDefinedImported = true;
220220
bool warnDebugInfoUnusable = true;
221+
bool warnLongSectionNames = true;
221222
bool incremental = true;
222223
bool integrityCheck = false;
223224
bool killAt = false;

lld/COFF/Driver.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,8 @@ void LinkerDriver::link(ArrayRef<const char *> argsArr) {
11881188
config->warnDebugInfoUnusable = false;
11891189
else if (s == "4217")
11901190
config->warnLocallyDefinedImported = false;
1191+
else if (s == "longsections")
1192+
config->warnLongSectionNames = false;
11911193
// Other warning numbers are ignored.
11921194
}
11931195
}
@@ -1527,6 +1529,11 @@ void LinkerDriver::link(ArrayRef<const char *> argsArr) {
15271529
config->debugGHashes = debug == DebugKind::GHash;
15281530
config->debugSymtab = debug == DebugKind::Symtab;
15291531

1532+
// Don't warn about long section names, such as .debug_info, for mingw or when
1533+
// -debug:dwarf is requested.
1534+
if (config->mingw || config->debugDwarf)
1535+
config->warnLongSectionNames = false;
1536+
15301537
config->mapFile = getMapFile(args);
15311538

15321539
if (config->incremental && args.hasArg(OPT_profile)) {

lld/COFF/Writer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,11 @@ void Writer::createSymbolAndStringTable() {
11481148
continue;
11491149
if ((sec->header.Characteristics & IMAGE_SCN_MEM_DISCARDABLE) == 0)
11501150
continue;
1151+
if (config->warnLongSectionNames) {
1152+
warn("section name " + sec->name +
1153+
" is longer than 8 characters and will use a non-standard string "
1154+
"table");
1155+
}
11511156
sec->setStringTableOff(addEntryToStringTable(sec->name));
11521157
}
11531158

lld/test/COFF/long-section-name.test

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
# RUN: yaml2obj < %s > %t.obj
2-
# RUN: lld-link /out:%t.exe /entry:main %t.obj
2+
# RUN: lld-link /out:%t.exe /entry:main %t.obj 2>&1 | FileCheck %s --check-prefix=WARN
33
# RUN: llvm-readobj --sections %t.exe | FileCheck %s
4-
# RUN: lld-link /debug /out:%t2.exe /entry:main %t.obj
4+
# RUN: lld-link /debug /out:%t2.exe /entry:main %t.obj 2>&1 | FileCheck %s --check-prefix=WARN
55
# RUN: llvm-readobj --sections %t2.exe | FileCheck %s
6+
#
7+
# No warnings in mingw mode or with ignore flag.
8+
# RUN: lld-link /out:%t.exe /entry:main %t.obj /ignore:longsections 2>&1 | FileCheck %s --check-prefix=IGNORE --allow-empty
9+
# RUN: lld-link /out:%t.exe /entry:main %t.obj -lldmingw 2>&1 | FileCheck %s --check-prefix=IGNORE --allow-empty
10+
# RUN: lld-link /out:%t.exe /entry:main %t.obj -debug:dwarf 2>&1 | FileCheck %s --check-prefix=IGNORE --allow-empty
11+
12+
# WARN: warning: section name .data_long_section_name is longer than 8 characters and will use a non-standard string table
13+
# WARN: warning: section name .text_long_section_name is longer than 8 characters and will use a non-standard string table
14+
15+
# IGNORE-NOT: warning:
616

717
# CHECK: Name: .eh_fram (
818
# CHECK: Name: .data_long_section_name

0 commit comments

Comments
 (0)