This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Replace InputBaseSection::{areRelocsRela,firstRelocation,numRelocation} with relSecIdx
ClosedPublic

Authored by MaskRay on Oct 25 2021, 10:22 PM.

Details

Summary

For InputSection .foo, its InputBaseSection::{areRelocsRela,firstRelocation,numRelocation} basically
encode the information of .rel[a].foo. However, one uint32_t (the relocation section index)
suffices. See the implementation of relsOrRelas.

This change decreases sizeof(InputSection) from 184 to 176 on 64-bit Linux.

The maximum resident set size linking a large application (1.2G output) decreases by 0.39%.

Diff Detail

Event Timeline

MaskRay created this revision.Oct 25 2021, 10:22 PM
MaskRay requested review of this revision.Oct 25 2021, 10:22 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 25 2021, 10:22 PM
MaskRay edited the summary of this revision. (Show Details)Oct 25 2021, 10:24 PM

Nice and easy size reduction :) It seems unlikely that the calls to relsOrRelas() add noticeable overhead compared to looking at the cached values. Would prefer a named struct over std::pair though.

lld/ELF/InputSection.cpp
163

I would define a struct for the two arrays instead of using std::pair since it's not obvious what .first/.second is accessing in the rest of the patch.

MaskRay updated this revision to Diff 382380.Oct 26 2021, 10:08 AM

Add struct RelsOrRelas<ELFT>

MaskRay edited the summary of this revision. (Show Details)Oct 26 2021, 11:56 AM

Only a small suggestion, no objections from me.

lld/ELF/InputSection.h
38

May be worth a member function like bool areRelocsRel() const { return rels.size(); } that could be used instead of if (rels.rels.size()) not a strong opinion, may not be worth the change.

MaskRay updated this revision to Diff 382432.Oct 26 2021, 12:48 PM

Add RelsOrRelas::areRelocsRel()

MaskRay marked 2 inline comments as done.Oct 26 2021, 1:34 PM
MaskRay accepted this revision.Oct 27 2021, 9:49 AM

I will do minor adjustment and push this.

This revision is now accepted and ready to land.Oct 27 2021, 9:49 AM
MaskRay updated this revision to Diff 382704.Oct 27 2021, 9:49 AM

use more areRelocsRel()

MaskRay edited the summary of this revision. (Show Details)Oct 27 2021, 9:50 AM
This revision was landed with ongoing or failed builds.Oct 27 2021, 9:51 AM
This revision was automatically updated to reflect the committed changes.