Skip to content

Commit

Permalink
kbuild: store the objtool command in *.cmd files
Browse files Browse the repository at this point in the history
objtool_dep includes include/config/{ORC_UNWINDER,STACK_VALIDATION}
so that all the objects are rebuilt when CONFIG_ORC_UNWINDER or
CONFIG_STACK_VALIDATION is toggled.

BTW, the correct option name is not CONFIG_ORC_UNWINDER, but
CONFIG_UNWINDER_ORC. Commit 11af847 ("x86/unwind: Rename
unwinder config options to 'CONFIG_UNWINDER_*'") missed to
adjust this part. So, this dependency has been broken for a
long time.

As you can see in 'objtool_args', there are more CONFIG options
that affect the objtool command line.

Adding more and more include/config/* is ugly and unmaintainable.

Another issue is that non-standard objects are needlessly rebuilt.
Objects specified as OBJECT_FILES_NON_STANDARD is not processed by
objtool, but they are rebuilt anyway when CONFIG_STACK_VALIDATION
is toggled. This is not a big deal, but better to fix.

A cleaner and more precise fix is to include the objtool command in
*.cmd files so any command change is naturally detected by if_change.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
  • Loading branch information
masahir0y committed Sep 22, 2021
1 parent 5c4859e commit 92594d5
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions scripts/Makefile.build
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ $(obj)/%.ll: $(src)/%.c FORCE
# (See cmd_cc_o_c + relevant part of rule_cc_o_c)

quiet_cmd_cc_o_c = CC $(quiet_modtag) $@
cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< $(cmd_objtool)

ifdef CONFIG_MODVERSIONS
# When module versioning is enabled the following steps are executed:
Expand Down Expand Up @@ -243,18 +243,16 @@ ifndef CONFIG_LTO_CLANG
# 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
cmd_objtool = $(if $(patsubst y%,, \
$(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
$(objtool) $(objtool_args) $@)
; $(objtool) $(objtool_args) $@)
objtool_obj = $(if $(patsubst y%,, \
$(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
$(objtool))

endif # CONFIG_LTO_CLANG
endif # CONFIG_STACK_VALIDATION

# Rebuild all objects when objtool changes, or is enabled/disabled.
objtool_dep = $(objtool_obj) \
$(wildcard include/config/ORC_UNWINDER \
include/config/STACK_VALIDATION)
# Rebuild all objects when objtool changes
objtool_dep = $(objtool_obj)

ifdef CONFIG_TRIM_UNUSED_KSYMS
cmd_gen_ksymdeps = \
Expand All @@ -269,15 +267,13 @@ define rule_cc_o_c
$(call cmd,gen_ksymdeps)
$(call cmd,checksrc)
$(call cmd,checkdoc)
$(call cmd,objtool)
$(call cmd,modversions_c)
$(call cmd,record_mcount)
endef

define rule_as_o_S
$(call cmd_and_fixdep,as_o_S)
$(call cmd,gen_ksymdeps)
$(call cmd,objtool)
$(call cmd,modversions_S)
endef

Expand Down Expand Up @@ -365,7 +361,7 @@ $(obj)/%.s: $(src)/%.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_as_o_S = $(CC) $(a_flags) -c -o $@ $< $(cmd_objtool)

ifdef CONFIG_ASM_MODVERSIONS

Expand Down

0 comments on commit 92594d5

Please sign in to comment.