[lld] r343078 - [ELF] - Do not fail on R_*_NONE relocations when parsing the debug info.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 26 01:11:35 PDT 2018


Author: grimar
Date: Wed Sep 26 01:11:34 2018
New Revision: 343078

URL: http://llvm.org/viewvc/llvm-project?rev=343078&view=rev
Log:
[ELF] - Do not fail on R_*_NONE relocations when parsing the debug info.

This is https://bugs.llvm.org//show_bug.cgi?id=38919.

Currently, LLD may report "unsupported relocation target while parsing debug info"
when parsing the debug information.

At the same time LLD does that for zeroed R_X86_64_NONE relocations,
which obviously has "invalid" targets.

The nature of R_*_NONE relocation assumes them should be ignored.
This patch teaches LLD to stop reporting the debug information parsing errors for them.

Differential revision: https://reviews.llvm.org/D52408

Added:
    lld/trunk/test/ELF/debug-relocation-none.test
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/Hexagon.cpp
    lld/trunk/ELF/Arch/Mips.cpp
    lld/trunk/ELF/Arch/PPC.cpp
    lld/trunk/ELF/Arch/PPC64.cpp
    lld/trunk/ELF/Arch/RISCV.cpp
    lld/trunk/ELF/Arch/SPARCV9.cpp
    lld/trunk/ELF/Arch/X86.cpp
    lld/trunk/ELF/Arch/X86_64.cpp
    lld/trunk/ELF/DWARF.cpp
    lld/trunk/ELF/Target.h
    lld/trunk/test/ELF/undef-broken-debug.test

Modified: lld/trunk/ELF/Arch/AArch64.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/AArch64.cpp?rev=343078&r1=343077&r2=343078&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/AArch64.cpp (original)
+++ lld/trunk/ELF/Arch/AArch64.cpp Wed Sep 26 01:11:34 2018
@@ -58,6 +58,7 @@ AArch64::AArch64() {
   RelativeRel = R_AARCH64_RELATIVE;
   IRelativeRel = R_AARCH64_IRELATIVE;
   GotRel = R_AARCH64_GLOB_DAT;
+  NoneRel = R_AARCH64_NONE;
   PltRel = R_AARCH64_JUMP_SLOT;
   TlsDescRel = R_AARCH64_TLSDESC;
   TlsGotRel = R_AARCH64_TLS_TPREL64;

Modified: lld/trunk/ELF/Arch/AMDGPU.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/AMDGPU.cpp?rev=343078&r1=343077&r2=343078&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/AMDGPU.cpp (original)
+++ lld/trunk/ELF/Arch/AMDGPU.cpp Wed Sep 26 01:11:34 2018
@@ -35,6 +35,7 @@ public:
 AMDGPU::AMDGPU() {
   RelativeRel = R_AMDGPU_RELATIVE64;
   GotRel = R_AMDGPU_ABS64;
+  NoneRel = R_AMDGPU_NONE;
   GotEntrySize = 8;
 }
 

Modified: lld/trunk/ELF/Arch/ARM.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/ARM.cpp?rev=343078&r1=343077&r2=343078&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/ARM.cpp (original)
+++ lld/trunk/ELF/Arch/ARM.cpp Wed Sep 26 01:11:34 2018
@@ -51,6 +51,7 @@ ARM::ARM() {
   RelativeRel = R_ARM_RELATIVE;
   IRelativeRel = R_ARM_IRELATIVE;
   GotRel = R_ARM_GLOB_DAT;
+  NoneRel = R_ARM_NONE;
   PltRel = R_ARM_JUMP_SLOT;
   TlsGotRel = R_ARM_TLS_TPOFF32;
   TlsModuleIndexRel = R_ARM_TLS_DTPMOD32;

Modified: lld/trunk/ELF/Arch/AVR.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/AVR.cpp?rev=343078&r1=343077&r2=343078&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/AVR.cpp (original)
+++ lld/trunk/ELF/Arch/AVR.cpp Wed Sep 26 01:11:34 2018
@@ -43,12 +43,15 @@ using namespace lld::elf;
 namespace {
 class AVR final : public TargetInfo {
 public:
+  AVR();
   RelExpr getRelExpr(RelType Type, const Symbol &S,
                      const uint8_t *Loc) const override;
   void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override;
 };
 } // namespace
 
+AVR::AVR() { NoneRel = R_AVR_NONE; }
+
 RelExpr AVR::getRelExpr(RelType Type, const Symbol &S,
                         const uint8_t *Loc) const {
   return R_ABS;

Modified: lld/trunk/ELF/Arch/Hexagon.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/Hexagon.cpp?rev=343078&r1=343077&r2=343078&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/Hexagon.cpp (original)
+++ lld/trunk/ELF/Arch/Hexagon.cpp Wed Sep 26 01:11:34 2018
@@ -36,6 +36,7 @@ public:
 Hexagon::Hexagon() {
   // Hexagon Linux uses 64K pages by default.
   DefaultMaxPageSize = 0x10000;
+  NoneRel = R_HEX_NONE;
 }
 
 // Support V60 only at the moment.

Modified: lld/trunk/ELF/Arch/Mips.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/Mips.cpp?rev=343078&r1=343077&r2=343078&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/Mips.cpp (original)
+++ lld/trunk/ELF/Arch/Mips.cpp Wed Sep 26 01:11:34 2018
@@ -53,6 +53,7 @@ template <class ELFT> MIPS<ELFT>::MIPS()
   PltEntrySize = 16;
   PltHeaderSize = 32;
   CopyRel = R_MIPS_COPY;
+  NoneRel = R_MIPS_NONE;
   PltRel = R_MIPS_JUMP_SLOT;
   NeedsThunks = true;
   TrapInstr = 0xefefefef;

Modified: lld/trunk/ELF/Arch/PPC.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/PPC.cpp?rev=343078&r1=343077&r2=343078&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/PPC.cpp (original)
+++ lld/trunk/ELF/Arch/PPC.cpp Wed Sep 26 01:11:34 2018
@@ -29,6 +29,7 @@ public:
 } // namespace
 
 PPC::PPC() {
+  NoneRel = R_PPC_NONE;
   GotBaseSymOff = 0x8000;
   GotBaseSymInGotPlt = false;
 }

Modified: lld/trunk/ELF/Arch/PPC64.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/PPC64.cpp?rev=343078&r1=343077&r2=343078&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/PPC64.cpp (original)
+++ lld/trunk/ELF/Arch/PPC64.cpp Wed Sep 26 01:11:34 2018
@@ -192,6 +192,7 @@ static uint32_t readInstrFromHalf16(cons
 
 PPC64::PPC64() {
   GotRel = R_PPC64_GLOB_DAT;
+  NoneRel = R_PPC64_NONE;
   PltRel = R_PPC64_JMP_SLOT;
   RelativeRel = R_PPC64_RELATIVE;
   IRelativeRel = R_PPC64_IRELATIVE;

Modified: lld/trunk/ELF/Arch/RISCV.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/RISCV.cpp?rev=343078&r1=343077&r2=343078&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/RISCV.cpp (original)
+++ lld/trunk/ELF/Arch/RISCV.cpp Wed Sep 26 01:11:34 2018
@@ -21,6 +21,7 @@ namespace {
 
 class RISCV final : public TargetInfo {
 public:
+  RISCV();
   virtual uint32_t calcEFlags() const override;
   RelExpr getRelExpr(RelType Type, const Symbol &S,
                      const uint8_t *Loc) const override;
@@ -29,6 +30,8 @@ public:
 
 } // end anonymous namespace
 
+RISCV::RISCV() { NoneRel = R_RISCV_NONE; }
+
 static uint32_t getEFlags(InputFile *F) {
   if (Config->Is64)
     return cast<ObjFile<ELF64LE>>(F)->getObj().getHeader()->e_flags;

Modified: lld/trunk/ELF/Arch/SPARCV9.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/SPARCV9.cpp?rev=343078&r1=343077&r2=343078&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/SPARCV9.cpp (original)
+++ lld/trunk/ELF/Arch/SPARCV9.cpp Wed Sep 26 01:11:34 2018
@@ -35,6 +35,7 @@ public:
 SPARCV9::SPARCV9() {
   CopyRel = R_SPARC_COPY;
   GotRel = R_SPARC_GLOB_DAT;
+  NoneRel = R_SPARC_NONE;
   PltRel = R_SPARC_JMP_SLOT;
   RelativeRel = R_SPARC_RELATIVE;
   GotEntrySize = 8;

Modified: lld/trunk/ELF/Arch/X86.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/X86.cpp?rev=343078&r1=343077&r2=343078&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/X86.cpp (original)
+++ lld/trunk/ELF/Arch/X86.cpp Wed Sep 26 01:11:34 2018
@@ -48,6 +48,7 @@ public:
 X86::X86() {
   CopyRel = R_386_COPY;
   GotRel = R_386_GLOB_DAT;
+  NoneRel = R_386_NONE;
   PltRel = R_386_JUMP_SLOT;
   IRelativeRel = R_386_IRELATIVE;
   RelativeRel = R_386_RELATIVE;

Modified: lld/trunk/ELF/Arch/X86_64.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/X86_64.cpp?rev=343078&r1=343077&r2=343078&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/X86_64.cpp (original)
+++ lld/trunk/ELF/Arch/X86_64.cpp Wed Sep 26 01:11:34 2018
@@ -55,6 +55,7 @@ private:
 template <class ELFT> X86_64<ELFT>::X86_64() {
   CopyRel = R_X86_64_COPY;
   GotRel = R_X86_64_GLOB_DAT;
+  NoneRel = R_X86_64_NONE;
   PltRel = R_X86_64_JUMP_SLOT;
   RelativeRel = R_X86_64_RELATIVE;
   IRelativeRel = R_X86_64_IRELATIVE;

Modified: lld/trunk/ELF/DWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/DWARF.cpp?rev=343078&r1=343077&r2=343078&view=diff
==============================================================================
--- lld/trunk/ELF/DWARF.cpp (original)
+++ lld/trunk/ELF/DWARF.cpp Wed Sep 26 01:11:34 2018
@@ -16,6 +16,7 @@
 
 #include "DWARF.h"
 #include "Symbols.h"
+#include "Target.h"
 #include "lld/Common/Memory.h"
 #include "llvm/DebugInfo/DWARF/DWARFDebugPubTable.h"
 #include "llvm/Object/ELFObjectFile.h"
@@ -73,7 +74,10 @@ LLDDwarfObj<ELFT>::findAux(const InputSe
   // Broken debug info can point to a non-Defined symbol.
   auto *DR = dyn_cast<Defined>(&File->getRelocTargetSym(Rel));
   if (!DR) {
-    error("unsupported relocation target while parsing debug info");
+    RelType Type = Rel.getType(Config->IsMips64EL);
+    if (Type != Target->NoneRel)
+      error(toString(File) + ": relocation " + lld::toString(Type) + " at 0x" +
+            llvm::utohexstr(Rel.r_offset) + " has unsupported target");
     return None;
   }
   uint64_t Val = DR->Value + getAddend<ELFT>(Rel);

Modified: lld/trunk/ELF/Target.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.h?rev=343078&r1=343077&r2=343078&view=diff
==============================================================================
--- lld/trunk/ELF/Target.h (original)
+++ lld/trunk/ELF/Target.h Wed Sep 26 01:11:34 2018
@@ -95,6 +95,7 @@ public:
 
   RelType CopyRel;
   RelType GotRel;
+  RelType NoneRel;
   RelType PltRel;
   RelType RelativeRel;
   RelType IRelativeRel;

Added: lld/trunk/test/ELF/debug-relocation-none.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/debug-relocation-none.test?rev=343078&view=auto
==============================================================================
--- lld/trunk/test/ELF/debug-relocation-none.test (added)
+++ lld/trunk/test/ELF/debug-relocation-none.test Wed Sep 26 01:11:34 2018
@@ -0,0 +1,58 @@
+# REQUIRES: x86
+# RUN: yaml2obj %s -o %t.o
+# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s
+
+## Previously we would report an error saying the relocation in .debug_info
+## has an unsupported target.
+## Check we do not report debug information parsing errors when relocation
+## used is of type R_*_NONE, what actually means it should be ignored.
+
+# CHECK-NOT: error
+# CHECK: error: undefined symbol: bar
+# CHECK-NOT: error
+
+--- !ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_X86_64
+Sections:
+  - Name:            .text
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
+    Content:         '0000000000000000'
+  - Name:            .rela.text
+    Type:            SHT_RELA
+    AddressAlign:    8
+    Link:            .symtab
+    Info:            .text
+    Relocations:
+      - Offset:          0x0000000000000000
+        Symbol:          bar
+        Type:            R_X86_64_64
+  - Name:            .debug_line
+    Type:            SHT_PROGBITS
+    Content:         3300000002001C0000000101FB0E0D000101010100000001000001006162632E7300000000000009020000000000000000140208000101
+  - Name:            .rela.debug_line
+    AddressAlign:    8
+    Type:            SHT_RELA
+    Link:            .symtab
+    Info:            .debug_line
+    Relocations:
+      - Offset:          0x0000000000000029
+        Type:            R_X86_64_NONE
+  - Name:            .debug_info
+    Type:            SHT_PROGBITS
+    AddressAlign:    0x0000000000000001
+    Content:         0C000000040000000000080100000000
+  - Name:            .debug_abbrev
+    Type:            SHT_PROGBITS
+    AddressAlign:    0x0000000000000001
+    Content:         '0111001017000000'
+
+Symbols:
+  Global:
+    - Name:            _start
+      Section:         .text
+    - Name:            bar

Modified: lld/trunk/test/ELF/undef-broken-debug.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/undef-broken-debug.test?rev=343078&r1=343077&r2=343078&view=diff
==============================================================================
--- lld/trunk/test/ELF/undef-broken-debug.test (original)
+++ lld/trunk/test/ELF/undef-broken-debug.test Wed Sep 26 01:11:34 2018
@@ -5,7 +5,7 @@
 # The debug info has a broken relocation. Check that we don't crash
 # and still report the undefined symbol.
 
-# CHECK: error: unsupported relocation target while parsing debug info
+# CHECK: error: {{.*}}.o: relocation R_X86_64_64 at 0x29 has unsupported target
 # CHECK: error: undefined symbol: bar
 
 --- !ELF




More information about the llvm-commits mailing list