From 8ffee678c69495ca5529728938751a84d5c3cb8d Mon Sep 17 00:00:00 2001 From: Samar Sunkaria Date: Mon, 13 May 2024 17:21:28 +0200 Subject: [PATCH] Add support for R_ARM_REL32 relocations. (#3631) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is fairly straightforward to correctly resolve an R_ARM_REL32 relocation as described in in the "Relocation types" section of ARM ELF Specification (https://developer.arm.com/documentation/espc0003/1-0/?lang=en). The documentation provides the following formula: ``` S - P + A ``` where `S` is the value of the symbol (symAddr), `P` is the address of the place being relocated (relAddr), and `A` is the addend (value extracted from the storage unit being relocated, in this case). I encountered the R_ARM_REL32 relocation type as part of my work for building apps written in Swift for the Flipper Zero. I have manually tested that this relocation works correctly by building and running multiple apps that depend on this relocation. Co-authored-by: あく --- lib/flipper_application/elf/elf_file.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/flipper_application/elf/elf_file.c b/lib/flipper_application/elf/elf_file.c index 654316866..398f25209 100644 --- a/lib/flipper_application/elf/elf_file.c +++ b/lib/flipper_application/elf/elf_file.c @@ -202,6 +202,7 @@ __attribute__((unused)) static const char* elf_reloc_type_to_str(int symt) { STRCASE(R_ARM_NONE) STRCASE(R_ARM_TARGET1) STRCASE(R_ARM_ABS32) + STRCASE(R_ARM_REL32) STRCASE(R_ARM_THM_PC22) STRCASE(R_ARM_THM_JUMP24) default: @@ -329,6 +330,10 @@ static bool elf_relocate_symbol(ELFFile* elf, Elf32_Addr relAddr, int type, Elf3 *((uint32_t*)relAddr) += symAddr; FURI_LOG_D(TAG, " R_ARM_ABS32 relocated is 0x%08X", (unsigned int)*((uint32_t*)relAddr)); break; + case R_ARM_REL32: + *((uint32_t*)relAddr) += symAddr - relAddr; + FURI_LOG_D(TAG, " R_ARM_REL32 relocated is 0x%08X", (unsigned int)*((uint32_t*)relAddr)); + break; case R_ARM_THM_PC22: case R_ARM_CALL: case R_ARM_THM_JUMP24: