From f3c143188ded5102336aad435ebb76d16edcbe10 Mon Sep 17 00:00:00 2001 From: George Rimar Date: Wed, 16 Nov 2016 08:34:19 +0000 Subject: [PATCH] [ELF] - Better diagnostic for "can't create dynamic relocation" error. Patch improves message to show locations for "can't create dynamic relocation" error. Differential revision: https://reviews.llvm.org/D26548 llvm-svn: 287086 --- lld/ELF/Relocations.cpp | 7 +++++-- lld/test/ELF/aarch64-fpic-add_abs_lo12_nc.s | 2 +- lld/test/ELF/aarch64-fpic-adr_prel_lo21.s | 2 +- lld/test/ELF/aarch64-fpic-adr_prel_pg_hi21.s | 2 +- lld/test/ELF/aarch64-fpic-ldst32_abs_lo12_nc.s | 2 +- lld/test/ELF/aarch64-fpic-ldst64_abs_lo12_nc.s | 2 +- lld/test/ELF/aarch64-fpic-ldst8_abs_lo12_nc.s | 2 +- lld/test/ELF/arm-target1.s | 2 +- lld/test/ELF/copy-in-shared.s | 2 +- lld/test/ELF/copy-rel-pie-error.s | 4 ++-- lld/test/ELF/dynamic-reloc-in-ro.s | 2 +- lld/test/ELF/eh-frame-dyn-rel.s | 2 +- 12 files changed, 17 insertions(+), 14 deletions(-) diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index 4e9c8a868583..526ea97b743f 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -445,8 +445,11 @@ static RelExpr adjustExpr(const elf::ObjectFile &File, SymbolBody &Body, // the refered symbol can be preemepted to refer to the executable. if (Config->Shared || (Config->Pic && !isRelExpr(Expr))) { StringRef Name = getSymbolName(File.getStringTable(), Body); - error("can't create dynamic relocation " + getRelName(Type) + " against " + - (Name.empty() ? "readonly segment" : "symbol " + Name)); + error(getLocation(S, RelOff) + ": can't create dynamic relocation " + + getRelName(Type) + " against " + + ((Name.empty() ? "local symbol in readonly segment" + : "symbol '" + Name + "'")) + + " defined in " + getFilename(Body.File)); return Expr; } if (Body.getVisibility() != STV_DEFAULT) { diff --git a/lld/test/ELF/aarch64-fpic-add_abs_lo12_nc.s b/lld/test/ELF/aarch64-fpic-add_abs_lo12_nc.s index 0b07ee186fe3..4757ed25b978 100644 --- a/lld/test/ELF/aarch64-fpic-add_abs_lo12_nc.s +++ b/lld/test/ELF/aarch64-fpic-add_abs_lo12_nc.s @@ -1,7 +1,7 @@ // REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o // RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s -// CHECK: can't create dynamic relocation R_AARCH64_ADD_ABS_LO12_NC against symbol dat +// CHECK: {{.*}}.o (.text+0x0): can't create dynamic relocation R_AARCH64_ADD_ABS_LO12_NC against symbol 'dat' defined in {{.*}}.o add x0, x0, :lo12:dat .data diff --git a/lld/test/ELF/aarch64-fpic-adr_prel_lo21.s b/lld/test/ELF/aarch64-fpic-adr_prel_lo21.s index f86bd9f25ddd..fb51450fba98 100644 --- a/lld/test/ELF/aarch64-fpic-adr_prel_lo21.s +++ b/lld/test/ELF/aarch64-fpic-adr_prel_lo21.s @@ -1,7 +1,7 @@ // REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o // RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s -// CHECK: can't create dynamic relocation R_AARCH64_ADR_PREL_LO21 against symbol dat +// CHECK: {{.*}}.o (.text+0x0): can't create dynamic relocation R_AARCH64_ADR_PREL_LO21 against symbol 'dat' defined in {{.*}}.o adr x0, dat .data diff --git a/lld/test/ELF/aarch64-fpic-adr_prel_pg_hi21.s b/lld/test/ELF/aarch64-fpic-adr_prel_pg_hi21.s index b7e70ef86dde..9ca1e6782e0d 100644 --- a/lld/test/ELF/aarch64-fpic-adr_prel_pg_hi21.s +++ b/lld/test/ELF/aarch64-fpic-adr_prel_pg_hi21.s @@ -1,7 +1,7 @@ // REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o // RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s -// CHECK: can't create dynamic relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol dat +// CHECK: {{.*}}.o (.text+0x0): can't create dynamic relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol 'dat' defined in {{.*}}.o adrp x0, dat .data diff --git a/lld/test/ELF/aarch64-fpic-ldst32_abs_lo12_nc.s b/lld/test/ELF/aarch64-fpic-ldst32_abs_lo12_nc.s index 140d7994835b..fba314d87e4b 100644 --- a/lld/test/ELF/aarch64-fpic-ldst32_abs_lo12_nc.s +++ b/lld/test/ELF/aarch64-fpic-ldst32_abs_lo12_nc.s @@ -1,7 +1,7 @@ // REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o // RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s -// CHECK: can't create dynamic relocation R_AARCH64_LDST32_ABS_LO12_NC against symbol dat +// CHECK: {{.*}}.o (.text+0x0): can't create dynamic relocation R_AARCH64_LDST32_ABS_LO12_NC against symbol 'dat' defined in {{.*}}.o ldr s4, [x0, :lo12:dat] .data diff --git a/lld/test/ELF/aarch64-fpic-ldst64_abs_lo12_nc.s b/lld/test/ELF/aarch64-fpic-ldst64_abs_lo12_nc.s index ff5fb41b6fcd..8147398df731 100644 --- a/lld/test/ELF/aarch64-fpic-ldst64_abs_lo12_nc.s +++ b/lld/test/ELF/aarch64-fpic-ldst64_abs_lo12_nc.s @@ -1,7 +1,7 @@ // REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o // RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s -// CHECK: can't create dynamic relocation R_AARCH64_LDST64_ABS_LO12_NC against symbol dat +// CHECK: {{.*}}.o (.text+0x0): can't create dynamic relocation R_AARCH64_LDST64_ABS_LO12_NC against symbol 'dat' defined in {{.*}}.o ldr x0, [x0, :lo12:dat] .data diff --git a/lld/test/ELF/aarch64-fpic-ldst8_abs_lo12_nc.s b/lld/test/ELF/aarch64-fpic-ldst8_abs_lo12_nc.s index a0ea37c30deb..aa6d5a0d7d89 100644 --- a/lld/test/ELF/aarch64-fpic-ldst8_abs_lo12_nc.s +++ b/lld/test/ELF/aarch64-fpic-ldst8_abs_lo12_nc.s @@ -1,7 +1,7 @@ // REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o // RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s -// CHECK: can't create dynamic relocation R_AARCH64_LDST8_ABS_LO12_NC against symbol dat +// CHECK: {{.*}}.o (.text+0x0): can't create dynamic relocation R_AARCH64_LDST8_ABS_LO12_NC against symbol 'dat' defined in {{.*}}.o ldrsb x0, [x1, :lo12:dat] .data diff --git a/lld/test/ELF/arm-target1.s b/lld/test/ELF/arm-target1.s index a7584e9fa479..8ad4089002d1 100644 --- a/lld/test/ELF/arm-target1.s +++ b/lld/test/ELF/arm-target1.s @@ -29,4 +29,4 @@ // RELATIVE: SYMBOL TABLE: // RELATIVE: 00001004 .text 00000000 patatino -// ABS: can't create dynamic relocation R_ARM_TARGET1 against symbol patatino +// ABS: {{.*}}.o (.text+0x0): can't create dynamic relocation R_ARM_TARGET1 against symbol 'patatino' defined in {{.*}}.o diff --git a/lld/test/ELF/copy-in-shared.s b/lld/test/ELF/copy-in-shared.s index 8dde5a61fefa..c5dbc7f77ce2 100644 --- a/lld/test/ELF/copy-in-shared.s +++ b/lld/test/ELF/copy-in-shared.s @@ -7,4 +7,4 @@ .quad foo -// CHECK: can't create dynamic relocation R_X86_64_64 against symbol foo +// CHECK: {{.*}}.o (.text+0x0): can't create dynamic relocation R_X86_64_64 against symbol 'foo' defined in {{.*}}.so diff --git a/lld/test/ELF/copy-rel-pie-error.s b/lld/test/ELF/copy-rel-pie-error.s index d64746bf2600..9418eee5b42a 100644 --- a/lld/test/ELF/copy-rel-pie-error.s +++ b/lld/test/ELF/copy-rel-pie-error.s @@ -3,8 +3,8 @@ // RUN: ld.lld %t2.o -o %t2.so -shared // RUN: not ld.lld %t.o %t2.so -o %t.exe -pie 2>&1 | FileCheck %s -// CHECK: can't create dynamic relocation R_X86_64_64 against symbol bar -// CHECK: can't create dynamic relocation R_X86_64_64 against symbol foo +// CHECK: {{.*}}.o (.text+0x0): can't create dynamic relocation R_X86_64_64 against symbol 'bar' defined in {{.*}}.so +// CHECK: {{.*}}.o (.text+0x8): can't create dynamic relocation R_X86_64_64 against symbol 'foo' defined in {{.*}}.so .global _start _start: diff --git a/lld/test/ELF/dynamic-reloc-in-ro.s b/lld/test/ELF/dynamic-reloc-in-ro.s index 2ef36f695fb6..cd469daa25c9 100644 --- a/lld/test/ELF/dynamic-reloc-in-ro.s +++ b/lld/test/ELF/dynamic-reloc-in-ro.s @@ -5,4 +5,4 @@ foo: .quad foo -// CHECK: can't create dynamic relocation R_X86_64_64 against readonly segment +// CHECK: {{.*}}.o (.text+0x0): can't create dynamic relocation R_X86_64_64 against local symbol in readonly segment defined in {{.*}}.o diff --git a/lld/test/ELF/eh-frame-dyn-rel.s b/lld/test/ELF/eh-frame-dyn-rel.s index b17cdd41fce6..00b7b12456d6 100644 --- a/lld/test/ELF/eh-frame-dyn-rel.s +++ b/lld/test/ELF/eh-frame-dyn-rel.s @@ -7,4 +7,4 @@ .cfi_personality 0x8c, foo .cfi_endproc -// CHECK: can't create dynamic relocation R_X86_64_64 against symbol foo +// CHECK: {{.*}}.o (.eh_frame+0x12): can't create dynamic relocation R_X86_64_64 against symbol 'foo' defined in {{.*}}.o