From 4b0f8e9a20e5193684e94f23494d2a510e5fcf47 Mon Sep 17 00:00:00 2001 From: Timon Kruiper Date: Mon, 30 Jan 2023 15:28:46 +0100 Subject: [PATCH] LibELF+LibC: Add support for relative relocations in aarch64 binaries This commit adds R_AARCH64_RELATIVE to elf.h and uses it in ELF::perform_relative_relocations to correctly verify the relocation type. This is the only change needed to support relative relocations for aarch64. --- Userland/Libraries/LibC/elf.h | 2 ++ Userland/Libraries/LibELF/Relocation.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibC/elf.h b/Userland/Libraries/LibC/elf.h index 76baf1525e..d7baed9312 100644 --- a/Userland/Libraries/LibC/elf.h +++ b/Userland/Libraries/LibC/elf.h @@ -821,3 +821,5 @@ struct elf_args { #define R_X86_64_RELATIVE 8 #define R_X86_64_TPOFF64 18 #define R_X86_64_IRELATIVE 37 + +#define R_AARCH64_RELATIVE 1027 diff --git a/Userland/Libraries/LibELF/Relocation.cpp b/Userland/Libraries/LibELF/Relocation.cpp index 14e3e8db84..6f03b59cde 100644 --- a/Userland/Libraries/LibELF/Relocation.cpp +++ b/Userland/Libraries/LibELF/Relocation.cpp @@ -59,7 +59,7 @@ bool perform_relative_relocations(FlatPtr base_address) for (unsigned i = 0; i < relocation_count; ++i) { size_t offset_in_section = i * relocation_entry_size; auto* relocation = (ElfW(Rela)*)(relocation_section_addr + offset_in_section); - VERIFY(ELF64_R_TYPE(relocation->r_info) == R_X86_64_RELATIVE); + VERIFY(ELF64_R_TYPE(relocation->r_info) == R_X86_64_RELATIVE || ELF64_R_TYPE(relocation->r_info) == R_AARCH64_RELATIVE); auto* patch_address = (FlatPtr*)(base_address + relocation->r_offset); FlatPtr relocated_address; if (use_addend) {