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
This commit is contained in:
Dmitry Chagin 2023-07-11 15:11:22 +03:00
parent e541cf8316
commit d7e2580a14
2 changed files with 10 additions and 4 deletions

View file

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

View file

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