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 support for building with static glibc #1899

Merged
merged 3 commits into from Sep 30, 2020

Conversation

joshtriplett
Copy link
Member

This will need corresponding changes in rust-lang/rust to activate, but
this will make it possible to make those changes.

Note that despite the apparent redundancy in config directives, the link
directives cannot be simplified any further. Attempting to factor out
the checks for target_feature = "crt-static" does not work.

@rust-highfive
Copy link

r? @JohnTitor

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

@joshtriplett
Copy link
Member Author

Still WIP, need to do something similar for the link lines for dl and util buried inside Linux-specific code.

@joshtriplett
Copy link
Member Author

OK, this should work now.

@joshtriplett
Copy link
Member Author

Update: had to reverse the order of the libraries so that symbol resolution worked correctly when linking statically.

@joshtriplett
Copy link
Member Author

Both of the failures seem entirely unrelated to this PR.

@joshtriplett
Copy link
Member Author

Also, as far as I can tell, this change (together with some corresponding changes in rust-lang/rust) will noticeably speed up linking of all Rust binaries on linux-gnu targets, by reducing the amount of work the linker needs to do, since it won't need to process some libraries twice. I've tested this by manually re-invoking the linker and timing it, and overall, eliminating repeated libraries seems to provide a ~5% improvement in link time for a "hello world" Rust program.

This will need corresponding changes in rust-lang/rust to activate, but
this will make it possible to make those changes.

Note that despite the apparent redundancy in config directives, the link
directives cannot be simplified any further. Attempting to factor out
the checks for `target_feature = "crt-static"` does not work.
The two library blocks that specify `#[link(name = "util")]` do not
actually reference any functions in `libutil`; the functions that do use
`libutil` don't have any reference to it. And having two library blocks
specify it results in two separate inclusions of `-lutil` on the linker
command line. Move the link lines up to `src/unix/mod.rs`, making it
easier to see all the libraries `libc` links to.

This also makes `libutil` respect `target-feature=+crt-static`.
Move the link line for `libdl` up to `src/unix/mod.rs`, making it easier
to see all the libraries `libc` links to.

This also makes `libdl` respect `target-feature=+crt-static`.
@JohnTitor
Copy link
Member

Thanks for the work and sorry for the delay! Looks great to me, let's re-trigger CI to make sure it.

@JohnTitor JohnTitor closed this Sep 30, 2020
@JohnTitor JohnTitor reopened this Sep 30, 2020
Copy link
Member

@JohnTitor JohnTitor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failure is due to timeout and it was green previously so I'd ignore here. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants