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"? | |
956 | 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. | |
576 | nit: no else after return. | |
577 | If getDefaultDebugType is called by this line, I'd inline that function here. | |
938 | DebugArg -> A for consistency. | |
943 | 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 | ||
---|---|---|
573 | You probably should warn on unknown string. | |
576 | Please avoid using auto unless its actual type is obvious. | |
578 | StringSwitch has CaseLower, so you can use that instead of calling lower beforehand. | |
578 | Return early. | |
589 | Just return DebugKind::Full. | |
592 | Ditto | |
937–939 | I'd name DK Debug. We don't usually use acronym for variable names. |
Looks much better!
COFF/Driver.cpp | ||
---|---|---|
939 | It is better to initialize directly to a desired value here: bool ShouldCreatePDB = (Debug == DebugKind::Full || Debug == DebugKind::GHash); | |
941–942 | 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 | ||
---|---|---|
950 | 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 | ||
---|---|---|
546 | 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 | ||
---|---|---|
546 | 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 | ||
---|---|---|
546 | I tried to fix both of these problems in r365182. |
Why does the name contani "Generation"?