Skip to content

Commit bb27321

Browse files
committed
kbuild: move CFLAGS_{KASAN,UBSAN,KCSAN} exports to relevant Makefiles
Move CFLAGS_KASAN*, CFLAGS_UBSAN, CFLAGS_KCSAN to Makefile.kasan, Makefile.ubsan, Makefile.kcsan, respectively. This commit also avoids the same -fsanitize=* flags being added to CFLAGS_UBSAN multiple times. Prior to this commit, the ubsan flags were appended by the '+=' operator, without any initialization. Some build targets such as 'make bindeb-pkg' recurses to the top Makefile, and ended up with adding the same flags to CFLAGS_UBSAN twice. Clear CFLAGS_UBSAN with ':=' to make it a simply expanded variable. This is better than a recursively expanded variable, which evaluates $(call cc-option, ...) multiple times before Kbuild starts descending to subdirectories. Signed-off-by: Masahiro Yamada <[email protected]> Acked-by: Marco Elver <[email protected]>
1 parent 9909b76 commit bb27321

File tree

4 files changed

+6
-2
lines changed

4 files changed

+6
-2
lines changed

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,6 @@ export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE
516516

517517
export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS
518518
export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
519-
export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE CFLAGS_UBSAN CFLAGS_KCSAN
520519
export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
521520
export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
522521
export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL

scripts/Makefile.kasan

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ CFLAGS_KASAN := -fsanitize=kernel-hwaddress \
4747
$(instrumentation_flags)
4848

4949
endif # CONFIG_KASAN_SW_TAGS
50+
51+
export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE

scripts/Makefile.kcsan

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ endif
99

1010
# Keep most options here optional, to allow enabling more compilers if absence
1111
# of some options does not break KCSAN nor causes false positive reports.
12-
CFLAGS_KCSAN := -fsanitize=thread \
12+
export CFLAGS_KCSAN := -fsanitize=thread \
1313
$(call cc-option,$(call cc-param,tsan-instrument-func-entry-exit=0) -fno-optimize-sibling-calls) \
1414
$(call cc-option,$(call cc-param,tsan-instrument-read-before-write=1)) \
1515
$(call cc-param,tsan-distinguish-volatile=1)

scripts/Makefile.ubsan

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0
2+
3+
export CFLAGS_UBSAN :=
4+
25
ifdef CONFIG_UBSAN_ALIGNMENT
36
CFLAGS_UBSAN += $(call cc-option, -fsanitize=alignment)
47
endif

0 commit comments

Comments
 (0)