@@ -86,12 +86,18 @@ ifdef need-builtin
8686targets-for-builtin += $(obj)/built-in.a
8787endif
8888
89- targets-for-modules := $(patsubst %.o, %.mod, $(filter %.o, $(obj-m)))
89+ targets-for-modules :=
9090
9191ifdef CONFIG_LTO_CLANG
9292targets-for-modules += $(patsubst %.o, %.lto.o, $(filter %.o, $(obj-m)))
9393endif
9494
95+ ifdef CONFIG_X86_KERNEL_IBT
96+ targets-for-modules += $(patsubst %.o, %.objtool, $(filter %.o, $(obj-m)))
97+ endif
98+
99+ targets-for-modules += $(patsubst %.o, %.mod, $(filter %.o, $(obj-m)))
100+
95101ifdef need-modorder
96102targets-for-modules += $(obj)/modules.order
97103endif
@@ -230,15 +236,16 @@ objtool := $(objtree)/tools/objtool/objtool
230236objtool_args = \
231237 $(if $(CONFIG_UNWINDER_ORC),orc generate,check) \
232238 $(if $(part-of-module), --module) \
239+ $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \
233240 $(if $(CONFIG_FRAME_POINTER),, --no-fp) \
234241 $(if $(CONFIG_GCOV_KERNEL)$(CONFIG_LTO_CLANG), --no-unreachable)\
235242 $(if $(CONFIG_RETPOLINE), --retpoline) \
236243 $(if $(CONFIG_X86_SMAP), --uaccess) \
237244 $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \
238245 $(if $(CONFIG_SLS), --sls)
239246
240- cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@ )
241- cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@ : $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
247+ cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $(@:.objtool=.o) )
248+ cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$(@:.objtool=.o) : $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
242249
243250endif # CONFIG_STACK_VALIDATION
244251
@@ -247,6 +254,21 @@ ifdef CONFIG_LTO_CLANG
247254# Skip objtool for LLVM bitcode
248255$(obj)/%.o: objtool-enabled :=
249256
257+ # objtool was skipped for LLVM bitcode, run it now that we have compiled
258+ # modules into native code
259+ $(obj)/%.lto.o: objtool-enabled = y
260+ $(obj)/%.lto.o: part-of-module := y
261+
262+ else ifdef CONFIG_X86_KERNEL_IBT
263+
264+ # Skip objtool on individual files
265+ $(obj)/%.o: objtool-enabled :=
266+
267+ # instead run objtool on the module as a whole, right before
268+ # the final link pass with the linker script.
269+ $(obj)/%.objtool: objtool-enabled = y
270+ $(obj)/%.objtool: part-of-module := y
271+
250272else
251273
252274# 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory
@@ -292,18 +314,13 @@ ifdef CONFIG_LTO_CLANG
292314# Module .o files may contain LLVM bitcode, compile them into native code
293315# before ELF processing
294316quiet_cmd_cc_lto_link_modules = LTO [M] $@
295- cmd_cc_lto_link_modules = \
317+ cmd_cc_lto_link_modules = \
296318 $(LD) $(ld_flags) -r -o $@ \
297319 $(shell [ -s $(@:.lto.o=.o.symversions) ] && \
298320 echo -T $(@:.lto.o=.o.symversions)) \
299321 --whole-archive $(filter-out FORCE,$^) \
300322 $(cmd_objtool)
301323
302- # objtool was skipped for LLVM bitcode, run it now that we have compiled
303- # modules into native code
304- $(obj)/%.lto.o: objtool-enabled = y
305- $(obj)/%.lto.o: part-of-module := y
306-
307324$(obj)/%.lto.o: $(obj)/%.o FORCE
308325 $(call if_changed,cc_lto_link_modules)
309326endif
@@ -316,6 +333,18 @@ cmd_mod = { \
316333$(obj)/%.mod: $(obj)/%$(mod-prelink-ext).o FORCE
317334 $(call if_changed,mod)
318335
336+ #
337+ # Since objtool will re-write the file it will change the timestamps, therefore
338+ # it is critical that the %.objtool file gets a timestamp *after* objtool runs.
339+ #
340+ # Additionally, care must be had with ordering this rule against the other rules
341+ # that take %.o as a dependency.
342+ #
343+ cmd_objtool_mod = true $(cmd_objtool) ; touch $@
344+
345+ $(obj)/%.objtool: $(obj)/%$(mod-prelink-ext).o FORCE
346+ $(call if_changed,objtool_mod)
347+
319348quiet_cmd_cc_lst_c = MKLST $@
320349 cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
321350 $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
0 commit comments