]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
i386: Don't unnecessarily save and restore EAX, ECX and EDX [BZ# 25262]
authorH.J. Lu <hjl.tools@gmail.com>
Sat, 1 Feb 2020 13:44:55 +0000 (05:44 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Sat, 1 Feb 2020 13:44:55 +0000 (05:44 -0800)
On i386, since EAX, ECX and EDX are caller-saved, there are no need
to save and restore EAX, ECX and EDX in getcontext, setcontext and
swapcontext.  They just need to clear EAX on success.  The extra
scratch registers are needed to enable CET.

Tested on i386.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
sysdeps/unix/sysv/linux/i386/getcontext.S
sysdeps/unix/sysv/linux/i386/setcontext.S
sysdeps/unix/sysv/linux/i386/swapcontext.S
sysdeps/unix/sysv/linux/i386/ucontext_i.sym

index f86df4d5552bd63a43bf1160adb177fc082d0753..9c1df9a2aa5fbae1d238a9c54658d7340e5d6def 100644 (file)
@@ -26,13 +26,7 @@ ENTRY(__getcontext)
        /* Load address of the context data structure.  */
        movl    4(%esp), %eax
 
-       /* Return value of getcontext.  EAX is the only register whose
-          value is not preserved.  */
-       movl    $0, oEAX(%eax)
-
-       /* Save the 32-bit register values and the return address.  */
-       movl    %ecx, oECX(%eax)
-       movl    %edx, oEDX(%eax)
+       /* Save the preserved register values and the return address.  */
        movl    %edi, oEDI(%eax)
        movl    %esi, oESI(%eax)
        movl    %ebp, oEBP(%eax)
index b4b5c0298c50061b65fba7ac294e4cf48b106324..f042d80bf40358a25f89f12a2105b7bde4fde042 100644 (file)
@@ -65,22 +65,19 @@ ENTRY(__setcontext)
        cfi_offset (esi, oESI)
        cfi_offset (ebp, oEBP)
        cfi_offset (ebx, oEBX)
-       cfi_offset (edx, oEDX)
-       cfi_offset (ecx, oECX)
        movl    oESP(%eax), %esp
 
        /* Push the return address on the new stack so we can return there.  */
        pushl   %ecx
 
-       /* Load the values of all the 32-bit registers (except ESP).
-          Since we are loading from EAX, it must be last.  */
+       /* Load the values of all the preserved registers (except ESP).  */
        movl    oEDI(%eax), %edi
        movl    oESI(%eax), %esi
        movl    oEBP(%eax), %ebp
        movl    oEBX(%eax), %ebx
-       movl    oEDX(%eax), %edx
-       movl    oECX(%eax), %ecx
-       movl    oEAX(%eax), %eax
+
+       /* All done, return 0 for success.  */
+       xorl    %eax, %eax
 
        /* End FDE here, we fall into another context.  */
        cfi_endproc
index 792bfdf7e6d8dbcf6b9d80f7be3ea1f6faf1a21a..090c2d8c3ef9280887c95d71fe1cf853763ea1b9 100644 (file)
@@ -26,13 +26,7 @@ ENTRY(__swapcontext)
        /* Load address of the context data structure we save in.  */
        movl    4(%esp), %eax
 
-       /* Return value of swapcontext.  EAX is the only register whose
-          value is not preserved.  */
-       movl    $0, oEAX(%eax)
-
-       /* Save the 32-bit register values and the return address.  */
-       movl    %ecx, oECX(%eax)
-       movl    %edx, oEDX(%eax)
+       /* Save the preserved register values and the return address.  */
        movl    %edi, oEDI(%eax)
        movl    %esi, oESI(%eax)
        movl    %ebp, oEBP(%eax)
@@ -91,15 +85,14 @@ ENTRY(__swapcontext)
        /* Push the return address on the new stack so we can return there.  */
        pushl   %ecx
 
-       /* Load the values of all the 32-bit registers (except ESP).
-          Since we are loading from EAX, it must be last.  */
+       /* Load the values of all the preserved registers (except ESP).  */
        movl    oEDI(%eax), %edi
        movl    oESI(%eax), %esi
        movl    oEBP(%eax), %ebp
        movl    oEBX(%eax), %ebx
-       movl    oEDX(%eax), %edx
-       movl    oECX(%eax), %ecx
-       movl    oEAX(%eax), %eax
+
+       /* All done, return 0 for success.  */
+       xorl    %eax, %eax
 
        /* The following 'ret' will pop the address of the code and jump
           to it.  */
index b11a5509cd469b320b4c92bdcb429b6e2470c756..1dfe03d2cc5e8642b1f91295d115b9fc2724814a 100644 (file)
@@ -21,9 +21,6 @@ oESI          mreg (ESI)
 oEBP           mreg (EBP)
 oESP           mreg (ESP)
 oEBX           mreg (EBX)
-oEDX           mreg (EDX)
-oECX           mreg (ECX)
-oEAX           mreg (EAX)
 oEIP           mreg (EIP)
 oFPREGS                mcontext (fpregs)
 oSIGMASK       ucontext (uc_sigmask)