This fixes PR31824.
Details
Diff Detail
Event Timeline
COFF/Options.td | ||
---|---|---|
101–102 | Since they are lld-specific flags, I'd name -lld-whole-archive and -lld-no-whole-archive. |
COFF/Options.td | ||
---|---|---|
101–102 | I don't think you need to add lld-specific flags to support --whole-archive. Instead, you could implement support for the equivalent link.exe flag, /wholearchive. See also PR31824. |
COFF/Options.td | ||
---|---|---|
101–102 | @pcc - Oh, that probably makes sense - I hadn't seen that option before. Then the MinGW driver just needs to inject -wholearchive: before each library between --whole-archive and --no-whole-archive. Since the driver doesn't do file magic detection, it probably needs to only match this for *.a, *.lib and -lfoo entries, but that's probably fine for most sensible use cases. |
COFF/Options.td | ||
---|---|---|
101–102 | Right. I think you wouldn't even need to do the matching; MSVC link.exe allows /wholearchive to be used with object files, and we can do the same. |
Generally looking good.
Could you split this patch into two, one for COFF and one for MinGW?
COFF/Driver.cpp | ||
---|---|---|
135 | It's not new code, but can you write it in two lines? Symtab->addFile(make<ArchiveFile>(MBRef)); return; Because addFile returns void and this function returns void too, it is legal to write return Symtab->addFile(...), but this is still an odd feature of C++, and I believe we generally want to avoid this unless it's generated as instantiated templates. | |
137 | nit: add a blank line befor ethis line. | |
138 | Likewise, separate into two lines. | |
975 | Replacing WholeArchive with Args.hasArg(OPT_wholearchive_flag) might improve readability. | |
MinGW/Driver.cpp | ||
175 | I think I'd name this just Prefix as we generally prefer shorter variable names in lld. | |
183 | 80 cols (please run clang-format if you have installed it.) |
Sure, will repost with it split, and with your suggestions applied.
COFF/Driver.cpp | ||
---|---|---|
135 | Sure, I can fix that at the same time. |
Split the patch, moving the MinGW specific parts to a separate patch. Applied Rui's style suggestions.
COFF/Driver.cpp | ||
---|---|---|
229 | No, I can try to construct a test to figure out how it's supposed to behave. |
COFF/Driver.cpp | ||
---|---|---|
229 | I checked - link.exe doesn't apply the -wholearchive option to -defaultlib options, neither on the command line nor in directives. So I'll update the handling of the command line version of -defaultlib accordingly as well. | |
975 | So it seems, based on reading ArgList.h. Will push with this changed back to a bool WholeArchiveFlag variable, to avoid the O(N^2) complexity. |
It's not new code, but can you write it in two lines?
Because addFile returns void and this function returns void too, it is legal to write return Symtab->addFile(...), but this is still an odd feature of C++, and I believe we generally want to avoid this unless it's generated as instantiated templates.