[PATCH] D49812: When getting an error location, don't assumethat all sections prior to a given offset can be castto an InputSection.

Sterling Augustine via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 25 11:43:21 PDT 2018


saugustine created this revision.
saugustine added a reviewer: ruiu.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a reviewer: espindola.

Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D49812

Files:
  ELF/InputSection.cpp
  ELF/Target.cpp


Index: ELF/Target.cpp
===================================================================
--- ELF/Target.cpp
+++ ELF/Target.cpp
@@ -91,13 +91,13 @@
 
 template <class ELFT> static ErrorPlace getErrPlace(const uint8_t *Loc) {
   for (InputSectionBase *D : InputSections) {
-    auto *IS = cast<InputSection>(D);
-    if (!IS->getParent())
-      continue;
-
-    uint8_t *ISLoc = IS->getParent()->Loc + IS->OutSecOff;
-    if (ISLoc <= Loc && Loc < ISLoc + IS->getSize())
-      return {IS, IS->template getLocation<ELFT>(Loc - ISLoc) + ": "};
+    InputSection *IS = dyn_cast<InputSection>(D);
+
+    if (IS && IS->getParent()) {
+      uint8_t *ISLoc = IS->getParent()->Loc + IS->OutSecOff;
+      if (ISLoc <= Loc && Loc < ISLoc + IS->getSize())
+        return {IS, IS->template getLocation<ELFT>(Loc - ISLoc) + ": "};
+    }
   }
   return {};
 }
Index: ELF/InputSection.cpp
===================================================================
--- ELF/InputSection.cpp
+++ ELF/InputSection.cpp
@@ -923,7 +923,10 @@
       continue;
 
     if (Defined *F = getEnclosingFunction<ELFT>(Rel.Offset)) {
-      if (Target->adjustPrologueForCrossSplitStack(Buf + F->Value, End)) {
+      uint64_t SecOffset = 0;
+      if (auto *Sec = dyn_cast<InputSection>(this))
+        SecOffset = Sec->OutSecOff;
+      if (Target->adjustPrologueForCrossSplitStack(Buf + SecOffset + F->Value, End)) {
         AdjustedPrologues.insert(F);
         continue;
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49812.157327.patch
Type: text/x-patch
Size: 1452 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180725/f0e98bf4/attachment.bin>


More information about the llvm-commits mailing list