@@ -86,18 +86,12 @@ ifdef need-builtin
8686targets-for-builtin += $(obj)/built-in.a
8787endif
8888
89- targets-for-modules :=
89+ targets-for-modules := $(patsubst %.o, %.mod, $(filter %.o, $(obj-m)))
9090
91- ifdef CONFIG_LTO_CLANG
92- targets-for-modules += $(patsubst %.o, %.lto.o, $(filter %.o, $(obj-m)))
93- endif
94-
95- ifdef CONFIG_X86_KERNEL_IBT
96- targets-for-modules += $(patsubst %.o, %.objtool, $(filter %.o, $(obj-m)))
91+ ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),)
92+ targets-for-modules += $(patsubst %.o, %.prelink.o, $(filter %.o, $(obj-m)))
9793endif
9894
99- targets-for-modules += $(patsubst %.o, %.mod, $(filter %.o, $(obj-m)))
100-
10195ifdef need-modorder
10296targets-for-modules += $(obj)/modules.order
10397endif
@@ -244,31 +238,16 @@ objtool_args = \
244238 $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \
245239 $(if $(CONFIG_SLS), --sls)
246240
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)
241+ cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@ )
242+ cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@ : $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
249243
250244endif # CONFIG_STACK_VALIDATION
251245
252- ifdef CONFIG_LTO_CLANG
246+ ifneq ($( CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),)
253247
254248# Skip objtool for LLVM bitcode
255249$(obj)/%.o: objtool-enabled :=
256250
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-
272251else
273252
274253# 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory
@@ -310,19 +289,24 @@ $(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE
310289 $(call if_changed_rule,cc_o_c)
311290 $(call cmd,force_checksrc)
312291
313- ifdef CONFIG_LTO_CLANG
292+ ifneq ($( CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),)
314293# Module .o files may contain LLVM bitcode, compile them into native code
315294# before ELF processing
316- quiet_cmd_cc_lto_link_modules = LTO [M] $@
317- cmd_cc_lto_link_modules = \
295+ quiet_cmd_cc_prelink_modules = LD [M] $@
296+ cmd_cc_prelink_modules = \
318297 $(LD) $(ld_flags) -r -o $@ \
319- $(shell [ -s $(@:.lto .o=.o.symversions) ] && \
320- echo -T $(@:.lto .o=.o.symversions)) \
298+ $(shell [ -s $(@:.prelink .o=.o.symversions) ] && \
299+ echo -T $(@:.prelink .o=.o.symversions)) \
321300 --whole-archive $(filter-out FORCE,$^) \
322301 $(cmd_objtool)
323302
324- $(obj)/%.lto.o: $(obj)/%.o FORCE
325- $(call if_changed,cc_lto_link_modules)
303+ # objtool was skipped for LLVM bitcode, run it now that we have compiled
304+ # modules into native code
305+ $(obj)/%.prelink.o: objtool-enabled = y
306+ $(obj)/%.prelink.o: part-of-module := y
307+
308+ $(obj)/%.prelink.o: $(obj)/%.o FORCE
309+ $(call if_changed,cc_prelink_modules)
326310endif
327311
328312cmd_mod = { \
@@ -333,18 +317,6 @@ cmd_mod = { \
333317$(obj)/%.mod: $(obj)/%$(mod-prelink-ext).o FORCE
334318 $(call if_changed,mod)
335319
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-
348320quiet_cmd_cc_lst_c = MKLST $@
349321 cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
350322 $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
@@ -498,7 +470,7 @@ $(obj)/lib.a: $(lib-y) FORCE
498470# Do not replace $(filter %.o,^) with $(real-prereqs). When a single object
499471# module is turned into a multi object module, $^ will contain header file
500472# dependencies recorded in the .*.cmd file.
501- ifdef CONFIG_LTO_CLANG
473+ ifneq ($( CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),)
502474quiet_cmd_link_multi-m = AR [M] $@
503475cmd_link_multi-m = \
504476 $(cmd_update_lto_symversions); \
0 commit comments