[PATCH 08/12] ARM32: module: handle more relocations
Ahmad Fatoum
a.fatoum at barebox.org
Thu Jan 15 03:54:34 PST 2026
Compiling with arm-linux-gnueabihf-gcc (Debian 14.2.0-19) 14.2.0
generates a few more relocation types than the module loader currently
supports.
Import support for them from Linux, so we can start automatically
testing this feature.
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
arch/arm/include/asm/elf.h | 2 ++
arch/arm/lib32/module.c | 20 ++++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
index 0b4704a4a561..f3b6e0dd37c3 100644
--- a/arch/arm/include/asm/elf.h
+++ b/arch/arm/include/asm/elf.h
@@ -29,9 +29,11 @@ typedef struct user_fp elf_fpregset_t;
#define R_ARM_NONE 0
#define R_ARM_PC24 1
+#define R_ARM_REL32 3
#define R_ARM_ABS32 2
#define R_ARM_CALL 28
#define R_ARM_JUMP24 29
+#define R_ARM_PREL31 42
#define R_ARM_THM_CALL 10
#define R_ARM_THM_JUMP24 30
diff --git a/arch/arm/lib32/module.c b/arch/arm/lib32/module.c
index 7214e3c73c3d..0cf04ea9faba 100644
--- a/arch/arm/lib32/module.c
+++ b/arch/arm/lib32/module.c
@@ -49,6 +49,9 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex,
loc = dstsec->sh_addr + rel->r_offset;
switch (ELF32_R_TYPE(rel->r_info)) {
+ case R_ARM_NONE:
+ /* ignore */
+ break;
case R_ARM_ABS32:
*(u32 *)loc += sym->st_value;
break;
@@ -90,6 +93,23 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex,
*(u32 *)loc |= offset & 0x00ffffff;
break;
+ case R_ARM_PREL31:
+ offset = (*(s32 *)loc << 1) >> 1; /* sign extend */
+ offset += sym->st_value - loc;
+ if (offset >= 0x40000000 || offset < -0x40000000) {
+ pr_err("%s: section %u reloc %u sym '%s': relocation %u out of range (%#lx -> %#x)\n",
+ module->name, relindex, i, strtab + sym->st_name,
+ ELF32_R_TYPE(rel->r_info), loc,
+ sym->st_value);
+ return -ENOEXEC;
+ }
+ *(u32 *)loc &= 0x80000000;
+ *(u32 *)loc |= offset & 0x7fffffff;
+ break;
+
+ case R_ARM_REL32:
+ *(u32 *)loc += sym->st_value - loc;
+ break;
default:
printf("%s: unknown relocation: %u\n",
module->name, ELF32_R_TYPE(rel->r_info));
--
2.47.3
More information about the barebox
mailing list