git: 43e29d03f416 - main - csu: Add the prologue and epilogue to the _init and _fini on aarch64

From: Dmitry Chagin <dchagin_at_FreeBSD.org>
Date: Fri, 07 Jul 2023 16:56:18 UTC
The branch main has been updated by dchagin:

URL: https://cgit.FreeBSD.org/src/commit/?id=43e29d03f416d7dda52112a29600a7c82ee1a91e

commit 43e29d03f416d7dda52112a29600a7c82ee1a91e
Author:     Dmitry Chagin <dchagin@FreeBSD.org>
AuthorDate: 2023-07-07 16:54:53 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2023-07-07 16:54:53 +0000

    csu: Add the prologue and epilogue to the _init and _fini on aarch64
    
    Normally, modern unwinders uses Dwarf information to unwind stack,
    however in case when the code is not annotated by Dwarf instructions,
    unwinders fallbacks to a frame-pointer based algorithm.
    
    That is allows libunwind to unwind stack from global constructors and
    destructors. Also it makes gdb happy as it printed nonexistent frame
    before.
    
    Reviewed by:
    Differential Revision:  https://reviews.freebsd.org/D40842
---
 lib/csu/aarch64/crti.S | 8 ++++----
 lib/csu/aarch64/crtn.S | 6 ++----
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/lib/csu/aarch64/crti.S b/lib/csu/aarch64/crti.S
index 13e3b74642d8..af10c0f00d7d 100644
--- a/lib/csu/aarch64/crti.S
+++ b/lib/csu/aarch64/crti.S
@@ -35,14 +35,14 @@ __FBSDID("$FreeBSD$");
 	.globl	_init
 	.type	_init,@function
 _init:
-	sub	sp, sp, #16
-	str	lr, [sp]
+	stp	x29, x30, [sp, #-16]!
+	mov	x29, sp
 
 	.section .fini,"ax",@progbits
 	.align 4
 	.globl	_fini
 	.type	_fini,@function
 _fini:
-	sub	sp, sp, #16
-	str	lr, [sp]
+	stp	x29, x30, [sp, #-16]!
+	mov	x29, sp
 
diff --git a/lib/csu/aarch64/crtn.S b/lib/csu/aarch64/crtn.S
index ebb59b710412..c62433537f36 100644
--- a/lib/csu/aarch64/crtn.S
+++ b/lib/csu/aarch64/crtn.S
@@ -31,14 +31,12 @@
 __FBSDID("$FreeBSD$");
 
 	.section .init,"ax",@progbits
-	ldr	lr, [sp]
-	add	sp, sp, #16
+	ldp	x29, x30, [sp], #16
 	ret
 
 
 	.section .fini,"ax",@progbits
-	ldr	lr, [sp]
-	add	sp, sp, #16
+	ldp	x29, x30, [sp], #16
 	ret
 
 	.section .note.GNU-stack,"",%progbits