[PATCH] D56453: Modify InputSectionBase::getLocation to add section and offset to every location string.

Sean Fertile via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 8 13:30:07 PST 2019


sfertile created this revision.
sfertile added reviewers: MaskRay, ruiu, grimar.
Herald added subscribers: llvm-commits, kbarton, arichardson, nemanjai, emaste.
Herald added a reviewer: espindola.

The section and offset can be very helpful in diagnosing why an error was emitted and how to remedy it, add them to each source location string in InputSectionBase.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D56453

Files:
  ELF/InputSection.cpp
  test/ELF/ppc64-split-stack-adjust-overflow.s
  test/ELF/x86-64-reloc-error2.s
  test/ELF/x86-64-reloc-range-debug-loc.s


Index: test/ELF/x86-64-reloc-range-debug-loc.s
===================================================================
--- test/ELF/x86-64-reloc-range-debug-loc.s
+++ test/ELF/x86-64-reloc-range-debug-loc.s
@@ -5,7 +5,7 @@
 
 ## Check we are able to report file and location from debug information
 ## when reporting such kind of errors.
-# CHECK: error: test.s:3: relocation R_X86_64_32 out of range: 68719476736 is not in [0, 4294967295]
+# CHECK: error: test.s:3:(.text+0x1): relocation R_X86_64_32 out of range: 68719476736 is not in [0, 4294967295]
 
 .section .text,"ax", at progbits
 foo:
Index: test/ELF/x86-64-reloc-error2.s
===================================================================
--- test/ELF/x86-64-reloc-error2.s
+++ test/ELF/x86-64-reloc-error2.s
@@ -4,7 +4,7 @@
 
 ## Check we are able to find a function symbol that encloses
 ## a given location when reporting error messages.
-# CHECK: {{.*}}.o:(function func): relocation R_X86_64_32S out of range: -281474974609408 is not in [-2147483648, 2147483647]
+# CHECK: {{.*}}.o:(function func: .text.func+0x3): relocation R_X86_64_32S out of range: -281474974609408 is not in [-2147483648, 2147483647]
 
 # This mergeable section will be garbage collected. We had a crash issue in that case. Test it.
 .section .rodata.str1,"aMS", at progbits,1
Index: test/ELF/ppc64-split-stack-adjust-overflow.s
===================================================================
--- test/ELF/ppc64-split-stack-adjust-overflow.s
+++ test/ELF/ppc64-split-stack-adjust-overflow.s
@@ -20,7 +20,7 @@
 # RUN: ld.lld %t1.o %t2.o -o %t --defsym __morestack=0x10010000 -split-stack-adjust-size 4096
 # RUN: llvm-objdump -d %t | FileCheck %s
 
-# OVERFLOW: error: {{.*}}.o:(function caller): split-stack prologue adjustment overflows
+# OVERFLOW: error: {{.*}}.o:(function caller: .text+0x8): split-stack prologue adjustment overflows
 
         .p2align    2
         .global caller
Index: ELF/InputSection.cpp
===================================================================
--- ELF/InputSection.cpp
+++ ELF/InputSection.cpp
@@ -288,14 +288,17 @@
 // Returns a source location string. Used to construct an error message.
 template <class ELFT>
 std::string InputSectionBase::getLocation(uint64_t Offset) {
+  std::string SecAndOffset =  (Name + "+0x" + utohexstr(Offset)).str();
+
   // We don't have file for synthetic sections.
   if (getFile<ELFT>() == nullptr)
-    return (Config->OutputFile + ":(" + Name + "+0x" + utohexstr(Offset) + ")")
+    return (Config->OutputFile + ":(" + SecAndOffset + ")")
         .str();
 
   // First check if we can get desired values from debugging information.
   if (Optional<DILineInfo> Info = getFile<ELFT>()->getDILineInfo(this, Offset))
-    return Info->FileName + ":" + std::to_string(Info->Line);
+    return Info->FileName + ":" + std::to_string(Info->Line) + ":(" +
+           SecAndOffset + ")";
 
   // File->SourceFile contains STT_FILE symbol that contains a
   // source file name. If it's missing, we use an object file name.
@@ -304,10 +307,10 @@
     SrcFile = toString(File);
 
   if (Defined *D = getEnclosingFunction<ELFT>(Offset))
-    return SrcFile + ":(function " + toString(*D) + ")";
+    return SrcFile + ":(function " + toString(*D) + ": " + SecAndOffset + ")";
 
   // If there's no symbol, print out the offset in the section.
-  return (SrcFile + ":(" + Name + "+0x" + utohexstr(Offset) + ")").str();
+  return (SrcFile + ":(" + SecAndOffset + ")");
 }
 
 // This function is intended to be used for constructing an error message.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56453.180725.patch
Type: text/x-patch
Size: 3547 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190108/5e2c6f12/attachment.bin>


More information about the llvm-commits mailing list