mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: David Dgien <dgienda125@gmail.com>, Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 08/12] ARM32: module: handle more relocations
Date: Thu, 15 Jan 2026 12:54:34 +0100	[thread overview]
Message-ID: <20260115115924.3428886-9-a.fatoum@barebox.org> (raw)
In-Reply-To: <20260115115924.3428886-1-a.fatoum@barebox.org>

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




  parent reply	other threads:[~2026-01-15 12:00 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-15 11:54 [PATCH 00/12] ARM32: modules: fix bitrot and add test Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 01/12] boards: qemu-virt: reserve BIOS device tree Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 02/12] ARM: qemu-virt: add image for use as -bios Ahmad Fatoum
2026-01-16  8:33   ` Sascha Hauer
2026-01-16 10:21     ` Ahmad Fatoum
2026-01-16 12:52       ` Ahmad Fatoum
2026-01-16 15:16         ` Sascha Hauer
2026-01-15 11:54 ` [PATCH 03/12] kbuild: build *.mod.c with -std=gnu11 Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 04/12] ARM32: mark modules as incompatible with ARM_MMU_PERMISSIONS Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 05/12] treewide: fix some missing EXPORT_SYMBOL Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 06/12] pci: ecam: enable build as module Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 07/12] kbuild: add support for installing and stripping modules Ahmad Fatoum
2026-01-15 11:54 ` Ahmad Fatoum [this message]
2026-01-15 11:54 ` [PATCH 09/12] commands: pm_domain: make command tristate Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 10/12] test: conftest: add support for describing FW_CFG environment in YAML Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 11/12] defaultenv: add barebox_modules_env target Ahmad Fatoum
2026-01-15 11:54 ` [PATCH 12/12] test: arm: add simple driver/command module test Ahmad Fatoum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260115115924.3428886-9-a.fatoum@barebox.org \
    --to=a.fatoum@barebox.org \
    --cc=barebox@lists.infradead.org \
    --cc=dgienda125@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox