From b8f52d14f490a357161321f85632fea1dee1e016 Mon Sep 17 00:00:00 2001 From: John Reiser Date: Wed, 4 Dec 2019 14:26:46 -0800 Subject: [PATCH] user_init_va on AARCH64 https://github.com/upx/upx/issues/318 (work-in-progress) modified: p_elf_enum.h modified: p_lx_elf.cpp --- src/p_elf_enum.h | 2 ++ src/p_lx_elf.cpp | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/p_elf_enum.h b/src/p_elf_enum.h index dc078c4c..18ec96b2 100644 --- a/src/p_elf_enum.h +++ b/src/p_elf_enum.h @@ -242,6 +242,8 @@ R_PPC_JMP_SLOT = 21, R_PPC64_JMP_SLOT = R_PPC_JMP_SLOT, R_X86_64_JUMP_SLOT = 7 + + , R_AARCH64_ABS64 = 257 }; #endif //} diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index bfbe536a..adb83bd2 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -2446,7 +2446,7 @@ PackLinuxElf64::canPack() xct_va = ~0ull; if (e_shnum) { for (int j= e_shnum; --j>=0; ++shdr) { - unsigned const sh_type = get_te64(&shdr->sh_type); + unsigned const sh_type = get_te32(&shdr->sh_type); if (Elf64_Shdr::SHF_EXECINSTR & get_te64(&shdr->sh_flags)) { xct_va = umin(xct_va, get_te64(&shdr->sh_addr)); } @@ -2482,6 +2482,10 @@ PackLinuxElf64::canPack() && R_AARCH64_RELATIVE == r_type) { user_init_va = get_te64(&rp->r_addend); } + else if (Elf64_Ehdr::EM_AARCH64 == e_machine + && R_AARCH64_ABS64 == r_type) { + user_init_va = get_te64(&file_image[user_init_off]); + } else { char msg[50]; snprintf(msg, sizeof(msg), "bad relocation %#x DT_INIT_ARRAY[0]",