Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1601760

[PATCH 2/2] x86, boot: Use regparm=0 for memcpy and memset when using clang

Path csiph.com!news.freedyn.net!open-news-network.org!aioe.org!bofh.it!news.nic.it!robomod
From Michael Davidson <md@google.com>
Newsgroups linux.kernel
Subject [PATCH 2/2] x86, boot: Use regparm=0 for memcpy and memset when using clang
Date Wed, 15 Mar 2017 22:50:01 +0100
Message-ID <tloXT-59Y-7@gated-at.bofh.it> (permalink)
References <tloXT-59Y-9@gated-at.bofh.it>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xH+MYTPiE3fH9mHsw5DlLlg9Gfv6RKzosfw/DmgMXz0=; b=qpX3WE+Ziy+MV1jvWgvIOQFwEHriLYLnuhXtL2O+HzKujji9rjJ0xbulvWJw0/ffd8 8De97Sx+ws4codtc9VK9tUXyO8VC/PgcU2LNvX2aVMsOVtE06EiO4G6H13yFGYsfiXRR 8j5okiExGftWEJpTBt+q3WECTagMGc4ngT4DKj/l7KUfVLGN8WHkDlXPILKcZLvfvCtS +FCeyjxwpwFsA7mRjKwjrtvuDP5Aw5jtoK2xmpX0DJFa2ovejWbmFKthoRwfUPU7gc9P t7gHXQsK4LugH/e8XAzU3qH2mjvXk4qF6GeDv5J1R0VGsyPwl1jZPzqn9jnEY/FQTqLP 7uBw==
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xH+MYTPiE3fH9mHsw5DlLlg9Gfv6RKzosfw/DmgMXz0=; b=Sy9a4G/85Lab4IQDVDsvSR++P3MhwljUrkrDQNL0s+7SvoukfaRjpdbv/deJ+bwXoc M/5RUt9WQsKjIo3PgjGAWn2He5XyMIlSyb83PZs/+ogxzxQ5SiJ0vWpXBKMIPIvyBt73 WQR8W0DGmVSEE7a4CSHzTb7DNWQxtPe0b1X2zaZIcEznrLVqRm8TxGGE/PulADprefVi z3R1D4RJrS0aVnbAy5H1mSdMdUrNVMe2B6iZPJm1g1MxVASp/Pcl928Tr2m1Bj6pEWQ3 BPspbbKeup8yby3fZqKoXr8ufBL6X9uvbo9cheUoncAX2Ygd97O7Pd1iLMX4oA0Qakw0 i+Pw==
X-Gm-Message-State AFeK/H2+V5Z26BOQoGrLvqIlkcwpyHYcEooQMH+Cu5xGS/aXy423Q6zSPPuv735E1bZP38RL
X-Received by 10.98.218.76 with SMTP id w12mr6224833pfl.162.1489614532429; Wed, 15 Mar 2017 14:48:52 -0700 (PDT)
X-Mailer git-send-email 2.12.0.367.g23dc2f6d3c-goog
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 91
Organization linux.* mail to news gateway
X-Original-Cc Alexander Potapenko <glider@google.com>, Dmitry Vyukov <dvyukov@google.com>, x86@kernel.org, linux-kernel@vger.kernel.org, Michael Davidson <md@google.com>
X-Original-Date Wed, 15 Mar 2017 14:48:21 -0700
X-Original-Message-ID <20170315214821.127170-2-md@google.com>
X-Original-References <20170315214821.127170-1-md@google.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1601760

Show key headers only | View raw


Use the standard regparm=0 calling convention for memcpy and
memset when building with clang.

This is a work around for a long standing clang bug
(see https://llvm.org/bugs/show_bug.cgi?id=3997) where
clang always uses the standard regparm=0 calling convention
for any implcit calls to memcpy and memset that it generates
(eg for structure assignments and initialization) even if an
alternate calling convention such as regparm=3 has been specified.

Signed-off-by: Michael Davidson <md@google.com>
---
 arch/x86/boot/copy.S   | 15 +++++++++++++--
 arch/x86/boot/string.h | 13 +++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/arch/x86/boot/copy.S b/arch/x86/boot/copy.S
index 1eb7d298b47d..57142d1ad0d2 100644
--- a/arch/x86/boot/copy.S
+++ b/arch/x86/boot/copy.S
@@ -18,6 +18,12 @@
 	.text
 
 GLOBAL(memcpy)
+#ifdef	__clang__	/* Use normal ABI calling conventions */
+	movw	4(%esp), %ax
+	movw	8(%esp), %dx
+	movw	12(%esp), %cx
+#endif
+_memcpy:
 	pushw	%si
 	pushw	%di
 	movw	%ax, %di
@@ -34,6 +40,11 @@ GLOBAL(memcpy)
 ENDPROC(memcpy)
 
 GLOBAL(memset)
+#ifdef	__clang__	/* Use normal ABI calling conventions */
+	movw	4(%esp), %ax
+	movw	8(%esp), %dx
+	movw	12(%esp), %cx
+#endif
 	pushw	%di
 	movw	%ax, %di
 	movzbl	%dl, %eax
@@ -52,7 +63,7 @@ GLOBAL(copy_from_fs)
 	pushw	%ds
 	pushw	%fs
 	popw	%ds
-	calll	memcpy
+	calll	_memcpy
 	popw	%ds
 	retl
 ENDPROC(copy_from_fs)
@@ -61,7 +72,7 @@ GLOBAL(copy_to_fs)
 	pushw	%es
 	pushw	%fs
 	popw	%es
-	calll	memcpy
+	calll	_memcpy
 	popw	%es
 	retl
 ENDPROC(copy_to_fs)
diff --git a/arch/x86/boot/string.h b/arch/x86/boot/string.h
index 113588ddb43f..e735cccb3fc8 100644
--- a/arch/x86/boot/string.h
+++ b/arch/x86/boot/string.h
@@ -6,8 +6,21 @@
 #undef memset
 #undef memcmp
 
+/*
+ * Use normal ABI calling conventions - i.e. regparm(0) -
+ * for memcpy() and memset() if we are building the real
+ * mode setup code with clang since clang may make implicit
+ * calls to these functions that assume regparm(0).
+ */
+#if defined(_SETUP) && defined(__clang__)
+void __attribute__((regparm(0))) *memcpy(void *dst, const void *src,
+					 size_t len);
+void __attribute__((regparm(0))) *memset(void *dst, int c, size_t len);
+#else
 void *memcpy(void *dst, const void *src, size_t len);
 void *memset(void *dst, int c, size_t len);
+#endif
+
 int memcmp(const void *s1, const void *s2, size_t len);
 
 /*
-- 
2.12.0.367.g23dc2f6d3c-goog

Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

[PATCH 2/2] x86, boot: Use regparm=0 for memcpy and memset when using clang Michael Davidson <md@google.com> - 2017-03-15 22:50 +0100
  Re: [PATCH 2/2] x86, boot: Use regparm=0 for memcpy and memset when  using clang Ingo Molnar <mingo@kernel.org> - 2017-03-16 08:50 +0100
    Re: [PATCH 2/2] x86, boot: Use regparm=0 for memcpy and memset when  using clang Michael Davidson <md@google.com> - 2017-03-16 16:30 +0100

csiph-web