Page MenuHomePhabricator

[ELF] Set DF_1_PIE for -pie
ClosedPublic

Authored by MaskRay on May 30 2020, 10:43 AM.

Details

Summary

DF_1_PIE originated from Solaris (https://docs.oracle.com/cd/E36784_01/html/E36857/chapter6-42444.html ).
GNU ld since
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=5fe2850dd96483f176858fd75c098313d5b20bc2
sets the flag on non-Solaris platforms.

It can help distinguish PIE from ET_DYN.
eu-classify from elfutils uses this to recognize PIE (https://sourceware.org/git/?p=elfutils.git;a=commit;h=3f489b5c7c78df6d52f8982f79c36e9a220e8951 )

glibc uses this flag to reject dlopen'ing a PIE (https://sourceware.org/bugzilla/show_bug.cgi?id=24323 )

Diff Detail

Event Timeline

MaskRay created this revision.May 30 2020, 10:43 AM
emaste added inline comments.May 30 2020, 12:03 PM
lld/ELF/SyntheticSections.cpp
1320–1321

should this be in alpha order?

MaskRay marked 2 inline comments as done.May 30 2020, 12:20 PM
MaskRay added inline comments.
lld/ELF/SyntheticSections.cpp
1320–1321

For options which only affect DF_1_*, this order is already alphabetical.

This LGTM.
I'm now adding support in FreeBSD, e.g. https://reviews.freebsd.org/rS361657

lld/ELF/SyntheticSections.cpp
1320–1321

Ah, indeed, order of flag bit.

Loaders that don't recognise the flag presumably won't be adversely affected?

grimar added a comment.Jun 1 2020, 2:10 AM

GNU ld supports this for about 5 years. I have no objections.

psmith accepted this revision.Jun 1 2020, 2:32 AM

LGTM too, makes sense to keep as compatible with binutils as possible.

This revision is now accepted and ready to land.Jun 1 2020, 2:32 AM
MaskRay marked an inline comment as done.Jun 1 2020, 8:50 AM

Loaders that don't recognise the flag presumably won't be adversely affected?

Not affected. Many people think that the spirit of ELF is to ignore what you don't use.
I was inspired by the "ET_EXEC vs ET_DYN" thread on generic-abi.

MaskRay marked an inline comment as done.Jun 1 2020, 9:56 AM
MaskRay updated this revision to Diff 267657.Jun 1 2020, 10:14 AM

Update tests

MaskRay edited the summary of this revision. (Show Details)Jun 1 2020, 10:17 AM
This revision was automatically updated to reflect the committed changes.