Skip to content

Commit dd8cb3d

Browse files
authored
[ELF] Support high address DW_EH_sdata4 for ELFCLASS32
When the address pointer encoding in FDEs uses DW_EH_PE_absptr|DW_EH_PE_sdata4, the address is sign-extended to 64-bit by `readFdeAddr`. We should truncate the address to 32-bit for ELFCLASS32. Otherwise, `isInt<32>(pc - va)` could be false, leading to a spurious error in `getFdeData`. In LLVM, this appears a MIPS-specific issue. Fix #88852 Pull Request: #92438
1 parent 073488c commit dd8cb3d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lld/ELF/SyntheticSections.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ uint64_t EhFrameSection::getFdePc(uint8_t *buf, size_t fdeOff,
613613
size_t off = fdeOff + 8;
614614
uint64_t addr = readFdeAddr(buf + off, enc & 0xf);
615615
if ((enc & 0x70) == DW_EH_PE_absptr)
616-
return addr;
616+
return config->is64 ? addr : uint32_t(addr);
617617
if ((enc & 0x70) == DW_EH_PE_pcrel)
618618
return addr + getParent()->addr + off + outSecOff;
619619
fatal("unknown FDE size relative encoding");

lld/test/ELF/mips-eh_frame-pic.s

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
## relative addressing.
2828
# NOPIC32-ERR: ld.lld: error: relocation R_MIPS_32 cannot be used against local symbol
2929

30+
## https://github.com/llvm/llvm-project/issues/88852: getFdePc should return a
31+
## 32-bit address.
32+
# RUN: ld.lld --eh-frame-hdr -Ttext=0x80000000 %t-nopic32.o -o %t-nopic32
33+
# RUN: llvm-readelf -x .eh_frame_hdr %t-nopic32 | FileCheck %s --check-prefix=NOPIC32-HDR
34+
3035
## For -fPIC, .eh_frame should contain DW_EH_PE_pcrel | DW_EH_PE_sdata4 values:
3136
# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux --position-independent %s -o %t-pic32.o
3237
# RUN: llvm-readobj -r %t-pic32.o | FileCheck %s --check-prefixes=RELOCS,PIC32-RELOCS
@@ -51,6 +56,10 @@
5156
## Note: ld.bfd converts the R_MIPS_64 relocs to DW_EH_PE_pcrel | DW_EH_PE_sdata8
5257
## for N64 ABI (and DW_EH_PE_pcrel | DW_EH_PE_sdata4 for MIPS32)
5358

59+
# NOPIC32-HDR: Hex dump of section '.eh_frame_hdr':
60+
# NOPIC32-HDR: 0x80010038 011b033b 00000010 00000001 fffeffc8 .
61+
# NOPIC32-HDR: 0x80010048 00000028 .
62+
5463
.ent func
5564
.global func
5665
func:

0 commit comments

Comments
 (0)