mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-24 12:44:11 +08:00
90fd833609
Some unknown -mllvm options (i.e. those starting with the letter "h")
don't cause an error to be returned by clang, so the cc-option helper adds
the unknown hwasan-kernel-mem-intrinsic-prefix=1 flag to CFLAGS with
compilers that are new enough for hwasan but too old for this option.
This causes a rather unreadable build failure:
fixdep: error opening file: scripts/mod/.empty.o.d: No such file or directory
make[4]: *** [/home/arnd/arm-soc/scripts/Makefile.build:252: scripts/mod/empty.o] Error 2
fixdep: error opening file: scripts/mod/.devicetable-offsets.s.d: No such file or directory
make[4]: *** [/home/arnd/arm-soc/scripts/Makefile.build:114: scripts/mod/devicetable-offsets.s] Error 2
Add a version check to only allow this option with clang-15, gcc-13
or later versions.
Link: https://lkml.kernel.org/r/20230418122350.1646391-1-arnd@kernel.org
Fixes: 51287dcb00
("kasan: emit different calls for instrumentable memintrinsics")
Link: https://lore.kernel.org/all/CANpmjNMwYosrvqh4ogDO8rgn+SeDHM2b-shD21wTypm_6MMe=g@mail.gmail.com/
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Marco Elver <elver@google.com>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Nicolas Schier <nicolas@fjasle.eu>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Tom Rix <trix@redhat.com>
Cc: Vincenzo Frascino <Vincenzo.Frascino@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
79 lines
2.5 KiB
Makefile
79 lines
2.5 KiB
Makefile
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
ifdef CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX
|
|
# Safe for compiler to generate meminstrinsic calls in uninstrumented files.
|
|
CFLAGS_KASAN_NOSANITIZE :=
|
|
else
|
|
# Don't let compiler generate memintrinsic calls in uninstrumented files
|
|
# because they are instrumented.
|
|
CFLAGS_KASAN_NOSANITIZE := -fno-builtin
|
|
endif
|
|
|
|
KASAN_SHADOW_OFFSET ?= $(CONFIG_KASAN_SHADOW_OFFSET)
|
|
|
|
cc-param = $(call cc-option, -mllvm -$(1), $(call cc-option, --param $(1)))
|
|
|
|
ifdef CONFIG_KASAN_STACK
|
|
stack_enable := 1
|
|
else
|
|
stack_enable := 0
|
|
endif
|
|
|
|
ifdef CONFIG_KASAN_GENERIC
|
|
|
|
ifdef CONFIG_KASAN_INLINE
|
|
call_threshold := 10000
|
|
else
|
|
call_threshold := 0
|
|
endif
|
|
|
|
CFLAGS_KASAN_MINIMAL := -fsanitize=kernel-address
|
|
|
|
# -fasan-shadow-offset fails without -fsanitize
|
|
CFLAGS_KASAN_SHADOW := $(call cc-option, -fsanitize=kernel-address \
|
|
-fasan-shadow-offset=$(KASAN_SHADOW_OFFSET), \
|
|
$(call cc-option, -fsanitize=kernel-address \
|
|
-mllvm -asan-mapping-offset=$(KASAN_SHADOW_OFFSET)))
|
|
|
|
ifeq ($(strip $(CFLAGS_KASAN_SHADOW)),)
|
|
CFLAGS_KASAN := $(CFLAGS_KASAN_MINIMAL)
|
|
else
|
|
# Now add all the compiler specific options that are valid standalone
|
|
CFLAGS_KASAN := $(CFLAGS_KASAN_SHADOW) \
|
|
$(call cc-param,asan-globals=1) \
|
|
$(call cc-param,asan-instrumentation-with-call-threshold=$(call_threshold)) \
|
|
$(call cc-param,asan-instrument-allocas=1)
|
|
endif
|
|
|
|
CFLAGS_KASAN += $(call cc-param,asan-stack=$(stack_enable))
|
|
|
|
# Instrument memcpy/memset/memmove calls by using instrumented __asan_mem*()
|
|
# instead. With compilers that don't support this option, compiler-inserted
|
|
# memintrinsics won't be checked by KASAN on GENERIC_ENTRY architectures.
|
|
CFLAGS_KASAN += $(call cc-param,asan-kernel-mem-intrinsic-prefix=1)
|
|
|
|
endif # CONFIG_KASAN_GENERIC
|
|
|
|
ifdef CONFIG_KASAN_SW_TAGS
|
|
|
|
ifdef CONFIG_KASAN_INLINE
|
|
instrumentation_flags := $(call cc-param,hwasan-mapping-offset=$(KASAN_SHADOW_OFFSET))
|
|
else
|
|
instrumentation_flags := $(call cc-param,hwasan-instrument-with-calls=1)
|
|
endif
|
|
|
|
CFLAGS_KASAN := -fsanitize=kernel-hwaddress \
|
|
$(call cc-param,hwasan-instrument-stack=$(stack_enable)) \
|
|
$(call cc-param,hwasan-use-short-granules=0) \
|
|
$(call cc-param,hwasan-inline-all-checks=0) \
|
|
$(instrumentation_flags)
|
|
|
|
# Instrument memcpy/memset/memmove calls by using instrumented __hwasan_mem*().
|
|
ifeq ($(call clang-min-version, 150000)$(call gcc-min-version, 130000),y)
|
|
CFLAGS_KASAN += $(call cc-param,hwasan-kernel-mem-intrinsic-prefix=1)
|
|
endif
|
|
|
|
endif # CONFIG_KASAN_SW_TAGS
|
|
|
|
export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE
|