Skip to content

Commit d31ed5d

Browse files
author
Peter Zijlstra
committed
kbuild: Fixup the IBT kbuild changes
Masahiro-san deemed my kbuild changes to support whole module objtool runs too terrible to live and gracefully provided an alternative. Suggested-by: Masahiro Yamada <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/CAK7LNAQ2mYMnOKMQheVi+6byUFE3KEkjm1zcndNUfe0tORGvug@mail.gmail.com
1 parent 9cea0d4 commit d31ed5d

File tree

3 files changed

+27
-55
lines changed

3 files changed

+27
-55
lines changed

scripts/Makefile.build

Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,12 @@ ifdef need-builtin
8686
targets-for-builtin += $(obj)/built-in.a
8787
endif
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)))
9793
endif
9894

99-
targets-for-modules += $(patsubst %.o, %.mod, $(filter %.o, $(obj-m)))
100-
10195
ifdef need-modorder
10296
targets-for-modules += $(obj)/modules.order
10397
endif
@@ -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

250244
endif # 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-
272251
else
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)
326310
endif
327311

328312
cmd_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-
348320
quiet_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),)
502474
quiet_cmd_link_multi-m = AR [M] $@
503475
cmd_link_multi-m = \
504476
$(cmd_update_lto_symversions); \

scripts/Makefile.lib

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,11 @@ dtc_cpp_flags = -Wp,-MMD,$(depfile).pre.tmp -nostdinc \
230230
$(addprefix -I,$(DTC_INCLUDE)) \
231231
-undef -D__DTS__
232232

233-
ifeq ($(CONFIG_LTO_CLANG),y)
233+
ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),)
234234
# With CONFIG_LTO_CLANG, .o files in modules might be LLVM bitcode, so we
235235
# need to run LTO to compile them into native code (.lto.o) before further
236236
# processing.
237-
mod-prelink-ext := .lto
237+
mod-prelink-ext := .prelink
238238
endif
239239

240240
# Useful for describing the dependency of composite objects

scripts/mod/modpost.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,9 +1989,9 @@ static char *remove_dot(char *s)
19891989
if (m && (s[n + m] == '.' || s[n + m] == 0))
19901990
s[n] = 0;
19911991

1992-
/* strip trailing .lto */
1993-
if (strends(s, ".lto"))
1994-
s[strlen(s) - 4] = '\0';
1992+
/* strip trailing .prelink */
1993+
if (strends(s, ".prelink"))
1994+
s[strlen(s) - 8] = '\0';
19951995
}
19961996
return s;
19971997
}
@@ -2015,9 +2015,9 @@ static void read_symbols(const char *modname)
20152015
/* strip trailing .o */
20162016
tmp = NOFAIL(strdup(modname));
20172017
tmp[strlen(tmp) - 2] = '\0';
2018-
/* strip trailing .lto */
2019-
if (strends(tmp, ".lto"))
2020-
tmp[strlen(tmp) - 4] = '\0';
2018+
/* strip trailing .prelink */
2019+
if (strends(tmp, ".prelink"))
2020+
tmp[strlen(tmp) - 8] = '\0';
20212021
mod = new_module(tmp);
20222022
free(tmp);
20232023
}

0 commit comments

Comments
 (0)