This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Add -z separate-loadable-segments to complement separate-code and noseparate-code
ClosedPublic

Authored by MaskRay on Sep 12 2019, 1:15 AM.

Details

Summary

D64906 allows PT_LOAD to have overlapping p_offset ranges. In the
default R RX RW RW layout + -z noseparate-code case, we do not tail pad
segments when transiting to another segment. This can save at most
3*maxPageSize bytes.

a) Before D64906, we tail pad R, RX and the first RW.
b) With -z separate-code, we tail pad R and RX, but not the first RW (RELRO).

In some cases, b) saves one file page. In some cases, b) wastes one
virtual memory page. The waste is a concern on Fuchsia. Because it uses
compressed binaries, it doesn't benefit from the saved file page.

This patch adds -z separate-loadable-segments to restore the behavior before
D64906. It can affect section addresses and can thus be used as a
debugging mechanism (see PR43214 and ld.so partition bug in
crbug.com/998712).

Diff Detail

Repository
rL LLVM

Event Timeline

MaskRay created this revision.Sep 12 2019, 1:15 AM
MaskRay marked an inline comment as done.Sep 12 2019, 1:17 AM
MaskRay added inline comments.
ELF/Config.h
64 ↗(On Diff #219854)

separate-segment -> separate-segments

Which one do you prefer?

peter.smith added inline comments.Sep 12 2019, 1:56 AM
ELF/Config.h
64 ↗(On Diff #219854)

Given that there is generally only one PF_X segment separate-code being singular makes sense. There can be more than one segment involved here so personally I'd use the plural form of separate-segments. It may also be worth being more specific with "--separate-loadable-segments" as I think that is more self descriptive, if a bit long.

MaskRay updated this revision to Diff 219858.Sep 12 2019, 2:07 AM
MaskRay marked an inline comment as done.
MaskRay retitled this revision from [ELF] Add -z separate-segments to complement separate-code and noseparate-code to [ELF] Add -z separate-loadable-segments to complement separate-code and noseparate-code.
MaskRay edited the summary of this revision. (Show Details)

separate-segments -> separate-loadable-segments

ELF/Config.h
64 ↗(On Diff #219854)

Makes sense. Thanks for the suggestion!

jakehehrlich accepted this revision.Sep 13 2019, 4:04 PM

LGTM! Thanks for working on this.

This revision is now accepted and ready to land.Sep 13 2019, 4:04 PM

@phosek @mcgrathr Is -z separate-loadable-segments a good name for you?

MaskRay updated this revision to Diff 220458.Sep 17 2019, 2:29 AM

Rebase (bool enabled = ... has been deleted)

@phosek @mcgrathr Is -z separate-loadable-segments a good name for you?

@phosek @mcgrathr 🤔

ruiu added a comment.Sep 24 2019, 4:55 AM

Can you add this option to the man page?

MaskRay updated this revision to Diff 221524.Sep 24 2019, 5:58 AM

Update docs/ld.lld.1

MaskRay updated this revision to Diff 221547.Sep 24 2019, 8:42 AM

ld.lld.1: use -compact .Bl and add .Pp (paragraph break)

ruiu accepted this revision.Sep 24 2019, 7:20 PM

LGTM

MaskRay updated this revision to Diff 221665.Sep 24 2019, 8:36 PM

ld.lld.1: fix display of execstack

This revision was automatically updated to reflect the committed changes.