mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Stefan Kerkmann <s.kerkmann@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	 "open list:BAREBOX" <barebox@lists.infradead.org>
Cc: Stefan Kerkmann <s.kerkmann@pengutronix.de>
Subject: [PATCH 2/2] ARM64: setup_c: abi safe link register storage
Date: Wed, 19 Aug 2026 16:12:51 +0200	[thread overview]
Message-ID: <20260819-next-v1-2-c1a1a8b44d02@pengutronix.de> (raw)
In-Reply-To: <20260819-next-v1-0-c1a1a8b44d02@pengutronix.de>

The ARM64 setup_c function saved the link register (x30) in the caller
save register (x15). This is fragile as a constructor might use x15,
thus save it on the stack just like ARM32 and RISC-V.

Fixes: bb07ef11d6 ("ARM/ARM64/RISC-V: pbl: add constructor support")
Signed-off-by: Stefan Kerkmann <s.kerkmann@pengutronix.de>
---
 arch/arm/cpu/setupc_64.S | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/arm/cpu/setupc_64.S b/arch/arm/cpu/setupc_64.S
index e3c6149e27..b1cfea47b1 100644
--- a/arch/arm/cpu/setupc_64.S
+++ b/arch/arm/cpu/setupc_64.S
@@ -10,10 +10,10 @@
  * setup_c: clear bss if not yet done
  */
 ENTRY(setup_c)
+	str x30, [sp, #-16]!
 	adr_l	x0, bss_cleared
 	ldr	w1, [x0]
 	cbnz	w1, 1f			/* skip if already done */
-	mov	x15, x30
 	adr_l	x0, __bss_start
 	mov	x1, #0
 	adr_l	x2, __bss_stop
@@ -25,8 +25,9 @@ ENTRY(setup_c)
 #ifdef __PBL__
 	bl	pbl_do_ctors
 #endif
-	mov	x30, x15
-1:	ret
+1:
+	ldr x30, [sp], #16
+	ret
 ENDPROC(setup_c)
 
 .section .data.bss_cleared

-- 
2.47.3




  parent reply	other threads:[~2026-08-19 14:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-19 14:12 [PATCH 0/2] PBL: constructor fixes Stefan Kerkmann
2026-08-19 14:12 ` [PATCH 1/2] ARM/ARM64/RISC-V: pbl: guard constructor support Stefan Kerkmann
2026-08-19 14:12 ` Stefan Kerkmann [this message]
2026-08-19 14:16 ` [PATCH 0/2] PBL: constructor fixes Ahmad Fatoum
2026-08-19 15:01   ` Sascha Hauer
2026-08-20  7:14     ` Stefan Kerkmann
2026-08-20  7:18       ` Sascha Hauer
2026-08-20  7:24         ` Stefan Kerkmann

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=20260819-next-v1-2-c1a1a8b44d02@pengutronix.de \
    --to=s.kerkmann@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /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