[PATCH] D70659: [ELF] Allow getErrPlace() to work before Out::bufferStart is set

Alexander Richardson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 25 02:06:50 PST 2019


arichardson created this revision.
arichardson added reviewers: ruiu, grimar, MaskRay.
Herald added subscribers: llvm-commits, atanasyan, jrtc27, sdardis, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

So far it seems like the only test affected by this change is the one I
recently added for R_MIPS_JALR relocations since the other test cases that
use this function early (unknown-relocation-*) do not have a valid input
section for the relocation offset.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70659

Files:
  lld/ELF/Target.cpp
  lld/test/ELF/mips-jalr-non-functions.s


Index: lld/test/ELF/mips-jalr-non-functions.s
===================================================================
--- lld/test/ELF/mips-jalr-non-functions.s
+++ lld/test/ELF/mips-jalr-non-functions.s
@@ -15,13 +15,13 @@
 .Ltmp1:
   jr  $t9
   nop
-# WARNING-MESSAGE: warning: found R_MIPS_JALR relocation against non-function symbol tls_obj. This is invalid and most likely a compiler bug.
+# WARNING-MESSAGE: warning: {{.+}}.tmp.o:(.text+0x0): found R_MIPS_JALR relocation against non-function symbol tls_obj. This is invalid and most likely a compiler bug.
 
   .reloc .Ltmp2, R_MIPS_JALR, reg_obj
 .Ltmp2:
   jr  $t9
   nop
-# WARNING-MESSAGE: warning: found R_MIPS_JALR relocation against non-function symbol reg_obj. This is invalid and most likely a compiler bug.
+# WARNING-MESSAGE: warning: {{.+}}.tmp.o:(.text+0x8): found R_MIPS_JALR relocation against non-function symbol reg_obj. This is invalid and most likely a compiler bug.
 
   .reloc .Ltmp3, R_MIPS_JALR, untyped
 .Ltmp3:
Index: lld/ELF/Target.cpp
===================================================================
--- lld/ELF/Target.cpp
+++ lld/ELF/Target.cpp
@@ -91,15 +91,15 @@
 }
 
 template <class ELFT> static ErrorPlace getErrPlace(const uint8_t *loc) {
-  if (!Out::bufferStart)
-    return {};
-
   for (InputSectionBase *d : inputSections) {
     auto *isec = cast<InputSection>(d);
     if (!isec->getParent())
       continue;
 
-    uint8_t *isecLoc = Out::bufferStart + isec->getParent()->offset + isec->outSecOff;
+    const uint8_t *isecLoc =
+        Out::bufferStart
+            ? (Out::bufferStart + isec->getParent()->offset + isec->outSecOff)
+            : isec->data().data();
     if (isecLoc <= loc && loc < isecLoc + isec->getSize())
       return {isec, isec->template getLocation<ELFT>(loc - isecLoc) + ": "};
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70659.230854.patch
Type: text/x-patch
Size: 1812 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191125/678f1514/attachment.bin>


More information about the llvm-commits mailing list