diff mbox series

AARCH64 clean bss bug

Message ID zfknlzcemnnaka5w2er5wjwefwoidrpndc4gjhx6d5xr6nlcjr@pasfayjiutii
State Changes Requested
Delegated to: Ilias Apalodimas
Headers show
Series AARCH64 clean bss bug | expand

Commit Message

brock.zheng June 29, 2025, 4:37 a.m. UTC
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@techyauld.com>
郑 祎

北京中科腾越科技发展有限公司
北京市 海淀区 东北旺西路8号 中关村软件园27号院 千方大厦A座2层 (邮编:100193)
From 799060d6d373236951afa9d3e571b36fc9e9d026 Mon Sep 17 00:00:00 2001
From: Brock Zheng <yzheng@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(-)

Comments

Ilias Apalodimas July 1, 2025, 5:08 p.m. UTC | #1
Hi Brock

On Sun Jun 29, 2025 at 7:37 AM EEST, brock_zheng wrote:
>
> 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.o

One of the problems when using the literal pool is that the access is PC-relative, but
the entry itself contains an asbolute address. This code runs after relocation right?
It the literal pool entries relocated?
Any idea why __bss_end is wrong? It would be helpful to have a more complete commit message

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

Uisng adr for linker symbols is fine, but can you please use adrp+add instead of adr?

Thanks
/Ilias
>
>
> --
> Brock Zheng <yzheng@techyauld.com>
> 郑 祎
>
> 北京中科腾越科技发展有限公司
> 北京市 海淀区 东北旺西路8号 中关村软件园27号院 千方大厦A座2层 (邮编:100193)
diff mbox series

Patch

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