git: f049c92ad6c3 - main - csu: Add the prologue and epilogue to the _init and _fini on x86_64

From: Dmitry Chagin <dchagin_at_FreeBSD.org>
Date: Sat, 01 Jul 2023 07:52:25 UTC
The branch main has been updated by dchagin:

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

commit f049c92ad6c38ef42265956545897d8e3be1c228
Author:     Dmitry Chagin <dchagin@FreeBSD.org>
AuthorDate: 2023-07-01 07:52:10 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2023-07-01 07:52:10 +0000

    csu: Add the prologue and epilogue to the _init and _fini on x86_64
    
    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:            kib
    Differential Revision:  https://reviews.freebsd.org/D40795
---
 lib/csu/amd64/crti.S | 6 ++++--
 lib/csu/amd64/crtn.S | 4 ++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/lib/csu/amd64/crti.S b/lib/csu/amd64/crti.S
index 618dca178877..05b8ad8a431a 100644
--- a/lib/csu/amd64/crti.S
+++ b/lib/csu/amd64/crti.S
@@ -31,13 +31,15 @@ __FBSDID("$FreeBSD$");
 	.globl	_init
 	.type	_init,@function
 _init:
-	subq	$8,%rsp
+	pushq	%rbp
+	movq	%rsp,%rbp
 
 	.section .fini,"ax",@progbits
 	.align	4
 	.globl	_fini
 	.type	_fini,@function
 _fini:
-	subq	$8,%rsp
+	pushq	%rbp
+	movq	%rsp,%rbp
 
 	.section .note.GNU-stack,"",%progbits
diff --git a/lib/csu/amd64/crtn.S b/lib/csu/amd64/crtn.S
index c411f001ac1f..50b5003b9f7c 100644
--- a/lib/csu/amd64/crtn.S
+++ b/lib/csu/amd64/crtn.S
@@ -27,11 +27,11 @@
 __FBSDID("$FreeBSD$");
 
 	.section .init,"ax",@progbits
-	addq	$8,%rsp
+	popq	%rbp
 	ret
 
 	.section .fini,"ax",@progbits
-	addq	$8,%rsp
+	popq	%rbp
 	ret
 
 	.section .note.GNU-stack,"",%progbits