Skip to content

Commit efe017f

Browse files
authored
[LLD] [COFF] Parse all /debug: options, like /opt: (#75178)
Most option handling is like it was before; the last /debug: option takes effect. However, the options /debug:dwarf or /debug:symtab don't reset all flags into the specific behaviour they chose before - e.g. if an earlier option enables writing a PDB, a later /debug:dwarf or /debug:symtab doesn't disable that. This allows combining these options with options for controlling PDB writing, for finetuning what is done.
1 parent e6e615c commit efe017f

File tree

3 files changed

+50
-29
lines changed

3 files changed

+50
-29
lines changed

lld/COFF/Driver.cpp

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,37 +1616,48 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
16161616

16171617
// Handle /debug
16181618
bool shouldCreatePDB = false;
1619-
if (auto *arg = args.getLastArg(OPT_debug, OPT_debug_opt)) {
1620-
std::string s;
1619+
for (auto *arg : args.filtered(OPT_debug, OPT_debug_opt)) {
1620+
std::string str;
16211621
if (arg->getOption().getID() == OPT_debug)
1622-
s = "full";
1622+
str = "full";
16231623
else
1624-
s = StringRef(arg->getValue()).lower();
1625-
if (s == "fastlink") {
1626-
warn("/debug:fastlink unsupported; using /debug:full");
1627-
s = "full";
1628-
}
1629-
if (s == "none") {
1630-
} else if (s == "full" || s == "ghash" || s == "noghash") {
1631-
config->debug = true;
1632-
config->incremental = true;
1633-
config->includeDwarfChunks = true;
1634-
if (s == "full" || s == "ghash")
1635-
config->debugGHashes = true;
1636-
shouldCreatePDB = true;
1637-
doGC = false;
1638-
} else if (s == "dwarf") {
1639-
config->debug = true;
1640-
config->incremental = true;
1641-
config->includeDwarfChunks = true;
1642-
config->writeSymtab = true;
1643-
config->warnLongSectionNames = false;
1644-
doGC = false;
1645-
} else if (s == "symtab") {
1646-
config->writeSymtab = true;
1647-
doGC = false;
1648-
} else {
1649-
error("/debug: unknown option: " + s);
1624+
str = StringRef(arg->getValue()).lower();
1625+
SmallVector<StringRef, 1> vec;
1626+
StringRef(str).split(vec, ',');
1627+
for (StringRef s : vec) {
1628+
if (s == "fastlink") {
1629+
warn("/debug:fastlink unsupported; using /debug:full");
1630+
s = "full";
1631+
}
1632+
if (s == "none") {
1633+
config->debug = false;
1634+
config->incremental = false;
1635+
config->includeDwarfChunks = false;
1636+
config->debugGHashes = false;
1637+
config->writeSymtab = false;
1638+
shouldCreatePDB = false;
1639+
doGC = true;
1640+
} else if (s == "full" || s == "ghash" || s == "noghash") {
1641+
config->debug = true;
1642+
config->incremental = true;
1643+
config->includeDwarfChunks = true;
1644+
if (s == "full" || s == "ghash")
1645+
config->debugGHashes = true;
1646+
shouldCreatePDB = true;
1647+
doGC = false;
1648+
} else if (s == "dwarf") {
1649+
config->debug = true;
1650+
config->incremental = true;
1651+
config->includeDwarfChunks = true;
1652+
config->writeSymtab = true;
1653+
config->warnLongSectionNames = false;
1654+
doGC = false;
1655+
} else if (s == "symtab") {
1656+
config->writeSymtab = true;
1657+
doGC = false;
1658+
} else {
1659+
error("/debug: unknown option: " + s);
1660+
}
16501661
}
16511662
}
16521663

lld/test/COFF/debug-dwarf.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,11 @@
1717
# RUN: rm -f %t.pdb
1818
# RUN: lld-link /debug:dwarf /pdb:%t.pdb /entry:main /out:%t.exe %p/Inputs/ret42.obj
1919
# RUN: not ls %t.pdb
20+
21+
# Check that /debug /debug:dwarf or /debug:full,dwarf creates %t.pdb.
22+
# RUN: rm -f %t.pdb
23+
# RUN: lld-link /debug /debug:dwarf /entry:main /out:%t.exe %p/Inputs/ret42.obj
24+
# RUN: ls %t.pdb
25+
# RUN: rm -f %t.pdb
26+
# RUN: lld-link /debug:full,dwarf /entry:main /out:%t.exe %p/Inputs/ret42.obj
27+
# RUN: ls %t.pdb

lld/test/COFF/symtab.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# RUN: llvm-readobj --symbols %t.exe | FileCheck %s
66
# RUN: lld-link /debug:symtab /opt:noref /out:%t.exe /entry:main %t.obj %p/Inputs/std64.lib
77
# RUN: llvm-readobj --symbols %t.exe | FileCheck %s
8+
# RUN: lld-link /debug:full,symtab /opt:noref /out:%t.exe /entry:main %t.obj %p/Inputs/std64.lib
9+
# RUN: llvm-readobj --symbols %t.exe | FileCheck %s
810

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

0 commit comments

Comments
 (0)