public inbox for llvm@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH v2 0/3] fortify: fix various issues in test_fortify Makefile
@ 2024-07-27 15:02 Masahiro Yamada
  2024-07-27 15:02 ` [PATCH v2 3/3] fortify: use if_changed_dep to record header dependency in *.cmd files Masahiro Yamada
  2024-08-06  4:25 ` [PATCH v2 0/3] fortify: fix various issues in test_fortify Makefile Kees Cook
  0 siblings, 2 replies; 3+ messages in thread
From: Masahiro Yamada @ 2024-07-27 15:02 UTC (permalink / raw)
  To: Kees Cook
  Cc: linux-kernel, Masahiro Yamada, Andrew Morton, Bill Wendling,
	Justin Stitt, Nathan Chancellor, Nick Desaulniers,
	linux-hardening, llvm


This version fixes new warnings for GCC <= 7, which were reported
by 0 day bot.

I changed the patch order, as 3/3 is the most controvertial.
I am confident with 1/3 and 2/3.
3/3 drops the test coverage for GCC <= 7.



Masahiro Yamada (3):
  fortify: refactor test_fortify Makefile to fix some build problems
  fortify: move test_fortify.sh to lib/test_fortify/
  fortify: use if_changed_dep to record header dependency in *.cmd files

 MAINTAINERS                                   |  1 -
 lib/.gitignore                                |  2 -
 lib/Makefile                                  | 38 +------------------
 lib/test_fortify/.gitignore                   |  2 +
 lib/test_fortify/Makefile                     | 28 ++++++++++++++
 {scripts => lib/test_fortify}/test_fortify.sh |  0
 6 files changed, 31 insertions(+), 40 deletions(-)
 create mode 100644 lib/test_fortify/.gitignore
 create mode 100644 lib/test_fortify/Makefile
 rename {scripts => lib/test_fortify}/test_fortify.sh (100%)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2 3/3] fortify: use if_changed_dep to record header dependency in *.cmd files
  2024-07-27 15:02 [PATCH v2 0/3] fortify: fix various issues in test_fortify Makefile Masahiro Yamada
@ 2024-07-27 15:02 ` Masahiro Yamada
  2024-08-06  4:25 ` [PATCH v2 0/3] fortify: fix various issues in test_fortify Makefile Kees Cook
  1 sibling, 0 replies; 3+ messages in thread
From: Masahiro Yamada @ 2024-07-27 15:02 UTC (permalink / raw)
  To: Kees Cook
  Cc: linux-kernel, Masahiro Yamada, Bill Wendling, Justin Stitt,
	Nathan Chancellor, Nick Desaulniers, linux-hardening, llvm

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 <masahiroy@kernel.org>
---

Changes in v2:
  - Skip the tests for GCC <= 7

 lib/test_fortify/Makefile | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/test_fortify/Makefile b/lib/test_fortify/Makefile
index 1826172c32d4..1c3f82ad8bb2 100644
--- a/lib/test_fortify/Makefile
+++ b/lib/test_fortify/Makefile
@@ -6,11 +6,8 @@ quiet_cmd_test_fortify = TEST    $@
       cmd_test_fortify = $(CONFIG_SHELL) $(src)/test_fortify.sh \
 			$< $@ "$(NM)" $(CC) $(c_flags) -DKBUILD_EXTRA_WARN1
 
-$(obj)/%.log: $(src)/%.c $(src)/test_fortify.sh \
-	      $(src)/test_fortify.h \
-	      $(srctree)/include/linux/fortify-string.h \
-	      FORCE
-	$(call if_changed,test_fortify)
+$(obj)/%.log: $(src)/%.c $(src)/test_fortify.sh FORCE
+	$(call if_changed_dep,test_fortify)
 
 logs = $(patsubst $(src)/%.c, %.log, $(wildcard $(src)/*-*.c))
 targets += $(logs)
@@ -21,7 +18,10 @@ quiet_cmd_gen_fortify_log = CAT     $@
 $(obj)/test_fortify.log: $(addprefix $(obj)/, $(logs)) FORCE
 	$(call if_changed,gen_fortify_log)
 
-always-y += test_fortify.log
+# GCC<=7 does not always produce *.d files.
+# Run the tests only for GCC>=8 or Clang.
+always-$(call gcc-min-version, 80000) += test_fortify.log
+always-$(CONFIG_CC_IS_CLANG)          += test_fortify.log
 
 # Some architectures define __NO_FORTIFY if __SANITIZE_ADDRESS__ is undefined.
 # Pass CFLAGS_KASAN to avoid warnings.
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2 0/3] fortify: fix various issues in test_fortify Makefile
  2024-07-27 15:02 [PATCH v2 0/3] fortify: fix various issues in test_fortify Makefile Masahiro Yamada
  2024-07-27 15:02 ` [PATCH v2 3/3] fortify: use if_changed_dep to record header dependency in *.cmd files Masahiro Yamada
@ 2024-08-06  4:25 ` Kees Cook
  1 sibling, 0 replies; 3+ messages in thread
From: Kees Cook @ 2024-08-06  4:25 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Kees Cook, linux-kernel, Andrew Morton, Bill Wendling,
	Justin Stitt, Nathan Chancellor, Nick Desaulniers,
	linux-hardening, llvm

On Sun, 28 Jul 2024 00:02:35 +0900, Masahiro Yamada wrote:
> This version fixes new warnings for GCC <= 7, which were reported
> by 0 day bot.
> 
> I changed the patch order, as 3/3 is the most controvertial.
> I am confident with 1/3 and 2/3.
> 3/3 drops the test coverage for GCC <= 7.
> 
> [...]

Applied to for-next/hardening, thanks!

[1/3] fortify: refactor test_fortify Makefile to fix some build problems
      https://git.kernel.org/kees/c/61b317f70aa7
[2/3] fortify: move test_fortify.sh to lib/test_fortify/
      https://git.kernel.org/kees/c/728dc04bc4e3
[3/3] fortify: use if_changed_dep to record header dependency in *.cmd files
      https://git.kernel.org/kees/c/634a52a98f04

Take care,

-- 
Kees Cook


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-08-06  4:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-27 15:02 [PATCH v2 0/3] fortify: fix various issues in test_fortify Makefile Masahiro Yamada
2024-07-27 15:02 ` [PATCH v2 3/3] fortify: use if_changed_dep to record header dependency in *.cmd files Masahiro Yamada
2024-08-06  4:25 ` [PATCH v2 0/3] fortify: fix various issues in test_fortify Makefile Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox