x86-64: Allocate state buffer space for RDI, RSI and RBX
commit717ebfa85c8240d32d0d19d86a484c31c55c9617
authorH.J. Lu <hjl.tools@gmail.com>
Mon, 18 Mar 2024 13:40:16 +0000 (18 06:40 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 19 Mar 2024 02:45:13 +0000 (18 19:45 -0700)
treea9302ec711b0562c6313682e786b03cfe8bf1254
parentf44f3aed31a2d18dc1aa70fce8d466cf6e56b93c
x86-64: Allocate state buffer space for RDI, RSI and RBX

_dl_tlsdesc_dynamic preserves RDI, RSI and RBX before realigning stack.
After realigning stack, it saves RCX, RDX, R8, R9, R10 and R11.  Define
TLSDESC_CALL_REGISTER_SAVE_AREA to allocate space for RDI, RSI and RBX
to avoid clobbering saved RDI, RSI and RBX values on stack by xsave to
STATE_SAVE_OFFSET(%rsp).

   +==================+<- stack frame start aligned at 8 or 16 bytes
   |                  |<- RDI saved in the red zone
   |                  |<- RSI saved in the red zone
   |                  |<- RBX saved in the red zone
   |                  |<- paddings for stack realignment of 64 bytes
   |------------------|<- xsave buffer end aligned at 64 bytes
   |                  |<-
   |                  |<-
   |                  |<-
   |------------------|<- xsave buffer start at STATE_SAVE_OFFSET(%rsp)
   |                  |<- 8-byte padding for 64-byte alignment
   |                  |<- 8-byte padding for 64-byte alignment
   |                  |<- R11
   |                  |<- R10
   |                  |<- R9
   |                  |<- R8
   |                  |<- RDX
   |                  |<- RCX
   +==================+<- RSP aligned at 64 bytes

Define TLSDESC_CALL_REGISTER_SAVE_AREA, the total register save area size
for all integer registers by adding 24 to STATE_SAVE_OFFSET since RDI, RSI
and RBX are saved onto stack without adjusting stack pointer first, using
the red-zone.  This fixes BZ #31501.
Reviewed-by: Sunil K Pandey <skpgkp2@gmail.com>
sysdeps/x86/cpu-features.c
sysdeps/x86/sysdep.h
sysdeps/x86_64/tst-gnu2-tls2mod1.S [new file with mode: 0644]