-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Static linking without LTO on Linux does not remove unused code #39270
Comments
I can repro this on CentOS 6. We're passing this to
Could it be that CentOS 6's ld doesn't actually support |
I'm running on Debian/unstable with GNU ld 2.27.90.20170118 on x86-64, which definitely supports --gc-sections |
If we linked these as usual then we'd have all these exported symbols, but we tell the linker to use a version script which should hide all the symbols in the standard library. I think it does that at least, but all the others are still exported... somehow. I'm not super familiar with all the various levels of visibility. |
cc @michaelwoerister maybe related to #38117? |
It's not only about having the symbols exported, but also about having the code corresponding to those symbols in the binaries at all although none of them are used |
Yes my assumption is that the linker sees that we're not exporting a symbol and it's in its own section, so it eliminates it. Apparently that's not happening though. |
Does this also happen with the nightly compiler? |
@michaelwoerister aha, looks like no! I think I misinterpreted results from earlier... In that case I think this is dealt with already! |
At least the problem description sounds a lot like what #38117 was meant to solve |
Yes, with nightly this problem does not exist anymore. Thanks for fixing this before I even reported it :) |
When linking a minimal cdylib on Linux with Rust 1.14.0, lots of code from libstd is included that should not be. According to @sfackler, on MacOS all that code is not included.
Enabling LTO will get it removed on Linux, while it's not required on MacOS.
When compiling a mini-cdylib (see below), you can e.g. find functions for receiving packets from UDP sockets:
See following mini-cdylib for reproducing
src/lib.rs
Cargo.toml
The text was updated successfully, but these errors were encountered: