svn commit: r336880 - stable/11/contrib/llvm/tools/lld/ELF
Ed Maste
emaste at FreeBSD.org
Mon Jul 30 00:08:37 UTC 2018
Author: emaste
Date: Mon Jul 30 00:08:36 2018
New Revision: 336880
URL: https://svnweb.freebsd.org/changeset/base/336880
Log:
MFC r336664: lld: fix addends with partial linking
[ELF] Update addends in non-allocatable sections for REL targets when
creating a relocatable output.
LLVM PR: 37735
LLVM Differential Revision: https://reviews.llvm.org/D48929
PR: 225128, 228753
Obtained from: LLVM r336799 by Igor Kudrin
Modified:
stable/11/contrib/llvm/tools/lld/ELF/InputSection.cpp
Directory Properties:
stable/11/ (props changed)
Modified: stable/11/contrib/llvm/tools/lld/ELF/InputSection.cpp
==============================================================================
--- stable/11/contrib/llvm/tools/lld/ELF/InputSection.cpp Mon Jul 30 00:04:42 2018 (r336879)
+++ stable/11/contrib/llvm/tools/lld/ELF/InputSection.cpp Mon Jul 30 00:08:36 2018 (r336880)
@@ -686,6 +686,23 @@ void InputSection::relocateNonAlloc(uint8_t *Buf, Arra
}
}
+// This is used when '-r' is given.
+// For REL targets, InputSection::copyRelocations() may store artificial
+// relocations aimed to update addends. They are handled in relocateAlloc()
+// for allocatable sections, and this function does the same for
+// non-allocatable sections, such as sections with debug information.
+static void relocateNonAllocForRelocatable(InputSection *Sec, uint8_t *Buf) {
+ const unsigned Bits = Config->Is64 ? 64 : 32;
+
+ for (const Relocation &Rel : Sec->Relocations) {
+ // InputSection::copyRelocations() adds only R_ABS relocations.
+ assert(Rel.Expr == R_ABS);
+ uint8_t *BufLoc = Buf + Rel.Offset + Sec->OutSecOff;
+ uint64_t TargetVA = SignExtend64(Rel.Sym->getVA(Rel.Addend), Bits);
+ Target->relocateOne(BufLoc, Rel.Type, TargetVA);
+ }
+}
+
template <class ELFT>
void InputSectionBase::relocate(uint8_t *Buf, uint8_t *BufEnd) {
if (Flags & SHF_ALLOC) {
@@ -694,7 +711,9 @@ void InputSectionBase::relocate(uint8_t *Buf, uint8_t
}
auto *Sec = cast<InputSection>(this);
- if (Sec->AreRelocsRela)
+ if (Config->Relocatable)
+ relocateNonAllocForRelocatable(Sec, Buf);
+ else if (Sec->AreRelocsRela)
Sec->relocateNonAlloc<ELFT>(Buf, Sec->template relas<ELFT>());
else
Sec->relocateNonAlloc<ELFT>(Buf, Sec->template rels<ELFT>());
More information about the svn-src-all
mailing list