Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Jul 2018 11:35:23 +0000 (UTC)
From:      Ed Maste <emaste@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r336664 - head/contrib/llvm/tools/lld/ELF
Message-ID:  <201807241135.w6OBZNZg077113@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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>());



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201807241135.w6OBZNZg077113>