Uh oh!
There was an error while loading. Please reload this page.
pass correct pie args to gcc linker - #48076
Conversation
rust-highfive
commented
Feb 8, 2018
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @eddyb (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
nagisa
commented
Feb 8, 2018
Can we pass the |
canarysnort01
commented
Feb 8, 2018
no, the -no-pie flag will cause older versions of gcc to error out because it doesn't recognize the flag. |
eddyb
commented
Feb 8, 2018
alexcrichton
commented
Feb 8, 2018
Thanks for the PR @canarysnort01! Would it be possible to avoid running |
canarysnort01
commented
Feb 9, 2018
Yes, this would run the version check on all platforms on all executables when the link step is configured to use gcc. The benefit here is we know for sure how gcc is configured and we're doing the right thing. An alternative approach would be:
The benefit to this approach would be the user only has to pay for the extra linker invocation when it is actually necessary, and would get used less and less as the user base upgrades gcc. |
alexcrichton
commented
Feb 9, 2018
When was |
canarysnort01
commented
Feb 9, 2018
According to https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=867853 around gcc 5.3, so a couple years, although it doesn't appear to have been documented until 6.1. The gcc 6.3 in debian stable (stretch) accepts -no-pie, but the gcc in debian oldstable (jessie) (I think 4.8) does not. |
alexcrichton
commented
Feb 9, 2018
Ok thanks for the info! I think that sounds like a reasonable approach in that case. I believe by default all Rust executables are pie and so it won't hit the "slow path" anyway, but in those cases it does then a gcc upgrade should do it! |
There was a problem hiding this comment.
To help prevent an accidental infinite loop, could this also have a clause that the cmd has an argument of -no-pie in it?
alexcrichton
commented
Feb 11, 2018
@bors: r+ |
bors
commented
Feb 11, 2018
📌 Commit bc82fec has been approved by |
kennytm
commented
Feb 12, 2018
@bors r- Failed on macOS ( |
There was a problem hiding this comment.
This should check for "error: unknown argument" as well.
alexcrichton
commented
Feb 12, 2018
Since this probably isn't applicable to OSX as well, could this logic only get triggered on unix targets? |
canarysnort01
commented
Feb 12, 2018
@alexcrichton IIUC you want to check if the target is an OSX target and, if so, never issue the -no-pie argument at all? It looks like clang might follow in gcc's footsteps in this respect, here's an open issue to do just that: https://bugs.llvm.org/show_bug.cgi?id=13410 Also, it looks like I'm concerned if we add this exception and osx upgrades/patches their clang to default to pie it will break. |
alexcrichton
commented
Feb 12, 2018
Is the |
canarysnort01
commented
Feb 13, 2018
Ah I think see where you are coming from now. I was thinking the build failure from @kennytm was from the test suite like in #47037 which I would expect to hit this code path, but iiuc now all builds on OSX failed. (I don't have a mac to test with). Which makes sense now that I see that position-independent-executables isn't set in OSX's target or the mac base target. Which leads back to does pie mean anything on OSX... hmm good question. |
canarysnort01
commented
Feb 13, 2018
I don't have an answer yet, but I think one option to address this would be to make position-independent-executables have three possible values: yes, no, default.
|
alexcrichton
commented
Feb 13, 2018
Invoking the linker tends to be a fickle beast so it's often best to leave it as is unless we need to change it, so perhaps a flag could be added to only pass the flag when |
canarysnort01
commented
Feb 14, 2018
That seems like a reasonable solution. |
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. Fixesrust-lang#48032 and fixesrust-lang#35061
Recent versions of gcc default to creating a position independent executable and must be explicitly told not to with the -no-pie argument. Old versions of gcc don't understand -no-pie and will throw an error. Check for that case and retry without -no-pie. This is safe because these old versions of gcc should never default to creating a position independent executable.
canarysnort01
commented
Feb 14, 2018
Should I update this PR description to the current solution? Is that what gets put in the merge commit description? |
canarysnort01
commented
Feb 14, 2018
@alexcrichton this pr will conflict with #48125 |
alexcrichton
commented
Feb 14, 2018
bors
commented
Feb 14, 2018
📌 Commit ab9cae1 has been approved by |
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. Fixesrust-lang#48032 and fixesrust-lang#35061
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#48032 and fixes#35061