Skip to content

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

Closed
@canarysnort01

Description

@canarysnort01

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions