This is an archive of the discontinued LLVM Phabricator instance.

[exposition-only] Refactor RelocVisitor and fix computation of SHT_RELA-typed relocation entries
AbandonedPublic

Authored by MaskRay on Feb 10 2019, 5:25 PM.

Details

Reviewers
None
Summary

getRelocatedValue may compute incorrect value for SHT_RELA-typed relocation entries.

// DWARFDataExtractor.cpp
uint64_t DWARFDataExtractor::getRelocatedValue(uint32_t Size, uint32_t *Off,
...
  // This formula is correct for SHT_REL-typed relocation entries.
  // But for SHT_RELA-typed, if the implicit r_addend (getUnsigned(Off, Size)) is not zero, it will be incorrect.
  return getUnsigned(Off, Size) + Rel->Value;

In this patch, we refactor these visit* functions to include a new
parameter int64_t A (implicit r_addend). They should use either the
explicit r_addend (SHT_RELA: getELFAddend(R)) or the implicit r_addend (SHT_REL: A) according to processor supplement requirements.

Since these visit* functions are no longer used as a prescan manner but
will be called on-demand in getRelocatedValue, rename them to resolve*.

Diff Detail

Event Timeline

MaskRay created this revision.Feb 10 2019, 5:25 PM
MaskRay edited the summary of this revision. (Show Details)Feb 10 2019, 5:27 PM
MaskRay edited the summary of this revision. (Show Details)Feb 10 2019, 5:27 PM
MaskRay updated this revision to Diff 186173.Feb 10 2019, 5:33 PM

How does this relate to D57940?

How does this relate to D57940?

D57940 is some small adaptation change on the lld side for D57939. That change is omitted from this exposition-only patch.

MaskRay abandoned this revision.Mar 24 2019, 7:44 PM