[PATCH v2 0/6] x86-64: Use standard frame records in ld.so trampolines

Aliaksei Kandratsenka alkondratenko@gmail.com
Tue Nov 3 00:02:00 GMT 2026


_dl_runtime_resolve, _dl_runtime_profile and the slow path of
_dl_tlsdesc_dynamic realign the stack and use RBX as the CFA register
while they call into C code.  Unwinders that track only SP, FP and RA
(SFrame, the Linux kernel user-space unwinder, aw-backtrace) cannot
unwind through them.  Frame-pointer walkers skip a frame, because none
of them sets up a frame record.

I found this with aw-backtrace
(https://github.com/gperftools/aw-backtrace), whose test single-steps
code, runs a signal handler at every instruction boundary, and checks
that the captured backtrace matches the actual call/ret sequence.

This series makes all three functions use RBP as the CFA register and
point RBP at a standard frame record (caller's RBP at 0(%rbp), return
address at 8(%rbp)), so that every unwinder sees the same frame.

  1. Remove dead !DL_RUNTIME_RESOLVE_REALIGN_STACK code.  No change in
     generated code; it makes the following patches simpler.
  2. Use RBP instead of RBX in the PLT trampolines.  This is v1,
     rebased on top of patch 1.
  3. Set up a standard frame record in _dl_runtime_resolve.
  4. Set up a standard frame record in _dl_runtime_profile.
  5. Use RBP instead of RBX in _dl_tlsdesc_dynamic.
  6. Set up a standard frame record in _dl_tlsdesc_dynamic.  This also
     reserves the red-zone slots explicitly instead of through
     TLSDESC_CALL_REGISTER_SAVE_AREA (BZ #31501).

Changes since v1, mostly following Adhemerval's review:

  - In v1, RBP pointed at the caller's RBP with the link map above it,
    so a frame-pointer walker would report the link map as a return
    address.  Adhemerval suggested pushing a copy of the return
    address.  Instead, patches 3 and 4 store the caller's RBP in the
    reloc index slot pushed by the PLT, which is directly below the
    real return address; the reloc index is kept in R11 (or in local
    storage in _dl_runtime_profile).  This needs no extra push, and the
    CFA is RBP + 16 as in any normal frame, so DWARF, SFrame and
    frame-pointer walkers all agree on the caller's frame.  The
    epilogue becomes LEAVE.

  - Adhemerval suggested leaving _dl_runtime_profile alone.  With this
    approach the change costs nothing there either, and
    _dl_runtime_profile calls into audit modules and the target
    function, so unwinding through it is useful.  It also replaces a lea
    that only worked because LR_RSP_OFFSET happens to equal 56.

  - As Adhemerval pointed out, _dl_tlsdesc_dynamic had the same
    RBX-based CFA.  Patches 5 and 6 switch it to RBP and give it a
    standard frame record too.

Tested on x86_64-linux-gnu: make check on x86_64 and x32, no
regressions compared to the base commit.  LD_AUDIT tested manually.
Also verified that aw-backtrace's backtrace-comparer now passes on
/usr/bin/true without suppressing _dl_fixup or _dl_runtime_resolve.

v1: https://sourceware.org/pipermail/libc-alpha/2026-October/181360.html

Aliaksei Kandratsenka (6):
  x86-64: Remove dead code for !DL_RUNTIME_RESOLVE_REALIGN_STACK
  x86-64: Use RBP instead of RBX as CFA register in PLT trampolines
  x86-64: Set up a standard frame record in _dl_runtime_resolve
  x86-64: Set up a standard frame record in _dl_runtime_profile
  x86-64: Use RBP instead of RBX as CFA register in _dl_tlsdesc_dynamic
  x86-64: Set up a standard frame record in _dl_tlsdesc_dynamic

 sysdeps/x86/cpu-features.c           |   5 +-
 sysdeps/x86/sysdep.h                 |  79 +++----------
 sysdeps/x86_64/dl-tlsdesc-dynamic.h  |  66 ++++++-----
 sysdeps/x86_64/dl-trampoline-state.h |  26 +----
 sysdeps/x86_64/dl-trampoline.h       | 162 +++++++++++++--------------
 5 files changed, 137 insertions(+), 201 deletions(-)

-- 
2.55.0



More information about the Libc-alpha mailing list