Skip to content

Commit bede169

Browse files
committed
kbuild: enable objtool for *.mod.o and additional kernel objects
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 <[email protected]>
1 parent 000e22a commit bede169

File tree

4 files changed

+29
-28
lines changed

4 files changed

+29
-28
lines changed

scripts/Makefile.build

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,6 @@ $(obj)/%.ll: $(obj)/%.c FORCE
129129

130130
is-single-obj-m = $(and $(part-of-module),$(filter $@, $(obj-m)),y)
131131

132-
# When a module consists of a single object, there is no reason to keep LLVM IR.
133-
# Make $(LD) covert LLVM IR to ELF here.
134-
ifdef CONFIG_LTO_CLANG
135-
cmd_ld_single_m = $(if $(is-single-obj-m), ; $(LD) $(ld_flags) -r -o $(tmp-target) $@; mv $(tmp-target) $@)
136-
endif
137-
138132
ifdef CONFIG_MODVERSIONS
139133
# When module versioning is enabled the following steps are executed:
140134
# o compile a <file>.o from <file>.c
@@ -195,23 +189,6 @@ ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),)
195189
cmd_warn_shared_object = $(if $(word 2, $(modname-multi)),$(warning $(kbuild-file): $*.o is added to multiple modules: $(modname-multi)))
196190
endif
197191

198-
define rule_cc_o_c
199-
$(call cmd_and_fixdep,cc_o_c)
200-
$(call cmd,checksrc)
201-
$(call cmd,checkdoc)
202-
$(call cmd,gen_objtooldep)
203-
$(call cmd,gen_symversions_c)
204-
$(call cmd,record_mcount)
205-
$(call cmd,warn_shared_object)
206-
endef
207-
208-
define rule_as_o_S
209-
$(call cmd_and_fixdep,as_o_S)
210-
$(call cmd,gen_objtooldep)
211-
$(call cmd,gen_symversions_S)
212-
$(call cmd,warn_shared_object)
213-
endef
214-
215192
# Built-in and composite module parts
216193
$(obj)/%.o: $(obj)/%.c $(recordmcount_source) FORCE
217194
$(call if_changed_rule,cc_o_c)

scripts/Makefile.lib

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,38 @@ endef
302302
# ===========================================================================
303303
# These are shared by some Makefile.* files.
304304

305+
objtool-enabled := y
306+
307+
ifdef CONFIG_LTO_CLANG
308+
# objtool cannot process LLVM IR. Make $(LD) covert LLVM IR to ELF here.
309+
cmd_ld_single = $(if $(objtool-enabled), ; $(LD) $(ld_flags) -r -o $(tmp-target) $@; mv $(tmp-target) $@)
310+
endif
311+
305312
quiet_cmd_cc_o_c = CC $(quiet_modtag) $@
306313
cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< \
307-
$(cmd_ld_single_m) \
314+
$(cmd_ld_single) \
308315
$(cmd_objtool)
309316

317+
define rule_cc_o_c
318+
$(call cmd_and_fixdep,cc_o_c)
319+
$(call cmd,checksrc)
320+
$(call cmd,checkdoc)
321+
$(call cmd,gen_objtooldep)
322+
$(call cmd,gen_symversions_c)
323+
$(call cmd,record_mcount)
324+
$(call cmd,warn_shared_object)
325+
endef
326+
310327
quiet_cmd_as_o_S = AS $(quiet_modtag) $@
311328
cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< $(cmd_objtool)
312329

330+
define rule_as_o_S
331+
$(call cmd_and_fixdep,as_o_S)
332+
$(call cmd,gen_objtooldep)
333+
$(call cmd,gen_symversions_S)
334+
$(call cmd,warn_shared_object)
335+
endef
336+
313337
# Copy a file
314338
# ===========================================================================
315339
# 'cp' preserves permissions. If you use it to copy a file in read-only srctree,

scripts/Makefile.modfinal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ KCSAN_SANITIZE := n
2424
ccflags-remove-y := $(CC_FLAGS_CFI)
2525

2626
%.mod.o: %.mod.c FORCE
27-
$(call if_changed_dep,cc_o_c)
27+
$(call if_changed_rule,cc_o_c)
2828

2929
.module-common.o: $(srctree)/scripts/module-common.c FORCE
30-
$(call if_changed_dep,cc_o_c)
30+
$(call if_changed_rule,cc_o_c)
3131

3232
quiet_cmd_ld_ko_o = LD [M] $@
3333
cmd_ld_ko_o = \

scripts/Makefile.vmlinux

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ include $(srctree)/scripts/Makefile.lib
1010
targets :=
1111

1212
%.o: %.c FORCE
13-
$(call if_changed_dep,cc_o_c)
13+
$(call if_changed_rule,cc_o_c)
1414

1515
%.o: %.S FORCE
16-
$(call if_changed_dep,as_o_S)
16+
$(call if_changed_rule,as_o_S)
1717

1818
# Built-in dtb
1919
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)