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.
This patch has been previously mailed as part of KMSAN RFC patch series.
Signed-off-by: Alexander Potapenko <glider@google.com>
To: Alexander Potapenko <glider@google.com>
Cc: Vegard Nossum <redacted>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Marco Elver <elver@google.com>
Cc: Andrey Konovalov <redacted>
Cc: Sergey Senozhatsky <redacted>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Andrey Ryabinin <redacted>
Cc: linux-mm@kvack.org
---
lib/Makefile | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/lib/Makefile b/lib/Makefile
index 23ca78d43d247..390e90d2ee88b 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -220,6 +220,10 @@ obj-$(CONFIG_MEMREGION) += memregion.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
--
2.25.0.265.gbab2e86ba0-goog