From patchwork Wed Jan 8 16:15:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 37261 Received: (qmail 11133 invoked by alias); 8 Jan 2020 16:15:44 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 11021 invoked by uid 89); 8 Jan 2020 16:15:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SCC_5_SHORT_WORD_LINES, SPF_PASS autolearn=ham version=3.3.1 spammy=HContent-Transfer-Encoding:8bit X-HELO: mail-pf1-f194.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=MRahjK3LafsGcwEz35NMALHmL1xzBp5ruDwivif3ftc=; b=Nf7qawZs9/MTv+Fzh9hxIUXlqpGVJrRkBPuZbCnt4VbfsY6Rll2FZx7JEeTKKx5E+s 2YN7ueh7UWIS1kWR8eVagDA6dTcqwFCojShH1KmjN+rkrQzlF/HyfYBwIf/rgQWeqgus nNLCWJ7FvMFmgiF5qEtt3UWe6s9MpnuOuKofKKSmhQPXtkVnquEsm4WTSsm1qNQ4lpbh kCMy5RWRI0q/9sNru5Ea5efmC+nRH8zHrRoYWIkUQSWXAIjXKo+06GAnrYRlmPf4DrfJ Z1fqQNIVz9vamkJjmO3LhiAsIuszbTp5s7Vg922PGmXJUaouo5ti3hu+ebZddWLyc6Ak JmJA== Return-Path: From: "H.J. Lu" To: libc-alpha@sourceware.org Subject: V2 [PATCH 1/5] i386: Don't unnecessarily save and restore EAX, ECX and EDX [BZ# 25262] Date: Wed, 8 Jan 2020 08:15:31 -0800 Message-Id: <20200108161535.6141-2-hjl.tools@gmail.com> In-Reply-To: <20200108161535.6141-1-hjl.tools@gmail.com> References: <20200108161535.6141-1-hjl.tools@gmail.com> MIME-Version: 1.0 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 --- sysdeps/unix/sysv/linux/i386/getcontext.S | 8 +------- sysdeps/unix/sysv/linux/i386/setcontext.S | 11 ++++------- sysdeps/unix/sysv/linux/i386/swapcontext.S | 17 +++++------------ 3 files changed, 10 insertions(+), 26 deletions(-) diff --git a/sysdeps/unix/sysv/linux/i386/getcontext.S b/sysdeps/unix/sysv/linux/i386/getcontext.S index f86df4d555..9c1df9a2aa 100644 --- a/sysdeps/unix/sysv/linux/i386/getcontext.S +++ b/sysdeps/unix/sysv/linux/i386/getcontext.S @@ -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) diff --git a/sysdeps/unix/sysv/linux/i386/setcontext.S b/sysdeps/unix/sysv/linux/i386/setcontext.S index b4b5c0298c..f042d80bf4 100644 --- a/sysdeps/unix/sysv/linux/i386/setcontext.S +++ b/sysdeps/unix/sysv/linux/i386/setcontext.S @@ -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 diff --git a/sysdeps/unix/sysv/linux/i386/swapcontext.S b/sysdeps/unix/sysv/linux/i386/swapcontext.S index 792bfdf7e6..090c2d8c3e 100644 --- a/sysdeps/unix/sysv/linux/i386/swapcontext.S +++ b/sysdeps/unix/sysv/linux/i386/swapcontext.S @@ -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. */