Description
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:
- call "gcc -v" to see if --enable-default-pie is set
- 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.