Index: ELF/Arch/AArch64.cpp =================================================================== --- ELF/Arch/AArch64.cpp +++ ELF/Arch/AArch64.cpp @@ -58,6 +58,7 @@ 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; Index: ELF/Arch/AMDGPU.cpp =================================================================== --- ELF/Arch/AMDGPU.cpp +++ ELF/Arch/AMDGPU.cpp @@ -35,6 +35,7 @@ AMDGPU::AMDGPU() { RelativeRel = R_AMDGPU_RELATIVE64; GotRel = R_AMDGPU_ABS64; + NoneRel = R_AMDGPU_NONE; GotEntrySize = 8; } Index: ELF/Arch/ARM.cpp =================================================================== --- ELF/Arch/ARM.cpp +++ ELF/Arch/ARM.cpp @@ -51,6 +51,7 @@ 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; Index: ELF/Arch/AVR.cpp =================================================================== --- ELF/Arch/AVR.cpp +++ ELF/Arch/AVR.cpp @@ -43,12 +43,15 @@ 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; Index: ELF/Arch/Hexagon.cpp =================================================================== --- ELF/Arch/Hexagon.cpp +++ ELF/Arch/Hexagon.cpp @@ -36,6 +36,7 @@ Hexagon::Hexagon() { // Hexagon Linux uses 64K pages by default. DefaultMaxPageSize = 0x10000; + NoneRel = R_HEX_NONE; } // Support V60 only at the moment. Index: ELF/Arch/Mips.cpp =================================================================== --- ELF/Arch/Mips.cpp +++ ELF/Arch/Mips.cpp @@ -53,6 +53,7 @@ PltEntrySize = 16; PltHeaderSize = 32; CopyRel = R_MIPS_COPY; + NoneRel = R_MIPS_NONE; PltRel = R_MIPS_JUMP_SLOT; NeedsThunks = true; TrapInstr = 0xefefefef; Index: ELF/Arch/PPC.cpp =================================================================== --- ELF/Arch/PPC.cpp +++ ELF/Arch/PPC.cpp @@ -29,6 +29,7 @@ } // namespace PPC::PPC() { + NoneRel = R_PPC_NONE; GotBaseSymOff = 0x8000; GotBaseSymInGotPlt = false; } Index: ELF/Arch/PPC64.cpp =================================================================== --- ELF/Arch/PPC64.cpp +++ ELF/Arch/PPC64.cpp @@ -192,6 +192,7 @@ PPC64::PPC64() { GotRel = R_PPC64_GLOB_DAT; + NoneRel = R_PPC64_NONE; PltRel = R_PPC64_JMP_SLOT; RelativeRel = R_PPC64_RELATIVE; IRelativeRel = R_PPC64_IRELATIVE; Index: ELF/Arch/RISCV.cpp =================================================================== --- ELF/Arch/RISCV.cpp +++ ELF/Arch/RISCV.cpp @@ -21,6 +21,7 @@ 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 @@ } // end anonymous namespace +RISCV::RISCV() { NoneRel = R_RISCV_NONE; } + static uint32_t getEFlags(InputFile *F) { if (Config->Is64) return cast>(F)->getObj().getHeader()->e_flags; Index: ELF/Arch/SPARCV9.cpp =================================================================== --- ELF/Arch/SPARCV9.cpp +++ ELF/Arch/SPARCV9.cpp @@ -35,6 +35,7 @@ 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; Index: ELF/Arch/X86.cpp =================================================================== --- ELF/Arch/X86.cpp +++ ELF/Arch/X86.cpp @@ -48,6 +48,7 @@ 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; Index: ELF/Arch/X86_64.cpp =================================================================== --- ELF/Arch/X86_64.cpp +++ ELF/Arch/X86_64.cpp @@ -55,6 +55,7 @@ template X86_64::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; Index: ELF/DWARF.cpp =================================================================== --- ELF/DWARF.cpp +++ ELF/DWARF.cpp @@ -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 @@ // Broken debug info can point to a non-Defined symbol. auto *DR = dyn_cast(&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(Rel); Index: ELF/Target.h =================================================================== --- ELF/Target.h +++ ELF/Target.h @@ -95,6 +95,7 @@ RelType CopyRel; RelType GotRel; + RelType NoneRel; RelType PltRel; RelType RelativeRel; RelType IRelativeRel; Index: test/ELF/debug-relocation-none.test =================================================================== --- test/ELF/debug-relocation-none.test +++ test/ELF/debug-relocation-none.test @@ -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 Index: test/ELF/undef-broken-debug.test =================================================================== --- test/ELF/undef-broken-debug.test +++ test/ELF/undef-broken-debug.test @@ -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