[PATCH] D57940: Refactor RelocVisitor and fix computation of SHT_RELA-typed relocation entries

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 8 00:05:03 PST 2019


MaskRay created this revision.
MaskRay added reviewers: echristo, dblaikie, ruiu.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

This is lld-side change of D57939 <https://reviews.llvm.org/D57939>


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D57940

Files:
  ELF/DWARF.cpp


Index: ELF/DWARF.cpp
===================================================================
--- ELF/DWARF.cpp
+++ ELF/DWARF.cpp
@@ -54,6 +54,20 @@
   }
 }
 
+template <class RelTy> struct Resolver {
+  static Optional<uint64_t> Resolve(object::RelocationRef Ref, uint64_t S,
+                                    int64_t A) {
+    return S + Ref.getRawDataRefImpl().p;
+  }
+};
+
+template <class ELFT> struct Resolver<Elf_Rel_Impl<ELFT, false>> {
+  static Optional<uint64_t> Resolve(object::RelocationRef Ref, uint64_t S,
+                                    int64_t A) {
+    return S + A;
+  }
+};
+
 // Find if there is a relocation at Pos in Sec.  The code is a bit
 // more complicated than usual because we need to pass a section index
 // to llvm since it has no idea about InputSection.
@@ -83,14 +97,17 @@
             llvm::utohexstr(Rel.r_offset) + " has unsupported target");
     return None;
   }
-  uint64_t Val = DR->Value + getAddend<ELFT>(Rel);
+  uint64_t Val = DR->Value;
 
   // FIXME: We should be consistent about always adding the file
   // offset or not.
   if (DR->Section->Flags & ELF::SHF_ALLOC)
     Val += cast<InputSection>(DR->Section)->getOffsetInFile();
 
-  return RelocAddrEntry{SecIndex, Val};
+  DataRefImpl D;
+  D.p = getAddend<ELFT>(Rel);
+  return RelocAddrEntry{SecIndex, RelocationRef(D, nullptr),
+                        Resolver<typename ELFT::Rela>::Resolve, Val};
 }
 
 template <class ELFT>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57940.185916.patch
Type: text/x-patch
Size: 1440 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190208/c7dd879a/attachment.bin>


More information about the llvm-commits mailing list