* [PATCH 0/3] kbuild: enable objtool for more objects and re-enable KCSAN for *.mod.o
@ 2024-11-13 23:45 Masahiro Yamada
2024-11-13 23:45 ` [PATCH 1/3] kbuild: move cmd_cc_o_c and cmd_as_o_S to scripts/Malefile.lib Masahiro Yamada
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Masahiro Yamada @ 2024-11-13 23:45 UTC (permalink / raw)
To: linux-kbuild
Cc: Paul Menzel, Borislav Petkov, Nikolay Borisov, Marco Elver,
Josh Poimboeuf, Masahiro Yamada, Nathan Chancellor,
Nicolas Schier, linux-kernel
Now, objtool will have better coverage, and we can revert 54babdc0343f.
Masahiro Yamada (3):
kbuild: move cmd_cc_o_c and cmd_as_o_S to scripts/Malefile.lib
kbuild: enable objtool for *.mod.o and additional kernel objects
kbuild: re-enable KCSAN for autogenerated *.mod.c intermediaries
scripts/Makefile.build | 25 -------------------------
scripts/Makefile.lib | 31 +++++++++++++++++++++++++++++++
scripts/Makefile.modfinal | 11 ++++-------
scripts/Makefile.vmlinux | 12 +++---------
4 files changed, 38 insertions(+), 41 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/3] kbuild: move cmd_cc_o_c and cmd_as_o_S to scripts/Malefile.lib
2024-11-13 23:45 [PATCH 0/3] kbuild: enable objtool for more objects and re-enable KCSAN for *.mod.o Masahiro Yamada
@ 2024-11-13 23:45 ` Masahiro Yamada
2024-11-16 9:19 ` Masahiro Yamada
2024-11-13 23:45 ` [PATCH 2/3] kbuild: enable objtool for *.mod.o and additional kernel objects Masahiro Yamada
2024-11-13 23:45 ` [PATCH 3/3] kbuild: re-enable KCSAN for autogenerated *.mod.c intermediaries Masahiro Yamada
2 siblings, 1 reply; 7+ messages in thread
From: Masahiro Yamada @ 2024-11-13 23:45 UTC (permalink / raw)
To: linux-kbuild
Cc: Paul Menzel, Borislav Petkov, Nikolay Borisov, Marco Elver,
Josh Poimboeuf, Masahiro Yamada, Nathan Chancellor,
Nicolas Schier, linux-kernel
The cmd_cc_o_c and cmd_as_o_S macros are duplicated in
scripts/Makefile.{build,modfinal,vmlinux}.
This commit factors them out to scripts/Makefile.lib.
No functional changes are intended.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
scripts/Makefile.build | 8 --------
scripts/Makefile.lib | 12 ++++++++++++
scripts/Makefile.modfinal | 6 ++----
scripts/Makefile.vmlinux | 8 +-------
4 files changed, 15 insertions(+), 19 deletions(-)
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 1aa928a6fb4f..24e10c821461 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -141,11 +141,6 @@ ifdef CONFIG_LTO_CLANG
cmd_ld_single_m = $(if $(is-single-obj-m), ; $(LD) $(ld_flags) -r -o $(tmp-target) $@; mv $(tmp-target) $@)
endif
-quiet_cmd_cc_o_c = CC $(quiet_modtag) $@
- cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< \
- $(cmd_ld_single_m) \
- $(cmd_objtool)
-
ifdef CONFIG_MODVERSIONS
# When module versioning is enabled the following steps are executed:
# o compile a <file>.o from <file>.c
@@ -336,9 +331,6 @@ cmd_cpp_s_S = $(CPP) $(a_flags) -o $@ $<
$(obj)/%.s: $(obj)/%.S FORCE
$(call if_changed_dep,cpp_s_S)
-quiet_cmd_as_o_S = AS $(quiet_modtag) $@
- cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< $(cmd_objtool)
-
ifdef CONFIG_ASM_MODVERSIONS
# versioning matches the C process described above, with difference that
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 5660dfc9ed36..73e385946855 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -298,6 +298,18 @@ $(foreach m, $1, \
$(addprefix $(obj)/, $(call suffix-search, $(patsubst $(obj)/%,%,$m), $2, $3))))
endef
+# Build commads
+# ===========================================================================
+# These are shared by some Makefile.* files.
+
+quiet_cmd_cc_o_c = CC $(quiet_modtag) $@
+ cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< \
+ $(cmd_ld_single_m) \
+ $(cmd_objtool)
+
+quiet_cmd_as_o_S = AS $(quiet_modtag) $@
+ cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< $(cmd_objtool)
+
# Copy a file
# ===========================================================================
# 'cp' preserves permissions. If you use it to copy a file in read-only srctree,
diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal
index bab53884f7e3..d0153d033bbb 100644
--- a/scripts/Makefile.modfinal
+++ b/scripts/Makefile.modfinal
@@ -9,7 +9,7 @@ __modfinal:
include $(objtree)/include/config/auto.conf
include $(srctree)/scripts/Kbuild.include
-# for c_flags
+# include some build commands
include $(srctree)/scripts/Makefile.lib
# find all modules listed in modules.order
@@ -23,9 +23,7 @@ modname = $(notdir $(@:.mod.o=))
part-of-module = y
GCOV_PROFILE := n
KCSAN_SANITIZE := n
-
-quiet_cmd_cc_o_c = CC [M] $@
- cmd_cc_o_c = $(CC) $(filter-out $(CC_FLAGS_CFI), $(c_flags)) -c -o $@ $<
+ccflags-remove-y := $(CC_FLAGS_CFI)
%.mod.o: %.mod.c FORCE
$(call if_changed_dep,cc_o_c)
diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
index 9ef0480ed755..1652561896eb 100644
--- a/scripts/Makefile.vmlinux
+++ b/scripts/Makefile.vmlinux
@@ -6,20 +6,14 @@ __default: vmlinux
include include/config/auto.conf
include $(srctree)/scripts/Kbuild.include
-# for c_flags
+# include some build commands
include $(srctree)/scripts/Makefile.lib
targets :=
-quiet_cmd_cc_o_c = CC $@
- cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
-
%.o: %.c FORCE
$(call if_changed_dep,cc_o_c)
-quiet_cmd_as_o_S = AS $@
- cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
-
%.o: %.S FORCE
$(call if_changed_dep,as_o_S)
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/3] kbuild: enable objtool for *.mod.o and additional kernel objects
2024-11-13 23:45 [PATCH 0/3] kbuild: enable objtool for more objects and re-enable KCSAN for *.mod.o Masahiro Yamada
2024-11-13 23:45 ` [PATCH 1/3] kbuild: move cmd_cc_o_c and cmd_as_o_S to scripts/Malefile.lib Masahiro Yamada
@ 2024-11-13 23:45 ` Masahiro Yamada
2024-11-19 2:27 ` Nathan Chancellor
2024-11-13 23:45 ` [PATCH 3/3] kbuild: re-enable KCSAN for autogenerated *.mod.c intermediaries Masahiro Yamada
2 siblings, 1 reply; 7+ messages in thread
From: Masahiro Yamada @ 2024-11-13 23:45 UTC (permalink / raw)
To: linux-kbuild
Cc: Paul Menzel, Borislav Petkov, Nikolay Borisov, Marco Elver,
Josh Poimboeuf, Masahiro Yamada, Nathan Chancellor,
Nicolas Schier, linux-kernel
Currently, objtool is disabled in scripts/Makefile.{modfinal,vmlinux}.
This commit moves rule_cc_o_c and rule_as_o_S to scripts/Makefile.lib
and set objtool-enabled to y there.
With this change, *.mod.o, .module-common.o, builtin-dtb.o, and
vmlinux.export.o will now be covered by objtool.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
scripts/Makefile.build | 17 -----------------
scripts/Makefile.lib | 19 +++++++++++++++++++
scripts/Makefile.modfinal | 4 ++--
scripts/Makefile.vmlinux | 4 ++--
4 files changed, 23 insertions(+), 21 deletions(-)
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 24e10c821461..18b76947fe96 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -202,23 +202,6 @@ ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),)
cmd_warn_shared_object = $(if $(word 2, $(modname-multi)),$(warning $(kbuild-file): $*.o is added to multiple modules: $(modname-multi)))
endif
-define rule_cc_o_c
- $(call cmd_and_fixdep,cc_o_c)
- $(call cmd,checksrc)
- $(call cmd,checkdoc)
- $(call cmd,gen_objtooldep)
- $(call cmd,gen_symversions_c)
- $(call cmd,record_mcount)
- $(call cmd,warn_shared_object)
-endef
-
-define rule_as_o_S
- $(call cmd_and_fixdep,as_o_S)
- $(call cmd,gen_objtooldep)
- $(call cmd,gen_symversions_S)
- $(call cmd,warn_shared_object)
-endef
-
# Built-in and composite module parts
$(obj)/%.o: $(obj)/%.c $(recordmcount_source) FORCE
$(call if_changed_rule,cc_o_c)
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 73e385946855..17c81c346e36 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -302,14 +302,33 @@ endef
# ===========================================================================
# These are shared by some Makefile.* files.
+objtool-enabled := y
+
quiet_cmd_cc_o_c = CC $(quiet_modtag) $@
cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< \
$(cmd_ld_single_m) \
$(cmd_objtool)
+define rule_cc_o_c
+ $(call cmd_and_fixdep,cc_o_c)
+ $(call cmd,checksrc)
+ $(call cmd,checkdoc)
+ $(call cmd,gen_objtooldep)
+ $(call cmd,gen_symversions_c)
+ $(call cmd,record_mcount)
+ $(call cmd,warn_shared_object)
+endef
+
quiet_cmd_as_o_S = AS $(quiet_modtag) $@
cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< $(cmd_objtool)
+define rule_as_o_S
+ $(call cmd_and_fixdep,as_o_S)
+ $(call cmd,gen_objtooldep)
+ $(call cmd,gen_symversions_S)
+ $(call cmd,warn_shared_object)
+endef
+
# Copy a file
# ===========================================================================
# 'cp' preserves permissions. If you use it to copy a file in read-only srctree,
diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal
index d0153d033bbb..0547a4b59f13 100644
--- a/scripts/Makefile.modfinal
+++ b/scripts/Makefile.modfinal
@@ -26,10 +26,10 @@ KCSAN_SANITIZE := n
ccflags-remove-y := $(CC_FLAGS_CFI)
%.mod.o: %.mod.c FORCE
- $(call if_changed_dep,cc_o_c)
+ $(call if_changed_rule,cc_o_c)
.module-common.o: $(srctree)/scripts/module-common.c FORCE
- $(call if_changed_dep,cc_o_c)
+ $(call if_changed_rule,cc_o_c)
quiet_cmd_ld_ko_o = LD [M] $@
cmd_ld_ko_o = \
diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
index 1652561896eb..83fc1a861f41 100644
--- a/scripts/Makefile.vmlinux
+++ b/scripts/Makefile.vmlinux
@@ -12,10 +12,10 @@ include $(srctree)/scripts/Makefile.lib
targets :=
%.o: %.c FORCE
- $(call if_changed_dep,cc_o_c)
+ $(call if_changed_rule,cc_o_c)
%.o: %.S FORCE
- $(call if_changed_dep,as_o_S)
+ $(call if_changed_rule,as_o_S)
# Built-in dtb
# ---------------------------------------------------------------------------
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/3] kbuild: re-enable KCSAN for autogenerated *.mod.c intermediaries
2024-11-13 23:45 [PATCH 0/3] kbuild: enable objtool for more objects and re-enable KCSAN for *.mod.o Masahiro Yamada
2024-11-13 23:45 ` [PATCH 1/3] kbuild: move cmd_cc_o_c and cmd_as_o_S to scripts/Malefile.lib Masahiro Yamada
2024-11-13 23:45 ` [PATCH 2/3] kbuild: enable objtool for *.mod.o and additional kernel objects Masahiro Yamada
@ 2024-11-13 23:45 ` Masahiro Yamada
2 siblings, 0 replies; 7+ messages in thread
From: Masahiro Yamada @ 2024-11-13 23:45 UTC (permalink / raw)
To: linux-kbuild
Cc: Paul Menzel, Borislav Petkov, Nikolay Borisov, Marco Elver,
Josh Poimboeuf, Masahiro Yamada, Nathan Chancellor,
Nicolas Schier, linux-kernel
This reverts commit 54babdc0343f ("kbuild: Disable KCSAN for
autogenerated *.mod.c intermediaries").
Now that objtool is enabled for *.mod.c, there is no need to filter
out CFLAGS_KCSAN.
I no longer see "Unpatched return thunk in use. This should not happen!"
error with KCSAN when loading a module.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
scripts/Makefile.modfinal | 1 -
1 file changed, 1 deletion(-)
diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal
index 0547a4b59f13..3e56a3f733e9 100644
--- a/scripts/Makefile.modfinal
+++ b/scripts/Makefile.modfinal
@@ -22,7 +22,6 @@ __modfinal: $(modules:%.o=%.ko)
modname = $(notdir $(@:.mod.o=))
part-of-module = y
GCOV_PROFILE := n
-KCSAN_SANITIZE := n
ccflags-remove-y := $(CC_FLAGS_CFI)
%.mod.o: %.mod.c FORCE
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] kbuild: move cmd_cc_o_c and cmd_as_o_S to scripts/Malefile.lib
2024-11-13 23:45 ` [PATCH 1/3] kbuild: move cmd_cc_o_c and cmd_as_o_S to scripts/Malefile.lib Masahiro Yamada
@ 2024-11-16 9:19 ` Masahiro Yamada
0 siblings, 0 replies; 7+ messages in thread
From: Masahiro Yamada @ 2024-11-16 9:19 UTC (permalink / raw)
To: linux-kbuild
Cc: Paul Menzel, Borislav Petkov, Nikolay Borisov, Marco Elver,
Josh Poimboeuf, Nathan Chancellor, Nicolas Schier, linux-kernel
On Thu, Nov 14, 2024 at 8:45 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> The cmd_cc_o_c and cmd_as_o_S macros are duplicated in
> scripts/Makefile.{build,modfinal,vmlinux}.
>
> This commit factors them out to scripts/Makefile.lib.
>
> No functional changes are intended.
>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
>
> scripts/Makefile.build | 8 --------
> scripts/Makefile.lib | 12 ++++++++++++
> scripts/Makefile.modfinal | 6 ++----
> scripts/Makefile.vmlinux | 8 +-------
> 4 files changed, 15 insertions(+), 19 deletions(-)
>
> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> index 1aa928a6fb4f..24e10c821461 100644
> --- a/scripts/Makefile.build
> +++ b/scripts/Makefile.build
> @@ -141,11 +141,6 @@ ifdef CONFIG_LTO_CLANG
> cmd_ld_single_m = $(if $(is-single-obj-m), ; $(LD) $(ld_flags) -r -o $(tmp-target) $@; mv $(tmp-target) $@)
> endif
>
> -quiet_cmd_cc_o_c = CC $(quiet_modtag) $@
> - cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< \
> - $(cmd_ld_single_m) \
> - $(cmd_objtool)
> -
> ifdef CONFIG_MODVERSIONS
> # When module versioning is enabled the following steps are executed:
> # o compile a <file>.o from <file>.c
> @@ -336,9 +331,6 @@ cmd_cpp_s_S = $(CPP) $(a_flags) -o $@ $<
> $(obj)/%.s: $(obj)/%.S FORCE
> $(call if_changed_dep,cpp_s_S)
>
> -quiet_cmd_as_o_S = AS $(quiet_modtag) $@
> - cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< $(cmd_objtool)
> -
> ifdef CONFIG_ASM_MODVERSIONS
>
> # versioning matches the C process described above, with difference that
> diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> index 5660dfc9ed36..73e385946855 100644
> --- a/scripts/Makefile.lib
> +++ b/scripts/Makefile.lib
> @@ -298,6 +298,18 @@ $(foreach m, $1, \
> $(addprefix $(obj)/, $(call suffix-search, $(patsubst $(obj)/%,%,$m), $2, $3))))
> endef
>
> +# Build commads
I will fix the typo.
s/commads/commands/
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/3] kbuild: enable objtool for *.mod.o and additional kernel objects
2024-11-13 23:45 ` [PATCH 2/3] kbuild: enable objtool for *.mod.o and additional kernel objects Masahiro Yamada
@ 2024-11-19 2:27 ` Nathan Chancellor
2024-11-19 17:22 ` Masahiro Yamada
0 siblings, 1 reply; 7+ messages in thread
From: Nathan Chancellor @ 2024-11-19 2:27 UTC (permalink / raw)
To: Masahiro Yamada
Cc: linux-kbuild, Paul Menzel, Borislav Petkov, Nikolay Borisov,
Marco Elver, Josh Poimboeuf, Nicolas Schier, linux-kernel
Hi Masahiro,
On Thu, Nov 14, 2024 at 08:45:22AM +0900, Masahiro Yamada wrote:
> Currently, objtool is disabled in scripts/Makefile.{modfinal,vmlinux}.
>
> This commit moves rule_cc_o_c and rule_as_o_S to scripts/Makefile.lib
> and set objtool-enabled to y there.
>
> With this change, *.mod.o, .module-common.o, builtin-dtb.o, and
> vmlinux.export.o will now be covered by objtool.
>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
I am seeing some build failures when LTO is enabled with this change in
-next as commit d8d3f6c6690c ("kbuild: enable objtool for *.mod.o and
additional kernel objects").
$ printf 'CONFIG_LTO_%s\n' NONE=n CLANG_THIN=y >kernel/configs/thinlto.config
$ make -skj"$(nproc)" ARCH=x86_64 LLVM=1 mrproper {def,thinlto.}config all
...
.vmlinux.export.o: warning: objtool: gelf_getehdr: invalid `Elf' handle
make[4]: *** [scripts/Makefile.vmlinux:13: .vmlinux.export.o] Error 1
...
When LTO is enabled, these files are LLVM bitcode, not ELF, so objtool
can't process them:
$ file .vmlinux.export.o
.vmlinux.export.o: LLVM IR bitcode
Cheers,
Nathan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/3] kbuild: enable objtool for *.mod.o and additional kernel objects
2024-11-19 2:27 ` Nathan Chancellor
@ 2024-11-19 17:22 ` Masahiro Yamada
0 siblings, 0 replies; 7+ messages in thread
From: Masahiro Yamada @ 2024-11-19 17:22 UTC (permalink / raw)
To: Nathan Chancellor
Cc: linux-kbuild, Paul Menzel, Borislav Petkov, Nikolay Borisov,
Marco Elver, Josh Poimboeuf, Nicolas Schier, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1360 bytes --]
On Tue, Nov 19, 2024 at 11:27 AM Nathan Chancellor <nathan@kernel.org> wrote:
>
> Hi Masahiro,
>
> On Thu, Nov 14, 2024 at 08:45:22AM +0900, Masahiro Yamada wrote:
> > Currently, objtool is disabled in scripts/Makefile.{modfinal,vmlinux}.
> >
> > This commit moves rule_cc_o_c and rule_as_o_S to scripts/Makefile.lib
> > and set objtool-enabled to y there.
> >
> > With this change, *.mod.o, .module-common.o, builtin-dtb.o, and
> > vmlinux.export.o will now be covered by objtool.
> >
> > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
>
> I am seeing some build failures when LTO is enabled with this change in
> -next as commit d8d3f6c6690c ("kbuild: enable objtool for *.mod.o and
> additional kernel objects").
>
> $ printf 'CONFIG_LTO_%s\n' NONE=n CLANG_THIN=y >kernel/configs/thinlto.config
>
> $ make -skj"$(nproc)" ARCH=x86_64 LLVM=1 mrproper {def,thinlto.}config all
> ...
> .vmlinux.export.o: warning: objtool: gelf_getehdr: invalid `Elf' handle
> make[4]: *** [scripts/Makefile.vmlinux:13: .vmlinux.export.o] Error 1
> ...
>
> When LTO is enabled, these files are LLVM bitcode, not ELF, so objtool
> can't process them:
>
> $ file .vmlinux.export.o
> .vmlinux.export.o: LLVM IR bitcode
Good catch!
I will squash the attached diff.
Thank you.
--
Best Regards
Masahiro Yamada
[-- Attachment #2: 0001-fixup.patch --]
[-- Type: application/x-patch, Size: 1770 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-11-19 17:23 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-13 23:45 [PATCH 0/3] kbuild: enable objtool for more objects and re-enable KCSAN for *.mod.o Masahiro Yamada
2024-11-13 23:45 ` [PATCH 1/3] kbuild: move cmd_cc_o_c and cmd_as_o_S to scripts/Malefile.lib Masahiro Yamada
2024-11-16 9:19 ` Masahiro Yamada
2024-11-13 23:45 ` [PATCH 2/3] kbuild: enable objtool for *.mod.o and additional kernel objects Masahiro Yamada
2024-11-19 2:27 ` Nathan Chancellor
2024-11-19 17:22 ` Masahiro Yamada
2024-11-13 23:45 ` [PATCH 3/3] kbuild: re-enable KCSAN for autogenerated *.mod.c intermediaries Masahiro Yamada
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox