Skip to content

Commit 9c6b7fb

Browse files
masahir0ykees
authored andcommitted
fortify: use if_changed_dep to record header dependency in *.cmd files
After building with CONFIG_FORTIFY_SOURCE=y, many .*.d files are left in lib/test_fortify/ because the compiler outputs header dependencies into *.d without fixdep being invoked. When compiling C files, if_changed_dep should be used so that the auto-generated header dependencies are recorded in .*.cmd files. Currently, if_changed is incorrectly used, and only two headers are hard-coded in lib/Makefile. In the previous patch version, the kbuild test robot detected new errors on GCC 7. GCC 7 or older does not produce test.d with the following test code: $ echo 'void b(void) __attribute__((__error__(""))); void a(void) { b(); }' | gcc -Wp,-MMD,test.d -c -o /dev/null -x c - Perhaps, this was a bug that existed in older GCC versions. Skip the tests for GCC<=7 for now, as this will be eventually solved when we bump the minimal supported GCC version. Link: https://lore.kernel.org/oe-kbuild-all/CAK7LNARmJcyyzL-jVJfBPi3W684LTDmuhMf1koF0TXoCpKTmcw@mail.gmail.com/T/#m13771bf78ae21adff22efc4d310c973fb4bcaf67 Signed-off-by: Masahiro Yamada <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent 5a8d0c4 commit 9c6b7fb

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/test_fortify/Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ quiet_cmd_test_fortify = TEST $@
66
cmd_test_fortify = $(CONFIG_SHELL) $(src)/test_fortify.sh \
77
$< $@ "$(NM)" $(CC) $(c_flags) -DKBUILD_EXTRA_WARN1
88

9-
$(obj)/%.log: $(src)/%.c $(src)/test_fortify.sh \
10-
$(src)/test_fortify.h \
11-
$(srctree)/include/linux/fortify-string.h \
12-
FORCE
13-
$(call if_changed,test_fortify)
9+
$(obj)/%.log: $(src)/%.c $(src)/test_fortify.sh FORCE
10+
$(call if_changed_dep,test_fortify)
1411

1512
logs = $(patsubst $(src)/%.c, %.log, $(wildcard $(src)/*-*.c))
1613
targets += $(logs)
@@ -21,7 +18,10 @@ quiet_cmd_gen_fortify_log = CAT $@
2118
$(obj)/test_fortify.log: $(addprefix $(obj)/, $(logs)) FORCE
2219
$(call if_changed,gen_fortify_log)
2320

24-
always-y += test_fortify.log
21+
# GCC<=7 does not always produce *.d files.
22+
# Run the tests only for GCC>=8 or Clang.
23+
always-$(call gcc-min-version, 80000) += test_fortify.log
24+
always-$(CONFIG_CC_IS_CLANG) += test_fortify.log
2525

2626
# Some architectures define __NO_FORTIFY if __SANITIZE_ADDRESS__ is undefined.
2727
# Pass CFLAGS_KASAN to avoid warnings.

0 commit comments

Comments
 (0)