[ELF] Move the outSecOff addend from relocAlloc/relocNonAlloc/... to InputSectionBase...
authorFangrui Song <i@maskray.me>
Mon, 10 Aug 2020 15:57:19 +0000 (08:57 -0700)
committerFangrui Song <i@maskray.me>
Tue, 11 Aug 2020 15:06:38 +0000 (08:06 -0700)
commite973c1375ed04b1d71fa86f1519d5067d8a6fc1f
tree9c9265b1fbd47dea08f68e41c208ea51c9f52b28
parent73ca96ebc156daeb56d63981b316b8bf060b0d7f
[ELF] Move the outSecOff addend from relocAlloc/relocNonAlloc/... to InputSectionBase::relocate

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`

Reviewed By: grimar

Differential Revision: https://reviews.llvm.org/D85618
lld/ELF/AArch64ErrataFix.cpp
lld/ELF/ARMErrataFix.cpp
lld/ELF/InputSection.cpp
lld/ELF/SyntheticSections.cpp
lld/test/ELF/non-abs-reloc.s