From: Michael Davidson <md@google.com>
To: Michal Marek <mmarek@suse.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
Shaohua Li <shli@kernel.org>
Cc: Alexander Potapenko <glider@google.com>,
Dmitry Vyukov <dvyukov@google.com>,
Matthias Kaehlcke <mka@chromium.org>,
x86@kernel.org, linux-kbuild@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org,
linux-raid@vger.kernel.org, Michael Davidson <md@google.com>
Subject: [PATCH 5/7] x86, boot, LLVM: Use regparm=0 for memcpy and memset
Date: Thu, 16 Mar 2017 17:15:18 -0700 [thread overview]
Message-ID: <20170317001520.85223-6-md@google.com> (raw)
In-Reply-To: <20170317001520.85223-1-md@google.com>
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
next prev parent reply other threads:[~2017-03-17 0:25 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-17 0:15 [PATCH 0/7] LLVM: make x86_64 kernel build with clang Michael Davidson
2017-03-17 0:15 ` [PATCH 1/7] Makefile, LLVM: add -no-integrated-as to KBUILD_[AC]FLAGS Michael Davidson
2017-04-03 22:49 ` Matthias Kaehlcke
2017-04-21 7:49 ` Masahiro Yamada
2017-03-17 0:15 ` [PATCH 2/7] Makefile, x86, LLVM: disable unsupported optimization flags Michael Davidson
2017-03-17 21:32 ` H. Peter Anvin
2017-03-17 21:34 ` H. Peter Anvin
2017-04-05 18:08 ` Masahiro Yamada
2017-04-05 19:01 ` Matthias Kaehlcke
2017-04-05 19:11 ` Michael Davidson
2017-04-10 14:54 ` Masahiro Yamada
2017-03-17 0:15 ` [PATCH 3/7] x86, LLVM: suppress clang warnings about unaligned accesses Michael Davidson
2017-03-17 23:50 ` hpa
2017-04-03 23:01 ` Matthias Kaehlcke
2017-04-13 23:14 ` Matthias Kaehlcke
2017-04-13 23:55 ` H. Peter Anvin
2017-04-14 0:23 ` Matthias Kaehlcke
2017-04-14 5:30 ` hpa
2017-03-17 0:15 ` [PATCH 4/7] x86, boot, LLVM: #undef memcpy etc in string.c Michael Davidson
2017-06-22 22:31 ` Matthias Kaehlcke
2017-06-22 22:37 ` H. Peter Anvin
2017-06-30 18:32 ` Matthias Kaehlcke
2017-03-17 0:15 ` Michael Davidson [this message]
2017-03-17 12:08 ` [PATCH 5/7] x86, boot, LLVM: Use regparm=0 for memcpy and memset Peter Zijlstra
2017-06-22 22:38 ` H. Peter Anvin
2017-03-17 0:15 ` [PATCH 6/7] md/raid10, LLVM: get rid of variable length array Michael Davidson
2017-03-17 12:08 ` Peter Zijlstra
2017-03-17 12:31 ` Alexander Potapenko
2017-03-17 12:32 ` Alexander Potapenko
2017-03-17 18:03 ` Borislav Petkov
2017-03-17 18:47 ` Dmitry Vyukov
2017-03-17 18:57 ` Borislav Petkov
2017-03-17 19:05 ` Dmitry Vyukov
2017-03-17 19:26 ` Peter Zijlstra
2017-03-17 19:29 ` Peter Zijlstra
2017-03-24 13:50 ` Dmitry Vyukov
2017-03-24 14:10 ` Peter Zijlstra
2017-03-24 14:22 ` Dmitry Vyukov
2017-03-18 0:41 ` Fengguang Wu
2017-03-17 12:44 ` Peter Zijlstra
2017-03-17 18:52 ` Michael Davidson
2017-03-17 19:27 ` Peter Zijlstra
2017-03-17 20:04 ` hpa
2017-03-24 13:47 ` Dmitry Vyukov
2017-03-24 14:09 ` Peter Zijlstra
2017-03-17 0:15 ` [PATCH 7/7] crypto, x86, LLVM: aesni - fix token pasting Michael Davidson
2017-04-03 23:14 ` Matthias Kaehlcke
2017-03-17 8:17 ` [PATCH 0/7] LLVM: make x86_64 kernel build with clang Dmitry Vyukov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170317001520.85223-6-md@google.com \
--to=md@google.com \
--cc=davem@davemloft.net \
--cc=dvyukov@google.com \
--cc=glider@google.com \
--cc=herbert@gondor.apana.org.au \
--cc=hpa@zytor.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mka@chromium.org \
--cc=mmarek@suse.com \
--cc=shli@kernel.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).