Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Jul 2023 12:12:19 GMT
From:      Dmitry Chagin <dchagin@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: d7e2580a1494 - main - csu: Add the prologue and epilogue to the _init and _fini on i386
Message-ID:  <202307111212.36BCCJWC025125@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by dchagin:

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

commit d7e2580a1494a8a05d4a97fa472612df84c1539b
Author:     Dmitry Chagin <dchagin@FreeBSD.org>
AuthorDate: 2023-07-11 12:11:22 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2023-07-11 12:11:22 +0000

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

diff --git a/lib/csu/i386/crti.S b/lib/csu/i386/crti.S
index 77e4e77722d7..f5883db0ba0f 100644
--- a/lib/csu/i386/crti.S
+++ b/lib/csu/i386/crti.S
@@ -31,13 +31,17 @@ __FBSDID("$FreeBSD$");
 	.globl	_init
 	.type	_init,@function
 _init:
-	sub	$12,%esp	/* re-align stack pointer */
+	pushl	%ebp
+	movl	%esp,%ebp
+	subl	$8,%esp		/* re-align stack pointer */
 
 	.section .fini,"ax",@progbits
 	.align	4
 	.globl	_fini
 	.type	_fini,@function
 _fini:
-	sub	$12,%esp	/* re-align stack pointer */
+	pushl	%ebp
+	movl	%esp,%ebp
+	subl	$8,%esp		/* re-align stack pointer */
 
 	.section .note.GNU-stack,"",%progbits
diff --git a/lib/csu/i386/crtn.S b/lib/csu/i386/crtn.S
index 0264e22540f1..f223062bb787 100644
--- a/lib/csu/i386/crtn.S
+++ b/lib/csu/i386/crtn.S
@@ -27,11 +27,13 @@
 __FBSDID("$FreeBSD$");
 
 	.section .init,"ax",@progbits
-	add	$12,%esp
+	addl	$8,%esp
+	popl	%ebp
 	ret
 
 	.section .fini,"ax",@progbits
-	add	$12,%esp
+	addl	$8,%esp
+	popl	%ebp
 	ret
 
 	.section .note.GNU-stack,"",%progbits



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202307111212.36BCCJWC025125>