mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 3/3] common: elf: reorganize barebox proper parts in struct elf_image
Date: Fri, 23 Jan 2026 14:17:13 +0100	[thread overview]
Message-ID: <20260123131922.2663665-4-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260123131922.2663665-1-a.fatoum@pengutronix.de>

To make it clearer which parts of struct elf_image are used only in
barebox proper, reorganize the struct.

Also .base_load_addr is assigned and never used outside the function
that sets it, so turn it into a local variable instead.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/elf.c      | 13 +++++++------
 include/lib/elf.h | 11 ++++++-----
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/common/elf.c b/common/elf.c
index 296ff3ec7d4c..0df40c13a3a6 100644
--- a/common/elf.c
+++ b/common/elf.c
@@ -65,6 +65,7 @@ static int elf_compute_load_offset(struct elf_image *elf)
 	void *phdr = buf + elf_hdr_e_phoff(elf, buf);
 	u64 min_vaddr = (u64)-1;
 	u64 min_paddr = (u64)-1;
+	unsigned long base_load_addr;
 
 	/* Find lowest p_vaddr and p_paddr in PT_LOAD segments */
 	elf_for_each_segment(phdr, elf, buf) {
@@ -86,11 +87,11 @@ static int elf_compute_load_offset(struct elf_image *elf)
 	 * 3. For ET_DYN, use lowest p_paddr
 	 */
 	if (elf->load_address)
-		elf->base_load_addr = elf->load_address;
+		base_load_addr = (unsigned long)elf->load_address;
 	else if (elf->type == ET_EXEC)
-		elf->base_load_addr = NULL;
+		base_load_addr = 0;
 	else
-		elf->base_load_addr = (void *)(phys_addr_t)min_paddr;
+		base_load_addr = min_paddr;
 
 	/*
 	 * Calculate relocation offset:
@@ -100,11 +101,11 @@ static int elf_compute_load_offset(struct elf_image *elf)
 	if (elf->type == ET_EXEC && !elf->load_address)
 		elf->reloc_offset = 0;
 	else
-		elf->reloc_offset = ((unsigned long)elf->base_load_addr - min_vaddr);
+		elf->reloc_offset = base_load_addr - min_vaddr;
 
-	pr_debug("ELF load: type=%s, base=%p, offset=%08lx\n",
+	pr_debug("ELF load: type=%s, base=%08lx, offset=%08lx\n",
 		 elf->type == ET_EXEC ? "ET_EXEC" : "ET_DYN",
-		 elf->base_load_addr, elf->reloc_offset);
+		 base_load_addr, elf->reloc_offset);
 
 	return 0;
 }
diff --git a/include/lib/elf.h b/include/lib/elf.h
index 1521c81df6a7..c62d8f791273 100644
--- a/include/lib/elf.h
+++ b/include/lib/elf.h
@@ -7,17 +7,18 @@
 #include <linux/list.h>
 
 struct elf_image {
-	struct list_head list;
 	u8 class;
 	u16 type;		/* ET_EXEC or ET_DYN */
 	u64 entry;
+	void *hdr_buf;
+	void *load_address;	/* User-specified load address (NULL = use p_paddr) */
+	unsigned long reloc_offset;	/* Offset between p_vaddr and actual load address */
+
+	/* Only used in barebox proper */
+	struct list_head list;
 	void *low_addr;
 	void *high_addr;
-	void *hdr_buf;
 	const char *filename;
-	void *load_address;	/* User-specified load address (NULL = use p_paddr) */
-	void *base_load_addr;	/* Calculated base address for ET_DYN */
-	unsigned long reloc_offset;	/* Offset between p_vaddr and actual load address */
 };
 
 static inline void elf_init_struct(struct elf_image *elf)
-- 
2.47.3




  parent reply	other threads:[~2026-01-23 13:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-23 13:17 [PATCH master 0/3] elf: restructure to fix sandbox allyesconfig breakage Ahmad Fatoum
2026-01-23 13:17 ` [PATCH master 1/3] elf: rename elf.h to <linux/elf.h> Ahmad Fatoum
2026-01-23 13:17 ` [PATCH master 2/3] common: elf: split barebox proper-only ELF support from the rest Ahmad Fatoum
2026-01-23 13:17 ` Ahmad Fatoum [this message]
2026-01-26  7:33 ` [PATCH master 0/3] elf: restructure to fix sandbox allyesconfig breakage Sascha Hauer

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=20260123131922.2663665-4-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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