[PATCH 2/2] kasan: disallow compiler to optimize away memset in tests

From: Andrey Konovalov
Date: Thu Mar 01 2018 - 12:16:14 EST


A compiler can optimize away memset calls by replacing them with mov
instructions. There are KASAN tests, that specifically test that KASAN
correctly handles memset calls, we don't want this optimization to
happen.

The solution is to add -fno-builtin flag to test_kasan.ko

Signed-off-by: Andrey Konovalov <andreyknvl@xxxxxxxxxx>
---
lib/Makefile | 1 +
1 file changed, 1 insertion(+)

diff --git a/lib/Makefile b/lib/Makefile
index a90d4fcd748f..9c940c4c0593 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -52,6 +52,7 @@ obj-$(CONFIG_TEST_FIRMWARE) += test_firmware.o
obj-$(CONFIG_TEST_SYSCTL) += test_sysctl.o
obj-$(CONFIG_TEST_HASH) += test_hash.o test_siphash.o
obj-$(CONFIG_TEST_KASAN) += test_kasan.o
+CFLAGS_test_kasan.o += -fno-builtin
obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o
obj-$(CONFIG_TEST_LIST_SORT) += test_list_sort.o
obj-$(CONFIG_TEST_LKM) += test_module.o
--
2.16.2.395.g2e18187dfd-goog