From d832547ba2f7765f34b5885565468597d80f5cd4 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Thu, 18 Jan 2024 18:28:26 +0100 Subject: [PATCH] Add support for .eh_frame section on arm32 --- elf/arch-arm32.cc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/elf/arch-arm32.cc b/elf/arch-arm32.cc index fe72ecfffc..e46b15c046 100644 --- a/elf/arch-arm32.cc +++ b/elf/arch-arm32.cc @@ -228,11 +228,24 @@ void write_pltgot_entry(Context &ctx, u8 *buf, Symbol &sym) { *(ul32 *)(buf + 12) = sym.get_got_pltgot_addr(ctx) - sym.get_plt_addr(ctx) - 12; } -// ARM does not use .eh_frame for exception handling. Instead, it uses -// .ARM.exidx and .ARM.extab. So this function is empty. template <> void EhFrameSection::apply_eh_reloc(Context &ctx, const ElfRel &rel, - u64 offset, u64 val) {} + u64 offset, u64 val) { + u8 *loc = ctx.buf + this->shdr.sh_offset + offset; + + switch (rel.r_type) { + case R_NONE: + break; + case R_ARM_ABS32: + *(ul32 *)loc = val; + break; + case R_ARM_REL32: + *(ul32 *)loc = val - this->shdr.sh_addr - offset; + break; + default: + Fatal(ctx) << "unsupported relocation in .eh_frame: " << rel; + } +} // ARM and Thumb branch instructions can jump within ±16 MiB. static bool is_jump_reachable(i64 val) {