[PATCH v2 3/6] x86-64: Set up a standard frame record in _dl_runtime_resolve

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


_dl_runtime_resolve now uses RBP as the CFA register, but it saves the
caller's RBP below the link map and reloc index pushed by the PLT
stubs, not directly below the return address.  Unwinders that follow
the frame-pointer chain expect the saved RBP at 0(%rbp) and the return
address at 8(%rbp), so they still stop at _dl_runtime_resolve.

Load the reloc index into R11 and store the caller's RBP in its slot.
RBP then points to a standard frame record.  The epilogue becomes a
single LEAVE, which also drops the link map pushed by the PLT.

LOCAL_STORAGE_AREA and BASE are no longer used; remove them.

Signed-off-by: Aliaksei Kandratsenka <alkondratenko@gmail.com>
---
 sysdeps/x86_64/dl-tlsdesc-dynamic.h  |  2 --
 sysdeps/x86_64/dl-trampoline-state.h |  3 --
 sysdeps/x86_64/dl-trampoline.h       | 50 +++++++++++++++++-----------
 3 files changed, 30 insertions(+), 25 deletions(-)

diff --git a/sysdeps/x86_64/dl-tlsdesc-dynamic.h b/sysdeps/x86_64/dl-tlsdesc-dynamic.h
index 6314529df1..7f47275c21 100644
--- a/sysdeps/x86_64/dl-tlsdesc-dynamic.h
+++ b/sysdeps/x86_64/dl-tlsdesc-dynamic.h
@@ -21,8 +21,6 @@
 #endif
 
 #undef REGISTER_SAVE_AREA
-#undef LOCAL_STORAGE_AREA
-#undef BASE
 
 #include "dl-trampoline-state.h"
 
diff --git a/sysdeps/x86_64/dl-trampoline-state.h b/sysdeps/x86_64/dl-trampoline-state.h
index 65eb080cf7..d2cd454d7c 100644
--- a/sysdeps/x86_64/dl-trampoline-state.h
+++ b/sysdeps/x86_64/dl-trampoline-state.h
@@ -24,9 +24,6 @@
 # error STATE_SAVE_OFFSET must be multiple of STATE_SAVE_ALIGNMENT
 #endif
 
-/* Local stack area before jumping to function address: RBP.  */
-#define LOCAL_STORAGE_AREA	8
-#define BASE			rbp
 #ifdef USE_FXSAVE
 /* Use fxsave to save XMM registers.  */
 # define REGISTER_SAVE_AREA	(512 + STATE_SAVE_OFFSET)
diff --git a/sysdeps/x86_64/dl-trampoline.h b/sysdeps/x86_64/dl-trampoline.h
index c9cb12dee6..2630655fcc 100644
--- a/sysdeps/x86_64/dl-trampoline.h
+++ b/sysdeps/x86_64/dl-trampoline.h
@@ -24,8 +24,6 @@
 #ifdef _dl_runtime_resolve
 
 # undef REGISTER_SAVE_AREA
-# undef LOCAL_STORAGE_AREA
-# undef BASE
 
 # include "dl-trampoline-state.h"
 
@@ -33,18 +31,34 @@
 	.hidden _dl_runtime_resolve
 	.type _dl_runtime_resolve, @function
 	.align 16
-	cfi_startproc
 _dl_runtime_resolve:
+	/* On entry, the PLT stubs have pushed the link map and the
+	   reloc index below the return address:
+
+	     16(%rsp)  return address
+	      8(%rsp)  reloc index
+	      0(%rsp)  link map
+
+	   Move the reloc index to %r11 and store the caller's %rbp in
+	   its slot, so that %rbp points to a standard frame record:
+
+	      8(%rbp)  return address
+	      0(%rbp)  caller's %rbp
+	     -8(%rbp)  link map
+	               padding             (realign to STATE_SAVE_ALIGNMENT)
+	               fxsave/xsave area   <- STATE_SAVE_OFFSET(%rsp)
+	               one 8-byte padding slot
+	               r9 r8 rdi rsi rdx rcx rax  <- %rsp
+	*/
+	cfi_startproc
 	cfi_adjust_cfa_offset(16) # Incorporate PLT
 	_CET_ENDBR
-# if LOCAL_STORAGE_AREA != 8
-#  error LOCAL_STORAGE_AREA must be 8
-# endif
-	pushq %rbp			# push subtracts stack by 8.
-	cfi_adjust_cfa_offset(8)
-	cfi_rel_offset(%rbp, 0)
-	mov %RSP_LP, %RBP_LP
-	cfi_def_cfa_register(%rbp)
+	mov 8(%rsp), %R11_LP	# Reloc index; its slot gets %rbp.
+	mov %rbp, 8(%rsp)
+	lea 8(%RSP_LP), %RBP_LP
+	cfi_def_cfa (%rbp, 16)
+	cfi_offset (%rbp, -16)
+
 	and $-STATE_SAVE_ALIGNMENT, %RSP_LP
 # ifdef REGISTER_SAVE_AREA
 	sub $REGISTER_SAVE_AREA, %RSP_LP
@@ -88,8 +102,8 @@ _dl_runtime_resolve:
 # endif
 	# Copy args pushed by PLT in register.
 	# %rdi: link_map, %rsi: reloc_index
-	mov (LOCAL_STORAGE_AREA + 8)(%BASE), %RSI_LP
-	mov LOCAL_STORAGE_AREA(%BASE), %RDI_LP
+	mov -8(%rbp), %RDI_LP
+	mov %R11_LP, %RSI_LP
 	call _dl_fixup		# Call resolver.
 	mov %RAX_LP, %R11_LP	# Save return value
 	# Get register content back.
@@ -107,13 +121,9 @@ _dl_runtime_resolve:
 	movq REGISTER_SAVE_RDX(%rsp), %rdx
 	movq REGISTER_SAVE_RCX(%rsp), %rcx
 	movq REGISTER_SAVE_RAX(%rsp), %rax
-	mov %RBP_LP, %RSP_LP
-	cfi_def_cfa_register(%rsp)
-	movq (%rsp), %rbp
-	cfi_restore(%rbp)
-	# Adjust stack(PLT did 2 pushes)
-	add $(LOCAL_STORAGE_AREA + 16), %RSP_LP
-	cfi_adjust_cfa_offset(-(LOCAL_STORAGE_AREA + 16))
+	leave
+	cfi_def_cfa (%rsp, 8)
+	cfi_restore (%rbp)
 	jmp *%r11		# Jump to function address.
 	cfi_endproc
 	.size _dl_runtime_resolve, .-_dl_runtime_resolve
-- 
2.55.0



More information about the Libc-alpha mailing list