This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho][nfc] Remove InputSection::outSecFileOff
ClosedPublic

Authored by int3 on Jun 11 2021, 11:38 PM.

Details

Reviewers
gkm
thakis
Group Reviewers
Restricted Project
Commits
rGb2a073901216: [lld-macho][nfc] Remove InputSection::outSecFileOff
Summary

outSecFileOff and the associated getFileOffset() accessors were
unnecessary.

For all the cases we care about, outSecFileOff is the same as
outSecOff. The only time they deviate is if there are zerofill
sections within a given segment. But since zerofill sections are always
at the end of a segment, the only sections where the two values deviate
are zerofill sections themselves. And we never actually query the
outSecFileOff of zerofill sections.

As for getFileOffset(), the only place it was being used was to
calculate the offset of the entry symbol. However, we can compute that
value by just taking the difference between the address of the entry
symbol and the address of the Mach-O header. In fact, this appears to be
what ld64 itself does. This difference is the same as the file offset as
long as there are no intervening zerofill sections, but since __text
is the first section in __TEXT, this never happens, so our previous
use of getFileOffset() was not wrong -- just inefficient.

Diff Detail

Event Timeline

int3 created this revision.Jun 11 2021, 11:38 PM
Herald added a project: Restricted Project. · View Herald Transcript
int3 requested review of this revision.Jun 11 2021, 11:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 11 2021, 11:38 PM
int3 retitled this revision from [lld-macho] Remove InputSection::outSecFileOff to [lld-macho][nfc] Remove InputSection::outSecFileOff.Jun 13 2021, 10:55 AM
thakis accepted this revision.Jun 13 2021, 1:44 PM
thakis added a subscriber: thakis.

Nice!

I'm a bit surprised that this has such a big effect.

This revision is now accepted and ready to land.Jun 13 2021, 1:44 PM
int3 added a comment.Jun 13 2021, 4:40 PM

Sorry, I think that was spurious :( I can no longer replicate that performance win...

int3 edited the summary of this revision. (Show Details)Jun 13 2021, 4:41 PM
This revision was landed with ongoing or failed builds.Jun 13 2021, 4:52 PM
This revision was automatically updated to reflect the committed changes.