Index: ELF/OutputSections.cpp =================================================================== --- ELF/OutputSections.cpp +++ ELF/OutputSections.cpp @@ -667,26 +667,29 @@ template typename EhFrameHeader::uintX_t EhFrameHeader::getFdePc(uintX_t EhVA, const FdeData &F) { - const endianness E = ELFT::TargetEndianness; - assert((F.Enc & 0xF0) != DW_EH_PE_datarel); - - uintX_t FdeOff = EhVA + F.Off + 8; - switch (F.Enc & 0xF) { - case DW_EH_PE_udata2: - case DW_EH_PE_sdata2: - return FdeOff + read16(F.PCRel); - case DW_EH_PE_udata4: - case DW_EH_PE_sdata4: - return FdeOff + read32(F.PCRel); - case DW_EH_PE_udata8: - case DW_EH_PE_sdata8: - return FdeOff + read64(F.PCRel); + auto Read = [=](uint8_t Size) -> uint64_t { + const endianness E = ELFT::TargetEndianness; + if (Size == DW_EH_PE_absptr) + Size = sizeof(uintX_t) == 8 ? DW_EH_PE_udata8 : DW_EH_PE_udata4; + switch (Size) { + case DW_EH_PE_udata2: + return read16(F.PCRel); + case DW_EH_PE_udata4: + return read32(F.PCRel); + case DW_EH_PE_udata8: + return read64(F.PCRel); + default: + fatal("unknown FDE size encoding"); + } + }; + switch (F.Enc & 0x70) { case DW_EH_PE_absptr: - if (sizeof(uintX_t) == 8) - return FdeOff + read64(F.PCRel); - return FdeOff + read32(F.PCRel); + return Read(F.Enc & 0x7); + case DW_EH_PE_pcrel: + return Read(F.Enc & 0x7) + EhVA + F.Off + 8; + default: + fatal("unknown FDE size relative encoding"); } - fatal("unknown FDE size encoding"); } template void EhFrameHeader::writeTo(uint8_t *Buf) { @@ -1084,8 +1087,10 @@ skipAugP(D); continue; } - if (C == 'L') + if (C == 'L') { + readByte(D); continue; + } fatal("unknown .eh_frame augmentation string: " + Aug); } return DW_EH_PE_absptr; Index: test/ELF/eh-frame-hdr-abs-fde.s =================================================================== --- /dev/null +++ test/ELF/eh-frame-hdr-abs-fde.s @@ -0,0 +1,33 @@ +# Check reading PC values of FDEs and writing lookup table in the .eh_frame_hdr +# if CIE augmentation string has 'L' token and PC values are encoded using +# absolute (not relative) format. + +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o +# RUN: ld.lld --eh-frame-hdr %t.o -o %t +# RUN: llvm-objdump -s -dwarf=frames %t | FileCheck %s + +# REQUIRES: mips + +# CHECK: Contents of section .eh_frame_hdr: +# CHECK-NEXT: 10158 011b033b ffffffcc 00000001 0000fea8 +# ^-- 0x20000 - 0x10158 +# .text - .eh_frame_hdr +# CHECK-NEXT: 10168 ffffffe8 +# CHECK-NEXT: Contents of section .text: +# CHECK-NEXT: 20000 00000000 + +# CHECK: Augmentation: "zLR" +# CHECK: Augmentation data: 00 0B +# ^-- DW_EH_PE_udata4 | DW_EH_PE_signed + + .text + .globl __start +__start: + .cfi_startproc + .cfi_lsda 0, _ex + nop + .cfi_endproc + + .data +_ex: + .word 0