[lld] ffa1118 - [ELF] Mention section name for STT_SECTION in reportRangeError()
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 3 12:35:11 PST 2023
Author: Fangrui Song
Date: 2023-03-03T12:35:05-08:00
New Revision: ffa11183303289654d26b8f761dcf54e611058ca
URL: https://github.com/llvm/llvm-project/commit/ffa11183303289654d26b8f761dcf54e611058ca
DIFF: https://github.com/llvm/llvm-project/commit/ffa11183303289654d26b8f761dcf54e611058ca.diff
LOG: [ELF] Mention section name for STT_SECTION in reportRangeError()
D73518 mentioned non-STT_SECTION symbol names. This patch extends the code to
handle STT_SECTION symbols, where we report the section name.
This change helps at least the following cases with very little code.
* Whether a out-of-range relocation is due to code or data.
* For a relocation in .debug_info, which referenced `.debug_*` section (due to DWARF32 limitation) causes the problem.
Reviewed By: peter.smith
Differential Revision: https://reviews.llvm.org/D145199
Added:
Modified:
lld/ELF/Relocations.cpp
lld/test/ELF/aarch64-movw-error.s
lld/test/ELF/linkerscript/eh-frame-reloc-out-of-range.test
lld/test/ELF/ppc64-reloc-pcrel34-overflow.s
lld/test/ELF/x86-64-reloc-range.s
Removed:
################################################################################
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index aeba918292a77..fc0c022f80961 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -99,8 +99,12 @@ void elf::reportRangeError(uint8_t *loc, const Relocation &rel, const Twine &v,
int64_t min, uint64_t max) {
ErrorPlace errPlace = getErrorPlace(loc);
std::string hint;
- if (rel.sym && !rel.sym->isSection())
- hint = "; references " + lld::toString(*rel.sym);
+ if (rel.sym) {
+ if (!rel.sym->isSection())
+ hint = "; references " + lld::toString(*rel.sym);
+ else if (auto *d = dyn_cast<Defined>(rel.sym))
+ hint = ("; references section '" + d->section->name + "'").str();
+ }
if (!errPlace.srcLoc.empty())
hint += "\n>>> referenced by " + errPlace.srcLoc;
if (rel.sym && !rel.sym->isSection())
diff --git a/lld/test/ELF/aarch64-movw-error.s b/lld/test/ELF/aarch64-movw-error.s
index a5bd2c9d88557..cfca054e6e664 100644
--- a/lld/test/ELF/aarch64-movw-error.s
+++ b/lld/test/ELF/aarch64-movw-error.s
@@ -22,7 +22,7 @@ movn x0, #:abs_g1_s:zero-0x100010000
# CHECK: relocation R_AARCH64_MOVW_SABS_G2 out of range: -281479271677952 is not in [-281474976710656, 281474976710655]
movn x0, #:abs_g2_s:zero-0x1000100000000
-# CHECK: relocation R_AARCH64_MOVW_PREL_G0 out of range: 65536 is not in [-65536, 65535]
+# CHECK: relocation R_AARCH64_MOVW_PREL_G0 out of range: 65536 is not in [-65536, 65535]; references section '.text'
movn x0, #:prel_g0:.+0x10000
# CHECK: relocation R_AARCH64_MOVW_PREL_G1 out of range: 4294967296 is not in [-4294967296, 4294967295]
movn x0, #:prel_g1:.+0x100000000
diff --git a/lld/test/ELF/linkerscript/eh-frame-reloc-out-of-range.test b/lld/test/ELF/linkerscript/eh-frame-reloc-out-of-range.test
index 9b8e6c8e4b656..9294f07519247 100644
--- a/lld/test/ELF/linkerscript/eh-frame-reloc-out-of-range.test
+++ b/lld/test/ELF/linkerscript/eh-frame-reloc-out-of-range.test
@@ -10,4 +10,4 @@ SECTIONS { . = 0x10000;
.text : { *(.text*) } : text
}
-# CHECK: error: {{.*}}:(.eh_frame+0x20): relocation R_X86_64_PC32 out of range: 64424443872 is not in [-2147483648, 2147483647]
+# CHECK: error: {{.*}}:(.eh_frame+0x20): relocation R_X86_64_PC32 out of range: 64424443872 is not in [-2147483648, 2147483647]; references section '.text'
diff --git a/lld/test/ELF/ppc64-reloc-pcrel34-overflow.s b/lld/test/ELF/ppc64-reloc-pcrel34-overflow.s
index ad80ed720b637..60b34a26ec490 100644
--- a/lld/test/ELF/ppc64-reloc-pcrel34-overflow.s
+++ b/lld/test/ELF/ppc64-reloc-pcrel34-overflow.s
@@ -10,7 +10,7 @@
# RUN: llvm-mc -filetype=obj -triple=powerpc64 %s -o %t.o
# RUN: not ld.lld -T %t.script %t.o -o /dev/null 2>&1 | FileCheck %s
-# CHECK: relocation R_PPC64_PCREL34 out of range: 8589934592 is not in [-8589934592, 8589934591]
+# CHECK: relocation R_PPC64_PCREL34 out of range: 8589934592 is not in [-8589934592, 8589934591]; references section '.data'
plwa 3, glob_overflow at PCREL(0), 1
# CHECK-NOT: relocation
diff --git a/lld/test/ELF/x86-64-reloc-range.s b/lld/test/ELF/x86-64-reloc-range.s
index 3f50076d85a0f..7e7a62cb66e38 100644
--- a/lld/test/ELF/x86-64-reloc-range.s
+++ b/lld/test/ELF/x86-64-reloc-range.s
@@ -4,7 +4,7 @@
// RUN: ld.lld --noinhibit-exec -shared %t.o -o %t 2>&1 | FileCheck %s
// RUN: ls %t
-// CHECK: {{.*}}:(.text+0x3): relocation R_X86_64_PC32 out of range: 2147483648 is not in [-2147483648, 2147483647]
+// CHECK: {{.*}}:(.text+0x3): relocation R_X86_64_PC32 out of range: 2147483648 is not in [-2147483648, 2147483647]; references section '.bss'
// CHECK-NOT: relocation
lea foo(%rip), %rax
More information about the llvm-commits
mailing list