Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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()
...

+289 -350
+2 -2
Makefile
··· 1490 1490 1491 1491 # Directories & files removed with 'make mrproper' 1492 1492 MRPROPER_FILES += include/config include/generated \ 1493 - arch/$(SRCARCH)/include/generated .tmp_objdiff \ 1493 + arch/$(SRCARCH)/include/generated .objdiff \ 1494 1494 debian snap tar-install \ 1495 1495 .config .config.old .version \ 1496 1496 Module.symvers \ ··· 1857 1857 -o -name '*.lex.c' -o -name '*.tab.[ch]' \ 1858 1858 -o -name '*.asn1.[ch]' \ 1859 1859 -o -name '*.symtypes' -o -name 'modules.order' \ 1860 - -o -name '.tmp_*.o.*' \ 1860 + -o -name '.tmp_*' \ 1861 1861 -o -name '*.c.[012]*.*' \ 1862 1862 -o -name '*.ll' \ 1863 1863 -o -name '*.gcno' \
-1
arch/parisc/Makefile
··· 18 18 boot := arch/parisc/boot 19 19 KBUILD_IMAGE := $(boot)/bzImage 20 20 21 - NM = sh $(srctree)/arch/parisc/nm 22 21 CHECKFLAGS += -D__hppa__=1 23 22 24 23 ifdef CONFIG_64BIT
-6
arch/parisc/nm
··· 1 - #!/bin/sh 2 - ## 3 - # Hack to have an nm which removes the local symbols. We also rely 4 - # on this nm being hidden out of the ordinarily executable path 5 - ## 6 - ${CROSS_COMPILE}nm $* | grep -v '.LC*[0-9]*$'
+8 -2
scripts/Kbuild.include
··· 16 16 dot-target = $(dir $@).$(notdir $@) 17 17 18 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 + 22 + ### 19 23 # The temporary file to save gcc -MMD generated dependencies must not 20 24 # contain a comma 21 25 depfile = $(subst $(comma),_,$(dot-target).d) ··· 142 138 if-changed-cond = $(newer-prereqs)$(cmd-check)$(check-FORCE) 143 139 144 140 # Execute command if command has changed or prerequisite(s) are updated. 145 - if_changed = $(if $(if-changed-cond), \ 141 + if_changed = $(if $(if-changed-cond),$(cmd_and_savecmd),@:) 142 + 143 + cmd_and_savecmd = \ 146 144 $(cmd); \ 147 - printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:) 145 + printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd 148 146 149 147 # Execute the command and also postprocess generated .d dependencies file. 150 148 if_changed_dep = $(if $(if-changed-cond),$(cmd_and_fixdep),@:)
+38 -72
scripts/Makefile.build
··· 88 88 targets-for-modules := $(foreach x, o mod $(if $(CONFIG_TRIM_UNUSED_KSYMS), usyms), \ 89 89 $(patsubst %.o, %.$x, $(filter %.o, $(obj-m)))) 90 90 91 - ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),) 92 - targets-for-modules += $(patsubst %.o, %.prelink.o, $(filter %.o, $(obj-m))) 93 - endif 94 - 95 91 ifdef need-modorder 96 92 targets-for-modules += $(obj)/modules.order 97 93 endif ··· 148 152 # The C file is compiled and updated dependency information is generated. 149 153 # (See cmd_cc_o_c + relevant part of rule_cc_o_c) 150 154 155 + is-single-obj-m = $(and $(part-of-module),$(filter $@, $(obj-m)),y) 156 + 157 + # When a module consists of a single object, there is no reason to keep LLVM IR. 158 + # Make $(LD) covert LLVM IR to ELF here. 159 + ifdef CONFIG_LTO_CLANG 160 + cmd_ld_single_m = $(if $(is-single-obj-m), ; $(LD) $(ld_flags) -r -o $(tmp-target) $@; mv $(tmp-target) $@) 161 + endif 162 + 151 163 quiet_cmd_cc_o_c = CC $(quiet_modtag) $@ 152 - cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< $(cmd_objtool) 164 + cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< \ 165 + $(cmd_ld_single_m) \ 166 + $(cmd_objtool) 153 167 154 168 ifdef CONFIG_MODVERSIONS 155 169 # When module versioning is enabled the following steps are executed: ··· 210 204 $(sub_cmd_record_mcount)) 211 205 endif # CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT 212 206 213 - ifdef CONFIG_OBJTOOL 214 - 215 - objtool := $(objtree)/tools/objtool/objtool 216 - 217 - objtool_args = \ 218 - $(if $(CONFIG_HAVE_JUMP_LABEL_HACK), --hacks=jump_label) \ 219 - $(if $(CONFIG_HAVE_NOINSTR_HACK), --hacks=noinstr) \ 220 - $(if $(CONFIG_X86_KERNEL_IBT), --ibt) \ 221 - $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ 222 - $(if $(CONFIG_UNWINDER_ORC), --orc) \ 223 - $(if $(CONFIG_RETPOLINE), --retpoline) \ 224 - $(if $(CONFIG_SLS), --sls) \ 225 - $(if $(CONFIG_STACK_VALIDATION), --stackval) \ 226 - $(if $(CONFIG_HAVE_STATIC_CALL_INLINE), --static-call) \ 227 - --uaccess \ 228 - $(if $(linked-object), --link) \ 229 - $(if $(part-of-module), --module) \ 230 - $(if $(CONFIG_GCOV_KERNEL), --no-unreachable) 231 - 232 - cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@) 233 - cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd) 234 - 235 - endif # CONFIG_OBJTOOL 236 - 237 - ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),) 238 - 239 - # Skip objtool for LLVM bitcode 240 - $(obj)/%.o: objtool-enabled := 241 - 242 - else 243 - 244 207 # 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory 245 208 # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file 246 209 # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file 247 210 248 - $(obj)/%.o: objtool-enabled = $(if $(filter-out y%, \ 249 - $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y) 211 + is-standard-object = $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y) 250 212 251 - endif 213 + $(obj)/%.o: objtool-enabled = $(if $(is-standard-object),$(if $(delay-objtool),$(is-single-obj-m),y)) 252 214 253 215 ifdef CONFIG_TRIM_UNUSED_KSYMS 254 216 cmd_gen_ksymdeps = \ 255 217 $(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ >> $(dot-target).cmd 256 218 endif 257 219 220 + cmd_check_local_export = $(srctree)/scripts/check-local-export $@ 221 + 258 222 define rule_cc_o_c 259 223 $(call cmd_and_fixdep,cc_o_c) 260 224 $(call cmd,gen_ksymdeps) 225 + $(call cmd,check_local_export) 261 226 $(call cmd,checksrc) 262 227 $(call cmd,checkdoc) 263 228 $(call cmd,gen_objtooldep) ··· 239 262 define rule_as_o_S 240 263 $(call cmd_and_fixdep,as_o_S) 241 264 $(call cmd,gen_ksymdeps) 265 + $(call cmd,check_local_export) 242 266 $(call cmd,gen_objtooldep) 243 267 $(call cmd,gen_symversions_S) 244 268 endef ··· 249 271 $(call if_changed_rule,cc_o_c) 250 272 $(call cmd,force_checksrc) 251 273 252 - ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),) 253 - # Module .o files may contain LLVM bitcode, compile them into native code 254 - # before ELF processing 255 - quiet_cmd_cc_prelink_modules = LD [M] $@ 256 - cmd_cc_prelink_modules = \ 257 - $(LD) $(ld_flags) -r -o $@ \ 258 - --whole-archive $(filter-out FORCE,$^) \ 259 - $(cmd_objtool) 260 - 261 - # objtool was skipped for LLVM bitcode, run it now that we have compiled 262 - # modules into native code 263 - $(obj)/%.prelink.o: objtool-enabled = y 264 - $(obj)/%.prelink.o: part-of-module := y 265 - $(obj)/%.prelink.o: linked-object := y 266 - 267 - $(obj)/%.prelink.o: $(obj)/%.o FORCE 268 - $(call if_changed,cc_prelink_modules) 269 - endif 270 - 271 - cmd_mod = echo $(addprefix $(obj)/, $(call real-search, $*.o, .o, -objs -y -m)) | \ 272 - $(AWK) -v RS='( |\n)' '!x[$$0]++' > $@ 274 + # To make this rule robust against "Argument list too long" error, 275 + # ensure to add $(obj)/ prefix by a shell command. 276 + cmd_mod = echo $(call real-search, $*.o, .o, -objs -y -m) | \ 277 + $(AWK) -v RS='( |\n)' '!x[$$0]++ { print("$(obj)/"$$0) }' > $@ 273 278 274 279 $(obj)/%.mod: FORCE 275 280 $(call if_changed,mod) ··· 260 299 # List module undefined symbols 261 300 cmd_undefined_syms = $(NM) $< | sed -n 's/^ *U //p' > $@ 262 301 263 - $(obj)/%.usyms: $(obj)/%$(mod-prelink-ext).o FORCE 302 + $(obj)/%.usyms: $(obj)/%.o FORCE 264 303 $(call if_changed,undefined_syms) 265 304 266 305 quiet_cmd_cc_lst_c = MKLST $@ ··· 353 392 # 354 393 # Rule to compile a set of .o files into one .a file (without symbol table) 355 394 # 395 + # To make this rule robust against "Argument list too long" error, 396 + # remove $(obj)/ prefix, and restore it by a shell command. 356 397 357 398 quiet_cmd_ar_builtin = AR $@ 358 - cmd_ar_builtin = rm -f $@; $(AR) cDPrST $@ $(real-prereqs) 399 + cmd_ar_builtin = rm -f $@; \ 400 + echo $(patsubst $(obj)/%,%,$(real-prereqs)) | \ 401 + sed -E 's:([^ ]+):$(obj)/\1:g' | \ 402 + xargs $(AR) cDPrST $@ 359 403 360 404 $(obj)/built-in.a: $(real-obj-y) FORCE 361 405 $(call if_changed,ar_builtin) ··· 387 421 $(obj)/lib.a: $(lib-y) FORCE 388 422 $(call if_changed,ar) 389 423 390 - ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),) 391 - quiet_cmd_link_multi-m = AR [M] $@ 392 - cmd_link_multi-m = \ 393 - rm -f $@; \ 394 - $(AR) cDPrsT $@ @$(patsubst %.o,%.mod,$@) 395 - else 396 - quiet_cmd_link_multi-m = LD [M] $@ 397 - cmd_link_multi-m = $(LD) $(ld_flags) -r -o $@ @$(patsubst %.o,%.mod,$@) 398 - endif 424 + quiet_cmd_ld_multi_m = LD [M] $@ 425 + cmd_ld_multi_m = $(LD) $(ld_flags) -r -o $@ @$(patsubst %.o,%.mod,$@) $(cmd_objtool) 399 426 427 + define rule_ld_multi_m 428 + $(call cmd_and_savecmd,ld_multi_m) 429 + $(call cmd,gen_objtooldep) 430 + endef 431 + 432 + $(multi-obj-m): objtool-enabled := $(delay-objtool) 433 + $(multi-obj-m): part-of-module := y 400 434 $(multi-obj-m): %.o: %.mod FORCE 401 - $(call if_changed,link_multi-m) 435 + $(call if_changed_rule,ld_multi_m) 402 436 $(call multi_depend, $(multi-obj-m), .o, -objs -y -m) 403 437 404 438 targets := $(filter-out $(PHONY), $(targets))
+25 -6
scripts/Makefile.lib
··· 225 225 $(addprefix -I,$(DTC_INCLUDE)) \ 226 226 -undef -D__DTS__ 227 227 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 234 253 235 254 # Useful for describing the dependency of composite objects 236 255 # Usage:
+2 -3
scripts/Makefile.modfinal
··· 9 9 include include/config/auto.conf 10 10 include $(srctree)/scripts/Kbuild.include 11 11 12 - # for c_flags and mod-prelink-ext 12 + # for c_flags 13 13 include $(srctree)/scripts/Makefile.lib 14 14 15 15 # find all modules listed in modules.order ··· 54 54 $(cmd); \ 55 55 printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:) 56 56 57 - 58 57 # 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 60 59 +$(call if_changed_except,ld_ko_o,vmlinux) 61 60 ifdef CONFIG_DEBUG_INFO_BTF_MODULES 62 61 +$(if $(newer-prereqs),$(call cmd,btf_ko))
+3 -9
scripts/Makefile.modpost
··· 41 41 include include/config/auto.conf 42 42 include $(srctree)/scripts/Kbuild.include 43 43 44 - # for mod-prelink-ext 45 - include $(srctree)/scripts/Makefile.lib 46 - 47 44 MODPOST = scripts/mod/modpost \ 48 45 $(if $(CONFIG_MODVERSIONS),-m) \ 49 46 $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a) \ ··· 84 87 src := $(obj) 85 88 86 89 # Include the module's Makefile to find KBUILD_EXTRA_SYMBOLS 87 - include $(if $(wildcard $(KBUILD_EXTMOD)/Kbuild), \ 88 - $(KBUILD_EXTMOD)/Kbuild, $(KBUILD_EXTMOD)/Makefile) 90 + include $(or $(wildcard $(src)/Kbuild), $(src)/Makefile) 89 91 90 92 # modpost option for external modules 91 93 MODPOST += -e ··· 114 118 @echo >&2 ' Modules may not have dependencies or modversions.' 115 119 @echo >&2 ' You may get many unresolved symbol warnings.' 116 120 117 - modules := $(sort $(shell cat $(MODORDER))) 118 - 119 121 # KBUILD_MODPOST_WARN can be set to avoid error out in case of undefined symbols 120 122 ifneq ($(KBUILD_MODPOST_WARN)$(filter-out $(existing-input-symdump), $(input-symdump)),) 121 123 MODPOST += -w ··· 122 128 # Read out modules.order to pass in modpost. 123 129 # Otherwise, allmodconfig would fail with "Argument list too long". 124 130 quiet_cmd_modpost = MODPOST $@ 125 - cmd_modpost = sed 's/\.ko$$/$(mod-prelink-ext)\.o/' $< | $(MODPOST) -T - 131 + cmd_modpost = sed 's/ko$$/o/' $< | $(MODPOST) -T - 126 132 127 - $(output-symdump): $(MODORDER) $(input-symdump) $(modules:.ko=$(mod-prelink-ext).o) FORCE 133 + $(output-symdump): $(MODORDER) $(input-symdump) FORCE 128 134 $(call if_changed,modpost) 129 135 130 136 targets += $(output-symdump)
+87
scripts/Makefile.vmlinux_o
··· 1 + # SPDX-License-Identifier: GPL-2.0-only 2 + 3 + PHONY := __default 4 + __default: vmlinux.o 5 + 6 + include include/config/auto.conf 7 + include $(srctree)/scripts/Kbuild.include 8 + 9 + # for objtool 10 + include $(srctree)/scripts/Makefile.lib 11 + 12 + # Generate a linker script to ensure correct ordering of initcalls for Clang LTO 13 + # --------------------------------------------------------------------------- 14 + 15 + quiet_cmd_gen_initcalls_lds = GEN $@ 16 + cmd_gen_initcalls_lds = \ 17 + $(PYTHON3) $(srctree)/scripts/jobserver-exec \ 18 + $(PERL) $(real-prereqs) > $@ 19 + 20 + .tmp_initcalls.lds: $(srctree)/scripts/generate_initcall_order.pl \ 21 + $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS) FORCE 22 + $(call if_changed,gen_initcalls_lds) 23 + 24 + targets := .tmp_initcalls.lds 25 + 26 + ifdef CONFIG_LTO_CLANG 27 + initcalls-lds := .tmp_initcalls.lds 28 + endif 29 + 30 + # objtool for vmlinux.o 31 + # --------------------------------------------------------------------------- 32 + # 33 + # For LTO and IBT, objtool doesn't run on individual translation units. 34 + # Run everything on vmlinux instead. 35 + 36 + objtool-enabled := $(or $(delay-objtool),$(CONFIG_NOINSTR_VALIDATION)) 37 + 38 + # Reuse objtool_args defined in scripts/Makefile.lib if LTO or IBT is enabled. 39 + # 40 + # Add some more flags as needed. 41 + # --no-unreachable and --link might be added twice, but it is fine. 42 + # 43 + # Expand objtool_args to a simple variable to avoid circular reference. 44 + 45 + objtool_args := \ 46 + $(if $(delay-objtool),$(objtool_args)) \ 47 + $(if $(CONFIG_NOINSTR_VALIDATION), --noinstr) \ 48 + $(if $(CONFIG_GCOV_KERNEL), --no-unreachable) \ 49 + --link 50 + 51 + # Link of vmlinux.o used for section mismatch analysis 52 + # --------------------------------------------------------------------------- 53 + 54 + quiet_cmd_ld_vmlinux.o = LD $@ 55 + cmd_ld_vmlinux.o = \ 56 + $(LD) ${KBUILD_LDFLAGS} -r -o $@ \ 57 + $(addprefix -T , $(initcalls-lds)) \ 58 + --whole-archive $(KBUILD_VMLINUX_OBJS) --no-whole-archive \ 59 + --start-group $(KBUILD_VMLINUX_LIBS) --end-group \ 60 + $(cmd_objtool) 61 + 62 + define rule_ld_vmlinux.o 63 + $(call cmd_and_savecmd,ld_vmlinux.o) 64 + $(call cmd,gen_objtooldep) 65 + endef 66 + 67 + vmlinux.o: $(initcalls-lds) $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS) FORCE 68 + $(call if_changed_rule,ld_vmlinux.o) 69 + 70 + targets += vmlinux.o 71 + 72 + # Add FORCE to the prequisites of a target to force it to be always rebuilt. 73 + # --------------------------------------------------------------------------- 74 + 75 + PHONY += FORCE 76 + FORCE: 77 + 78 + # Read all saved command lines and dependencies for the $(targets) we 79 + # may be building above, using $(if_changed{,_dep}). As an 80 + # optimization, we don't need to read them if the target does not 81 + # exist, we will rebuild anyway in that case. 82 + 83 + existing-targets := $(wildcard $(sort $(targets))) 84 + 85 + -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) 86 + 87 + .PHONY: $(PHONY)
+65
scripts/check-local-export
··· 1 + #!/usr/bin/env bash 2 + # SPDX-License-Identifier: GPL-2.0-only 3 + # 4 + # Copyright (C) 2022 Masahiro Yamada <masahiroy@kernel.org> 5 + # 6 + # Exit with error if a local exported symbol is found. 7 + # EXPORT_SYMBOL should be used for global symbols. 8 + 9 + set -e 10 + 11 + declare -A symbol_types 12 + declare -a export_symbols 13 + 14 + exit_code=0 15 + 16 + while read value type name 17 + do 18 + # Skip the line if the number of fields is less than 3. 19 + # 20 + # case 1) 21 + # For undefined symbols, the first field (value) is empty. 22 + # The outout looks like this: 23 + # " U _printk" 24 + # It is unneeded to record undefined symbols. 25 + # 26 + # case 2) 27 + # For Clang LTO, llvm-nm outputs a line with type 't' but empty name: 28 + # "---------------- t" 29 + if [[ -z ${name} ]]; then 30 + continue 31 + fi 32 + 33 + # save (name, type) in the associative array 34 + symbol_types[${name}]=${type} 35 + 36 + # append the exported symbol to the array 37 + if [[ ${name} == __ksymtab_* ]]; then 38 + export_symbols+=(${name#__ksymtab_}) 39 + fi 40 + 41 + # If there is no symbol in the object, ${NM} (both GNU nm and llvm-nm) 42 + # shows 'no symbols' diagnostic (but exits with 0). It is harmless and 43 + # hidden by '2>/dev/null'. However, it suppresses real error messages 44 + # as well. Add a hand-crafted error message here. 45 + # 46 + # Use --quiet instead of 2>/dev/null when we upgrade the minimum version 47 + # of binutils to 2.37, llvm to 13.0.0. 48 + # 49 + # Then, the following line will be really simple: 50 + # done < <(${NM} --quiet ${1}) 51 + done < <(${NM} ${1} 2>/dev/null || { echo "${0}: ${NM} failed" >&2; false; } ) 52 + 53 + # Catch error in the process substitution 54 + wait $! 55 + 56 + for name in "${export_symbols[@]}" 57 + do 58 + # nm(3) says "If lowercase, the symbol is usually local" 59 + if [[ ${symbol_types[$name]} =~ [a-z] ]]; then 60 + echo "$@: error: local symbol '${name}' was exported" >&2 61 + exit_code=1 62 + fi 63 + done 64 + 65 + exit ${exit_code}
+1 -1
scripts/kallsyms.c
··· 70 70 71 71 static void usage(void) 72 72 { 73 - fprintf(stderr, "Usage: kallsyms [--all-symbols] " 73 + fprintf(stderr, "Usage: kallsyms [--all-symbols] [--absolute-percpu] " 74 74 "[--base-relative] < in.map > out.S\n"); 75 75 exit(1); 76 76 }
+6 -2
scripts/kconfig/nconf.c
··· 52 52 "\n" 53 53 "Menu navigation keys\n" 54 54 "----------------------------------------------------------------------\n" 55 - "Linewise up <Up>\n" 56 - "Linewise down <Down>\n" 55 + "Linewise up <Up> <k>\n" 56 + "Linewise down <Down> <j>\n" 57 57 "Pagewise up <Page Up>\n" 58 58 "Pagewise down <Page Down>\n" 59 59 "First entry <Home>\n" ··· 1105 1105 break; 1106 1106 switch (res) { 1107 1107 case KEY_DOWN: 1108 + case 'j': 1108 1109 menu_driver(curses_menu, REQ_DOWN_ITEM); 1109 1110 break; 1110 1111 case KEY_UP: 1112 + case 'k': 1111 1113 menu_driver(curses_menu, REQ_UP_ITEM); 1112 1114 break; 1113 1115 case KEY_NPAGE: ··· 1289 1287 break; 1290 1288 switch (res) { 1291 1289 case KEY_DOWN: 1290 + case 'j': 1292 1291 menu_driver(curses_menu, REQ_DOWN_ITEM); 1293 1292 break; 1294 1293 case KEY_UP: 1294 + case 'k': 1295 1295 menu_driver(curses_menu, REQ_UP_ITEM); 1296 1296 break; 1297 1297 case KEY_NPAGE:
-2
scripts/mod/file2alias.c
··· 734 734 return 1; 735 735 } 736 736 737 - #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 738 - 739 737 static void do_input(char *alias, 740 738 kernel_ulong_t *arr, unsigned int min, unsigned int max) 741 739 {
+37 -124
scripts/mod/modpost.c
··· 13 13 14 14 #define _GNU_SOURCE 15 15 #include <elf.h> 16 + #include <fnmatch.h> 16 17 #include <stdio.h> 17 18 #include <ctype.h> 18 19 #include <string.h> ··· 173 172 return NULL; 174 173 } 175 174 176 - static struct module *new_module(const char *modname) 175 + static struct module *new_module(const char *name, size_t namelen) 177 176 { 178 177 struct module *mod; 179 178 180 - mod = NOFAIL(malloc(sizeof(*mod) + strlen(modname) + 1)); 179 + mod = NOFAIL(malloc(sizeof(*mod) + namelen + 1)); 181 180 memset(mod, 0, sizeof(*mod)); 182 181 183 182 INIT_LIST_HEAD(&mod->exported_symbols); ··· 185 184 INIT_LIST_HEAD(&mod->missing_namespaces); 186 185 INIT_LIST_HEAD(&mod->imported_namespaces); 187 186 188 - strcpy(mod->name, modname); 189 - mod->is_vmlinux = (strcmp(modname, "vmlinux") == 0); 187 + memcpy(mod->name, name, namelen); 188 + mod->name[namelen] = '\0'; 189 + mod->is_vmlinux = (strcmp(mod->name, "vmlinux") == 0); 190 190 191 191 /* 192 192 * Set mod->is_gpl_compatible to true by default. If MODULE_LICENSE() ··· 214 212 unsigned int crc; 215 213 bool crc_valid; 216 214 bool weak; 217 - bool is_static; /* true if symbol is not global */ 218 215 bool is_gpl_only; /* exported by EXPORT_SYMBOL_GPL */ 219 216 char name[]; 220 217 }; ··· 243 242 244 243 memset(s, 0, sizeof(*s)); 245 244 strcpy(s->name, name); 246 - s->is_static = true; 245 + 247 246 return s; 248 247 } 249 248 ··· 711 710 return get_next_modinfo(info, tag, NULL); 712 711 } 713 712 714 - /** 715 - * Test if string s ends in string sub 716 - * return 0 if match 717 - **/ 718 - static int strrcmp(const char *s, const char *sub) 719 - { 720 - int slen, sublen; 721 - 722 - if (!s || !sub) 723 - return 1; 724 - 725 - slen = strlen(s); 726 - sublen = strlen(sub); 727 - 728 - if ((slen == 0) || (sublen == 0)) 729 - return 1; 730 - 731 - if (sublen > slen) 732 - return 1; 733 - 734 - return memcmp(s + slen - sublen, sub, sublen); 735 - } 736 - 737 713 static const char *sym_name(struct elf_info *elf, Elf_Sym *sym) 738 714 { 739 715 if (sym) ··· 719 741 return "(unknown)"; 720 742 } 721 743 722 - /* The pattern is an array of simple patterns. 723 - * "foo" will match an exact string equal to "foo" 724 - * "*foo" will match a string that ends with "foo" 725 - * "foo*" will match a string that begins with "foo" 726 - * "*foo*" will match a string that contains "foo" 744 + /* 745 + * Check whether the 'string' argument matches one of the 'patterns', 746 + * an array of shell wildcard patterns (glob). 747 + * 748 + * Return true is there is a match. 727 749 */ 728 - static int match(const char *sym, const char * const pat[]) 750 + static bool match(const char *string, const char *const patterns[]) 729 751 { 730 - const char *p; 731 - while (*pat) { 732 - const char *endp; 752 + const char *pattern; 733 753 734 - p = *pat++; 735 - endp = p + strlen(p) - 1; 736 - 737 - /* "*foo*" */ 738 - if (*p == '*' && *endp == '*') { 739 - char *bare = NOFAIL(strndup(p + 1, strlen(p) - 2)); 740 - char *here = strstr(sym, bare); 741 - 742 - free(bare); 743 - if (here != NULL) 744 - return 1; 745 - } 746 - /* "*foo" */ 747 - else if (*p == '*') { 748 - if (strrcmp(sym, p + 1) == 0) 749 - return 1; 750 - } 751 - /* "foo*" */ 752 - else if (*endp == '*') { 753 - if (strncmp(sym, p, strlen(p) - 1) == 0) 754 - return 1; 755 - } 756 - /* no wildcards */ 757 - else { 758 - if (strcmp(p, sym) == 0) 759 - return 1; 760 - } 754 + while ((pattern = *patterns++)) { 755 + if (!fnmatch(pattern, string, 0)) 756 + return true; 761 757 } 762 - /* no match */ 763 - return 0; 758 + 759 + return false; 764 760 } 765 761 766 762 /* sections that we do not want to do full section mismatch check on */ ··· 1001 1049 const char *fromsec, const char *tosec) 1002 1050 { 1003 1051 int i; 1004 - int elems = sizeof(sectioncheck) / sizeof(struct sectioncheck); 1005 - const struct sectioncheck *check = &sectioncheck[0]; 1006 1052 1007 1053 /* 1008 1054 * The target section could be the SHT_NUL section when we're ··· 1011 1061 if (*tosec == '\0') 1012 1062 return NULL; 1013 1063 1014 - for (i = 0; i < elems; i++) { 1064 + for (i = 0; i < ARRAY_SIZE(sectioncheck); i++) { 1065 + const struct sectioncheck *check = &sectioncheck[i]; 1066 + 1015 1067 if (match(fromsec, check->fromsec)) { 1016 1068 if (check->bad_tosec[0] && match(tosec, check->bad_tosec)) 1017 1069 return check; 1018 1070 if (check->good_tosec[0] && !match(tosec, check->good_tosec)) 1019 1071 return check; 1020 1072 } 1021 - check++; 1022 1073 } 1023 1074 return NULL; 1024 1075 } ··· 1131 1180 1132 1181 static inline int is_arm_mapping_symbol(const char *str) 1133 1182 { 1134 - return str[0] == '$' && strchr("axtd", str[1]) 1183 + return str[0] == '$' && 1184 + (str[1] == 'a' || str[1] == 'd' || str[1] == 't' || str[1] == 'x') 1135 1185 && (str[2] == '\0' || str[2] == '.'); 1136 1186 } 1137 1187 ··· 1222 1270 continue; 1223 1271 if (!is_valid_name(elf, sym)) 1224 1272 continue; 1225 - if (sym->st_value <= addr) { 1226 - if ((addr - sym->st_value) < distance) { 1227 - distance = addr - sym->st_value; 1228 - near = sym; 1229 - } else if ((addr - sym->st_value) == distance) { 1230 - near = sym; 1231 - } 1273 + if (sym->st_value <= addr && addr - sym->st_value <= distance) { 1274 + distance = addr - sym->st_value; 1275 + near = sym; 1232 1276 } 1233 1277 } 1234 1278 return near; ··· 1831 1883 * to find all references to a section that reference a section that will 1832 1884 * be discarded and warns about it. 1833 1885 **/ 1834 - static void check_sec_ref(struct module *mod, const char *modname, 1835 - struct elf_info *elf) 1886 + static void check_sec_ref(const char *modname, struct elf_info *elf) 1836 1887 { 1837 1888 int i; 1838 1889 Elf_Shdr *sechdrs = elf->sechdrs; ··· 1853 1906 1854 1907 if (n && s[n]) { 1855 1908 size_t m = strspn(s + n + 1, "0123456789"); 1856 - if (m && (s[n + m] == '.' || s[n + m] == 0)) 1909 + if (m && (s[n + m + 1] == '.' || s[n + m + 1] == 0)) 1857 1910 s[n] = 0; 1858 - 1859 - /* strip trailing .prelink */ 1860 - if (strends(s, ".prelink")) 1861 - s[strlen(s) - 8] = '\0'; 1862 1911 } 1863 1912 return s; 1864 1913 } ··· 1970 2027 if (!parse_elf(&info, modname)) 1971 2028 return; 1972 2029 1973 - { 1974 - char *tmp; 1975 - 1976 - /* strip trailing .o */ 1977 - tmp = NOFAIL(strdup(modname)); 1978 - tmp[strlen(tmp) - 2] = '\0'; 1979 - /* strip trailing .prelink */ 1980 - if (strends(tmp, ".prelink")) 1981 - tmp[strlen(tmp) - 8] = '\0'; 1982 - mod = new_module(tmp); 1983 - free(tmp); 2030 + if (!strends(modname, ".o")) { 2031 + error("%s: filename must be suffixed with .o\n", modname); 2032 + return; 1984 2033 } 2034 + 2035 + /* strip trailing .o */ 2036 + mod = new_module(modname, strlen(modname) - strlen(".o")); 1985 2037 1986 2038 if (!mod->is_vmlinux) { 1987 2039 license = get_modinfo(&info, "license"); ··· 2014 2076 sym_get_data(&info, sym)); 2015 2077 } 2016 2078 2017 - // check for static EXPORT_SYMBOL_* functions && global vars 2018 - for (sym = info.symtab_start; sym < info.symtab_stop; sym++) { 2019 - unsigned char bind = ELF_ST_BIND(sym->st_info); 2020 - 2021 - if (bind == STB_GLOBAL || bind == STB_WEAK) { 2022 - struct symbol *s = 2023 - find_symbol(remove_dot(info.strtab + 2024 - sym->st_name)); 2025 - 2026 - if (s) 2027 - s->is_static = false; 2028 - } 2029 - } 2030 - 2031 - check_sec_ref(mod, modname, &info); 2079 + check_sec_ref(modname, &info); 2032 2080 2033 2081 if (!mod->is_vmlinux) { 2034 2082 version = get_modinfo(&info, "version"); ··· 2439 2515 2440 2516 mod = find_module(modname); 2441 2517 if (!mod) { 2442 - mod = new_module(modname); 2518 + mod = new_module(modname, strlen(modname)); 2443 2519 mod->from_dump = true; 2444 2520 } 2445 2521 s = sym_add_exported(symname, mod, gpl_only); 2446 - s->is_static = false; 2447 2522 sym_set_crc(s, crc); 2448 2523 sym_update_namespace(symname, namespace); 2449 2524 } ··· 2507 2584 char *missing_namespace_deps = NULL; 2508 2585 char *dump_write = NULL, *files_source = NULL; 2509 2586 int opt; 2510 - int n; 2511 2587 LIST_HEAD(dump_lists); 2512 2588 struct dump_list *dl, *dl2; 2513 2589 ··· 2582 2660 if (sec_mismatch_count && !sec_mismatch_warn_only) 2583 2661 error("Section mismatches detected.\n" 2584 2662 "Set CONFIG_SECTION_MISMATCH_WARN_ONLY=y to allow them.\n"); 2585 - for (n = 0; n < SYMBOL_HASH_SIZE; n++) { 2586 - struct symbol *s; 2587 - 2588 - for (s = symbolhash[n]; s; s = s->next) { 2589 - if (s->is_static) 2590 - error("\"%s\" [%s] is a static EXPORT_SYMBOL\n", 2591 - s->name, s->module->name); 2592 - } 2593 - } 2594 2663 2595 2664 if (nr_unresolved > MAX_UNRESOLVED_REPORTS) 2596 2665 warn("suppressed %u unresolved symbol warnings because there were too many)\n",
+3
scripts/mod/modpost.h
··· 97 97 #endif 98 98 99 99 #define NOFAIL(ptr) do_nofail((ptr), #ptr) 100 + 101 + #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) 102 + 100 103 void *do_nofail(void *ptr, const char *expr); 101 104 102 105 struct buffer {
+3 -3
scripts/objdiff
··· 20 20 # $ ./scripts/objdiff diff COMMIT_A COMMIT_B 21 21 # $ 22 22 23 - # And to clean up (everything is in .tmp_objdiff/*) 23 + # And to clean up (everything is in .objdiff/*) 24 24 # $ ./scripts/objdiff clean all 25 25 # 26 - # Note: 'make mrproper' will also remove .tmp_objdiff 26 + # Note: 'make mrproper' will also remove .objdiff 27 27 28 28 SRCTREE=$(cd $(git rev-parse --show-toplevel 2>/dev/null); pwd) 29 29 ··· 32 32 exit 1 33 33 fi 34 34 35 - TMPD=$SRCTREE/.tmp_objdiff 35 + TMPD=$SRCTREE/.objdiff 36 36 37 37 usage() { 38 38 echo >&2 "Usage: $0 <command> <args>"