On Fri, 22 Nov 2019 at 12:26, <glider@xxxxxxxxxx> wrote: > > Clang may replace stackdepot_memcmp() with a call to instrumented bcmp(), > which is exactly what we wanted to avoid creating stackdepot_memcmp(). > Building the file with -fno-builtin prevents such optimizations. > > Signed-off-by: Alexander Potapenko <glider@xxxxxxxxxx> > To: Alexander Potapenko <glider@xxxxxxxxxx> > Cc: Vegard Nossum <vegard.nossum@xxxxxxxxxx> > Cc: Dmitry Vyukov <dvyukov@xxxxxxxxxx> > Cc: Sergey Senozhatsky <sergey.senozhatsky@xxxxxxxxx> > Cc: Arnd Bergmann <arnd@xxxxxxxx> > Cc: Andrey Ryabinin <aryabinin@xxxxxxxxxxxxx> > Cc: linux-mm@xxxxxxxxx > --- > This patch was previously called "stackdepot: prevent Clang from optimizing > away stackdepot_memcmp()". > > v3: > - use -fno-builtin instead of a barrier > > Change-Id: I4495b617b15c0ab003a61c1f0d54d0026fa8b144 > --- > lib/Makefile | 4 ++++ > lib/stackdepot.c | 2 +- > 2 files changed, 5 insertions(+), 1 deletion(-) > > diff --git a/lib/Makefile b/lib/Makefile > index c5892807e06f..58a3e1b1a868 100644 > --- a/lib/Makefile > +++ b/lib/Makefile > @@ -215,6 +215,10 @@ obj-$(CONFIG_SG_POOL) += sg_pool.o > obj-$(CONFIG_STMP_DEVICE) += stmp_device.o > obj-$(CONFIG_IRQ_POLL) += irq_poll.o > > +# stackdepot.c should not be instrumented or call instrumented functions. > +# Prevent the compiler from calling builtins like memcmp() or bcmp() from this > +# file. > +CFLAGS_stackdepot.o += -fno-builtin > obj-$(CONFIG_STACKDEPOT) += stackdepot.o > KASAN_SANITIZE_stackdepot.o := n > KCOV_INSTRUMENT_stackdepot.o := n > diff --git a/lib/stackdepot.c b/lib/stackdepot.c > index 0bc6182bc7a6..6d1123123e56 100644 > --- a/lib/stackdepot.c > +++ b/lib/stackdepot.c > @@ -163,7 +163,7 @@ int stackdepot_memcmp(const unsigned long *u1, const unsigned long *u2, > unsigned int n) > { > for ( ; n-- ; u1++, u2++) { > - if (*u1 != *u2) > + if ((*u1) != (*u2)) Why this change? Can stackdepot.c be reverted? > return 1; > } > return 0; > -- > 2.24.0.432.g9d3f5f5b63-goog >