Skip to content

Commit e6e615c

Browse files
authored
[LLD] [COFF] Rewrite handling of the /debug: option. NFC. (#75175)
Don't treat the options as unique enum items, but more as flags that can be composed, like the /opt: options. This still only processes the last option on the command line though, so the behaviour should still remain exactly as it was, in all corner cases.
1 parent 23e6e88 commit e6e615c

File tree

1 file changed

+42
-57
lines changed

1 file changed

+42
-57
lines changed

lld/COFF/Driver.cpp

Lines changed: 42 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -858,46 +858,6 @@ static std::string createResponseFile(const opt::InputArgList &args,
858858
return std::string(data.str());
859859
}
860860

861-
enum class DebugKind {
862-
Unknown,
863-
None,
864-
Full,
865-
FastLink,
866-
GHash,
867-
NoGHash,
868-
Dwarf,
869-
Symtab
870-
};
871-
872-
static DebugKind parseDebugKind(const opt::InputArgList &args) {
873-
auto *a = args.getLastArg(OPT_debug, OPT_debug_opt);
874-
if (!a)
875-
return DebugKind::None;
876-
if (a->getNumValues() == 0)
877-
return DebugKind::Full;
878-
879-
DebugKind debug = StringSwitch<DebugKind>(a->getValue())
880-
.CaseLower("none", DebugKind::None)
881-
.CaseLower("full", DebugKind::Full)
882-
.CaseLower("fastlink", DebugKind::FastLink)
883-
// LLD extensions
884-
.CaseLower("ghash", DebugKind::GHash)
885-
.CaseLower("noghash", DebugKind::NoGHash)
886-
.CaseLower("dwarf", DebugKind::Dwarf)
887-
.CaseLower("symtab", DebugKind::Symtab)
888-
.Default(DebugKind::Unknown);
889-
890-
if (debug == DebugKind::FastLink) {
891-
warn("/debug:fastlink unsupported; using /debug:full");
892-
return DebugKind::Full;
893-
}
894-
if (debug == DebugKind::Unknown) {
895-
error("/debug: unknown option: " + Twine(a->getValue()));
896-
return DebugKind::None;
897-
}
898-
return debug;
899-
}
900-
901861
static unsigned parseDebugTypes(const opt::InputArgList &args) {
902862
unsigned debugTypes = static_cast<unsigned>(DebugType::None);
903863

@@ -1647,13 +1607,47 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
16471607
if (args.hasArg(OPT_force, OPT_force_multipleres))
16481608
config->forceMultipleRes = true;
16491609

1610+
// Don't warn about long section names, such as .debug_info, for mingw (or
1611+
// when -debug:dwarf is requested, handled below).
1612+
if (config->mingw)
1613+
config->warnLongSectionNames = false;
1614+
1615+
bool doGC = true;
1616+
16501617
// Handle /debug
1651-
DebugKind debug = parseDebugKind(args);
1652-
if (debug == DebugKind::Full || debug == DebugKind::Dwarf ||
1653-
debug == DebugKind::GHash || debug == DebugKind::NoGHash) {
1654-
config->debug = true;
1655-
config->incremental = true;
1656-
config->includeDwarfChunks = true;
1618+
bool shouldCreatePDB = false;
1619+
if (auto *arg = args.getLastArg(OPT_debug, OPT_debug_opt)) {
1620+
std::string s;
1621+
if (arg->getOption().getID() == OPT_debug)
1622+
s = "full";
1623+
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);
1650+
}
16571651
}
16581652

16591653
// Handle /demangle
@@ -1673,9 +1667,6 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
16731667
config->driverUponly || config->driverWdm || args.hasArg(OPT_driver);
16741668

16751669
// Handle /pdb
1676-
bool shouldCreatePDB =
1677-
(debug == DebugKind::Full || debug == DebugKind::GHash ||
1678-
debug == DebugKind::NoGHash);
16791670
if (shouldCreatePDB) {
16801671
if (auto *arg = args.getLastArg(OPT_pdb))
16811672
config->pdbPath = arg->getValue();
@@ -1838,8 +1829,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
18381829

18391830
config->noimplib = args.hasArg(OPT_noimplib);
18401831

1832+
if (args.hasArg(OPT_profile))
1833+
doGC = true;
18411834
// Handle /opt.
1842-
bool doGC = debug == DebugKind::None || args.hasArg(OPT_profile);
18431835
std::optional<ICFLevel> icfLevel;
18441836
if (args.hasArg(OPT_profile))
18451837
icfLevel = ICFLevel::None;
@@ -2030,8 +2022,6 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
20302022
parseSwaprun(arg->getValue());
20312023
config->terminalServerAware =
20322024
!config->dll && args.hasFlag(OPT_tsaware, OPT_tsaware_no, true);
2033-
config->debugGHashes = debug == DebugKind::GHash || debug == DebugKind::Full;
2034-
config->writeSymtab = debug == DebugKind::Dwarf || debug == DebugKind::Symtab;
20352025
config->autoImport =
20362026
args.hasFlag(OPT_auto_import, OPT_auto_import_no, config->mingw);
20372027
config->pseudoRelocs = args.hasFlag(
@@ -2048,11 +2038,6 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
20482038
if (args.hasFlag(OPT_inferasanlibs, OPT_inferasanlibs_no, false))
20492039
warn("ignoring '/inferasanlibs', this flag is not supported");
20502040

2051-
// Don't warn about long section names, such as .debug_info, for mingw or
2052-
// when -debug:dwarf is requested.
2053-
if (config->mingw || debug == DebugKind::Dwarf)
2054-
config->warnLongSectionNames = false;
2055-
20562041
if (config->incremental && args.hasArg(OPT_profile)) {
20572042
warn("ignoring '/incremental' due to '/profile' specification");
20582043
config->incremental = false;

0 commit comments

Comments
 (0)