diff --git a/lld/ELF/DWARF.cpp b/lld/ELF/DWARF.cpp --- a/lld/ELF/DWARF.cpp +++ b/lld/ELF/DWARF.cpp @@ -59,16 +59,16 @@ template struct LLDRelocationResolver { // In the ELF ABIs, S sepresents the value of the symbol in the relocation // entry. For Rela, the addend is stored as part of the relocation entry. - static uint64_t resolve(object::RelocationRef ref, uint64_t s, - uint64_t /* A */) { + static Expected resolve(object::RelocationRef ref, uint64_t s, + uint64_t /*a*/) { return s + ref.getRawDataRefImpl().p; } }; template struct LLDRelocationResolver> { // For Rel, the addend A is supplied by the caller. - static uint64_t resolve(object::RelocationRef /*Ref*/, uint64_t s, - uint64_t a) { + static Expected resolve(object::RelocationRef /*ref*/, uint64_t s, + uint64_t a) { return s + a; } }; diff --git a/llvm/include/llvm/Object/RelocationResolver.h b/llvm/include/llvm/Object/RelocationResolver.h --- a/llvm/include/llvm/Object/RelocationResolver.h +++ b/llvm/include/llvm/Object/RelocationResolver.h @@ -31,7 +31,8 @@ namespace llvm { namespace object { -using RelocationResolver = uint64_t (*)(RelocationRef R, uint64_t S, uint64_t A); +using RelocationResolver = Expected (*)(RelocationRef R, uint64_t S, + uint64_t A); std::pair getRelocationResolver(const ObjectFile &Obj); diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDataExtractor.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDataExtractor.cpp --- a/llvm/lib/DebugInfo/DWARF/DWARFDataExtractor.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDataExtractor.cpp @@ -25,10 +25,19 @@ return A; if (SecNdx) *SecNdx = E->SectionIndex; - uint64_t R = E->Resolver(E->Reloc, E->SymbolValue, A); - if (E->Reloc2) - R = E->Resolver(*E->Reloc2, E->SymbolValue2, R); - return R; + Expected R = E->Resolver(E->Reloc, E->SymbolValue, A); + if (!R) { + *Err = R.takeError(); + return A; + } + if (E->Reloc2) { + R = E->Resolver(*E->Reloc2, E->SymbolValue2, *R); + if (!R) { + *Err = R.takeError(); + return A; + } + } + return *R; } Optional diff --git a/llvm/lib/Object/RelocationResolver.cpp b/llvm/lib/Object/RelocationResolver.cpp --- a/llvm/lib/Object/RelocationResolver.cpp +++ b/llvm/lib/Object/RelocationResolver.cpp @@ -38,7 +38,8 @@ } } -static uint64_t resolveX86_64(RelocationRef R, uint64_t S, uint64_t A) { +static Expected resolveX86_64(RelocationRef R, uint64_t S, + uint64_t A) { switch (R.getType()) { case ELF::R_X86_64_NONE: return A; @@ -66,7 +67,8 @@ } } -static uint64_t resolveAArch64(RelocationRef R, uint64_t S, uint64_t A) { +static Expected resolveAArch64(RelocationRef R, uint64_t S, + uint64_t A) { switch (R.getType()) { case ELF::R_AARCH64_ABS32: return (S + getELFAddend(R)) & 0xFFFFFFFF; @@ -87,7 +89,7 @@ } } -static uint64_t resolveBPF(RelocationRef R, uint64_t S, uint64_t A) { +static Expected resolveBPF(RelocationRef R, uint64_t S, uint64_t A) { switch (R.getType()) { case ELF::R_BPF_64_32: return (S + A) & 0xFFFFFFFF; @@ -109,7 +111,8 @@ } } -static uint64_t resolveMips64(RelocationRef R, uint64_t S, uint64_t A) { +static Expected resolveMips64(RelocationRef R, uint64_t S, + uint64_t A) { switch (R.getType()) { case ELF::R_MIPS_32: return (S + getELFAddend(R)) & 0xFFFFFFFF; @@ -132,7 +135,8 @@ } } -static uint64_t resolvePPC64(RelocationRef R, uint64_t S, uint64_t A) { +static Expected resolvePPC64(RelocationRef R, uint64_t S, + uint64_t A) { switch (R.getType()) { case ELF::R_PPC64_ADDR32: return (S + getELFAddend(R)) & 0xFFFFFFFF; @@ -153,7 +157,8 @@ } } -static uint64_t resolveSystemZ(RelocationRef R, uint64_t S, uint64_t A) { +static Expected resolveSystemZ(RelocationRef R, uint64_t S, + uint64_t A) { switch (R.getType()) { case ELF::R_390_32: return (S + getELFAddend(R)) & 0xFFFFFFFF; @@ -176,7 +181,8 @@ } } -static uint64_t resolveSparc64(RelocationRef R, uint64_t S, uint64_t A) { +static Expected resolveSparc64(RelocationRef R, uint64_t S, + uint64_t A) { switch (R.getType()) { case ELF::R_SPARC_32: case ELF::R_SPARC_64: @@ -198,7 +204,8 @@ } } -static uint64_t resolveAmdgpu(RelocationRef R, uint64_t S, uint64_t A) { +static Expected resolveAmdgpu(RelocationRef R, uint64_t S, + uint64_t A) { switch (R.getType()) { case ELF::R_AMDGPU_ABS32: case ELF::R_AMDGPU_ABS64: @@ -219,7 +226,7 @@ } } -static uint64_t resolveX86(RelocationRef R, uint64_t S, uint64_t A) { +static Expected resolveX86(RelocationRef R, uint64_t S, uint64_t A) { switch (R.getType()) { case ELF::R_386_NONE: return A; @@ -236,7 +243,8 @@ return Type == ELF::R_PPC_ADDR32; } -static uint64_t resolvePPC32(RelocationRef R, uint64_t S, uint64_t A) { +static Expected resolvePPC32(RelocationRef R, uint64_t S, + uint64_t A) { if (R.getType() == ELF::R_PPC_ADDR32) return (S + getELFAddend(R)) & 0xFFFFFFFF; llvm_unreachable("Invalid relocation type"); @@ -246,7 +254,7 @@ return Type == ELF::R_ARM_ABS32; } -static uint64_t resolveARM(RelocationRef R, uint64_t S, uint64_t A) { +static Expected resolveARM(RelocationRef R, uint64_t S, uint64_t A) { if (R.getType() == ELF::R_ARM_ABS32) return (S + A) & 0xFFFFFFFF; llvm_unreachable("Invalid relocation type"); @@ -262,7 +270,7 @@ } } -static uint64_t resolveAVR(RelocationRef R, uint64_t S, uint64_t A) { +static Expected resolveAVR(RelocationRef R, uint64_t S, uint64_t A) { switch (R.getType()) { case ELF::R_AVR_16: return (S + getELFAddend(R)) & 0xFFFF; @@ -277,7 +285,8 @@ return Type == ELF::R_LANAI_32; } -static uint64_t resolveLanai(RelocationRef R, uint64_t S, uint64_t A) { +static Expected resolveLanai(RelocationRef R, uint64_t S, + uint64_t A) { if (R.getType() == ELF::R_LANAI_32) return (S + getELFAddend(R)) & 0xFFFFFFFF; llvm_unreachable("Invalid relocation type"); @@ -293,7 +302,8 @@ } } -static uint64_t resolveMips32(RelocationRef R, uint64_t S, uint64_t A) { +static Expected resolveMips32(RelocationRef R, uint64_t S, + uint64_t A) { // FIXME: Take in account implicit addends to get correct results. uint32_t Rel = R.getType(); if (Rel == ELF::R_MIPS_32) @@ -313,7 +323,8 @@ } } -static uint64_t resolveSparc32(RelocationRef R, uint64_t S, uint64_t A) { +static Expected resolveSparc32(RelocationRef R, uint64_t S, + uint64_t A) { uint32_t Rel = R.getType(); if (Rel == ELF::R_SPARC_32 || Rel == ELF::R_SPARC_UA32) return S + getELFAddend(R); @@ -324,7 +335,8 @@ return Type == ELF::R_HEX_32; } -static uint64_t resolveHexagon(RelocationRef R, uint64_t S, uint64_t A) { +static Expected resolveHexagon(RelocationRef R, uint64_t S, + uint64_t A) { if (R.getType() == ELF::R_HEX_32) return S + getELFAddend(R); llvm_unreachable("Invalid relocation type"); @@ -351,7 +363,8 @@ } } -static uint64_t resolveRISCV(RelocationRef R, uint64_t S, uint64_t A) { +static Expected resolveRISCV(RelocationRef R, uint64_t S, + uint64_t A) { int64_t RA = getELFAddend(R); switch (R.getType()) { case ELF::R_RISCV_NONE: @@ -395,7 +408,8 @@ } } -static uint64_t resolveCOFFX86(RelocationRef R, uint64_t S, uint64_t A) { +static Expected resolveCOFFX86(RelocationRef R, uint64_t S, + uint64_t A) { switch (R.getType()) { case COFF::IMAGE_REL_I386_SECREL: case COFF::IMAGE_REL_I386_DIR32: @@ -415,7 +429,8 @@ } } -static uint64_t resolveCOFFX86_64(RelocationRef R, uint64_t S, uint64_t A) { +static Expected resolveCOFFX86_64(RelocationRef R, uint64_t S, + uint64_t A) { switch (R.getType()) { case COFF::IMAGE_REL_AMD64_SECREL: return (S + A) & 0xFFFFFFFF; @@ -430,7 +445,8 @@ return Type == MachO::X86_64_RELOC_UNSIGNED; } -static uint64_t resolveMachOX86_64(RelocationRef R, uint64_t S, uint64_t A) { +static Expected resolveMachOX86_64(RelocationRef R, uint64_t S, + uint64_t A) { if (R.getType() == MachO::X86_64_RELOC_UNSIGNED) return S; llvm_unreachable("Invalid relocation type"); @@ -455,7 +471,8 @@ } } -static uint64_t resolveWasm32(RelocationRef R, uint64_t S, uint64_t A) { +static Expected resolveWasm32(RelocationRef R, uint64_t S, + uint64_t A) { switch (R.getType()) { case wasm::R_WASM_FUNCTION_INDEX_LEB: case wasm::R_WASM_TABLE_INDEX_SLEB: diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -4744,9 +4744,11 @@ FileStr); uint64_t Addend = Data.getAddress(&Offset); - uint64_t SymValue = Resolver(Reloc, RelocSymValue, Addend); - this->printFunctionStackSize(Obj, SymValue, FunctionSec, StackSizeSectionName, - Data, &Offset); + if (Expected SymValue = Resolver(Reloc, RelocSymValue, Addend)) + this->printFunctionStackSize(Obj, *SymValue, FunctionSec, + StackSizeSectionName, Data, &Offset); + else + reportWarning(SymValue.takeError(), FileStr); } template