Skip to content

Commit 71e8072

Browse files
committed
Merge tag 'kbuild-v5.19-3' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild
Pull more Kbuild updates from Masahiro Yamada: - Fix build regressions for parisc, csky, nios2, openrisc - Simplify module builds for CONFIG_LTO_CLANG and CONFIG_X86_KERNEL_IBT - Remove arch/parisc/nm, which was presumably a workaround for old tools - Check the odd combination of EXPORT_SYMBOL and 'static' precisely - Make external module builds robust against "too long argument error" - Support j, k keys for moving the cursor in nconfig * tag 'kbuild-v5.19-3' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: (25 commits) kbuild: Allow to select bash in a modified environment scripts: kconfig: nconf: make nconfig accept jk keybindings modpost: use fnmatch() to simplify match() modpost: simplify mod->name allocation kbuild: factor out the common objtool arguments kbuild: move vmlinux.o link to scripts/Makefile.vmlinux_o kbuild: clean .tmp_* pattern by make clean kbuild: remove redundant cleanups in scripts/link-vmlinux.sh kbuild: rebuild multi-object modules when objtool is updated kbuild: add cmd_and_savecmd macro kbuild: make *.mod rule robust against too long argument error kbuild: make built-in.a rule robust against too long argument error kbuild: check static EXPORT_SYMBOL* by script instead of modpost parisc: remove arch/parisc/nm kbuild: do not create *.prelink.o for Clang LTO or IBT kbuild: replace $(linked-object) with CONFIG options kbuild: do not try to parse *.cmd files for objects provided by compiler kbuild: replace $(if A,A,B) with $(or A,B) in scripts/Makefile.modpost modpost: squash if...else-if in find_elf_symbol2() modpost: reuse ARRAY_SIZE() macro for section_mismatch() ...
2 parents 952923d + 42ce60a commit 71e8072

17 files changed

+289
-350
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,7 @@ CLEAN_FILES += include/ksym vmlinux.symvers modules-only.symvers \
14901490

14911491
# Directories & files removed with 'make mrproper'
14921492
MRPROPER_FILES += include/config include/generated \
1493-
arch/$(SRCARCH)/include/generated .tmp_objdiff \
1493+
arch/$(SRCARCH)/include/generated .objdiff \
14941494
debian snap tar-install \
14951495
.config .config.old .version \
14961496
Module.symvers \
@@ -1857,7 +1857,7 @@ clean: $(clean-dirs)
18571857
-o -name '*.lex.c' -o -name '*.tab.[ch]' \
18581858
-o -name '*.asn1.[ch]' \
18591859
-o -name '*.symtypes' -o -name 'modules.order' \
1860-
-o -name '.tmp_*.o.*' \
1860+
-o -name '.tmp_*' \
18611861
-o -name '*.c.[012]*.*' \
18621862
-o -name '*.ll' \
18631863
-o -name '*.gcno' \

arch/parisc/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
boot := arch/parisc/boot
1919
KBUILD_IMAGE := $(boot)/bzImage
2020

21-
NM = sh $(srctree)/arch/parisc/nm
2221
CHECKFLAGS += -D__hppa__=1
2322

2423
ifdef CONFIG_64BIT

arch/parisc/nm

Lines changed: 0 additions & 6 deletions
This file was deleted.

scripts/Kbuild.include

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ pound := \#
1515
# Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o
1616
dot-target = $(dir $@).$(notdir $@)
1717

18+
###
19+
# Name of target with a '.tmp_' as filename prefix. foo/bar.o => foo/.tmp_bar.o
20+
tmp-target = $(dir $@).tmp_$(notdir $@)
21+
1822
###
1923
# The temporary file to save gcc -MMD generated dependencies must not
2024
# contain a comma
@@ -138,9 +142,11 @@ check-FORCE = $(if $(filter FORCE, $^),,$(warning FORCE prerequisite is missing)
138142
if-changed-cond = $(newer-prereqs)$(cmd-check)$(check-FORCE)
139143

140144
# Execute command if command has changed or prerequisite(s) are updated.
141-
if_changed = $(if $(if-changed-cond), \
145+
if_changed = $(if $(if-changed-cond),$(cmd_and_savecmd),@:)
146+
147+
cmd_and_savecmd = \
142148
$(cmd); \
143-
printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:)
149+
printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd
144150

145151
# Execute the command and also postprocess generated .d dependencies file.
146152
if_changed_dep = $(if $(if-changed-cond),$(cmd_and_fixdep),@:)

scripts/Makefile.build

Lines changed: 38 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ endif
8888
targets-for-modules := $(foreach x, o mod $(if $(CONFIG_TRIM_UNUSED_KSYMS), usyms), \
8989
$(patsubst %.o, %.$x, $(filter %.o, $(obj-m))))
9090

91-
ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),)
92-
targets-for-modules += $(patsubst %.o, %.prelink.o, $(filter %.o, $(obj-m)))
93-
endif
94-
9591
ifdef need-modorder
9692
targets-for-modules += $(obj)/modules.order
9793
endif
@@ -152,8 +148,18 @@ $(obj)/%.ll: $(src)/%.c FORCE
152148
# The C file is compiled and updated dependency information is generated.
153149
# (See cmd_cc_o_c + relevant part of rule_cc_o_c)
154150

151+
is-single-obj-m = $(and $(part-of-module),$(filter $@, $(obj-m)),y)
152+
153+
# When a module consists of a single object, there is no reason to keep LLVM IR.
154+
# Make $(LD) covert LLVM IR to ELF here.
155+
ifdef CONFIG_LTO_CLANG
156+
cmd_ld_single_m = $(if $(is-single-obj-m), ; $(LD) $(ld_flags) -r -o $(tmp-target) $@; mv $(tmp-target) $@)
157+
endif
158+
155159
quiet_cmd_cc_o_c = CC $(quiet_modtag) $@
156-
cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< $(cmd_objtool)
160+
cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< \
161+
$(cmd_ld_single_m) \
162+
$(cmd_objtool)
157163

158164
ifdef CONFIG_MODVERSIONS
159165
# When module versioning is enabled the following steps are executed:
@@ -204,54 +210,25 @@ cmd_record_mcount = $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)),
204210
$(sub_cmd_record_mcount))
205211
endif # CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT
206212

207-
ifdef CONFIG_OBJTOOL
208-
209-
objtool := $(objtree)/tools/objtool/objtool
210-
211-
objtool_args = \
212-
$(if $(CONFIG_HAVE_JUMP_LABEL_HACK), --hacks=jump_label) \
213-
$(if $(CONFIG_HAVE_NOINSTR_HACK), --hacks=noinstr) \
214-
$(if $(CONFIG_X86_KERNEL_IBT), --ibt) \
215-
$(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \
216-
$(if $(CONFIG_UNWINDER_ORC), --orc) \
217-
$(if $(CONFIG_RETPOLINE), --retpoline) \
218-
$(if $(CONFIG_SLS), --sls) \
219-
$(if $(CONFIG_STACK_VALIDATION), --stackval) \
220-
$(if $(CONFIG_HAVE_STATIC_CALL_INLINE), --static-call) \
221-
--uaccess \
222-
$(if $(linked-object), --link) \
223-
$(if $(part-of-module), --module) \
224-
$(if $(CONFIG_GCOV_KERNEL), --no-unreachable)
225-
226-
cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@)
227-
cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
228-
229-
endif # CONFIG_OBJTOOL
230-
231-
ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),)
232-
233-
# Skip objtool for LLVM bitcode
234-
$(obj)/%.o: objtool-enabled :=
235-
236-
else
237-
238213
# 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory
239214
# 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
240215
# 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
241216

242-
$(obj)/%.o: objtool-enabled = $(if $(filter-out y%, \
243-
$(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y)
217+
is-standard-object = $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y)
244218

245-
endif
219+
$(obj)/%.o: objtool-enabled = $(if $(is-standard-object),$(if $(delay-objtool),$(is-single-obj-m),y))
246220

247221
ifdef CONFIG_TRIM_UNUSED_KSYMS
248222
cmd_gen_ksymdeps = \
249223
$(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ >> $(dot-target).cmd
250224
endif
251225

226+
cmd_check_local_export = $(srctree)/scripts/check-local-export $@
227+
252228
define rule_cc_o_c
253229
$(call cmd_and_fixdep,cc_o_c)
254230
$(call cmd,gen_ksymdeps)
231+
$(call cmd,check_local_export)
255232
$(call cmd,checksrc)
256233
$(call cmd,checkdoc)
257234
$(call cmd,gen_objtooldep)
@@ -262,6 +239,7 @@ endef
262239
define rule_as_o_S
263240
$(call cmd_and_fixdep,as_o_S)
264241
$(call cmd,gen_ksymdeps)
242+
$(call cmd,check_local_export)
265243
$(call cmd,gen_objtooldep)
266244
$(call cmd,gen_symversions_S)
267245
endef
@@ -271,35 +249,18 @@ $(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE
271249
$(call if_changed_rule,cc_o_c)
272250
$(call cmd,force_checksrc)
273251

274-
ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),)
275-
# Module .o files may contain LLVM bitcode, compile them into native code
276-
# before ELF processing
277-
quiet_cmd_cc_prelink_modules = LD [M] $@
278-
cmd_cc_prelink_modules = \
279-
$(LD) $(ld_flags) -r -o $@ \
280-
--whole-archive $(filter-out FORCE,$^) \
281-
$(cmd_objtool)
282-
283-
# objtool was skipped for LLVM bitcode, run it now that we have compiled
284-
# modules into native code
285-
$(obj)/%.prelink.o: objtool-enabled = y
286-
$(obj)/%.prelink.o: part-of-module := y
287-
$(obj)/%.prelink.o: linked-object := y
288-
289-
$(obj)/%.prelink.o: $(obj)/%.o FORCE
290-
$(call if_changed,cc_prelink_modules)
291-
endif
292-
293-
cmd_mod = echo $(addprefix $(obj)/, $(call real-search, $*.o, .o, -objs -y -m)) | \
294-
$(AWK) -v RS='( |\n)' '!x[$$0]++' > $@
252+
# To make this rule robust against "Argument list too long" error,
253+
# ensure to add $(obj)/ prefix by a shell command.
254+
cmd_mod = echo $(call real-search, $*.o, .o, -objs -y -m) | \
255+
$(AWK) -v RS='( |\n)' '!x[$$0]++ { print("$(obj)/"$$0) }' > $@
295256

296257
$(obj)/%.mod: FORCE
297258
$(call if_changed,mod)
298259

299260
# List module undefined symbols
300261
cmd_undefined_syms = $(NM) $< | sed -n 's/^ *U //p' > $@
301262

302-
$(obj)/%.usyms: $(obj)/%$(mod-prelink-ext).o FORCE
263+
$(obj)/%.usyms: $(obj)/%.o FORCE
303264
$(call if_changed,undefined_syms)
304265

305266
quiet_cmd_cc_lst_c = MKLST $@
@@ -392,9 +353,14 @@ $(subdir-modorder): $(obj)/%/modules.order: $(obj)/% ;
392353
#
393354
# Rule to compile a set of .o files into one .a file (without symbol table)
394355
#
356+
# To make this rule robust against "Argument list too long" error,
357+
# remove $(obj)/ prefix, and restore it by a shell command.
395358

396359
quiet_cmd_ar_builtin = AR $@
397-
cmd_ar_builtin = rm -f $@; $(AR) cDPrST $@ $(real-prereqs)
360+
cmd_ar_builtin = rm -f $@; \
361+
echo $(patsubst $(obj)/%,%,$(real-prereqs)) | \
362+
sed -E 's:([^ ]+):$(obj)/\1:g' | \
363+
xargs $(AR) cDPrST $@
398364

399365
$(obj)/built-in.a: $(real-obj-y) FORCE
400366
$(call if_changed,ar_builtin)
@@ -421,18 +387,18 @@ $(obj)/modules.order: $(obj-m) FORCE
421387
$(obj)/lib.a: $(lib-y) FORCE
422388
$(call if_changed,ar)
423389

424-
ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),)
425-
quiet_cmd_link_multi-m = AR [M] $@
426-
cmd_link_multi-m = \
427-
rm -f $@; \
428-
$(AR) cDPrsT $@ @$(patsubst %.o,%.mod,$@)
429-
else
430-
quiet_cmd_link_multi-m = LD [M] $@
431-
cmd_link_multi-m = $(LD) $(ld_flags) -r -o $@ @$(patsubst %.o,%.mod,$@)
432-
endif
390+
quiet_cmd_ld_multi_m = LD [M] $@
391+
cmd_ld_multi_m = $(LD) $(ld_flags) -r -o $@ @$(patsubst %.o,%.mod,$@) $(cmd_objtool)
392+
393+
define rule_ld_multi_m
394+
$(call cmd_and_savecmd,ld_multi_m)
395+
$(call cmd,gen_objtooldep)
396+
endef
433397

398+
$(multi-obj-m): objtool-enabled := $(delay-objtool)
399+
$(multi-obj-m): part-of-module := y
434400
$(multi-obj-m): %.o: %.mod FORCE
435-
$(call if_changed,link_multi-m)
401+
$(call if_changed_rule,ld_multi_m)
436402
$(call multi_depend, $(multi-obj-m), .o, -objs -y -m)
437403

438404
targets := $(filter-out $(PHONY), $(targets))

scripts/Makefile.lib

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,31 @@ dtc_cpp_flags = -Wp,-MMD,$(depfile).pre.tmp -nostdinc \
225225
$(addprefix -I,$(DTC_INCLUDE)) \
226226
-undef -D__DTS__
227227

228-
ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),)
229-
# With CONFIG_LTO_CLANG, .o files in modules might be LLVM bitcode, so we
230-
# need to run LTO to compile them into native code (.lto.o) before further
231-
# processing.
232-
mod-prelink-ext := .prelink
233-
endif
228+
ifdef CONFIG_OBJTOOL
229+
230+
objtool := $(objtree)/tools/objtool/objtool
231+
232+
objtool_args = \
233+
$(if $(CONFIG_HAVE_JUMP_LABEL_HACK), --hacks=jump_label) \
234+
$(if $(CONFIG_HAVE_NOINSTR_HACK), --hacks=noinstr) \
235+
$(if $(CONFIG_X86_KERNEL_IBT), --ibt) \
236+
$(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \
237+
$(if $(CONFIG_UNWINDER_ORC), --orc) \
238+
$(if $(CONFIG_RETPOLINE), --retpoline) \
239+
$(if $(CONFIG_SLS), --sls) \
240+
$(if $(CONFIG_STACK_VALIDATION), --stackval) \
241+
$(if $(CONFIG_HAVE_STATIC_CALL_INLINE), --static-call) \
242+
--uaccess \
243+
$(if $(delay-objtool), --link) \
244+
$(if $(part-of-module), --module) \
245+
$(if $(CONFIG_GCOV_KERNEL), --no-unreachable)
246+
247+
delay-objtool := $(or $(CONFIG_LTO_CLANG),$(CONFIG_X86_KERNEL_IBT))
248+
249+
cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@)
250+
cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
251+
252+
endif # CONFIG_OBJTOOL
234253

235254
# Useful for describing the dependency of composite objects
236255
# Usage:

scripts/Makefile.modfinal

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ __modfinal:
99
include include/config/auto.conf
1010
include $(srctree)/scripts/Kbuild.include
1111

12-
# for c_flags and mod-prelink-ext
12+
# for c_flags
1313
include $(srctree)/scripts/Makefile.lib
1414

1515
# find all modules listed in modules.order
@@ -54,9 +54,8 @@ if_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check), \
5454
$(cmd); \
5555
printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:)
5656

57-
5857
# Re-generate module BTFs if either module's .ko or vmlinux changed
59-
$(modules): %.ko: %$(mod-prelink-ext).o %.mod.o scripts/module.lds $(if $(KBUILD_BUILTIN),vmlinux) FORCE
58+
$(modules): %.ko: %.o %.mod.o scripts/module.lds $(if $(KBUILD_BUILTIN),vmlinux) FORCE
6059
+$(call if_changed_except,ld_ko_o,vmlinux)
6160
ifdef CONFIG_DEBUG_INFO_BTF_MODULES
6261
+$(if $(newer-prereqs),$(call cmd,btf_ko))

scripts/Makefile.modpost

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ __modpost:
4141
include include/config/auto.conf
4242
include $(srctree)/scripts/Kbuild.include
4343

44-
# for mod-prelink-ext
45-
include $(srctree)/scripts/Makefile.lib
46-
4744
MODPOST = scripts/mod/modpost \
4845
$(if $(CONFIG_MODVERSIONS),-m) \
4946
$(if $(CONFIG_MODULE_SRCVERSION_ALL),-a) \
@@ -87,8 +84,7 @@ obj := $(KBUILD_EXTMOD)
8784
src := $(obj)
8885

8986
# Include the module's Makefile to find KBUILD_EXTRA_SYMBOLS
90-
include $(if $(wildcard $(KBUILD_EXTMOD)/Kbuild), \
91-
$(KBUILD_EXTMOD)/Kbuild, $(KBUILD_EXTMOD)/Makefile)
87+
include $(or $(wildcard $(src)/Kbuild), $(src)/Makefile)
9288

9389
# modpost option for external modules
9490
MODPOST += -e
@@ -118,8 +114,6 @@ $(input-symdump):
118114
@echo >&2 ' Modules may not have dependencies or modversions.'
119115
@echo >&2 ' You may get many unresolved symbol warnings.'
120116

121-
modules := $(sort $(shell cat $(MODORDER)))
122-
123117
# KBUILD_MODPOST_WARN can be set to avoid error out in case of undefined symbols
124118
ifneq ($(KBUILD_MODPOST_WARN)$(filter-out $(existing-input-symdump), $(input-symdump)),)
125119
MODPOST += -w
@@ -128,9 +122,9 @@ endif
128122
# Read out modules.order to pass in modpost.
129123
# Otherwise, allmodconfig would fail with "Argument list too long".
130124
quiet_cmd_modpost = MODPOST $@
131-
cmd_modpost = sed 's/\.ko$$/$(mod-prelink-ext)\.o/' $< | $(MODPOST) -T -
125+
cmd_modpost = sed 's/ko$$/o/' $< | $(MODPOST) -T -
132126

133-
$(output-symdump): $(MODORDER) $(input-symdump) $(modules:.ko=$(mod-prelink-ext).o) FORCE
127+
$(output-symdump): $(MODORDER) $(input-symdump) FORCE
134128
$(call if_changed,modpost)
135129

136130
targets += $(output-symdump)

0 commit comments

Comments
 (0)