Author: emaste Date: Tue Jul 24 11:35:22 2018 New Revision: 336664 URL: https://svnweb.freebsd.org/changeset/base/336664
Log: 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 Obtained from: LLVM r336799 by Igor Kudrin Modified: head/contrib/llvm/tools/lld/ELF/InputSection.cpp Modified: head/contrib/llvm/tools/lld/ELF/InputSection.cpp ============================================================================== --- head/contrib/llvm/tools/lld/ELF/InputSection.cpp Tue Jul 24 10:10:16 2018 (r336663) +++ head/contrib/llvm/tools/lld/ELF/InputSection.cpp Tue Jul 24 11:35:22 2018 (r336664) @@ -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>()); _______________________________________________ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"