[lld] r279162 - [ELF] Improve error reporting for relocations

Petr Hosek via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 18 14:55:24 PDT 2016


Author: phosek
Date: Thu Aug 18 16:55:23 2016
New Revision: 279162

URL: http://llvm.org/viewvc/llvm-project?rev=279162&view=rev
Log:
[ELF] Improve error reporting for relocations

We should always include symbol name when reporting relocations
error to simplify debugging of these issues. Without symbol names
users have to manually investigate which of the libraries contain
invalid relocations which can be cumbersome when linking multiple
libraries.

Differential Revision: https://reviews.llvm.org/D23690

Modified:
    lld/trunk/ELF/Relocations.cpp
    lld/trunk/test/ELF/aarch64-fpic-add_abs_lo12_nc.s
    lld/trunk/test/ELF/aarch64-fpic-adr_prel_lo21.s
    lld/trunk/test/ELF/aarch64-fpic-adr_prel_pg_hi21.s
    lld/trunk/test/ELF/aarch64-fpic-ldst32_abs_lo12_nc.s
    lld/trunk/test/ELF/aarch64-fpic-ldst64_abs_lo12_nc.s
    lld/trunk/test/ELF/aarch64-fpic-ldst8_abs_lo12_nc.s
    lld/trunk/test/ELF/arm-target1.s
    lld/trunk/test/ELF/copy-errors.s
    lld/trunk/test/ELF/copy-in-shared.s
    lld/trunk/test/ELF/copy-rel-corrupted.s
    lld/trunk/test/ELF/copy-rel-pie-error.s
    lld/trunk/test/ELF/dynamic-reloc-in-ro.s
    lld/trunk/test/ELF/eh-frame-dyn-rel.s

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=279162&r1=279161&r2=279162&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Thu Aug 18 16:55:23 2016
@@ -374,7 +374,7 @@ template <class ELFT> static void addCop
   // Copy relocation against zero-sized symbol doesn't make sense.
   uintX_t SymSize = SS->template getSize<ELFT>();
   if (SymSize == 0)
-    fatal("cannot create a copy relocation for " + SS->getName());
+    fatal("cannot create a copy relocation for symbol " + SS->getName());
 
   uintX_t Alignment = getAlignment(SS);
   uintX_t Off = alignTo(Out<ELFT>::Bss->getSize(), Alignment);
@@ -401,6 +401,12 @@ template <class ELFT> static void addCop
 }
 
 template <class ELFT>
+static StringRef getLocalSymbolName(const elf::ObjectFile<ELFT> &File,
+                                    SymbolBody &Body) {
+  return File.getStringTable().data() + Body.getNameOffset();
+}
+
+template <class ELFT>
 static RelExpr adjustExpr(const elf::ObjectFile<ELFT> &File, SymbolBody &Body,
                           bool IsWrite, RelExpr Expr, uint32_t Type,
                           const uint8_t *Data) {
@@ -422,12 +428,14 @@ static RelExpr adjustExpr(const elf::Obj
   // only memory. We can hack around it if we are producing an executable and
   // the refered symbol can be preemepted to refer to the executable.
   if (Config->Shared || (Config->Pic && !isRelExpr(Expr))) {
+    StringRef Name = Body.isLocal() ? getLocalSymbolName(File, Body)
+                                    : Body.getName();
     error("can't create dynamic relocation " + getRelName(Type) +
-          " against readonly segment");
+          " against symbol " + Name);
     return Expr;
   }
   if (Body.getVisibility() != STV_DEFAULT) {
-    error("cannot preempt symbol");
+    error("cannot preempt symbol " + Body.getName());
     return Expr;
   }
   if (Body.isObject()) {
@@ -461,7 +469,7 @@ static RelExpr adjustExpr(const elf::Obj
     Body.NeedsCopyOrPltAddr = true;
     return toPlt(Expr);
   }
-  error("symbol is missing type");
+  error("symbol " + Body.getName() + " is missing type");
 
   return Expr;
 }

Modified: lld/trunk/test/ELF/aarch64-fpic-add_abs_lo12_nc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/aarch64-fpic-add_abs_lo12_nc.s?rev=279162&r1=279161&r2=279162&view=diff
==============================================================================
--- lld/trunk/test/ELF/aarch64-fpic-add_abs_lo12_nc.s (original)
+++ lld/trunk/test/ELF/aarch64-fpic-add_abs_lo12_nc.s Thu Aug 18 16:55:23 2016
@@ -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 readonly segment
+// CHECK: can't create dynamic relocation R_AARCH64_ADD_ABS_LO12_NC against symbol dat
 
   add x0, x0, :lo12:dat
 .data

Modified: lld/trunk/test/ELF/aarch64-fpic-adr_prel_lo21.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/aarch64-fpic-adr_prel_lo21.s?rev=279162&r1=279161&r2=279162&view=diff
==============================================================================
--- lld/trunk/test/ELF/aarch64-fpic-adr_prel_lo21.s (original)
+++ lld/trunk/test/ELF/aarch64-fpic-adr_prel_lo21.s Thu Aug 18 16:55:23 2016
@@ -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 readonly segment
+// CHECK: can't create dynamic relocation R_AARCH64_ADR_PREL_LO21 against symbol dat
 
   adr x0, dat
 .data

Modified: lld/trunk/test/ELF/aarch64-fpic-adr_prel_pg_hi21.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/aarch64-fpic-adr_prel_pg_hi21.s?rev=279162&r1=279161&r2=279162&view=diff
==============================================================================
--- lld/trunk/test/ELF/aarch64-fpic-adr_prel_pg_hi21.s (original)
+++ lld/trunk/test/ELF/aarch64-fpic-adr_prel_pg_hi21.s Thu Aug 18 16:55:23 2016
@@ -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 readonly segment
+// CHECK: can't create dynamic relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol dat
 
   adrp x0, dat
 .data

Modified: lld/trunk/test/ELF/aarch64-fpic-ldst32_abs_lo12_nc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/aarch64-fpic-ldst32_abs_lo12_nc.s?rev=279162&r1=279161&r2=279162&view=diff
==============================================================================
--- lld/trunk/test/ELF/aarch64-fpic-ldst32_abs_lo12_nc.s (original)
+++ lld/trunk/test/ELF/aarch64-fpic-ldst32_abs_lo12_nc.s Thu Aug 18 16:55:23 2016
@@ -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 readonly segment
+// CHECK: can't create dynamic relocation R_AARCH64_LDST32_ABS_LO12_NC against symbol dat
 
   ldr s4, [x0, :lo12:dat]
 .data

Modified: lld/trunk/test/ELF/aarch64-fpic-ldst64_abs_lo12_nc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/aarch64-fpic-ldst64_abs_lo12_nc.s?rev=279162&r1=279161&r2=279162&view=diff
==============================================================================
--- lld/trunk/test/ELF/aarch64-fpic-ldst64_abs_lo12_nc.s (original)
+++ lld/trunk/test/ELF/aarch64-fpic-ldst64_abs_lo12_nc.s Thu Aug 18 16:55:23 2016
@@ -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 readonly segment
+// CHECK: can't create dynamic relocation R_AARCH64_LDST64_ABS_LO12_NC against symbol dat
 
   ldr x0, [x0, :lo12:dat]
 .data

Modified: lld/trunk/test/ELF/aarch64-fpic-ldst8_abs_lo12_nc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/aarch64-fpic-ldst8_abs_lo12_nc.s?rev=279162&r1=279161&r2=279162&view=diff
==============================================================================
--- lld/trunk/test/ELF/aarch64-fpic-ldst8_abs_lo12_nc.s (original)
+++ lld/trunk/test/ELF/aarch64-fpic-ldst8_abs_lo12_nc.s Thu Aug 18 16:55:23 2016
@@ -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 readonly segment
+// CHECK: can't create dynamic relocation R_AARCH64_LDST8_ABS_LO12_NC against symbol dat
 
   ldrsb x0, [x1, :lo12:dat]
 .data

Modified: lld/trunk/test/ELF/arm-target1.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/arm-target1.s?rev=279162&r1=279161&r2=279162&view=diff
==============================================================================
--- lld/trunk/test/ELF/arm-target1.s (original)
+++ lld/trunk/test/ELF/arm-target1.s Thu Aug 18 16:55:23 2016
@@ -23,4 +23,4 @@
 // RELATIVE: SYMBOL TABLE:
 // RELATIVE: 00001004         .text           00000000 patatino
 
-// ABS: can't create dynamic relocation R_ARM_TARGET1 against readonly segment
+// ABS: can't create dynamic relocation R_ARM_TARGET1 against symbol patatino

Modified: lld/trunk/test/ELF/copy-errors.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/copy-errors.s?rev=279162&r1=279161&r2=279162&view=diff
==============================================================================
--- lld/trunk/test/ELF/copy-errors.s (original)
+++ lld/trunk/test/ELF/copy-errors.s Thu Aug 18 16:55:23 2016
@@ -9,7 +9,7 @@ _start:
 
 
 call bar
-// CHECK: cannot preempt symbol
+// CHECK: cannot preempt symbol bar
 
 call zed
-// CHECK: symbol is missing type
+// CHECK: symbol zed is missing type

Modified: lld/trunk/test/ELF/copy-in-shared.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/copy-in-shared.s?rev=279162&r1=279161&r2=279162&view=diff
==============================================================================
--- lld/trunk/test/ELF/copy-in-shared.s (original)
+++ lld/trunk/test/ELF/copy-in-shared.s Thu Aug 18 16:55:23 2016
@@ -7,4 +7,4 @@
 
 .quad foo
 
-// CHECK: can't create dynamic relocation R_X86_64_64 against readonly segment
+// CHECK: can't create dynamic relocation R_X86_64_64 against symbol foo

Modified: lld/trunk/test/ELF/copy-rel-corrupted.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/copy-rel-corrupted.s?rev=279162&r1=279161&r2=279162&view=diff
==============================================================================
--- lld/trunk/test/ELF/copy-rel-corrupted.s (original)
+++ lld/trunk/test/ELF/copy-rel-corrupted.s Thu Aug 18 16:55:23 2016
@@ -3,7 +3,7 @@
 // RUN: ld.lld %t2.o -o %t2.so -shared
 // RUN: not ld.lld %t.o %t2.so -o %t.exe 2>&1 | FileCheck %s
 
-// CHECK: cannot create a copy relocation for x
+// CHECK: cannot create a copy relocation for symbol x
 
 .global _start
 _start:

Modified: lld/trunk/test/ELF/copy-rel-pie-error.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/copy-rel-pie-error.s?rev=279162&r1=279161&r2=279162&view=diff
==============================================================================
--- lld/trunk/test/ELF/copy-rel-pie-error.s (original)
+++ lld/trunk/test/ELF/copy-rel-pie-error.s Thu Aug 18 16:55:23 2016
@@ -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 readonly segment
-// CHECK: can't create dynamic relocation R_X86_64_64 against readonly segment
+// 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
 
 .global _start
 _start:

Modified: lld/trunk/test/ELF/dynamic-reloc-in-ro.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/dynamic-reloc-in-ro.s?rev=279162&r1=279161&r2=279162&view=diff
==============================================================================
--- lld/trunk/test/ELF/dynamic-reloc-in-ro.s (original)
+++ lld/trunk/test/ELF/dynamic-reloc-in-ro.s Thu Aug 18 16:55:23 2016
@@ -5,4 +5,4 @@
 foo:
 .quad foo
 
-// CHECK: can't create dynamic relocation R_X86_64_64 against readonly segment
+// CHECK: can't create dynamic relocation R_X86_64_64 against symbol

Modified: lld/trunk/test/ELF/eh-frame-dyn-rel.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/eh-frame-dyn-rel.s?rev=279162&r1=279161&r2=279162&view=diff
==============================================================================
--- lld/trunk/test/ELF/eh-frame-dyn-rel.s (original)
+++ lld/trunk/test/ELF/eh-frame-dyn-rel.s Thu Aug 18 16:55:23 2016
@@ -7,4 +7,4 @@
         .cfi_personality 0x8c, foo
         .cfi_endproc
 
-// CHECK: can't create dynamic relocation R_X86_64_64 against readonly segment
+// CHECK: can't create dynamic relocation R_X86_64_64 against symbol foo




More information about the llvm-commits mailing list