summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Fertile <sfertile@ca.ibm.com>2019-01-10 15:08:06 +0000
committerSean Fertile <sfertile@ca.ibm.com>2019-01-10 15:08:06 +0000
commita4f56ee1d31e44d9b30fd858219eaa438fe63047 (patch)
treeddf67291f74da8f35bd8a7b6c653fa83d389af56
parent2964123c3d993af781cbe58336b15764a7904794 (diff)
Modify InputSectionBase::getLocation to add section and offset to every loc.
The section and offset can be very helpful in diagnosing certian errors. For example on a relocation overflow or misalignment diagnostic: test.c:(function foo): relocation R_PPC64_ADDR16_DS out of range: ... The function foo can have many R_PPC64_ADDR16_DS relocations. Adding the offset and section will identify exactly which relocation is causing the failure. Differential Revision: https://reviews.llvm.org/D56453
-rw-r--r--lld/ELF/InputSection.cpp11
-rw-r--r--lld/test/ELF/ppc64-split-stack-adjust-overflow.s2
-rw-r--r--lld/test/ELF/x86-64-reloc-error2.s2
-rw-r--r--lld/test/ELF/x86-64-reloc-range-debug-loc.s2
4 files changed, 10 insertions, 7 deletions
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 7de3507c723..839bff7011e 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -288,14 +288,17 @@ Defined *InputSectionBase::getEnclosingFunction(uint64_t Offset) {
// 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 @@ std::string InputSectionBase::getLocation(uint64_t Offset) {
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.
diff --git a/lld/test/ELF/ppc64-split-stack-adjust-overflow.s b/lld/test/ELF/ppc64-split-stack-adjust-overflow.s
index bc958c75272..874f45cd0e7 100644
--- a/lld/test/ELF/ppc64-split-stack-adjust-overflow.s
+++ b/lld/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
diff --git a/lld/test/ELF/x86-64-reloc-error2.s b/lld/test/ELF/x86-64-reloc-error2.s
index 81f033f2804..230241b2be5 100644
--- a/lld/test/ELF/x86-64-reloc-error2.s
+++ b/lld/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",@progbits,1
diff --git a/lld/test/ELF/x86-64-reloc-range-debug-loc.s b/lld/test/ELF/x86-64-reloc-range-debug-loc.s
index 8be4df3c520..08a49607e80 100644
--- a/lld/test/ELF/x86-64-reloc-range-debug-loc.s
+++ b/lld/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",@progbits
foo: