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

rust: Add a -C default-linker-libraries option #54675

Merged
merged 1 commit into from
Oct 1, 2018

Conversation

alexcrichton
Copy link
Member

This commit adds a new codegen option for the compiler which disables
rustc's passing of -nodefaultlibs by default on relevant platforms.
Sometimes Rust is linked with C code which fails to link with
-nodefaultlibs and is unnecessarily onerous to get linking correctly
with -nodefaultlibs.

An example of this is that when you compile C code with sanitizers and
then pass -fsanitize=address to the linker, it's incompatible with
-nodefaultlibs also being passed to the linker.

In these situations it's easiest to turn off Rust's default passing of
-nodefaultlibs, which was more ideological to start with than
anything! Preserving the default is somewhat important but having this
be opt-in shouldn't cause any breakage.

Closes #54237

This commit adds a new codegen option for the compiler which disables
rustc's passing of `-nodefaultlibs` by default on relevant platforms.
Sometimes Rust is linked with C code which fails to link with
`-nodefaultlibs` and is unnecessarily onerous to get linking correctly
with `-nodefaultlibs`.

An example of this is that when you compile C code with sanitizers and
then pass `-fsanitize=address` to the linker, it's incompatible with
`-nodefaultlibs` also being passed to the linker.

In these situations it's easiest to turn off Rust's default passing of
`-nodefaultlibs`, which was more ideological to start with than
anything! Preserving the default is somewhat important but having this
be opt-in shouldn't cause any breakage.

Closes rust-lang#54237
@rust-highfive
Copy link
Collaborator

r? @varkor

(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 Sep 29, 2018
@varkor
Copy link
Member

varkor commented Sep 30, 2018

@bors r+

@bors
Copy link
Contributor

bors commented Sep 30, 2018

📌 Commit 6f4b378 has been approved by varkor

@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 Sep 30, 2018
@bors
Copy link
Contributor

bors commented Oct 1, 2018

⌛ Testing commit 6f4b378 with merge f55129d...

bors added a commit that referenced this pull request Oct 1, 2018
rust: Add a `-C default-linker-libraries` option

This commit adds a new codegen option for the compiler which disables
rustc's passing of `-nodefaultlibs` by default on relevant platforms.
Sometimes Rust is linked with C code which fails to link with
`-nodefaultlibs` and is unnecessarily onerous to get linking correctly
with `-nodefaultlibs`.

An example of this is that when you compile C code with sanitizers and
then pass `-fsanitize=address` to the linker, it's incompatible with
`-nodefaultlibs` also being passed to the linker.

In these situations it's easiest to turn off Rust's default passing of
`-nodefaultlibs`, which was more ideological to start with than
anything! Preserving the default is somewhat important but having this
be opt-in shouldn't cause any breakage.

Closes #54237
@bors
Copy link
Contributor

bors commented Oct 1, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: varkor
Pushing f55129d to master...

@xclaesse
Copy link

I found this PR while investiguating a bug reported in Meson: mesonbuild/meson#12877. I think using -C default-linker-libraries in Meson would fix this problem, but why does rustc use -nodefaultlibs in the first place? It looks like it's adding default libs manually anyway, we can even query them with rustc --print native-static-libs: -lgcc_s -lutil -lrt -lpthread -lm -ldl -lc. The problem with rustc injecting default libraries in the linker command is order now matters, and Meson has no way to tell rustc "put your native libs last".

@Fabian-Gruenbichler
Copy link
Contributor

some background is contained here: #11937

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

Option to disable -nodefaultlibs to the linker
6 participants