[lld] r310084 - Fix which file is in an error message.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 4 11:33:16 PDT 2017


Author: rafael
Date: Fri Aug  4 11:33:16 2017
New Revision: 310084

URL: http://llvm.org/viewvc/llvm-project?rev=310084&view=rev
Log:
Fix which file is in an error message.

When reporting an invalid relocation we were blaming the destination
file instead of the file with the relocation.

Modified:
    lld/trunk/ELF/Arch/AArch64.cpp
    lld/trunk/ELF/Arch/AMDGPU.cpp
    lld/trunk/ELF/Arch/ARM.cpp
    lld/trunk/ELF/Arch/AVR.cpp
    lld/trunk/ELF/Arch/Mips.cpp
    lld/trunk/ELF/Arch/PPC.cpp
    lld/trunk/ELF/Arch/PPC64.cpp
    lld/trunk/ELF/Arch/SPARCV9.cpp
    lld/trunk/ELF/Arch/X86.cpp
    lld/trunk/ELF/Arch/X86_64.cpp
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/ELF/Relocations.cpp
    lld/trunk/ELF/Target.h
    lld/trunk/test/ELF/invalid/invalid-relocation-x64.test

Modified: lld/trunk/ELF/Arch/AArch64.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/AArch64.cpp?rev=310084&r1=310083&r2=310084&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/AArch64.cpp (original)
+++ lld/trunk/ELF/Arch/AArch64.cpp Fri Aug  4 11:33:16 2017
@@ -32,7 +32,7 @@ namespace {
 class AArch64 final : public TargetInfo {
 public:
   AArch64();
-  RelExpr getRelExpr(uint32_t Type, const SymbolBody &S,
+  RelExpr getRelExpr(uint32_t Type, const SymbolBody &S, const InputFile &File,
                      const uint8_t *Loc) const override;
   bool isPicRel(uint32_t Type) const override;
   void writeGotPlt(uint8_t *Buf, const SymbolBody &S) const override;
@@ -69,7 +69,7 @@ AArch64::AArch64() {
 }
 
 RelExpr AArch64::getRelExpr(uint32_t Type, const SymbolBody &S,
-                            const uint8_t *Loc) const {
+                            const InputFile &File, const uint8_t *Loc) const {
   switch (Type) {
   default:
     return R_ABS;

Modified: lld/trunk/ELF/Arch/AMDGPU.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/AMDGPU.cpp?rev=310084&r1=310083&r2=310084&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/AMDGPU.cpp (original)
+++ lld/trunk/ELF/Arch/AMDGPU.cpp Fri Aug  4 11:33:16 2017
@@ -26,7 +26,7 @@ class AMDGPU final : public TargetInfo {
 public:
   AMDGPU();
   void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override;
-  RelExpr getRelExpr(uint32_t Type, const SymbolBody &S,
+  RelExpr getRelExpr(uint32_t Type, const SymbolBody &S, const InputFile &File,
                      const uint8_t *Loc) const override;
 };
 } // namespace
@@ -59,7 +59,7 @@ void AMDGPU::relocateOne(uint8_t *Loc, u
 }
 
 RelExpr AMDGPU::getRelExpr(uint32_t Type, const SymbolBody &S,
-                           const uint8_t *Loc) const {
+                           const InputFile &File, const uint8_t *Loc) const {
   switch (Type) {
   case R_AMDGPU_ABS32:
   case R_AMDGPU_ABS64:
@@ -73,7 +73,7 @@ RelExpr AMDGPU::getRelExpr(uint32_t Type
   case R_AMDGPU_GOTPCREL32_HI:
     return R_GOT_PC;
   default:
-    error(toString(S.File) + ": unknown relocation type: " + toString(Type));
+    error(toString(&File) + ": unknown relocation type: " + toString(Type));
     return R_HINT;
   }
 }

Modified: lld/trunk/ELF/Arch/ARM.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/ARM.cpp?rev=310084&r1=310083&r2=310084&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/ARM.cpp (original)
+++ lld/trunk/ELF/Arch/ARM.cpp Fri Aug  4 11:33:16 2017
@@ -26,7 +26,7 @@ namespace {
 class ARM final : public TargetInfo {
 public:
   ARM();
-  RelExpr getRelExpr(uint32_t Type, const SymbolBody &S,
+  RelExpr getRelExpr(uint32_t Type, const SymbolBody &S, const InputFile &File,
                      const uint8_t *Loc) const override;
   bool isPicRel(uint32_t Type) const override;
   uint32_t getDynRel(uint32_t Type) const override;
@@ -66,7 +66,7 @@ ARM::ARM() {
 }
 
 RelExpr ARM::getRelExpr(uint32_t Type, const SymbolBody &S,
-                        const uint8_t *Loc) const {
+                        const InputFile &File, const uint8_t *Loc) const {
   switch (Type) {
   default:
     return R_ABS;

Modified: lld/trunk/ELF/Arch/AVR.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/AVR.cpp?rev=310084&r1=310083&r2=310084&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/AVR.cpp (original)
+++ lld/trunk/ELF/Arch/AVR.cpp Fri Aug  4 11:33:16 2017
@@ -43,19 +43,19 @@ using namespace lld::elf;
 namespace {
 class AVR final : public TargetInfo {
 public:
-  RelExpr getRelExpr(uint32_t Type, const SymbolBody &S,
+  RelExpr getRelExpr(uint32_t Type, const SymbolBody &S, const InputFile &File,
                      const uint8_t *Loc) const override;
   void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override;
 };
 } // namespace
 
 RelExpr AVR::getRelExpr(uint32_t Type, const SymbolBody &S,
-                        const uint8_t *Loc) const {
+                        const InputFile &File, const uint8_t *Loc) const {
   switch (Type) {
   case R_AVR_CALL:
     return R_ABS;
   default:
-    error(toString(S.File) + ": unknown relocation type: " + toString(Type));
+    error(toString(&File) + ": unknown relocation type: " + toString(Type));
     return R_HINT;
   }
 }

Modified: lld/trunk/ELF/Arch/Mips.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/Mips.cpp?rev=310084&r1=310083&r2=310084&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/Mips.cpp (original)
+++ lld/trunk/ELF/Arch/Mips.cpp Fri Aug  4 11:33:16 2017
@@ -28,7 +28,7 @@ namespace {
 template <class ELFT> class MIPS final : public TargetInfo {
 public:
   MIPS();
-  RelExpr getRelExpr(uint32_t Type, const SymbolBody &S,
+  RelExpr getRelExpr(uint32_t Type, const SymbolBody &S, const InputFile &File,
                      const uint8_t *Loc) const override;
   int64_t getImplicitAddend(const uint8_t *Buf, uint32_t Type) const override;
   bool isPicRel(uint32_t Type) const override;
@@ -71,6 +71,7 @@ template <class ELFT> MIPS<ELFT>::MIPS()
 
 template <class ELFT>
 RelExpr MIPS<ELFT>::getRelExpr(uint32_t Type, const SymbolBody &S,
+                               const InputFile &File,
                                const uint8_t *Loc) const {
   // See comment in the calculateMipsRelChain.
   if (ELFT::Is64Bits || Config->MipsN32Abi)

Modified: lld/trunk/ELF/Arch/PPC.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/PPC.cpp?rev=310084&r1=310083&r2=310084&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/PPC.cpp (original)
+++ lld/trunk/ELF/Arch/PPC.cpp Fri Aug  4 11:33:16 2017
@@ -23,7 +23,7 @@ class PPC final : public TargetInfo {
 public:
   PPC() { GotBaseSymOff = 0x8000; }
   void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override;
-  RelExpr getRelExpr(uint32_t Type, const SymbolBody &S,
+  RelExpr getRelExpr(uint32_t Type, const SymbolBody &S, const InputFile &File,
                      const uint8_t *Loc) const override;
 };
 } // namespace
@@ -49,7 +49,7 @@ void PPC::relocateOne(uint8_t *Loc, uint
 }
 
 RelExpr PPC::getRelExpr(uint32_t Type, const SymbolBody &S,
-                        const uint8_t *Loc) const {
+                        const InputFile &File, const uint8_t *Loc) const {
   switch (Type) {
   case R_PPC_REL24:
   case R_PPC_REL32:

Modified: lld/trunk/ELF/Arch/PPC64.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/PPC64.cpp?rev=310084&r1=310083&r2=310084&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/PPC64.cpp (original)
+++ lld/trunk/ELF/Arch/PPC64.cpp Fri Aug  4 11:33:16 2017
@@ -39,7 +39,7 @@ namespace {
 class PPC64 final : public TargetInfo {
 public:
   PPC64();
-  RelExpr getRelExpr(uint32_t Type, const SymbolBody &S,
+  RelExpr getRelExpr(uint32_t Type, const SymbolBody &S, const InputFile &File,
                      const uint8_t *Loc) const override;
   void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr,
                 int32_t Index, unsigned RelOff) const override;
@@ -83,7 +83,7 @@ PPC64::PPC64() {
 }
 
 RelExpr PPC64::getRelExpr(uint32_t Type, const SymbolBody &S,
-                          const uint8_t *Loc) const {
+                          const InputFile &File, const uint8_t *Loc) const {
   switch (Type) {
   default:
     return R_ABS;

Modified: lld/trunk/ELF/Arch/SPARCV9.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/SPARCV9.cpp?rev=310084&r1=310083&r2=310084&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/SPARCV9.cpp (original)
+++ lld/trunk/ELF/Arch/SPARCV9.cpp Fri Aug  4 11:33:16 2017
@@ -24,7 +24,7 @@ namespace {
 class SPARCV9 final : public TargetInfo {
 public:
   SPARCV9();
-  RelExpr getRelExpr(uint32_t Type, const SymbolBody &S,
+  RelExpr getRelExpr(uint32_t Type, const SymbolBody &S, const InputFile &File,
                      const uint8_t *Loc) const override;
   void writePlt(uint8_t *Buf, uint64_t GotEntryAddr, uint64_t PltEntryAddr,
                 int32_t Index, unsigned RelOff) const override;
@@ -47,7 +47,7 @@ SPARCV9::SPARCV9() {
 }
 
 RelExpr SPARCV9::getRelExpr(uint32_t Type, const SymbolBody &S,
-                            const uint8_t *Loc) const {
+                            const InputFile &File, const uint8_t *Loc) const {
   switch (Type) {
   case R_SPARC_32:
   case R_SPARC_UA32:
@@ -68,7 +68,7 @@ RelExpr SPARCV9::getRelExpr(uint32_t Typ
   case R_SPARC_NONE:
     return R_NONE;
   default:
-    error(toString(S.File) + ": unknown relocation type: " + toString(Type));
+    error(toString(&File) + ": unknown relocation type: " + toString(Type));
     return R_HINT;
   }
 }

Modified: lld/trunk/ELF/Arch/X86.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/X86.cpp?rev=310084&r1=310083&r2=310084&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/X86.cpp (original)
+++ lld/trunk/ELF/Arch/X86.cpp Fri Aug  4 11:33:16 2017
@@ -24,7 +24,7 @@ namespace {
 class X86 final : public TargetInfo {
 public:
   X86();
-  RelExpr getRelExpr(uint32_t Type, const SymbolBody &S,
+  RelExpr getRelExpr(uint32_t Type, const SymbolBody &S, const InputFile &File,
                      const uint8_t *Loc) const override;
   int64_t getImplicitAddend(const uint8_t *Buf, uint32_t Type) const override;
   void writeGotPltHeader(uint8_t *Buf) const override;
@@ -64,7 +64,7 @@ X86::X86() {
 }
 
 RelExpr X86::getRelExpr(uint32_t Type, const SymbolBody &S,
-                        const uint8_t *Loc) const {
+                        const InputFile &File, const uint8_t *Loc) const {
   switch (Type) {
   case R_386_8:
   case R_386_16:
@@ -101,7 +101,7 @@ RelExpr X86::getRelExpr(uint32_t Type, c
     if ((Loc[-1] & 0xc7) != 0x5)
       return R_GOT_FROM_END;
     if (Config->Pic)
-      error(toString(S.File) + ": relocation " + toString(Type) + " against '" +
+      error(toString(&File) + ": relocation " + toString(Type) + " against '" +
             S.getName() +
             "' without base register can not be used when PIC enabled");
     return R_GOT;
@@ -116,7 +116,7 @@ RelExpr X86::getRelExpr(uint32_t Type, c
   case R_386_NONE:
     return R_NONE;
   default:
-    error(toString(S.File) + ": unknown relocation type: " + toString(Type));
+    error(toString(&File) + ": unknown relocation type: " + toString(Type));
     return R_HINT;
   }
 }

Modified: lld/trunk/ELF/Arch/X86_64.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/X86_64.cpp?rev=310084&r1=310083&r2=310084&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/X86_64.cpp (original)
+++ lld/trunk/ELF/Arch/X86_64.cpp Fri Aug  4 11:33:16 2017
@@ -26,7 +26,7 @@ namespace {
 template <class ELFT> class X86_64 final : public TargetInfo {
 public:
   X86_64();
-  RelExpr getRelExpr(uint32_t Type, const SymbolBody &S,
+  RelExpr getRelExpr(uint32_t Type, const SymbolBody &S, const InputFile &File,
                      const uint8_t *Loc) const override;
   bool isPicRel(uint32_t Type) const override;
   void writeGotPltHeader(uint8_t *Buf) const override;
@@ -74,6 +74,7 @@ template <class ELFT> X86_64<ELFT>::X86_
 
 template <class ELFT>
 RelExpr X86_64<ELFT>::getRelExpr(uint32_t Type, const SymbolBody &S,
+                                 const InputFile &File,
                                  const uint8_t *Loc) const {
   switch (Type) {
   case R_X86_64_8:
@@ -109,7 +110,7 @@ RelExpr X86_64<ELFT>::getRelExpr(uint32_
   case R_X86_64_NONE:
     return R_NONE;
   default:
-    error(toString(S.File) + ": unknown relocation type: " + toString(Type));
+    error(toString(&File) + ": unknown relocation type: " + toString(Type));
     return R_HINT;
   }
 }

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=310084&r1=310083&r2=310084&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Fri Aug  4 11:33:16 2017
@@ -669,7 +669,7 @@ void InputSection::relocateNonAlloc(uint
       Addend += Target->getImplicitAddend(BufLoc, Type);
 
     SymbolBody &Sym = this->getFile<ELFT>()->getRelocTargetSym(Rel);
-    RelExpr Expr = Target->getRelExpr(Type, Sym, BufLoc);
+    RelExpr Expr = Target->getRelExpr(Type, Sym, *File, BufLoc);
     if (Expr == R_NONE)
       continue;
     if (Expr != R_ABS) {

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=310084&r1=310083&r2=310084&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Fri Aug  4 11:33:16 2017
@@ -844,8 +844,8 @@ static void scanRelocs(InputSectionBase
     if (!Body.isLocal() && Body.isUndefined() && !Body.symbol()->isWeak())
       reportUndefined<ELFT>(Body, Sec, Rel.r_offset);
 
-    RelExpr Expr =
-        Target->getRelExpr(Type, Body, Sec.Data.begin() + Rel.r_offset);
+    RelExpr Expr = Target->getRelExpr(Type, Body, *Sec.File,
+                                      Sec.Data.begin() + Rel.r_offset);
 
     // Ignore "hint" relocations because they are only markers for relaxation.
     if (isRelExprOneOf<R_HINT, R_NONE>(Expr))

Modified: lld/trunk/ELF/Target.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.h?rev=310084&r1=310083&r2=310084&view=diff
==============================================================================
--- lld/trunk/ELF/Target.h (original)
+++ lld/trunk/ELF/Target.h Fri Aug  4 11:33:16 2017
@@ -55,6 +55,7 @@ public:
   virtual bool inBranchRange(uint32_t RelocType, uint64_t Src,
                              uint64_t Dst) const;
   virtual RelExpr getRelExpr(uint32_t Type, const SymbolBody &S,
+                             const InputFile &File,
                              const uint8_t *Loc) const = 0;
   virtual void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const = 0;
   virtual ~TargetInfo();

Modified: lld/trunk/test/ELF/invalid/invalid-relocation-x64.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid/invalid-relocation-x64.test?rev=310084&r1=310083&r2=310084&view=diff
==============================================================================
--- lld/trunk/test/ELF/invalid/invalid-relocation-x64.test (original)
+++ lld/trunk/test/ELF/invalid/invalid-relocation-x64.test Fri Aug  4 11:33:16 2017
@@ -1,7 +1,10 @@
-# RUN: yaml2obj %s -o %t.o
-# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s
-# CHECK: {{.*}}.o: unknown relocation type: Unknown (152)
-# CHECK: {{.*}}.o: unknown relocation type: Unknown (153)
+# REQUIRES: x86
+# RUN: yaml2obj %s -o %t1.o
+# RUN: echo ".global foo; foo:" > %t2.s
+# RUN: llvm-mc %t2.s -o %t2.o -filetype=obj -triple x86_64-pc-linux
+# RUN: not ld.lld %t1.o %t2.o -o /dev/null 2>&1 | FileCheck %s
+# CHECK: {{.*}}1.o: unknown relocation type: Unknown (152)
+# CHECK: {{.*}}1.o: unknown relocation type: Unknown (153)
 
 !ELF
 FileHeader:
@@ -20,8 +23,11 @@ Sections:
     Info:            .text
     Relocations:
       - Offset:          0x0000000000000000
-        Symbol:          ''
+        Symbol:          foo
         Type:            0x98
       - Offset:          0x0000000000000000
-        Symbol:          ''
+        Symbol:          foo
         Type:            0x99
+Symbols:
+  Global:
+      - Name:            foo




More information about the llvm-commits mailing list