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
This commit is contained in:
parent
a264e85dd9
commit
deaf121b65
|
@ -218,6 +218,7 @@ struct Configuration {
|
||||||
bool warnMissingOrderSymbol = true;
|
bool warnMissingOrderSymbol = true;
|
||||||
bool warnLocallyDefinedImported = true;
|
bool warnLocallyDefinedImported = true;
|
||||||
bool warnDebugInfoUnusable = true;
|
bool warnDebugInfoUnusable = true;
|
||||||
|
bool warnLongSectionNames = true;
|
||||||
bool incremental = true;
|
bool incremental = true;
|
||||||
bool integrityCheck = false;
|
bool integrityCheck = false;
|
||||||
bool killAt = false;
|
bool killAt = false;
|
||||||
|
|
|
@ -1188,6 +1188,8 @@ void LinkerDriver::link(ArrayRef<const char *> argsArr) {
|
||||||
config->warnDebugInfoUnusable = false;
|
config->warnDebugInfoUnusable = false;
|
||||||
else if (s == "4217")
|
else if (s == "4217")
|
||||||
config->warnLocallyDefinedImported = false;
|
config->warnLocallyDefinedImported = false;
|
||||||
|
else if (s == "longsections")
|
||||||
|
config->warnLongSectionNames = false;
|
||||||
// Other warning numbers are ignored.
|
// Other warning numbers are ignored.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1527,6 +1529,11 @@ void LinkerDriver::link(ArrayRef<const char *> argsArr) {
|
||||||
config->debugGHashes = debug == DebugKind::GHash;
|
config->debugGHashes = debug == DebugKind::GHash;
|
||||||
config->debugSymtab = debug == DebugKind::Symtab;
|
config->debugSymtab = debug == DebugKind::Symtab;
|
||||||
|
|
||||||
|
// Don't warn about long section names, such as .debug_info, for mingw or when
|
||||||
|
// -debug:dwarf is requested.
|
||||||
|
if (config->mingw || config->debugDwarf)
|
||||||
|
config->warnLongSectionNames = false;
|
||||||
|
|
||||||
config->mapFile = getMapFile(args);
|
config->mapFile = getMapFile(args);
|
||||||
|
|
||||||
if (config->incremental && args.hasArg(OPT_profile)) {
|
if (config->incremental && args.hasArg(OPT_profile)) {
|
||||||
|
|
|
@ -1148,6 +1148,11 @@ void Writer::createSymbolAndStringTable() {
|
||||||
continue;
|
continue;
|
||||||
if ((sec->header.Characteristics & IMAGE_SCN_MEM_DISCARDABLE) == 0)
|
if ((sec->header.Characteristics & IMAGE_SCN_MEM_DISCARDABLE) == 0)
|
||||||
continue;
|
continue;
|
||||||
|
if (config->warnLongSectionNames) {
|
||||||
|
warn("section name " + sec->name +
|
||||||
|
" is longer than 8 characters and will use a non-standard string "
|
||||||
|
"table");
|
||||||
|
}
|
||||||
sec->setStringTableOff(addEntryToStringTable(sec->name));
|
sec->setStringTableOff(addEntryToStringTable(sec->name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,18 @@
|
||||||
# RUN: yaml2obj < %s > %t.obj
|
# RUN: yaml2obj < %s > %t.obj
|
||||||
# RUN: lld-link /out:%t.exe /entry:main %t.obj
|
# RUN: lld-link /out:%t.exe /entry:main %t.obj 2>&1 | FileCheck %s --check-prefix=WARN
|
||||||
# RUN: llvm-readobj --sections %t.exe | FileCheck %s
|
# RUN: llvm-readobj --sections %t.exe | FileCheck %s
|
||||||
# RUN: lld-link /debug /out:%t2.exe /entry:main %t.obj
|
# RUN: lld-link /debug /out:%t2.exe /entry:main %t.obj 2>&1 | FileCheck %s --check-prefix=WARN
|
||||||
# RUN: llvm-readobj --sections %t2.exe | FileCheck %s
|
# RUN: llvm-readobj --sections %t2.exe | FileCheck %s
|
||||||
|
#
|
||||||
|
# No warnings in mingw mode or with ignore flag.
|
||||||
|
# RUN: lld-link /out:%t.exe /entry:main %t.obj /ignore:longsections 2>&1 | FileCheck %s --check-prefix=IGNORE --allow-empty
|
||||||
|
# RUN: lld-link /out:%t.exe /entry:main %t.obj -lldmingw 2>&1 | FileCheck %s --check-prefix=IGNORE --allow-empty
|
||||||
|
# RUN: lld-link /out:%t.exe /entry:main %t.obj -debug:dwarf 2>&1 | FileCheck %s --check-prefix=IGNORE --allow-empty
|
||||||
|
|
||||||
|
# WARN: warning: section name .data_long_section_name is longer than 8 characters and will use a non-standard string table
|
||||||
|
# WARN: warning: section name .text_long_section_name is longer than 8 characters and will use a non-standard string table
|
||||||
|
|
||||||
|
# IGNORE-NOT: warning:
|
||||||
|
|
||||||
# CHECK: Name: .eh_fram (
|
# CHECK: Name: .eh_fram (
|
||||||
# CHECK: Name: .data_long_section_name
|
# CHECK: Name: .data_long_section_name
|
||||||
|
|
Loading…
Reference in New Issue