From 3bdf68086de8bee79f09cba28fd0df3be6565216 Mon Sep 17 00:00:00 2001 From: Dmitry Chagin Date: Sat, 1 Jul 2023 10:51:35 +0300 Subject: [PATCH] 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 /*