This is an archive of the discontinued LLVM Phabricator instance.

[lld][MinGW] Introduce aliases for -Bdynamic and -Bstatic
ClosedPublic

Authored by zero9178 on May 17 2021, 10:08 AM.

Details

Summary

Besides -Bdynamic and -Bstatic, ld documents additional aliases for both of these options. Instead of -Bstatic, one may write -dn, -non_shared or -static. Instead of -Bdynamic one may write -dy or -call_shared. Source: https://sourceware.org/binutils/docs-2.36/ld/Options.html

This patch adds those aliases to the MinGW driver of lld for the sake of ld compatibility.

Encountered this case while compiling a static Qt 6.1 distribution and got build failures as -static was passed directly to the linker, instead of through the compiler driver.

Diff Detail

Event Timeline

zero9178 created this revision.May 17 2021, 10:08 AM
zero9178 requested review of this revision.May 17 2021, 10:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 17 2021, 10:08 AM
mstorsjo accepted this revision.May 17 2021, 12:53 PM

LGTM

Interesting, I wasn't aware of the others, other than -static.

Is this use of -static (which I'd presume is in the form of -Wl,-static) somewhere in the Qt source/build system itself (which would surprise me as I build Qt quite a lot, but I haven't tested building 6.x with cmake statically), or in a third party build script?

lld/MinGW/Options.td
125

Nit: I try to keep these alphabetical, especially as long as the existing ones are. And also, keep spaces after commas.

This revision is now accepted and ready to land.May 17 2021, 12:53 PM
zero9178 marked an inline comment as done.May 17 2021, 1:10 PM

LGTM

Interesting, I wasn't aware of the others, other than -static.

Is this use of -static (which I'd presume is in the form of -Wl,-static) somewhere in the Qt source/build system itself (which would surprise me as I build Qt quite a lot, but I haven't tested building 6.x with cmake statically), or in a third party build script?

I only first encountered it when compiling Qt 6.1 as well (I haven't checked Qt 6.0, assuming it's there too). The command is actually of the form -Xlinker -static. I just quickly ran a grep of it over the output of ninja -t commands and as far as I can tell it's added for every executable built by Qt.
Their build passes it directly to the linker here: https://github.com/qt/qtbase/blob/a4618c020d3923eb6c8c55115c49d7c9f00b3034/cmake/QtTargetHelpers.cmake#L196

lld/MinGW/Options.td
125

Ahh that makes sense. I shall commit with:

// Alias
+def alias_Bdynamic_call_shared: Flag<["-"], "call_shared">, Alias<Bdynamic>;
+def alias_Bdynamic_dy: Flag<["-"], "dy">, Alias<Bdynamic>;
+def alias_Bstatic_dn: Flag<["-"], "dn">, Alias<Bstatic>;
+def alias_Bstatic_non_shared: Flag<["-"], "non_shared">, Alias<Bstatic>;
+def alias_Bstatic_static: Flag<["-"], "static">, Alias<Bstatic>;
 def alias_entry_e: JoinedOrSeparate<["-"], "e">, Alias<entry>;
 def alias_strip_s: Flag<["-"], "s">, Alias<strip_all>;
 def alias_strip_S: Flag<["-"], "S">, Alias<strip_debug>;
 def alias_undefined_u: JoinedOrSeparate<["-"], "u">, Alias<undefined>;

then.

This revision was automatically updated to reflect the committed changes.
zero9178 marked an inline comment as done.

I only first encountered it when compiling Qt 6.1 as well (I haven't checked Qt 6.0, assuming it's there too). The command is actually of the form -Xlinker -static. I just quickly ran a grep of it over the output of ninja -t commands and as far as I can tell it's added for every executable built by Qt.
Their build passes it directly to the linker here: https://github.com/qt/qtbase/blob/a4618c020d3923eb6c8c55115c49d7c9f00b3034/cmake/QtTargetHelpers.cmake#L196

Ah, thanks! Ok so apparently that would hit everybody building it statically with the new cmake build system.

lld/MinGW/Options.td
125

That looks good, thanks!