This is an archive of the discontinued LLVM Phabricator instance.

[lld-link] Generalize handling of /debug and /debug:{none,full,fastlink,ghash,symtab}
ClosedPublic

Authored by lantictac on Aug 7 2018, 12:45 PM.

Details

Summary

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.

Diff Detail

Event Timeline

lantictac created this revision.Aug 7 2018, 12:45 PM
ruiu added a comment.Aug 7 2018, 12:53 PM

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.

lantictac updated this revision to Diff 160236.Aug 11 2018, 3:10 AM
lantictac retitled this revision from [lld-link] Support /DEBUG:NONE to [lld-link] Generalize handling of /debug and /debug:{none,full,fastlink,ghash,symtab}.
lantictac edited the summary of this revision. (Show Details)

Generalized /debug handling based on suggestion from ruiu.

ruiu added inline comments.Aug 28 2018, 11:58 PM
COFF/Driver.cpp
500

Why does the name contani "Generation"?

864

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 ...
lantictac updated this revision to Diff 164052.Sep 5 2018, 9:13 AM

Renamed DebugGeneration enum (name was based on MSDN description of /debug argument) to DebugKind. Flattened the argument handling code to be a little clearer.

lantictac added inline comments.Sep 5 2018, 9:15 AM
COFF/Driver.cpp
500

This was based on the MSDN docs as DebugType was already taken. I've changed to DebugKind in the hope it makes a little more sense.

864

Agreed. I've attempted to flatten the code a little in the latest patch.

ruiu added inline comments.Sep 12 2018, 8:45 AM
COFF/Driver.cpp
510

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.

547

nit: no else after return.

548

If getDefaultDebugType is called by this line, I'd inline that function here.

864

DebugArg -> A for consistency.

869

Let's do this inside parseDebugKind.

COFF/Options.td
93

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.

lantictac updated this revision to Diff 166303.Sep 20 2018, 8:56 AM

Moved/inlined parsing and diagnostic code into the specialized parse functions to (hopefully) simplify the calls in LinkerDriver::link().

lantictac marked 6 inline comments as done.Sep 20 2018, 8:57 AM
ruiu added inline comments.Sep 20 2018, 9:07 AM
COFF/Driver.cpp
539

Please avoid using auto unless its actual type is obvious.

541

StringSwitch has CaseLower, so you can use that instead of calling lower beforehand.

544

You probably should warn on unknown string.

549

Return early.

552

Just return DebugKind::Full.

555

Ditto

863–864

I'd name DK Debug. We don't usually use acronym for variable names.

Updated patch based on suggestions from ruiu

ruiu added a comment.Sep 20 2018, 10:09 AM

Looks much better!

COFF/Driver.cpp
863–864

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.

865

It is better to initialize directly to a desired value here:

bool ShouldCreatePDB = (Debug == DebugKind::Full || Debug == DebugKind::GHash);
lantictac updated this revision to Diff 166365.Sep 20 2018, 2:56 PM

Updated patch with ruiu's suggestions. Also added a test for the warning emitted when an unknown /debugtype option is used.

ruiu accepted this revision.Sep 20 2018, 3:03 PM

LGTM

COFF/Driver.cpp
863–864

If ShouldCreatePDB is used only once, remove the variable and directly write the boolean expression in this if.

This revision is now accepted and ready to land.Sep 20 2018, 3:03 PM

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.

Thanks for the clarification. Is there any way to manually close the review?

zturner closed this revision.Oct 2 2018, 12:44 PM
thakis added a subscriber: thakis.Jul 4 2019, 2:01 PM
thakis added inline comments.
COFF/Driver.cpp
557

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.

Herald added a project: Restricted Project. · View Herald TranscriptJul 4 2019, 2:01 PM
thakis added inline comments.Jul 4 2019, 2:14 PM
COFF/Driver.cpp
557

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.)

thakis added inline comments.Jul 5 2019, 4:28 AM
COFF/Driver.cpp
557

I tried to fix both of these problems in r365182.