[PATCH v2 1/6] x86-64: Remove dead code for !DL_RUNTIME_RESOLVE_REALIGN_STACK
Aliaksei Kandratsenka
alkondratenko@gmail.com
Tue Nov 3 00:02:01 GMT 2026
On x86-64, DL_STACK_ALIGNMENT is 8 and MINIMUM_ALIGNMENT is 16, so
DL_RUNTIME_RESOLVE_REALIGN_STACK is always true. Remove the code for
the false case from _dl_runtime_resolve, _dl_tlsdesc_dynamic and
dl-trampoline-state.h. Restrict the DL_STACK_ALIGNMENT and
DL_RUNTIME_RESOLVE_REALIGN_STACK definitions in sysdeps/x86/sysdep.h to
i386, which is now their only user.
No change in generated code.
Signed-off-by: Aliaksei Kandratsenka <alkondratenko@gmail.com>
---
sysdeps/x86/sysdep.h | 18 ++++++++----------
sysdeps/x86_64/dl-tlsdesc-dynamic.h | 12 ------------
sysdeps/x86_64/dl-trampoline-state.h | 27 ++++++---------------------
sysdeps/x86_64/dl-trampoline.h | 13 +++----------
4 files changed, 17 insertions(+), 53 deletions(-)
diff --git a/sysdeps/x86/sysdep.h b/sysdeps/x86/sysdep.h
index 41b040d51b..37276c6220 100644
--- a/sysdeps/x86/sysdep.h
+++ b/sysdeps/x86/sysdep.h
@@ -183,29 +183,27 @@
#define atom_text_section .section ".text.atom", "ax"
-#ifndef DL_STACK_ALIGNMENT
+#ifndef __x86_64__
+# ifndef DL_STACK_ALIGNMENT
/* Due to GCC bug:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58066
- __tls_get_addr may be called with 8-byte/4-byte stack alignment.
+ __tls_get_addr may be called with 4-byte stack alignment.
Although this bug has been fixed in GCC 4.9.4, 5.3 and 6, we can't
assume that stack will be always aligned at 16 bytes. */
-# ifdef __x86_64__
-# define DL_STACK_ALIGNMENT 8
-# define MINIMUM_ALIGNMENT 16
-# else
# define DL_STACK_ALIGNMENT 4
# endif
-#endif
-/* True if _dl_runtime_resolve/_dl_tlsdesc_dynamic should align stack for
+/* True if i386 _dl_tlsdesc_dynamic/___tls_get_addr should align stack for
STATE_SAVE or align stack to MINIMUM_ALIGNMENT bytes before calling
- _dl_fixup/__tls_get_addr. */
-#define DL_RUNTIME_RESOLVE_REALIGN_STACK \
+ ___tls_get_addr_internal. */
+# define DL_RUNTIME_RESOLVE_REALIGN_STACK \
(STATE_SAVE_ALIGNMENT > DL_STACK_ALIGNMENT \
|| MINIMUM_ALIGNMENT > DL_STACK_ALIGNMENT)
+#endif /* !__x86_64__ */
+
#endif /* __ASSEMBLER__ */
#endif /* _X86_SYSDEP_H */
diff --git a/sysdeps/x86_64/dl-tlsdesc-dynamic.h b/sysdeps/x86_64/dl-tlsdesc-dynamic.h
index f9148e4f29..6314529df1 100644
--- a/sysdeps/x86_64/dl-tlsdesc-dynamic.h
+++ b/sysdeps/x86_64/dl-tlsdesc-dynamic.h
@@ -81,22 +81,15 @@ _dl_tlsdesc_dynamic:
movq -8(%rsp), %rdi
ret
2:
-#if DL_RUNTIME_RESOLVE_REALIGN_STACK
movq %rbx, -24(%rsp)
mov %RSP_LP, %RBX_LP
cfi_def_cfa_register(%rbx)
and $-STATE_SAVE_ALIGNMENT, %RSP_LP
-#endif
#ifdef REGISTER_SAVE_AREA
-# if DL_RUNTIME_RESOLVE_REALIGN_STACK
/* STATE_SAVE_OFFSET has space for 8 integer registers. But we
need space for RCX, RDX, RSI, RDI, R8, R9, R10 and R11, plus
RBX above. */
sub $(REGISTER_SAVE_AREA + STATE_SAVE_ALIGNMENT), %RSP_LP
-# else
- sub $REGISTER_SAVE_AREA, %RSP_LP
- cfi_adjust_cfa_offset(REGISTER_SAVE_AREA)
-# endif
#else
/* Allocate stack space of the required size to save the state. */
sub _dl_x86_features_tlsdesc_state_size(%rip), %RSP_LP
@@ -150,15 +143,10 @@ _dl_tlsdesc_dynamic:
movq REGISTER_SAVE_R8(%rsp), %r8
movq REGISTER_SAVE_RDX(%rsp), %rdx
movq REGISTER_SAVE_RCX(%rsp), %rcx
-#if DL_RUNTIME_RESOLVE_REALIGN_STACK
mov %RBX_LP, %RSP_LP
cfi_def_cfa_register(%rsp)
movq -24(%rsp), %rbx
cfi_restore(%rbx)
-#else
- add $REGISTER_SAVE_AREA, %RSP_LP
- cfi_adjust_cfa_offset(-REGISTER_SAVE_AREA)
-#endif
jmp 1b
cfi_endproc
.size _dl_tlsdesc_dynamic, .-_dl_tlsdesc_dynamic
diff --git a/sysdeps/x86_64/dl-trampoline-state.h b/sysdeps/x86_64/dl-trampoline-state.h
index 21cc9d5082..d3a3d5d7c9 100644
--- a/sysdeps/x86_64/dl-trampoline-state.h
+++ b/sysdeps/x86_64/dl-trampoline-state.h
@@ -24,28 +24,13 @@
# error STATE_SAVE_OFFSET must be multiple of STATE_SAVE_ALIGNMENT
#endif
-#if DL_RUNTIME_RESOLVE_REALIGN_STACK
/* Local stack area before jumping to function address: RBX. */
-# define LOCAL_STORAGE_AREA 8
-# define BASE rbx
-# ifdef USE_FXSAVE
+#define LOCAL_STORAGE_AREA 8
+#define BASE rbx
+#ifdef USE_FXSAVE
/* Use fxsave to save XMM registers. */
-# define REGISTER_SAVE_AREA (512 + STATE_SAVE_OFFSET)
-# if (REGISTER_SAVE_AREA % 16) != 0
-# error REGISTER_SAVE_AREA must be multiple of 16
-# endif
-# endif
-#else
-# ifndef USE_FXSAVE
-# error USE_FXSAVE must be defined
-# endif
-/* Use fxsave to save XMM registers. */
-# define REGISTER_SAVE_AREA (512 + STATE_SAVE_OFFSET + 8)
-/* Local stack area before jumping to function address: All saved
- registers. */
-# define LOCAL_STORAGE_AREA REGISTER_SAVE_AREA
-# define BASE rsp
-# if (REGISTER_SAVE_AREA % 16) != 8
-# error REGISTER_SAVE_AREA must be odd multiple of 8
+# define REGISTER_SAVE_AREA (512 + STATE_SAVE_OFFSET)
+# if (REGISTER_SAVE_AREA % 16) != 0
+# error REGISTER_SAVE_AREA must be multiple of 16
# endif
#endif
diff --git a/sysdeps/x86_64/dl-trampoline.h b/sysdeps/x86_64/dl-trampoline.h
index b07f29c55a..6316b6e719 100644
--- a/sysdeps/x86_64/dl-trampoline.h
+++ b/sysdeps/x86_64/dl-trampoline.h
@@ -37,22 +37,17 @@
_dl_runtime_resolve:
cfi_adjust_cfa_offset(16) # Incorporate PLT
_CET_ENDBR
-# if DL_RUNTIME_RESOLVE_REALIGN_STACK
-# if LOCAL_STORAGE_AREA != 8
-# error LOCAL_STORAGE_AREA must be 8
-# endif
+# if LOCAL_STORAGE_AREA != 8
+# error LOCAL_STORAGE_AREA must be 8
+# endif
pushq %rbx # push subtracts stack by 8.
cfi_adjust_cfa_offset(8)
cfi_rel_offset(%rbx, 0)
mov %RSP_LP, %RBX_LP
cfi_def_cfa_register(%rbx)
and $-STATE_SAVE_ALIGNMENT, %RSP_LP
-# endif
# ifdef REGISTER_SAVE_AREA
sub $REGISTER_SAVE_AREA, %RSP_LP
-# if !DL_RUNTIME_RESOLVE_REALIGN_STACK
- cfi_adjust_cfa_offset(REGISTER_SAVE_AREA)
-# endif
# else
# Allocate stack space of the required size to save the state.
# if IS_IN (rtld)
@@ -112,12 +107,10 @@ _dl_runtime_resolve:
movq REGISTER_SAVE_RDX(%rsp), %rdx
movq REGISTER_SAVE_RCX(%rsp), %rcx
movq REGISTER_SAVE_RAX(%rsp), %rax
-# if DL_RUNTIME_RESOLVE_REALIGN_STACK
mov %RBX_LP, %RSP_LP
cfi_def_cfa_register(%rsp)
movq (%rsp), %rbx
cfi_restore(%rbx)
-# endif
# Adjust stack(PLT did 2 pushes)
add $(LOCAL_STORAGE_AREA + 16), %RSP_LP
cfi_adjust_cfa_offset(-(LOCAL_STORAGE_AREA + 16))
--
2.55.0
More information about the Libc-alpha
mailing list