Implement final argument precedence if multiple /debug arguments are passed on the command-line to match expected link.exe behavior. Support /debug:none and emit warning for /debug:fastlink with automatic fallback to /debug:full. Emit error if last /debug:option is unknown.
Details
Diff Detail
- Repository
- rLLD LLVM Linker
Event Timeline
This code was written when we supported only /debug and /debug:dwarf. At that time handling them as two separate options was a reasonable design. Now, we have /debug and /debug:{full,ghash,dwarf,symtab}, so I believe it's time to handle this just like other options that take a value after colon.
COFF/Driver.cpp | ||
---|---|---|
511 | Why does the name contani "Generation"? | |
946 | It feels more complicated than before. I believe this piece of code can be written in a more flat style with less nesting. Maybe you could just dispatch based on a /debug value like this: StringRef S = Args.getLastArg(OPT_debug, OPT_debug_opt)) if (S == "full") { Config->Debug = true; Config->Incremental = true; ShouldCreatePDB = true; ... } else if (S == "dwarf") { Config->Debug = true; Config->DebugTypes = DWARF; ... } else if ... |
Renamed DebugGeneration enum (name was based on MSDN description of /debug argument) to DebugKind. Flattened the argument handling code to be a little clearer.
COFF/Driver.cpp | ||
---|---|---|
521 | Let's report an error inside this function and return a dummy kind (e.g. DebugKind::None) for an unknown value, so that the caller doesn't have to care about the error condition. | |
567 | nit: no else after return. | |
568 | If getDefaultDebugType is called by this line, I'd inline that function here. | |
929 | DebugArg -> A for consistency. | |
934 | Let's do this inside parseDebugKind. | |
COFF/Options.td | ||
88 | Since this is the only place where you are using POpt, I wouldn't define that multiclass. Instead, I'd jsut define debug and debug_opt right here. |
Moved/inlined parsing and diagnostic code into the specialized parse functions to (hopefully) simplify the calls in LinkerDriver::link().
COFF/Driver.cpp | ||
---|---|---|
520 | Please avoid using auto unless its actual type is obvious. | |
522 | StringSwitch has CaseLower, so you can use that instead of calling lower beforehand. | |
533 | Just return DebugKind::Full. | |
536 | Ditto | |
547 | You probably should warn on unknown string. | |
552 | Return early. | |
928 | I'd name DK Debug. We don't usually use acronym for variable names. |
Looks much better!
COFF/Driver.cpp | ||
---|---|---|
930 | It is better to initialize directly to a desired value here: bool ShouldCreatePDB = (Debug == DebugKind::Full || Debug == DebugKind::GHash); | |
935–936 | Do you really have to call this function only when a debug flag is given? It looks to me that it is safe to do this unconditionally. |
Updated patch with ruiu's suggestions. Also added a test for the warning emitted when an unknown /debugtype option is used.
LGTM
COFF/Driver.cpp | ||
---|---|---|
940 | If ShouldCreatePDB is used only once, remove the variable and directly write the boolean expression in this if. |
It would be great if we could land this soon-ish. I have a lot of people complaining that lld-link rejects /DEBUG:FASTLINK when using the VS extension. Is there any work left to be done or can we land this?
I committed this as r342894 but for some reason the review didn't complete. Apologies, the last LLVM commits I did were pre-phabricator so it seems I messed up somewhere. Any pointers appreciated.
Ahh I see. You need to say "Differential Revision:
https://reviews.llvm.org/D50404" in the commit message. just the URL is
not sufficient to trigger the magic auto-close.
COFF/Driver.cpp | ||
---|---|---|
545 | getSpelling() returns the spelling of the name of the option, but not its values. For /debugtype:pdata, it returns "/debugtype:" for example. You want getValue(), not getSpelling(), here. The tests for /debugtype: aren't very good. invalid-debug-type.test checks that /debugtype:invalid produces a warning. It does: Types contains the string /debugtype: after the split, which counts as invalid and produces the warning.pdb-none.test passes /debugtype:pdata but that again just has /debugtype: in Types and produces the same warning, but the test doesn't use /WX or has a CHECK-NOT for it, and it doesn't check for the effect of pdata. I.e. the /debugtype: switch hasn't been working since this commit, and apparently nobody noticed. |
COFF/Driver.cpp | ||
---|---|---|
545 | Also, what's advertised as /*KeepEmpty=*/ here is actually the MaxSplit parameter; KeepEmpty comes after it. I suppose we don't build lld with -Wdocumentation anywhere? This means this flag is never split on ,s. (This bit isn't a new bug in this change.) |
COFF/Driver.cpp | ||
---|---|---|
545 | I tried to fix both of these problems in r365182. |
Why does the name contani "Generation"?