Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LLD flags for MinGW #75483

Merged
merged 1 commit into from
Aug 15, 2020
Merged

Add LLD flags for MinGW #75483

merged 1 commit into from
Aug 15, 2020

Conversation

mati865
Copy link
Contributor

@mati865 mati865 commented Aug 13, 2020

Tested locally and this now works:

  • RUSTFLAGS="-Zlink-self-contained=yes -Clinker=rust-lld" cargo b
  • RUSTFLAGS="-Zlink-self-contained=no -Clinker=rust-lld -Zpre-link-arg=-Ld:/msys64/mingw64/x86_64-w64-mingw32/lib -Zpre-link-arg=-Ld:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/10.2.0 -Zpre-link-arg=crt2.o" cargo b

This is "harmless" part of the changes to make possible linking with bare LLD with windows-gnu target. More debatable changes should follow in next PRs soon.

@rust-highfive
Copy link
Collaborator

r? @matthewjasper

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 13, 2020
@petrochenkov
Copy link
Contributor

r? @petrochenkov

@mati865
Copy link
Contributor Author

mati865 commented Aug 13, 2020

FTR afb3aeb is preliminary commit to enable LLD by default with self-contained mode but it depends on adding heuristic to crt_objects_fallback which in turn depends on rust-lang/compiler-team#343

@petrochenkov
Copy link
Contributor

So, we don't generally use linker directly for non bare-metal targets given the state of #11937, but using it in self-contained mode only and avoiding shipping ancient gcc is a good motivation to make an exception, especially if the replacement is fresh rust-lld that we are already shipping.

@petrochenkov
Copy link
Contributor

Is lld generally usable for mingw targets yet?
Issues like #68647 still exist, so it will likely fail to link a random sizable project.

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Aug 15, 2020

📌 Commit c75f7f9 has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 15, 2020
@bors
Copy link
Contributor

bors commented Aug 15, 2020

⌛ Testing commit c75f7f9 with merge e019be06c2a36f6bbb0456fb9dce423d797cc859...

@petrochenkov
Copy link
Contributor

@bors r-
Forgot to check the options not duplicated for LLD.
--nxcompat is missing (in windows_gnu_base.rs).

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 15, 2020
@mati865
Copy link
Contributor Author

mati865 commented Aug 15, 2020

@petrochenkov #68647 is fixed in MSYS2 MinGW LLD packages and in upcoming LLVM 11 which Rust is hopefully going to use soon: #73526

Is lld generally usable for mingw targets yet?

At least when it comes to 64-bit LLD is generally usable for C/C++ code since few releases, for Rust since #72049 (but requires defining WINAPI_NO_BUNDLED_LIBRARIES until retep998/winapi-rs#935 is resolved).
I've seen 32-bit LLD 10 to crash when linking LLVM with it.

So, we don't generally use linker directly for non bare-metal targets given the state of #11937

TBH calling linker directly is basically the same as calling $CC with -nostdlib which Rust did for long time with MinGW. To have it working without issues Rust would have to get paths by calling gcc --print-file-name crt2.o and gcc --print-file-name libgcc.a or similar.
I do agree it's easier to just pass -fuse-ld=lld.

--nxcompat is missing (in windows_gnu_base.rs).

LLD silently ignores --nxcompat since it's always enabled.

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Aug 15, 2020

📌 Commit c75f7f9 has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 15, 2020
@bors
Copy link
Contributor

bors commented Aug 15, 2020

⌛ Testing commit c75f7f9 with merge 5addb13...

@bors
Copy link
Contributor

bors commented Aug 15, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: petrochenkov
Pushing 5addb13 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 15, 2020
@bors bors merged commit 5addb13 into rust-lang:master Aug 15, 2020
@mati865 mati865 deleted the mingw-lld-flags branch August 15, 2020 18:33
@cuviper cuviper added this to the 1.47.0 milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants