AARCH64 clean bss bug

brock_zheng yzheng at techyauld.com
Sun Jun 29 06:37:35 CEST 2025


Hi, all

    I found a bug on AARCH64 platform about clean .bss section after relocating.

    In crt0_64.S, it use instruction 'ldr' to load the start/stop
    address of BSS after relocating.  My testing shows that
    __bss_start loaded successfuly, but 'x1 <= __bss_end' got the
    address _BEFORE_ allocating.

    If I swap the two instruction sequence, the result is swapped
    also. But neither code can gives the right result of those two
    addesses _AFTER_ relocation.

    my patch use 'adr' instead of 'ldr', seems OK for my RK3568 chip.


--
Brock Zheng <yzheng at techyauld.com>
郑 祎

北京中科腾越科技发展有限公司
北京市 海淀区 东北旺西路8号 中关村软件园27号院 千方大厦A座2层 (邮编:100193)
-------------- next part --------------
>From 799060d6d373236951afa9d3e571b36fc9e9d026 Mon Sep 17 00:00:00 2001
From: Brock Zheng <yzheng at techyauld.com>
Date: Sun, 29 Jun 2025 12:34:17 +0800
Subject: [PATCH] arm64: fix up .bss section cleaning after relocating

       __bss_start/__bss_end is not loaded correctly by instruction 'ldr'
       using 'adr' instead. Seems OK on RK3568 SoC.
---
 arch/arm/lib/crt0_64.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/lib/crt0_64.S b/arch/arm/lib/crt0_64.S
index 30950ddaf9b..b45c1b65dc4 100644
--- a/arch/arm/lib/crt0_64.S
+++ b/arch/arm/lib/crt0_64.S
@@ -158,8 +158,8 @@ relocation_return:
 /*
  * Clear BSS section
  */
-	ldr	x0, =__bss_start		/* this is auto-relocated! */
-	ldr	x1, =__bss_end			/* this is auto-relocated! */
+	adr	x0, __bss_start			/* this is auto-relocated! */
+	adr	x1, __bss_end			/* this is auto-relocated! */
 clear_loop:
 	str	xzr, [x0], #8
 	cmp	x0, x1
-- 
2.50.0



More information about the U-Boot mailing list