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

Various Rumprun fixes #200

Merged
merged 4 commits into from
Mar 1, 2016
Merged

Conversation

gandro
Copy link
Contributor

@gandro gandro commented Feb 27, 2016

This moves some pthread_*_np definitions that ended up in the wrong BSD modules. Additionally, it avoids linking against libc and librt on Rumprun when building libstd. librt is not available on Rumprun, and libc is pulled in automatically by Rumpruns own linker.

Because conditional compilation for Rumprun is using the unstable target_vendor attribute, I'm relying on the fact that #[cfg] evaluation is short-circuiting regarding feature gate checks.I had to change the cfg_if! macro to support this. Now, if the if #[cfg(..)] clause is true, then the else if #[cfg(..)] clause will not be evaluated, allowing me to use unstable attributes for libstd builds.

@@ -143,6 +143,9 @@ cfg_if! {
} else if #[cfg(target_os = "emscripten")] {
#[link(name = "c")]
extern {}
} else if #[cfg(all(target_vendor = "rumprun", target_os = "netbsd"))] {
#[link(name = "m")]
Copy link
Member

Choose a reason for hiding this comment

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

We pass a few flags to the linker to say that default system libraries shouldn't be included by default, so shouldn't we link both libc and libm like the block just below this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean -nodefaultlibs? That flag is actually not used in Rust's Rumprun target, since the Rumprun linker always pulls its own libc. So not passing -lc explicitly should be fine.

The reason why I removed the explicit -lc is however due to a bug in binutils (as invoked by the Rumprun linker). I haven't really been able to track it down, but for some reason it crashes with an assertion failure if -lc is passed to ld twice (once explicitly by Rust, and once by Rumprun's linker).

I can try to get a workaround in the Rumprun linker, so it removes the superfluous -lc passed to it, but opted for removing it here, I hope that's okay. Having a redundant -lc is not a problem when linking C programs, so I'm not really sure what's going on here.

Copy link
Member

Choose a reason for hiding this comment

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

Whoa, weird! If we're triggering bugs I guess it seems fine to leave this here. Could you add some comments to this effect though?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rebased and added a comment to clarify why we omit -lc. Note that while I only observed the assertion failure when linking Rust, I don't think the crash is Rust's fault. It probably is caused by Rumprun's use of ld -r which has triggered bugs in binutils before, see rumpkernel/rumprun-packages#19

@gandro gandro force-pushed the various-rumprun-fixes branch from fef0ad9 to a46ae76 Compare February 29, 2016 18:31
Since #[cfg] attributes are short-circuting, cfg_if! should not change
the order in which the predicates are listed. This enables the use of
unstable cfg attributes in cfg_if!, which is useful when building libstd.
The Rumprun linker wrapper already includes -lc when linking. Passing it
twice unfortunately causes binutils to crash with an assertion failure.

Rumprun does currently not provide librt.
These functions were never available on NetBSD, they belong to
OpenBSD/Bitrig.
@gandro gandro force-pushed the various-rumprun-fixes branch from a46ae76 to 35420e2 Compare February 29, 2016 18:33
@alexcrichton alexcrichton merged commit 35420e2 into rust-lang:master Mar 1, 2016
danielverkamp pushed a commit to danielverkamp/libc that referenced this pull request Apr 28, 2020
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.

2 participants