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

"position-independent-executables" target file option doesn't work with gcc compiled with --enable-default-pie #48032

Closed
canarysnort01 opened this issue Feb 6, 2018 · 0 comments · Fixed by #48076
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug.

Comments

@canarysnort01
Copy link
Contributor

The position-independent-executables target file option currently has the following behavior when using gcc as the linker:

  • When true, add "-pie" to the command line
  • When false, do nothing

However, if gcc is built with --enable-default-pie, which seems to be the default now for recent versions of gcc, this logic fails when position-independent-executables is set to false. In that case, the logic should be reversed:

  • When true, do nothing
  • When false, add "-no-pie" to the command line

The obvious way to resolve this would be to pass "-pie" when true and "-no-pie" when false, but sadly, older versions of gcc will fail to link with "-no-pie" because it doesn't recognize that command line option and errors out.

It seems like the correct thing to do would be split the link step for gcc into two steps:

  1. call "gcc -v" to see if --enable-default-pie is set
  2. pass the appropriate pie flag to gcc based on this

I think this is the root cause for these issues: #35061 #47037

If you all agree this is the correct path and can give me a hint as to where/how this should be done I can take a stab at writing the code for it.

@TimNN TimNN added A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. labels Feb 6, 2018
canarysnort01 added a commit to canarysnort01/rust that referenced this issue Feb 14, 2018
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
kennytm added a commit to kennytm/rust that referenced this issue Feb 25, 2018
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants