Re: [PATCH] Makefile: Add '-fno-builtin-bcmp' to CLANG_FLAGS
From: Nathan Chancellor
Date: Wed Mar 13 2019 - 11:32:17 EST
On Wed, Mar 13, 2019 at 02:48:49PM +0100, Arnd Bergmann wrote:
> On Wed, Mar 13, 2019 at 2:44 PM Nathan Chancellor
> <natechancellor@xxxxxxxxx> wrote:
> > On Wed, Mar 13, 2019 at 09:13:11AM +0100, Rasmus Villemoes wrote:
> > > Wouldn't it be better to just define bcmp as an alias for memcmp? They
> > > seem to have compatible prototypes, and then somebody might someday sit
> > > down and implement some word-at-a-time version of bcmp making use of the
> > > weaker guarantees about the return value to gain some performance. But I
> > > suppose that can also be done later.
> > Thank you much for the review, I didn't even realize this was possible :)
> > I'd certainly like to explore it as that is what glibc does. How would
> > you suggest going about it here?
> I suggested a possible implementation (likely contains bugs) and
> an alias for architectures that require strict alignment, see
> We could start out with just the alias.
So I've been messing around with this for a bit (forgive me, I'm still
learning all of the intricacies around here) and this is what I came up
with for when __ARCH_HAVE_MEMCMP is unset (not particularly difficult
obviously). I can compile, link, and boot an x86 in QEMU.
However, I am not sure how to handle memcmp definitions that are written
in assembly like arm64, as the alias attribute only works when the alias
is defined in the same translation unit. Thoughts?
diff --git a/lib/string.c b/lib/string.c
index 38e4ca08e757..69a9daca9179 100644
@@ -864,6 +864,9 @@ __visible int memcmp(const void *cs, const void *ct, size_t count)
+int bcmp(const void *cs, const void *ct, size_t count) __weak __alias(memcmp);