Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 1 Jul 2023 07:52:24 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: 3bdf68086de8 - main - rtld: Add a stop indicator to rtld_start to satisfy unwinders on x86_64
Message-ID:  <202307010752.3617qOLF023809@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=3bdf68086de8bee79f09cba28fd0df3be6565216

commit 3bdf68086de8bee79f09cba28fd0df3be6565216
Author:     Dmitry Chagin <dchagin@FreeBSD.org>
AuthorDate: 2023-07-01 07:51:35 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2023-07-01 07:51:35 +0000

    rtld: Add a stop indicator to rtld_start to satisfy unwinders on x86_64
    
    The right unwinding stop indicator should be CFI-undefined PC.
    https://dwarfstd.org/doc/Dwarf3.pdf - page 118:
    If a Return Address register is defined in the virtual unwind table,
    and its rule is undefined (for example, by DW_CFA_undefined), then
    there is no return address and no call address, and the virtual
    unwind of stack activations is complete.
    
    That is allows gdb and libunwind successfully stop when unwinding stack
    from global constructors and destructors.
    
    Reviewed by:            kib
    Differential Revision:  https://reviews.freebsd.org/D40794
---
 libexec/rtld-elf/amd64/rtld_start.S | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/libexec/rtld-elf/amd64/rtld_start.S b/libexec/rtld-elf/amd64/rtld_start.S
index 72240a92c063..5b5cb2ccb47f 100644
--- a/libexec/rtld-elf/amd64/rtld_start.S
+++ b/libexec/rtld-elf/amd64/rtld_start.S
@@ -30,14 +30,18 @@
 	.globl	.rtld_start
 	.type	.rtld_start,@function
 .rtld_start:
+	.cfi_startproc
+	.cfi_undefined %rip
 	xorq	%rbp,%rbp		# Clear frame pointer for good form
 	subq	$24,%rsp		# A place to store exit procedure addr
+	.cfi_def_cfa_offset 32
 	movq	%rdi,%r12
 	movq	%rsp,%rsi		# save address of exit proc
 	movq	%rsp,%rdx		# construct address of obj_main
 	addq	$8,%rdx
 	call	_rtld			# Call rtld(sp); returns entry point
 	popq	%rsi			# Get exit procedure address
+	.cfi_def_cfa_offset 24
 	movq	%r12,%rdi		# *ap
 /*
  * At this point, %rax contains the entry point of the main program, and
@@ -47,6 +51,7 @@
 .globl .rtld_goto_main
 .rtld_goto_main:	# This symbol exists just to make debugging easier.
 	jmp	*%rax			# Enter main program
+	.cfi_endproc
 
 
 /*



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