-
Notifications
You must be signed in to change notification settings - Fork 13k
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
relocation-model=dynamic-no-pic passes -pie
to ld
#35061
Comments
|
I did a bit of reading and here's what I figured out, please correct me if any of this is wrong. Linkers are new to me! Rust builds position independent executables by default on platforms that support it. These platforms have a relocation model of pic in their target config. The code @jvns linked is what sets that linker option, except if it's disallowed by The correct solution to this is to add a |
Hi, I am having the same issue. I am trying to link against non-position-independent C library, build process ends without error but results returned by Rust bindings are different (and incorrect) than those returned from clean C implementation. In order to overcome that issue currently I am setting RUSTFLAGS="-C relocation-model=dynamic-no-pic -C linker=./linker" where linker is bash script that wraps cc and filter -pie flags:
|
I'm also having this problem. I assumed that passing (cc: @alexcrichton) |
Let `-Crelocation-model` better control `-pie` linking Prior to this, if relocation model in the target options was "pic", as most targets have it, then the user's `-Crelocation-model` had no effect on whether `-pie` would be used. Only `-Clink-arg=-static` would have a further override here. Now we use `context::get_reloc_model`, which gives precedence to the user's option, and if it's `RelocMode::PIC` we enable `-pie`. This is the same test as `context::is_pie_binary`, except that folds across all `sess.crate_types`, not just the current one. Fixes #35061.
I'm still seeing this issue. Not sure if it's a regression or I'm doing something wrong. I have a "hello world" program in main.rs, and when I run I'm using nightly rust on Ubuntu: |
So, the problem here isn't with rust, but with the linker. In Ubuntu 15.10 and later the default GCC toolchain installed has been compiled with EDIT: Don't know why Github isn't linking cross-project PRs correctly right now. |
Can this issue be resolved by always passing |
Sadly, no. In testing I have seen that any build of GCC that was not built with |
So it's came out from the discussion on an issue related to this in tarpaulin that passing -no-pie before -shared (and maybe then -static if it exists for static linkages as well) resolves the issue. I'm going to test this tarpaulin side and I can report back but I feel it would be best if this could be solved rustc side as it can affect any user in a similar situation. |
When linking with gcc, run gcc -v to see if --enable-default-pie is compiled in. If it is, pass -no-pie when necessary to disable pie. Otherwise, pass -pie when necessary to enable it. Fixes rust-lang#48032 and fixes rust-lang#35061
pass correct pie args to gcc linker When linking with gcc, run gcc -v to see if --enable-default-pie is compiled in. If it is, pass -no-pie when necessary to disable pie. Otherwise, pass -pie when necessary to enable it. Fixes rust-lang#48032 and fixes rust-lang#35061
It appears from rust-lang/rust#35061 and from [some build failures][1] that position-independent executables are being built (see "-pie" flag in [1]'s build output), which would require the objects in `liblightning.a` to be built with `-fPIC` on x86_64, which is not desirable. Static linking would be more desirable in the long term, since it could enable extra optimizations (`-flto` particularly) and generate better code, but for now, switch to dynamic linking until a portable way becomes available to ensure linking succeeds statically. [1]: https://travis-ci.org/github/kulp/lightning-sys/jobs/685111507
I'm having trouble linking a Rust program to a non-position-independent C library. When I manually remove the
-pie
flag from the ld step that rustc runs, everything works correctly. I think that-C relocation-model=dynamic-no-pic
should remove the-pie
flag for me, but it doesn't.Here's what I think is going on:
When I run
It runs ld with the
-pie
flag:execve("/usr/bin/ld", ["/usr/bin/ld", "-pie"
But when I read the rustc code here, it seems like the intention is that
-pie
should only be passed to ld whenrelocation-model=pic
. That is, if we're not compiling a position independent executable, then we should not pass the position independent executable-pie
flag to ld.I think what may be happening here is that somehow the defaults from
rust/src/librustc_back/target/mod.rs
Line 315 in 5229e0e
This happens with stable and also the nightly I tried:
The text was updated successfully, but these errors were encountered: