From patchwork Tue Dec 10 20:47:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1207277 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-107926-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="f3/thM4u"; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="oaxMFW1Y"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47XXDz1bh7z9sPK for ; Wed, 11 Dec 2019 07:47:31 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; q=dns; s= default; b=F4qqbNgfl8pCE5km7S+c4Pk5ckHppcSXp+iG9joBCNnnDUYuTKM07 3PXrhVZFuct4k8sACm9jv/5bHrcK3kRcaR8u/hn5oLlamqv1be6zFlScA+umlUkE bis8olrneQ0ocmTkpxbfLxU8fy4SVgcqjiM3qP3KfXwehIOoIA1Vc8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; s=default; bh=zi3KVZ4YeM1cdFQkDEFKGBtWxps=; b=f3/thM4uR7pf95eSCCsYHnDWJEcs WeDp8MNjb+jwRAqsVHApg2AKKSeLdtPL2LkPMIFPQpH7R+/sb0yguLHTlwm8uekN VTxMvEIibSs4Y8DGHniBPijAr3/u0bOltbTlXAkhc4D6VMtLUNmJtquSDIOXMXj2 wE6pvk3ipXhGGcg= Received: (qmail 122850 invoked by alias); 10 Dec 2019 20:47:17 -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 122796 invoked by uid 89); 10 Dec 2019 20:47:17 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=unnecessarily, HContent-Transfer-Encoding:8bit X-HELO: mail-pj1-f65.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=qILRKzjt8wgkZiEaI6n3iMRY8ia0u7eDsqLsMZjWQb4=; b=oaxMFW1YxkHx9CD5TTDT5jls8gtsb8P6pEUCwXBAXdJr2uP43hGOjJ6pjUlBazoCb/ vjMlaXoJLEPh7BnN/cudrin1iEw89SjkgS1DlMRcddNEoQSls7pdD1XbSRU5S8u0Q40Q 5xryOTLYFpN0G5Ek/JEROEnzgRbpKwotIScX66dOERMdjdMySWJYCOC8zr0iEFwMgskm HkEdM253ms1cl8bkufAlIrEYVgkKiqU74IhlhY8O33qqHKK7wLQXlxEES42UZSbf+Asm tkpYKgWW1Ge8gZfDweySnmZJxmWlcLmZXjTGcaiu8nz8alnqxVgg+MaF1y4fr3wRqpwq 2fYw== From: "H.J. Lu" To: libc-alpha@sourceware.org Subject: [PATCH 1/4] i386: Don't unnecessarily save and restore EAX, ECX and EDX [BZ# 25262] Date: Tue, 10 Dec 2019 12:47:07 -0800 Message-Id: <20191210204710.4832-2-hjl.tools@gmail.com> In-Reply-To: <20191210204710.4832-1-hjl.tools@gmail.com> References: <20191210204710.4832-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. --- 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 1568f9604a..85da8195f9 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 dffe1d18e7..9095584b44 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 6fdc176535..83e5f0b2ff 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. */