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

Option to disable -nodefaultlibs to the linker #54237

Closed
alexcrichton opened this issue Sep 14, 2018 · 1 comment · Fixed by #54675
Closed

Option to disable -nodefaultlibs to the linker #54237

alexcrichton opened this issue Sep 14, 2018 · 1 comment · Fixed by #54675
Labels
A-linkage Area: linking into static, shared libraries and binaries

Comments

@alexcrichton
Copy link
Member

Currently the compiler unconditionally passes -nodefaultlibs (or the platform equivalent) to the linker. Unfortunately though this actually causes linking to fail in some circumstances. Some investigation has shown that when compiled with -fsanitize=address this has been seen to cause problems and cause link errors.

While there may be more bugs to fix here on various sides, we should have an option to disable passing this flag!

@Earlz
Copy link

Earlz commented Sep 14, 2018

I literally just ran into this as well, though I assumed it was due to me using no_std.

@memoryruins memoryruins added the A-linkage Area: linking into static, shared libraries and binaries label Sep 15, 2018
alexcrichton added a commit to alexcrichton/rust that referenced this issue Sep 29, 2018
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
bors added a commit that referenced this issue 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants