This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Move the outSecOff addend from relocAlloc/relocNonAlloc/... to InputSectionBase::relocate
ClosedPublic

Authored by MaskRay on Aug 9 2020, 12:32 PM.

Details

Summary

For an InputSection, the buf argument of InputSectionBase::relocate points
to the content of the containing OutputSection, instead of the content of the
InputSection itself, so outSecOff needs to be added in its callees. This is
counter-intuitive and leads to many - outSecOff and + outSecOff.

This patch makes InputSection::writeTo call InputSectionBase::relocate with
outSecOff added. relocAlloc/relocNonAlloc/relocateNonAllocForRelocatable can
thus be simplified now.

Updated test:

  • non-abs-reloc.s: A minor offset bug is fixed for a diagnostic in relocateNonAlloc

Diff Detail

Event Timeline

MaskRay created this revision.Aug 9 2020, 12:32 PM
MaskRay requested review of this revision.Aug 9 2020, 12:32 PM

Simplification looks good to me. I'm not sure about the test changes as I would have expected the change to be NFC. If these are test improvements it will be worth altering separately.

The comment in InputSections.h says

// Each section knows how to relocate itself. These functions apply
// relocations, assuming that Buf points to this section's copy in
// the mmap'ed output buffer.
template <class ELFT> void relocate(uint8_t *buf, uint8_t *bufEnd);
void relocateAlloc(uint8_t *buf, uint8_t *bufEnd);

May be worth changing "Buf points to this section's copy in the mmap'ed output buffer" to "Buf points to the start of the copy of the InputSection's data in the mmap'ed output buffer."

Simplification looks good to me.

+1.

I'm not sure about the test changes as I would have expected the change to be NFC. If these are test improvements it will be worth altering separately.

+1

MaskRay updated this revision to Diff 284398.Aug 10 2020, 8:58 AM
MaskRay edited the summary of this revision. (Show Details)

Address comments

MaskRay added inline comments.Aug 10 2020, 8:59 AM
lld/test/ELF/non-abs-reloc.s
5–6

This is the only behavior difference (a bug fix).

Thanks for the update, I'm happy when George is.

grimar accepted this revision.Aug 11 2020, 4:22 AM

LGTM too.

This revision is now accepted and ready to land.Aug 11 2020, 4:22 AM
This revision was landed with ongoing or failed builds.Aug 11 2020, 8:07 AM
This revision was automatically updated to reflect the committed changes.