1
mirror of https://github.com/flipperdevices/flipperzero-firmware.git synced 2025-12-12 04:41:26 +04:00

Add support for R_ARM_REL32 relocations. (#3631)

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: あく <alleteam@gmail.com>
This commit is contained in:
Samar Sunkaria
2024-05-13 17:21:28 +02:00
committed by GitHub
parent e1cb69d046
commit 8ffee678c6

View File

@@ -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: