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

Merge tag 'kbuild-v5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild

Pull Kbuild updates from Masahiro Yamada:

- Add HOSTPKG_CONFIG env variable to allow users to override pkg-config

- Support W=e as a shorthand for KCFLAGS=-Werror

- Fix CONFIG_IKHEADERS build to support toybox cpio

- Add scripts/dummy-tools/pahole to ease distro packagers' life

- Suppress false-positive warnings from checksyscalls.sh for W=2 build

- Factor out the common code of arch/*/boot/install.sh into
scripts/install.sh

- Support 'kernel-install' tool in scripts/prune-kernel

- Refactor module-versioning to link the symbol versions at the final
link of vmlinux and modules

- Remove CONFIG_MODULE_REL_CRCS because module-versioning now works in
an arch-agnostic way

- Refactor modpost, Makefiles

* tag 'kbuild-v5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: (56 commits)
genksyms: adjust the output format to modpost
kbuild: stop merging *.symversions
kbuild: link symbol CRCs at final link, removing CONFIG_MODULE_REL_CRCS
modpost: extract symbol versions from *.cmd files
modpost: add sym_find_with_module() helper
modpost: change the license of EXPORT_SYMBOL to bool type
modpost: remove left-over cross_compile declaration
kbuild: record symbol versions in *.cmd files
kbuild: generate a list of objects in vmlinux
modpost: move *.mod.c generation to write_mod_c_files()
modpost: merge add_{intree_flag,retpoline,staging_flag} to add_header
scripts/prune-kernel: Use kernel-install if available
kbuild: factor out the common installation code into scripts/install.sh
modpost: split new_symbol() to symbol allocation and hash table addition
modpost: make sym_add_exported() always allocate a new symbol
modpost: make multiple export error
modpost: dump Module.symvers in the same order of modules.order
modpost: traverse the namespace_list in order
modpost: use doubly linked list for dump_lists
modpost: traverse unresolved symbols in order
...

+875 -845
+1
.gitignore
··· 45 45 *.symversions 46 46 *.tab.[ch] 47 47 *.tar 48 + *.usyms 48 49 *.xz 49 50 *.zst 50 51 Module.symvers
+6
Documentation/kbuild/kconfig-language.rst
··· 693 693 semantics is welcomed. One project deduced Kconfig semantics through 694 694 the use of the xconfig configurator [1]_. Work should be done to confirm if 695 695 the deduced semantics matches our intended Kconfig design goals. 696 + Another project formalized a denotational semantics of a core subset of 697 + the Kconfig language [10]_. 696 698 697 699 Having well defined semantics can be useful for tools for practical 698 700 evaluation of dependencies, for instance one such case was work to ··· 702 700 translate Kconfig logic into boolean formulas and run a SAT solver on this to 703 701 find dead code / features (always inactive), 114 dead features were found in 704 702 Linux using this methodology [1]_ (Section 8: Threats to validity). 703 + The kismet tool, based on the semantics in [10]_, finds abuses of reverse 704 + dependencies and has led to dozens of committed fixes to Linux Kconfig files [11]_. 705 705 706 706 Confirming this could prove useful as Kconfig stands as one of the leading 707 707 industrial variability modeling languages [1]_ [2]_. Its study would help ··· 742 738 .. [7] https://vamos.cs.fau.de 743 739 .. [8] https://undertaker.cs.fau.de 744 740 .. [9] https://www4.cs.fau.de/Publications/2011/tartler_11_eurosys.pdf 741 + .. [10] https://paulgazzillo.com/papers/esecfse21.pdf 742 + .. [11] https://github.com/paulgazz/kmax
+10 -6
Makefile
··· 436 436 HOSTCC = gcc 437 437 HOSTCXX = g++ 438 438 endif 439 + HOSTPKG_CONFIG = pkg-config 439 440 440 441 KBUILD_USERHOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \ 441 442 -O2 -fomit-frame-pointer -std=gnu11 \ ··· 534 533 KBUILD_LDFLAGS := 535 534 CLANG_FLAGS := 536 535 537 - export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC 536 + export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC HOSTPKG_CONFIG 538 537 export CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL 539 538 export PERL PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX 540 539 export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ ZSTD ··· 1295 1294 # Install 1296 1295 1297 1296 # Many distributions have the custom install script, /sbin/installkernel. 1298 - # If DKMS is installed, 'make install' will eventually recuses back 1299 - # to the this Makefile to build and install external modules. 1297 + # If DKMS is installed, 'make install' will eventually recurse back 1298 + # to this Makefile to build and install external modules. 1300 1299 # Cancel sub_make_done so that options such as M=, V=, etc. are parsed. 1301 1300 1302 - install: sub_make_done := 1301 + quiet_cmd_install = INSTALL $(INSTALL_PATH) 1302 + cmd_install = unset sub_make_done; $(srctree)/scripts/install.sh 1303 1303 1304 1304 # --------------------------------------------------------------------------- 1305 1305 # Tools ··· 1652 1650 @echo ' 1: warnings which may be relevant and do not occur too often' 1653 1651 @echo ' 2: warnings which occur quite often but may still be relevant' 1654 1652 @echo ' 3: more obscure warnings, can most likely be ignored' 1653 + @echo ' e: warnings are being treated as errors' 1655 1654 @echo ' Multiple levels can be combined with W=12 or W=123' 1656 1655 @echo '' 1657 1656 @echo 'Execute "make" or "make all" to build all targets marked with [*] ' ··· 1795 1792 1796 1793 # .ko is special because modpost is needed 1797 1794 single-ko := $(sort $(filter %.ko, $(MAKECMDGOALS))) 1798 - single-no-ko := $(sort $(patsubst %.ko,%.mod, $(MAKECMDGOALS))) 1795 + single-no-ko := $(filter-out $(single-ko), $(MAKECMDGOALS)) \ 1796 + $(foreach x, o mod, $(patsubst %.ko, %.$x, $(single-ko))) 1799 1797 1800 1798 $(single-ko): single_modpost 1801 1799 @: ··· 1852 1848 -o -name '*.ko.*' \ 1853 1849 -o -name '*.dtb' -o -name '*.dtbo' -o -name '*.dtb.S' -o -name '*.dt.yaml' \ 1854 1850 -o -name '*.dwo' -o -name '*.lst' \ 1855 - -o -name '*.su' -o -name '*.mod' \ 1851 + -o -name '*.su' -o -name '*.mod' -o -name '*.usyms' \ 1856 1852 -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ 1857 1853 -o -name '*.lex.c' -o -name '*.tab.[ch]' \ 1858 1854 -o -name '*.asn1.[ch]' \
+2 -2
arch/arm/Makefile
··· 312 312 $(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $(boot)/$@ 313 313 @$(kecho) ' Kernel: $(boot)/$@ is ready' 314 314 315 + $(INSTALL_TARGETS): KBUILD_IMAGE = $(boot)/$(patsubst %install,%Image,$@) 315 316 $(INSTALL_TARGETS): 316 - $(CONFIG_SHELL) $(srctree)/$(boot)/install.sh "$(KERNELRELEASE)" \ 317 - $(boot)/$(patsubst %install,%Image,$@) System.map "$(INSTALL_PATH)" 317 + $(call cmd,install) 318 318 319 319 PHONY += vdso_install 320 320 vdso_install:
-21
arch/arm/boot/install.sh
··· 1 1 #!/bin/sh 2 2 # 3 - # arch/arm/boot/install.sh 4 - # 5 3 # This file is subject to the terms and conditions of the GNU General Public 6 4 # License. See the file "COPYING" in the main directory of this archive 7 5 # for more details. ··· 16 18 # $2 - kernel image file 17 19 # $3 - kernel map file 18 20 # $4 - default install path (blank if root directory) 19 - # 20 - 21 - verify () { 22 - if [ ! -f "$1" ]; then 23 - echo "" 1>&2 24 - echo " *** Missing file: $1" 1>&2 25 - echo ' *** You need to run "make" before "make install".' 1>&2 26 - echo "" 1>&2 27 - exit 1 28 - fi 29 - } 30 - 31 - # Make sure the files actually exist 32 - verify "$2" 33 - verify "$3" 34 - 35 - # User may have a custom install script 36 - if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi 37 - if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi 38 21 39 22 if [ "$(basename $2)" = "zImage" ]; then 40 23 # Compressed install
+2 -4
arch/arm64/Makefile
··· 162 162 Image.%: Image 163 163 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ 164 164 165 - install: install-image := Image 166 - zinstall: install-image := Image.gz 165 + install: KBUILD_IMAGE := $(boot)/Image 167 166 install zinstall: 168 - $(CONFIG_SHELL) $(srctree)/$(boot)/install.sh $(KERNELRELEASE) \ 169 - $(boot)/$(install-image) System.map "$(INSTALL_PATH)" 167 + $(call cmd,install) 170 168 171 169 PHONY += vdso_install 172 170 vdso_install:
-21
arch/arm64/boot/install.sh
··· 1 1 #!/bin/sh 2 2 # 3 - # arch/arm64/boot/install.sh 4 - # 5 3 # This file is subject to the terms and conditions of the GNU General Public 6 4 # License. See the file "COPYING" in the main directory of this archive 7 5 # for more details. ··· 16 18 # $2 - kernel image file 17 19 # $3 - kernel map file 18 20 # $4 - default install path (blank if root directory) 19 - # 20 - 21 - verify () { 22 - if [ ! -f "$1" ]; then 23 - echo "" 1>&2 24 - echo " *** Missing file: $1" 1>&2 25 - echo ' *** You need to run "make" before "make install".' 1>&2 26 - echo "" 1>&2 27 - exit 1 28 - fi 29 - } 30 - 31 - # Make sure the files actually exist 32 - verify "$2" 33 - verify "$3" 34 - 35 - # User may have a custom install script 36 - if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi 37 - if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi 38 21 39 22 if [ "$(basename $2)" = "Image.gz" ]; then 40 23 # Compressed install
+3 -2
arch/ia64/Makefile
··· 72 72 73 73 CLEAN_FILES += vmlinux.gz 74 74 75 - install: vmlinux.gz 76 - sh $(srctree)/arch/ia64/install.sh $(KERNELRELEASE) $< System.map "$(INSTALL_PATH)" 75 + install: KBUILD_IMAGE := vmlinux.gz 76 + install: 77 + $(call cmd,install) 77 78 78 79 define archhelp 79 80 echo '* compressed - Build compressed kernel image'
-10
arch/ia64/install.sh
··· 1 1 #!/bin/sh 2 2 # 3 - # arch/ia64/install.sh 4 - # 5 3 # This file is subject to the terms and conditions of the GNU General Public 6 4 # License. See the file "COPYING" in the main directory of this archive 7 5 # for more details. ··· 15 17 # $2 - kernel image file 16 18 # $3 - kernel map file 17 19 # $4 - default install path (blank if root directory) 18 - # 19 - 20 - # User may have a custom install script 21 - 22 - if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi 23 - if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi 24 - 25 - # Default install - same as make zlilo 26 20 27 21 if [ -f $4/vmlinuz ]; then 28 22 mv $4/vmlinuz $4/vmlinuz.old
+2 -1
arch/m68k/Makefile
··· 138 138 archheaders: 139 139 $(Q)$(MAKE) $(build)=arch/m68k/kernel/syscalls all 140 140 141 + install: KBUILD_IMAGE := vmlinux.gz 141 142 install: 142 - sh $(srctree)/arch/m68k/install.sh $(KERNELRELEASE) vmlinux.gz System.map "$(INSTALL_PATH)" 143 + $(call cmd,install)
+1
arch/m68k/include/asm/Kbuild
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 generated-y += syscall_table.h 3 + generic-y += export.h 3 4 generic-y += extable.h 4 5 generic-y += kvm_para.h 5 6 generic-y += mcs_spinlock.h
-2
arch/m68k/include/asm/export.h
··· 1 - #define KCRC_ALIGN 2 2 - #include <asm-generic/export.h>
-22
arch/m68k/install.sh
··· 15 15 # $2 - kernel image file 16 16 # $3 - kernel map file 17 17 # $4 - default install path (blank if root directory) 18 - # 19 - 20 - verify () { 21 - if [ ! -f "$1" ]; then 22 - echo "" 1>&2 23 - echo " *** Missing file: $1" 1>&2 24 - echo ' *** You need to run "make" before "make install".' 1>&2 25 - echo "" 1>&2 26 - exit 1 27 - fi 28 - } 29 - 30 - # Make sure the files actually exist 31 - verify "$2" 32 - verify "$3" 33 - 34 - # User may have a custom install script 35 - 36 - if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi 37 - if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi 38 - 39 - # Default install - same as make zlilo 40 18 41 19 if [ -f $4/vmlinuz ]; then 42 20 mv $4/vmlinuz $4/vmlinuz.old
+1 -2
arch/nios2/Makefile
··· 56 56 $(Q)$(MAKE) $(build)=$(nios2-boot) $(nios2-boot)/$@ 57 57 58 58 install: 59 - sh $(srctree)/$(nios2-boot)/install.sh $(KERNELRELEASE) \ 60 - $(KBUILD_IMAGE) System.map "$(INSTALL_PATH)" 59 + $(call cmd,install) 61 60 62 61 define archhelp 63 62 echo '* vmImage - Kernel-only image for U-Boot ($(KBUILD_IMAGE))'
-22
arch/nios2/boot/install.sh
··· 15 15 # $2 - kernel image file 16 16 # $3 - kernel map file 17 17 # $4 - default install path (blank if root directory) 18 - # 19 - 20 - verify () { 21 - if [ ! -f "$1" ]; then 22 - echo "" 1>&2 23 - echo " *** Missing file: $1" 1>&2 24 - echo ' *** You need to run "make" before "make install".' 1>&2 25 - echo "" 1>&2 26 - exit 1 27 - fi 28 - } 29 - 30 - # Make sure the files actually exist 31 - verify "$2" 32 - verify "$3" 33 - 34 - # User may have a custom install script 35 - 36 - if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi 37 - if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi 38 - 39 - # Default install - same as make zlilo 40 18 41 19 if [ -f $4/vmlinuz ]; then 42 20 mv $4/vmlinuz $4/vmlinuz.old
+5 -6
arch/parisc/Makefile
··· 184 184 $(Q)$(MAKE) $(build)=arch/parisc/kernel/vdso $@ 185 185 $(if $(CONFIG_COMPAT_VDSO), \ 186 186 $(Q)$(MAKE) $(build)=arch/parisc/kernel/vdso32 $@) 187 - install: 188 - $(CONFIG_SHELL) $(srctree)/arch/parisc/install.sh \ 189 - $(KERNELRELEASE) vmlinux System.map "$(INSTALL_PATH)" 190 - zinstall: 191 - $(CONFIG_SHELL) $(srctree)/arch/parisc/install.sh \ 192 - $(KERNELRELEASE) vmlinuz System.map "$(INSTALL_PATH)" 187 + 188 + install: KBUILD_IMAGE := vmlinux 189 + zinstall: KBUILD_IMAGE := vmlinuz 190 + install zinstall: 191 + $(call cmd,install) 193 192 194 193 CLEAN_FILES += lifimage 195 194 MRPROPER_FILES += palo.conf
-28
arch/parisc/install.sh
··· 1 1 #!/bin/sh 2 2 # 3 - # arch/parisc/install.sh, derived from arch/i386/boot/install.sh 4 - # 5 3 # This file is subject to the terms and conditions of the GNU General Public 6 4 # License. See the file "COPYING" in the main directory of this archive 7 5 # for more details. ··· 15 17 # $2 - kernel image file 16 18 # $3 - kernel map file 17 19 # $4 - default install path (blank if root directory) 18 - # 19 - 20 - verify () { 21 - if [ ! -f "$1" ]; then 22 - echo "" 1>&2 23 - echo " *** Missing file: $1" 1>&2 24 - echo ' *** You need to run "make" before "make install".' 1>&2 25 - echo "" 1>&2 26 - exit 1 27 - fi 28 - } 29 - 30 - # Make sure the files actually exist 31 - 32 - verify "$2" 33 - verify "$3" 34 - 35 - # User may have a custom install script 36 - 37 - if [ -n "${INSTALLKERNEL}" ]; then 38 - if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi 39 - if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi 40 - if [ -x /usr/sbin/${INSTALLKERNEL} ]; then exec /usr/sbin/${INSTALLKERNEL} "$@"; fi 41 - fi 42 - 43 - # Default install 44 20 45 21 if [ "$(basename $2)" = "vmlinuz" ]; then 46 22 # Compressed install
-1
arch/powerpc/Kconfig
··· 566 566 bool "Build a relocatable kernel" 567 567 depends on PPC64 || (FLATMEM && (44x || FSL_BOOKE)) 568 568 select NONSTATIC_KERNEL 569 - select MODULE_REL_CRCS if MODVERSIONS 570 569 help 571 570 This builds a kernel image that is capable of running at the 572 571 location the kernel is loaded at. For ppc32, there is no any
+1 -2
arch/powerpc/Makefile
··· 408 408 409 409 PHONY += install 410 410 install: 411 - sh -x $(srctree)/$(boot)/install.sh "$(KERNELRELEASE)" vmlinux \ 412 - System.map "$(INSTALL_PATH)" 411 + $(call cmd,install) 413 412 414 413 ifeq ($(KBUILD_EXTMOD),) 415 414 # We need to generate vdso-offsets.h before compiling certain files in kernel/.
+2 -2
arch/powerpc/boot/Makefile
··· 453 453 clean-kernel-base := vmlinux.strip vmlinux.bin 454 454 clean-kernel := $(addsuffix .gz,$(clean-kernel-base)) 455 455 clean-kernel += $(addsuffix .xz,$(clean-kernel-base)) 456 - # If not absolute clean-files are relative to $(obj). 457 - clean-files += $(addprefix $(objtree)/, $(clean-kernel)) 456 + # clean-files are relative to $(obj). 457 + clean-files += $(addprefix ../../../, $(clean-kernel)) 458 458 459 459 WRAPPER_OBJDIR := /usr/lib/kernel-wrapper 460 460 WRAPPER_DTSDIR := /usr/lib/kernel-wrapper/dts
-23
arch/powerpc/boot/install.sh
··· 15 15 # $2 - kernel image file 16 16 # $3 - kernel map file 17 17 # $4 - default install path (blank if root directory) 18 - # 19 18 20 - # Bail with error code if anything goes wrong 21 19 set -e 22 - 23 - verify () { 24 - if [ ! -f "$1" ]; then 25 - echo "" 1>&2 26 - echo " *** Missing file: $1" 1>&2 27 - echo ' *** You need to run "make" before "make install".' 1>&2 28 - echo "" 1>&2 29 - exit 1 30 - fi 31 - } 32 - 33 - # Make sure the files actually exist 34 - verify "$2" 35 - verify "$3" 36 - 37 - # User may have a custom install script 38 - 39 - if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi 40 - if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi 41 - 42 - # Default install 43 20 44 21 # this should work for both the pSeries zImage and the iSeries vmlinux.sm 45 22 image_name=`basename $2`
+3 -4
arch/riscv/Makefile
··· 139 139 Image.%: Image 140 140 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ 141 141 142 - install: install-image = Image 143 - zinstall: install-image = Image.gz 142 + install: KBUILD_IMAGE := $(boot)/Image 143 + zinstall: KBUILD_IMAGE := $(boot)/Image.gz 144 144 install zinstall: 145 - $(CONFIG_SHELL) $(srctree)/$(boot)/install.sh $(KERNELRELEASE) \ 146 - $(boot)/$(install-image) System.map "$(INSTALL_PATH)" 145 + $(call cmd,install) 147 146 148 147 PHONY += rv32_randconfig 149 148 rv32_randconfig:
-21
arch/riscv/boot/install.sh
··· 1 1 #!/bin/sh 2 2 # 3 - # arch/riscv/boot/install.sh 4 - # 5 3 # This file is subject to the terms and conditions of the GNU General Public 6 4 # License. See the file "COPYING" in the main directory of this archive 7 5 # for more details. ··· 16 18 # $2 - kernel image file 17 19 # $3 - kernel map file 18 20 # $4 - default install path (blank if root directory) 19 - # 20 - 21 - verify () { 22 - if [ ! -f "$1" ]; then 23 - echo "" 1>&2 24 - echo " *** Missing file: $1" 1>&2 25 - echo ' *** You need to run "make" before "make install".' 1>&2 26 - echo "" 1>&2 27 - exit 1 28 - fi 29 - } 30 - 31 - # Make sure the files actually exist 32 - verify "$2" 33 - verify "$3" 34 - 35 - # User may have a custom install script 36 - if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi 37 - if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi 38 21 39 22 if [ "$(basename $2)" = "Image.gz" ]; then 40 23 # Compressed install
-1
arch/s390/Kconfig
··· 586 586 587 587 config RELOCATABLE 588 588 bool "Build a relocatable kernel" 589 - select MODULE_REL_CRCS if MODVERSIONS 590 589 default y 591 590 help 592 591 This builds a kernel image that retains relocation information
+1 -2
arch/s390/Makefile
··· 142 142 KBUILD_IMAGE := $(boot)/bzImage 143 143 144 144 install: 145 - sh -x $(srctree)/$(boot)/install.sh $(KERNELRELEASE) $(KBUILD_IMAGE) \ 146 - System.map "$(INSTALL_PATH)" 145 + $(call cmd,install) 147 146 148 147 bzImage: vmlinux 149 148 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
-6
arch/s390/boot/install.sh
··· 14 14 # $2 - kernel image file 15 15 # $3 - kernel map file 16 16 # $4 - default install path (blank if root directory) 17 - # 18 - 19 - # User may have a custom install script 20 - 21 - if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi 22 - if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi 23 17 24 18 echo "Warning: '${INSTALLKERNEL}' command not available - additional " \ 25 19 "bootloader config required" >&2
+1 -2
arch/sparc/Makefile
··· 72 72 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ 73 73 74 74 install: 75 - sh $(srctree)/$(boot)/install.sh $(KERNELRELEASE) $(KBUILD_IMAGE) \ 76 - System.map "$(INSTALL_PATH)" 75 + $(call cmd,install) 77 76 78 77 archheaders: 79 78 $(Q)$(MAKE) $(build)=arch/sparc/kernel/syscalls all
-22
arch/sparc/boot/install.sh
··· 15 15 # $2 - kernel image file 16 16 # $3 - kernel map file 17 17 # $4 - default install path (blank if root directory) 18 - # 19 - 20 - verify () { 21 - if [ ! -f "$1" ]; then 22 - echo "" 1>&2 23 - echo " *** Missing file: $1" 1>&2 24 - echo ' *** You need to run "make" before "make install".' 1>&2 25 - echo "" 1>&2 26 - exit 1 27 - fi 28 - } 29 - 30 - # Make sure the files actually exist 31 - verify "$2" 32 - verify "$3" 33 - 34 - # User may have a custom install script 35 - 36 - if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi 37 - if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi 38 - 39 - # Default install - same as make zlilo 40 18 41 19 if [ -f $4/vmlinuz ]; then 42 20 mv $4/vmlinuz $4/vmlinuz.old
-1
arch/um/Kconfig
··· 106 106 bool 107 107 default y 108 108 depends on !LD_SCRIPT_STATIC 109 - select MODULE_REL_CRCS if MODVERSIONS 110 109 111 110 config LD_SCRIPT_DYN_RPATH 112 111 bool "set rpath in the binary" if EXPERT
+1 -2
arch/x86/Makefile
··· 271 271 272 272 PHONY += install 273 273 install: 274 - $(CONFIG_SHELL) $(srctree)/$(boot)/install.sh $(KERNELRELEASE) \ 275 - $(KBUILD_IMAGE) System.map "$(INSTALL_PATH)" 274 + $(call cmd,install) 276 275 277 276 PHONY += vdso_install 278 277 vdso_install:
-22
arch/x86/boot/install.sh
··· 15 15 # $2 - kernel image file 16 16 # $3 - kernel map file 17 17 # $4 - default install path (blank if root directory) 18 - # 19 - 20 - verify () { 21 - if [ ! -f "$1" ]; then 22 - echo "" 1>&2 23 - echo " *** Missing file: $1" 1>&2 24 - echo ' *** You need to run "make" before "make install".' 1>&2 25 - echo "" 1>&2 26 - exit 1 27 - fi 28 - } 29 - 30 - # Make sure the files actually exist 31 - verify "$2" 32 - verify "$3" 33 - 34 - # User may have a custom install script 35 - 36 - if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi 37 - if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi 38 - 39 - # Default install - same as make zlilo 40 18 41 19 if [ -f $4/vmlinuz ]; then 42 20 mv $4/vmlinuz $4/vmlinuz.old
+2 -2
certs/Makefile
··· 86 86 87 87 hostprogs := extract-cert 88 88 89 - HOSTCFLAGS_extract-cert.o = $(shell pkg-config --cflags libcrypto 2> /dev/null) 90 - HOSTLDLIBS_extract-cert = $(shell pkg-config --libs libcrypto 2> /dev/null || echo -lcrypto) 89 + HOSTCFLAGS_extract-cert.o = $(shell $(HOSTPKG_CONFIG) --cflags libcrypto 2> /dev/null) 90 + HOSTLDLIBS_extract-cert = $(shell $(HOSTPKG_CONFIG) --libs libcrypto 2> /dev/null || echo -lcrypto)
+8 -14
include/asm-generic/export.h
··· 2 2 #ifndef __ASM_GENERIC_EXPORT_H 3 3 #define __ASM_GENERIC_EXPORT_H 4 4 5 + /* 6 + * This comment block is used by fixdep. Please do not remove. 7 + * 8 + * When CONFIG_MODVERSIONS is changed from n to y, all source files having 9 + * EXPORT_SYMBOL variants must be re-compiled because genksyms is run as a 10 + * side effect of the *.o build rule. 11 + */ 12 + 5 13 #ifndef KSYM_FUNC 6 14 #define KSYM_FUNC(x) x 7 15 #endif ··· 19 11 #define KSYM_ALIGN 8 20 12 #else 21 13 #define KSYM_ALIGN 4 22 - #endif 23 - #ifndef KCRC_ALIGN 24 - #define KCRC_ALIGN 4 25 14 #endif 26 15 27 16 .macro __put, val, name ··· 48 43 __kstrtab_\name: 49 44 .asciz "\name" 50 45 .previous 51 - #ifdef CONFIG_MODVERSIONS 52 - .section ___kcrctab\sec+\name,"a" 53 - .balign KCRC_ALIGN 54 - #if defined(CONFIG_MODULE_REL_CRCS) 55 - .long __crc_\name - . 56 - #else 57 - .long __crc_\name 58 - #endif 59 - .weak __crc_\name 60 - .previous 61 - #endif 62 46 #endif 63 47 .endm 64 48
+17
include/linux/export-internal.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* 3 + * Please do not include this explicitly. 4 + * This is used by C files generated by modpost. 5 + */ 6 + 7 + #ifndef __LINUX_EXPORT_INTERNAL_H__ 8 + #define __LINUX_EXPORT_INTERNAL_H__ 9 + 10 + #include <linux/compiler.h> 11 + #include <linux/types.h> 12 + 13 + /* __used is needed to keep __crc_* for LTO */ 14 + #define SYMBOL_CRC(sym, crc, sec) \ 15 + u32 __section("___kcrctab" sec "+" #sym) __used __crc_##sym = crc 16 + 17 + #endif /* __LINUX_EXPORT_INTERNAL_H__ */
+8 -22
include/linux/export.h
··· 11 11 * hackers place grumpy comments in header files. 12 12 */ 13 13 14 + /* 15 + * This comment block is used by fixdep. Please do not remove. 16 + * 17 + * When CONFIG_MODVERSIONS is changed from n to y, all source files having 18 + * EXPORT_SYMBOL variants must be re-compiled because genksyms is run as a 19 + * side effect of the *.o build rule. 20 + */ 21 + 14 22 #ifndef __ASSEMBLY__ 15 23 #ifdef MODULE 16 24 extern struct module __this_module; 17 25 #define THIS_MODULE (&__this_module) 18 26 #else 19 27 #define THIS_MODULE ((struct module *)0) 20 - #endif 21 - 22 - #ifdef CONFIG_MODVERSIONS 23 - /* Mark the CRC weak since genksyms apparently decides not to 24 - * generate a checksums for some symbols */ 25 - #if defined(CONFIG_MODULE_REL_CRCS) 26 - #define __CRC_SYMBOL(sym, sec) \ 27 - asm(" .section \"___kcrctab" sec "+" #sym "\", \"a\" \n" \ 28 - " .weak __crc_" #sym " \n" \ 29 - " .long __crc_" #sym " - . \n" \ 30 - " .previous \n") 31 - #else 32 - #define __CRC_SYMBOL(sym, sec) \ 33 - asm(" .section \"___kcrctab" sec "+" #sym "\", \"a\" \n" \ 34 - " .weak __crc_" #sym " \n" \ 35 - " .long __crc_" #sym " \n" \ 36 - " .previous \n") 37 - #endif 38 - #else 39 - #define __CRC_SYMBOL(sym, sec) 40 28 #endif 41 29 42 30 #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS ··· 73 85 /* 74 86 * For every exported symbol, do the following: 75 87 * 76 - * - If applicable, place a CRC entry in the __kcrctab section. 77 88 * - Put the name of the symbol and namespace (empty string "" for none) in 78 89 * __ksymtab_strings. 79 90 * - Place a struct kernel_symbol entry in the __ksymtab section. ··· 85 98 extern typeof(sym) sym; \ 86 99 extern const char __kstrtab_##sym[]; \ 87 100 extern const char __kstrtabns_##sym[]; \ 88 - __CRC_SYMBOL(sym, sec); \ 89 101 asm(" .section \"__ksymtab_strings\",\"aMS\",%progbits,1 \n" \ 90 102 "__kstrtab_" #sym ": \n" \ 91 103 " .asciz \"" #sym "\" \n" \
-4
init/Kconfig
··· 2136 2136 assembly. This can be enabled only when the target architecture 2137 2137 supports it. 2138 2138 2139 - config MODULE_REL_CRCS 2140 - bool 2141 - depends on MODVERSIONS 2142 - 2143 2139 config MODULE_SRCVERSION_ALL 2144 2140 bool "Source checksum for all modules" 2145 2141 help
+1 -1
kernel/gen_kheaders.sh
··· 74 74 # of tree builds having stale headers in srctree. Just silence CPIO for now. 75 75 for f in $dir_list; 76 76 do find "$f" -name "*.h"; 77 - done | cpio --quiet -pd $cpio_dir >/dev/null 2>&1 77 + done | cpio --quiet -pdu $cpio_dir >/dev/null 2>&1 78 78 79 79 # Remove comments except SDPX lines 80 80 find $cpio_dir -type f -print0 |
+1 -9
kernel/module.c
··· 1231 1231 1232 1232 #ifdef CONFIG_MODVERSIONS 1233 1233 1234 - static u32 resolve_rel_crc(const s32 *crc) 1235 - { 1236 - return *(u32 *)((void *)crc + *crc); 1237 - } 1238 - 1239 1234 static int check_version(const struct load_info *info, 1240 1235 const char *symname, 1241 1236 struct module *mod, ··· 1259 1264 if (strcmp(versions[i].name, symname) != 0) 1260 1265 continue; 1261 1266 1262 - if (IS_ENABLED(CONFIG_MODULE_REL_CRCS)) 1263 - crcval = resolve_rel_crc(crc); 1264 - else 1265 - crcval = *crc; 1267 + crcval = *crc; 1266 1268 if (versions[i].crc == crcval) 1267 1269 return 1; 1268 1270 pr_debug("Found checksum %X vs module %lX\n",
+2 -2
scripts/Makefile
··· 14 14 HOSTCFLAGS_sorttable.o = -I$(srctree)/tools/include 15 15 HOSTLDLIBS_sorttable = -lpthread 16 16 HOSTCFLAGS_asn1_compiler.o = -I$(srctree)/include 17 - HOSTCFLAGS_sign-file.o = $(shell pkg-config --cflags libcrypto 2> /dev/null) 18 - HOSTLDLIBS_sign-file = $(shell pkg-config --libs libcrypto 2> /dev/null || echo -lcrypto) 17 + HOSTCFLAGS_sign-file.o = $(shell $(HOSTPKG_CONFIG) --cflags libcrypto 2> /dev/null) 18 + HOSTLDLIBS_sign-file = $(shell $(HOSTPKG_CONFIG) --libs libcrypto 2> /dev/null || echo -lcrypto) 19 19 20 20 ifdef CONFIG_UNWINDER_ORC 21 21 ifeq ($(ARCH),x86_64)
+38 -93
scripts/Makefile.build
··· 85 85 targets-for-builtin += $(obj)/built-in.a 86 86 endif 87 87 88 - targets-for-modules := $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) 88 + targets-for-modules := $(foreach x, o mod $(if $(CONFIG_TRIM_UNUSED_KSYMS), usyms), \ 89 + $(patsubst %.o, %.$x, $(filter %.o, $(obj-m)))) 89 90 90 91 ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),) 91 92 targets-for-modules += $(patsubst %.o, %.prelink.o, $(filter %.o, $(obj-m))) ··· 126 125 $(obj)/%.i: $(src)/%.c FORCE 127 126 $(call if_changed_dep,cpp_i_c) 128 127 128 + genksyms = scripts/genksyms/genksyms \ 129 + $(if $(1), -T $(2)) \ 130 + $(if $(KBUILD_PRESERVE), -p) \ 131 + -r $(or $(wildcard $(2:.symtypes=.symref)), /dev/null) 132 + 129 133 # These mirror gensymtypes_S and co below, keep them in synch. 130 - cmd_gensymtypes_c = \ 131 - $(CPP) -D__GENKSYMS__ $(c_flags) $< | \ 132 - scripts/genksyms/genksyms $(if $(1), -T $(2)) \ 133 - $(patsubst y,-R,$(CONFIG_MODULE_REL_CRCS)) \ 134 - $(if $(KBUILD_PRESERVE),-p) \ 135 - -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null)) 134 + cmd_gensymtypes_c = $(CPP) -D__GENKSYMS__ $(c_flags) $< | $(genksyms) 136 135 137 136 quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@ 138 - cmd_cc_symtypes_c = \ 139 - $(call cmd_gensymtypes_c,true,$@) >/dev/null; \ 140 - test -s $@ || rm -f $@ 137 + cmd_cc_symtypes_c = $(call cmd_gensymtypes_c,true,$@) >/dev/null 141 138 142 139 $(obj)/%.symtypes : $(src)/%.c FORCE 143 140 $(call cmd,cc_symtypes_c) ··· 161 162 # o if <file>.o doesn't contain a __ksymtab version, i.e. does 162 163 # not export symbols, it's done. 163 164 # o otherwise, we calculate symbol versions using the good old 164 - # genksyms on the preprocessed source and postprocess them in a way 165 - # that they are usable as a linker script 166 - # o generate .tmp_<file>.o from <file>.o using the linker to 167 - # replace the unresolved symbols __crc_exported_symbol with 168 - # the actual value of the checksum generated by genksyms 169 - # o remove .tmp_<file>.o to <file>.o 165 + # genksyms on the preprocessed source and dump them into the .cmd file. 166 + # o modpost will extract versions from that file and create *.c files that will 167 + # be compiled and linked to the kernel and/or modules. 170 168 171 - ifdef CONFIG_LTO_CLANG 172 - # Generate .o.symversions files for each .o with exported symbols, and link these 173 - # to the kernel and/or modules at the end. 174 - cmd_modversions_c = \ 169 + gen_symversions = \ 175 170 if $(NM) $@ 2>/dev/null | grep -q __ksymtab; then \ 176 - $(call cmd_gensymtypes_c,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \ 177 - > $@.symversions; \ 178 - else \ 179 - rm -f $@.symversions; \ 180 - fi; 181 - else 182 - cmd_modversions_c = \ 183 - if $(OBJDUMP) -h $@ | grep -q __ksymtab; then \ 184 - $(call cmd_gensymtypes_c,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \ 185 - > $(@D)/.tmp_$(@F:.o=.ver); \ 186 - \ 187 - $(LD) $(KBUILD_LDFLAGS) -r -o $(@D)/.tmp_$(@F) $@ \ 188 - -T $(@D)/.tmp_$(@F:.o=.ver); \ 189 - mv -f $(@D)/.tmp_$(@F) $@; \ 190 - rm -f $(@D)/.tmp_$(@F:.o=.ver); \ 171 + $(call cmd_gensymtypes_$(1),$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \ 172 + >> $(dot-target).cmd; \ 191 173 fi 192 - endif 174 + 175 + cmd_gen_symversions_c = $(call gen_symversions,c) 176 + 193 177 endif 194 178 195 179 ifdef CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT ··· 247 265 ifdef CONFIG_TRIM_UNUSED_KSYMS 248 266 cmd_gen_ksymdeps = \ 249 267 $(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ >> $(dot-target).cmd 250 - 251 - # List module undefined symbols 252 - undefined_syms = $(NM) $< | $(AWK) '$$1 == "U" { printf("%s%s", x++ ? " " : "", $$2) }'; 253 268 endif 254 269 255 270 define rule_cc_o_c ··· 255 276 $(call cmd,checksrc) 256 277 $(call cmd,checkdoc) 257 278 $(call cmd,gen_objtooldep) 258 - $(call cmd,modversions_c) 279 + $(call cmd,gen_symversions_c) 259 280 $(call cmd,record_mcount) 260 281 endef 261 282 ··· 263 284 $(call cmd_and_fixdep,as_o_S) 264 285 $(call cmd,gen_ksymdeps) 265 286 $(call cmd,gen_objtooldep) 266 - $(call cmd,modversions_S) 287 + $(call cmd,gen_symversions_S) 267 288 endef 268 289 269 290 # Built-in and composite module parts ··· 277 298 quiet_cmd_cc_prelink_modules = LD [M] $@ 278 299 cmd_cc_prelink_modules = \ 279 300 $(LD) $(ld_flags) -r -o $@ \ 280 - $(shell [ -s $(@:.prelink.o=.o.symversions) ] && \ 281 - echo -T $(@:.prelink.o=.o.symversions)) \ 282 301 --whole-archive $(filter-out FORCE,$^) \ 283 302 $(cmd_objtool) 284 303 ··· 290 313 $(call if_changed,cc_prelink_modules) 291 314 endif 292 315 293 - cmd_mod = { \ 294 - echo $(if $($*-objs)$($*-y)$($*-m), $(addprefix $(obj)/, $($*-objs) $($*-y) $($*-m)), $(@:.mod=.o)); \ 295 - $(undefined_syms) echo; \ 296 - } > $@ 316 + cmd_mod = echo $(addprefix $(obj)/, $(call real-search, $*.o, .o, -objs -y -m)) | \ 317 + $(AWK) -v RS='( |\n)' '!x[$$0]++' > $@ 297 318 298 - $(obj)/%.mod: $(obj)/%$(mod-prelink-ext).o FORCE 319 + $(obj)/%.mod: FORCE 299 320 $(call if_changed,mod) 321 + 322 + # List module undefined symbols 323 + cmd_undefined_syms = $(NM) $< | sed -n 's/^ *U //p' > $@ 324 + 325 + $(obj)/%.usyms: $(obj)/%$(mod-prelink-ext).o FORCE 326 + $(call if_changed,undefined_syms) 300 327 301 328 quiet_cmd_cc_lst_c = MKLST $@ 302 329 cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \ ··· 330 349 $(CPP) $(a_flags) $< | \ 331 350 grep "\<___EXPORT_SYMBOL\>" | \ 332 351 sed 's/.*___EXPORT_SYMBOL[[:space:]]*\([a-zA-Z0-9_]*\)[[:space:]]*,.*/EXPORT_SYMBOL(\1);/' ; } | \ 333 - $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | \ 334 - scripts/genksyms/genksyms $(if $(1), -T $(2)) \ 335 - $(patsubst y,-R,$(CONFIG_MODULE_REL_CRCS)) \ 336 - $(if $(KBUILD_PRESERVE),-p) \ 337 - -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null)) 352 + $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | $(genksyms) 338 353 339 354 quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@ 340 - cmd_cc_symtypes_S = \ 341 - $(call cmd_gensymtypes_S,true,$@) >/dev/null; \ 342 - test -s $@ || rm -f $@ 355 + cmd_cc_symtypes_S = $(call cmd_gensymtypes_S,true,$@) >/dev/null 343 356 344 357 $(obj)/%.symtypes : $(src)/%.S FORCE 345 358 $(call cmd,cc_symtypes_S) ··· 353 378 # versioning matches the C process described above, with difference that 354 379 # we parse asm-prototypes.h C header to get function definitions. 355 380 356 - cmd_modversions_S = \ 357 - if $(OBJDUMP) -h $@ | grep -q __ksymtab; then \ 358 - $(call cmd_gensymtypes_S,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \ 359 - > $(@D)/.tmp_$(@F:.o=.ver); \ 360 - \ 361 - $(LD) $(KBUILD_LDFLAGS) -r -o $(@D)/.tmp_$(@F) $@ \ 362 - -T $(@D)/.tmp_$(@F:.o=.ver); \ 363 - mv -f $(@D)/.tmp_$(@F) $@; \ 364 - rm -f $(@D)/.tmp_$(@F:.o=.ver); \ 365 - fi 381 + cmd_gen_symversions_S = $(call gen_symversions,S) 382 + 366 383 endif 367 384 368 385 $(obj)/%.o: $(src)/%.S FORCE ··· 389 422 $(subdir-builtin): $(obj)/%/built-in.a: $(obj)/% ; 390 423 $(subdir-modorder): $(obj)/%/modules.order: $(obj)/% ; 391 424 392 - # combine symversions for later processing 393 - ifeq ($(CONFIG_LTO_CLANG) $(CONFIG_MODVERSIONS),y y) 394 - cmd_update_lto_symversions = \ 395 - rm -f $@.symversions \ 396 - $(foreach n, $(filter-out FORCE,$^), \ 397 - $(if $(shell test -s $(n).symversions && echo y), \ 398 - ; cat $(n).symversions >> $@.symversions)) 399 - else 400 - cmd_update_lto_symversions = echo >/dev/null 401 - endif 402 - 403 425 # 404 426 # Rule to compile a set of .o files into one .a file (without symbol table) 405 427 # ··· 396 440 quiet_cmd_ar_builtin = AR $@ 397 441 cmd_ar_builtin = rm -f $@; $(AR) cDPrST $@ $(real-prereqs) 398 442 399 - quiet_cmd_ar_and_symver = AR $@ 400 - cmd_ar_and_symver = $(cmd_update_lto_symversions); $(cmd_ar_builtin) 401 - 402 443 $(obj)/built-in.a: $(real-obj-y) FORCE 403 - $(call if_changed,ar_and_symver) 444 + $(call if_changed,ar_builtin) 404 445 405 446 # 406 447 # Rule to create modules.order file ··· 417 464 # 418 465 # Rule to compile a set of .o files into one .a file (with symbol table) 419 466 # 420 - quiet_cmd_ar_lib = AR $@ 421 - cmd_ar_lib = $(cmd_update_lto_symversions); $(cmd_ar) 422 467 423 468 $(obj)/lib.a: $(lib-y) FORCE 424 - $(call if_changed,ar_lib) 469 + $(call if_changed,ar) 425 470 426 - # NOTE: 427 - # Do not replace $(filter %.o,^) with $(real-prereqs). When a single object 428 - # module is turned into a multi object module, $^ will contain header file 429 - # dependencies recorded in the .*.cmd file. 430 471 ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),) 431 472 quiet_cmd_link_multi-m = AR [M] $@ 432 473 cmd_link_multi-m = \ 433 - $(cmd_update_lto_symversions); \ 434 474 rm -f $@; \ 435 - $(AR) cDPrsT $@ $(filter %.o,$^) 475 + $(AR) cDPrsT $@ @$(patsubst %.o,%.mod,$@) 436 476 else 437 477 quiet_cmd_link_multi-m = LD [M] $@ 438 - cmd_link_multi-m = $(LD) $(ld_flags) -r -o $@ $(filter %.o,$^) 478 + cmd_link_multi-m = $(LD) $(ld_flags) -r -o $@ @$(patsubst %.o,%.mod,$@) 439 479 endif 440 480 441 - $(multi-obj-m): FORCE 481 + $(multi-obj-m): %.o: %.mod FORCE 442 482 $(call if_changed,link_multi-m) 443 483 $(call multi_depend, $(multi-obj-m), .o, -objs -y -m) 444 484 445 - targets += $(multi-obj-m) 446 485 targets := $(filter-out $(PHONY), $(targets)) 447 486 448 487 # Add intermediate targets:
+1 -7
scripts/Makefile.clean
··· 36 36 37 37 __clean-files := $(filter-out $(no-clean-files), $(__clean-files)) 38 38 39 - # clean-files is given relative to the current directory, unless it 40 - # starts with $(objtree)/ (which means "./", so do not add "./" unless 41 - # you want to delete a file from the toplevel object directory). 42 - 43 - __clean-files := $(wildcard \ 44 - $(addprefix $(obj)/, $(filter-out $(objtree)/%, $(__clean-files))) \ 45 - $(filter $(objtree)/%, $(__clean-files))) 39 + __clean-files := $(wildcard $(addprefix $(obj)/, $(__clean-files))) 46 40 47 41 # ========================================================================== 48 42
+11 -2
scripts/Makefile.extrawarn
··· 2 2 # ========================================================================== 3 3 # make W=... settings 4 4 # 5 - # There are three warning groups enabled by W=1, W=2, W=3. 6 - # They are independent, and can be combined like W=12 or W=123. 5 + # There are four warning groups enabled by W=1, W=2, W=3, and W=e 6 + # They are independent, and can be combined like W=12 or W=123e. 7 7 # ========================================================================== 8 8 9 9 KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned) ··· 92 92 KBUILD_CFLAGS += $(call cc-option, -Wpacked-bitfield-compat) 93 93 94 94 KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN3 95 + 96 + endif 97 + 98 + # 99 + # W=e - error out on warnings 100 + # 101 + ifneq ($(findstring e, $(KBUILD_EXTRA_WARN)),) 102 + 103 + KBUILD_CFLAGS += -Werror 95 104 96 105 endif
+3 -3
scripts/Makefile.lib
··· 236 236 # Usage: 237 237 # $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add) 238 238 define multi_depend 239 - $(foreach m, $(notdir $1), \ 240 - $(eval $(obj)/$m: \ 241 - $(addprefix $(obj)/, $(foreach s, $3, $($(m:%$(strip $2)=%$(s))))))) 239 + $(foreach m, $1, \ 240 + $(eval $m: \ 241 + $(addprefix $(obj)/, $(call suffix-search, $(patsubst $(obj)/%,%,$m), $2, $3)))) 242 242 endef 243 243 244 244 # Copy a file
+32
scripts/Makefile.vmlinux
··· 1 + # SPDX-License-Identifier: GPL-2.0-only 2 + 3 + include include/config/auto.conf 4 + include $(srctree)/scripts/Kbuild.include 5 + 6 + # for c_flags 7 + include $(srctree)/scripts/Makefile.lib 8 + 9 + quiet_cmd_cc_o_c = CC $@ 10 + cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< 11 + 12 + %.o: %.c FORCE 13 + $(call if_changed_dep,cc_o_c) 14 + 15 + targets := $(MAKECMDGOALS) 16 + 17 + # Add FORCE to the prequisites of a target to force it to be always rebuilt. 18 + # --------------------------------------------------------------------------- 19 + 20 + PHONY += FORCE 21 + FORCE: 22 + 23 + # Read all saved command lines and dependencies for the $(targets) we 24 + # may be building above, using $(if_changed{,_dep}). As an 25 + # optimization, we don't need to read them if the target does not 26 + # exist, we will rebuild anyway in that case. 27 + 28 + existing-targets := $(wildcard $(sort $(targets))) 29 + 30 + -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) 31 + 32 + .PHONY: $(PHONY)
+1 -1
scripts/adjust_autoksyms.sh
··· 35 35 esac 36 36 37 37 # Generate a new symbol list file 38 - $CONFIG_SHELL $srctree/scripts/gen_autoksyms.sh "$new_ksyms_file" 38 + $CONFIG_SHELL $srctree/scripts/gen_autoksyms.sh --modorder "$new_ksyms_file" 39 39 40 40 # Extract changes between old and new list and touch corresponding 41 41 # dependency files.
+1 -1
scripts/checksyscalls.sh
··· 268 268 } 269 269 270 270 (ignore_list && syscall_list $(dirname $0)/../arch/x86/entry/syscalls/syscall_32.tbl) | \ 271 - $* -Wno-error -E -x c - > /dev/null 271 + $* -Wno-error -Wno-unused-macros -E -x c - > /dev/null
+4
scripts/dummy-tools/pahole
··· 1 + #!/bin/sh 2 + # SPDX-License-Identifier: GPL-2.0-only 3 + 4 + echo v99.99
+11 -7
scripts/gen_autoksyms.sh
··· 2 2 # SPDX-License-Identifier: GPL-2.0-only 3 3 4 4 # Create an autoksyms.h header file from the list of all module's needed symbols 5 - # as recorded on the second line of *.mod files and the user-provided symbol 6 - # whitelist. 5 + # as recorded in *.usyms files and the user-provided symbol whitelist. 7 6 8 7 set -e 9 - 10 - output_file="$1" 11 8 12 9 # Use "make V=1" to debug this script. 13 10 case "$KBUILD_VERBOSE" in ··· 12 15 set -x 13 16 ;; 14 17 esac 18 + 19 + read_modorder= 20 + 21 + if [ "$1" = --modorder ]; then 22 + shift 23 + read_modorder=1 24 + fi 25 + 26 + output_file="$1" 15 27 16 28 needed_symbols= 17 29 ··· 47 41 48 42 EOT 49 43 50 - [ -f modules.order ] && modlist=modules.order || modlist=/dev/null 51 - 52 44 { 53 - sed 's/ko$/mod/' $modlist | xargs -n1 sed -n -e '2p' 45 + [ -n "${read_modorder}" ] && sed 's/ko$/usyms/' modules.order | xargs cat 54 46 echo "$needed_symbols" 55 47 [ -n "$ksym_wl" ] && cat "$ksym_wl" 56 48 } | sed -e 's/ /\n/g' | sed -n -e '/^$/!p' |
+4 -14
scripts/genksyms/genksyms.c
··· 33 33 int in_source_file; 34 34 35 35 static int flag_debug, flag_dump_defs, flag_reference, flag_dump_types, 36 - flag_preserve, flag_warnings, flag_rel_crcs; 36 + flag_preserve, flag_warnings; 37 37 38 38 static int errors; 39 39 static int nsyms; ··· 680 680 if (flag_dump_defs) 681 681 fputs(">\n", debugfile); 682 682 683 - /* Used as a linker script. */ 684 - printf(!flag_rel_crcs ? "__crc_%s = 0x%08lx;\n" : 685 - "SECTIONS { .rodata : ALIGN(4) { " 686 - "__crc_%s = .; LONG(0x%08lx); } }\n", 687 - name, crc); 683 + printf("#SYMVER %s 0x%08lx\n", name, crc); 688 684 } 689 685 } 690 686 ··· 729 733 " -q, --quiet Disable warnings (default)\n" 730 734 " -h, --help Print this message\n" 731 735 " -V, --version Print the release version\n" 732 - " -R, --relative-crc Emit section relative symbol CRCs\n" 733 736 #else /* __GNU_LIBRARY__ */ 734 737 " -s Select symbol prefix\n" 735 738 " -d Increment the debug level (repeatable)\n" ··· 740 745 " -q Disable warnings (default)\n" 741 746 " -h Print this message\n" 742 747 " -V Print the release version\n" 743 - " -R Emit section relative symbol CRCs\n" 744 748 #endif /* __GNU_LIBRARY__ */ 745 749 , stderr); 746 750 } ··· 760 766 {"preserve", 0, 0, 'p'}, 761 767 {"version", 0, 0, 'V'}, 762 768 {"help", 0, 0, 'h'}, 763 - {"relative-crc", 0, 0, 'R'}, 764 769 {0, 0, 0, 0} 765 770 }; 766 771 767 - while ((o = getopt_long(argc, argv, "s:dwqVDr:T:phR", 772 + while ((o = getopt_long(argc, argv, "s:dwqVDr:T:ph", 768 773 &long_opts[0], NULL)) != EOF) 769 774 #else /* __GNU_LIBRARY__ */ 770 - while ((o = getopt(argc, argv, "s:dwqVDr:T:phR")) != EOF) 775 + while ((o = getopt(argc, argv, "s:dwqVDr:T:ph")) != EOF) 771 776 #endif /* __GNU_LIBRARY__ */ 772 777 switch (o) { 773 778 case 'd': ··· 806 813 case 'h': 807 814 genksyms_usage(); 808 815 return 0; 809 - case 'R': 810 - flag_rel_crcs = 1; 811 - break; 812 816 default: 813 817 genksyms_usage(); 814 818 return 1;
+40
scripts/install.sh
··· 1 + #!/bin/sh 2 + # SPDX-License-Identifier: GPL-2.0-only 3 + # 4 + # Copyright (C) 1995 by Linus Torvalds 5 + # 6 + # Adapted from code in arch/i386/boot/Makefile by H. Peter Anvin 7 + # Common code factored out by Masahiro Yamada 8 + 9 + set -e 10 + 11 + # Make sure the files actually exist 12 + for file in "${KBUILD_IMAGE}" System.map 13 + do 14 + if [ ! -f "${file}" ]; then 15 + echo >&2 16 + echo >&2 " *** Missing file: ${file}" 17 + echo >&2 ' *** You need to run "make" before "make install".' 18 + echo >&2 19 + exit 1 20 + fi 21 + done 22 + 23 + # User/arch may have a custom install script 24 + for file in "${HOME}/bin/${INSTALLKERNEL}" \ 25 + "/sbin/${INSTALLKERNEL}" \ 26 + "${srctree}/arch/${SRCARCH}/install.sh" \ 27 + "${srctree}/arch/${SRCARCH}/boot/install.sh" 28 + do 29 + if [ ! -x "${file}" ]; then 30 + continue 31 + fi 32 + 33 + # installkernel(8) says the parameters are like follows: 34 + # 35 + # installkernel version zImage System.map [directory] 36 + exec "${file}" "${KERNELRELEASE}" "${KBUILD_IMAGE}" System.map "${INSTALL_PATH}" 37 + done 38 + 39 + echo "No install script found" >&2 40 + exit 1
+6 -6
scripts/kconfig/gconf-cfg.sh
··· 3 3 4 4 PKG="gtk+-2.0 gmodule-2.0 libglade-2.0" 5 5 6 - if [ -z "$(command -v pkg-config)" ]; then 6 + if [ -z "$(command -v ${HOSTPKG_CONFIG})" ]; then 7 7 echo >&2 "*" 8 - echo >&2 "* 'make gconfig' requires 'pkg-config'. Please install it." 8 + echo >&2 "* 'make gconfig' requires '${HOSTPKG_CONFIG}'. Please install it." 9 9 echo >&2 "*" 10 10 exit 1 11 11 fi 12 12 13 - if ! pkg-config --exists $PKG; then 13 + if ! ${HOSTPKG_CONFIG} --exists $PKG; then 14 14 echo >&2 "*" 15 15 echo >&2 "* Unable to find the GTK+ installation. Please make sure that" 16 16 echo >&2 "* the GTK+ 2.0 development package is correctly installed." ··· 19 19 exit 1 20 20 fi 21 21 22 - if ! pkg-config --atleast-version=2.0.0 gtk+-2.0; then 22 + if ! ${HOSTPKG_CONFIG} --atleast-version=2.0.0 gtk+-2.0; then 23 23 echo >&2 "*" 24 24 echo >&2 "* GTK+ is present but version >= 2.0.0 is required." 25 25 echo >&2 "*" 26 26 exit 1 27 27 fi 28 28 29 - echo cflags=\"$(pkg-config --cflags $PKG)\" 30 - echo libs=\"$(pkg-config --libs $PKG)\" 29 + echo cflags=\"$(${HOSTPKG_CONFIG} --cflags $PKG)\" 30 + echo libs=\"$(${HOSTPKG_CONFIG} --libs $PKG)\"
+8 -8
scripts/kconfig/mconf-cfg.sh
··· 4 4 PKG="ncursesw" 5 5 PKG2="ncurses" 6 6 7 - if [ -n "$(command -v pkg-config)" ]; then 8 - if pkg-config --exists $PKG; then 9 - echo cflags=\"$(pkg-config --cflags $PKG)\" 10 - echo libs=\"$(pkg-config --libs $PKG)\" 7 + if [ -n "$(command -v ${HOSTPKG_CONFIG})" ]; then 8 + if ${HOSTPKG_CONFIG} --exists $PKG; then 9 + echo cflags=\"$(${HOSTPKG_CONFIG} --cflags $PKG)\" 10 + echo libs=\"$(${HOSTPKG_CONFIG} --libs $PKG)\" 11 11 exit 0 12 12 fi 13 13 14 - if pkg-config --exists $PKG2; then 15 - echo cflags=\"$(pkg-config --cflags $PKG2)\" 16 - echo libs=\"$(pkg-config --libs $PKG2)\" 14 + if ${HOSTPKG_CONFIG} --exists $PKG2; then 15 + echo cflags=\"$(${HOSTPKG_CONFIG} --cflags $PKG2)\" 16 + echo libs=\"$(${HOSTPKG_CONFIG} --libs $PKG2)\" 17 17 exit 0 18 18 fi 19 19 fi ··· 46 46 echo >&2 "* Install ncurses (ncurses-devel or libncurses-dev" 47 47 echo >&2 "* depending on your distribution)." 48 48 echo >&2 "*" 49 - echo >&2 "* You may also need to install pkg-config to find the" 49 + echo >&2 "* You may also need to install ${HOSTPKG_CONFIG} to find the" 50 50 echo >&2 "* ncurses installed in a non-default location." 51 51 echo >&2 "*" 52 52 exit 1
+8 -8
scripts/kconfig/nconf-cfg.sh
··· 4 4 PKG="ncursesw menuw panelw" 5 5 PKG2="ncurses menu panel" 6 6 7 - if [ -n "$(command -v pkg-config)" ]; then 8 - if pkg-config --exists $PKG; then 9 - echo cflags=\"$(pkg-config --cflags $PKG)\" 10 - echo libs=\"$(pkg-config --libs $PKG)\" 7 + if [ -n "$(command -v ${HOSTPKG_CONFIG})" ]; then 8 + if ${HOSTPKG_CONFIG} --exists $PKG; then 9 + echo cflags=\"$(${HOSTPKG_CONFIG} --cflags $PKG)\" 10 + echo libs=\"$(${HOSTPKG_CONFIG} --libs $PKG)\" 11 11 exit 0 12 12 fi 13 13 14 - if pkg-config --exists $PKG2; then 15 - echo cflags=\"$(pkg-config --cflags $PKG2)\" 16 - echo libs=\"$(pkg-config --libs $PKG2)\" 14 + if ${HOSTPKG_CONFIG} --exists $PKG2; then 15 + echo cflags=\"$(${HOSTPKG_CONFIG} --cflags $PKG2)\" 16 + echo libs=\"$(${HOSTPKG_CONFIG} --libs $PKG2)\" 17 17 exit 0 18 18 fi 19 19 fi ··· 44 44 echo >&2 "* Install ncurses (ncurses-devel or libncurses-dev" 45 45 echo >&2 "* depending on your distribution)." 46 46 echo >&2 "*" 47 - echo >&2 "* You may also need to install pkg-config to find the" 47 + echo >&2 "* You may also need to install ${HOSTPKG_CONFIG} to find the" 48 48 echo >&2 "* ncurses installed in a non-default location." 49 49 echo >&2 "*" 50 50 exit 1
+7 -7
scripts/kconfig/qconf-cfg.sh
··· 3 3 4 4 PKG="Qt5Core Qt5Gui Qt5Widgets" 5 5 6 - if [ -z "$(command -v pkg-config)" ]; then 6 + if [ -z "$(command -v ${HOSTPKG_CONFIG})" ]; then 7 7 echo >&2 "*" 8 - echo >&2 "* 'make xconfig' requires 'pkg-config'. Please install it." 8 + echo >&2 "* 'make xconfig' requires '${HOSTPKG_CONFIG}'. Please install it." 9 9 echo >&2 "*" 10 10 exit 1 11 11 fi 12 12 13 - if pkg-config --exists $PKG; then 14 - echo cflags=\"-std=c++11 -fPIC $(pkg-config --cflags $PKG)\" 15 - echo libs=\"$(pkg-config --libs $PKG)\" 16 - echo moc=\"$(pkg-config --variable=host_bins Qt5Core)/moc\" 13 + if ${HOSTPKG_CONFIG} --exists $PKG; then 14 + echo cflags=\"-std=c++11 -fPIC $(${HOSTPKG_CONFIG} --cflags $PKG)\" 15 + echo libs=\"$(${HOSTPKG_CONFIG} --libs $PKG)\" 16 + echo moc=\"$(${HOSTPKG_CONFIG} --variable=host_bins Qt5Core)/moc\" 17 17 exit 0 18 18 fi 19 19 20 20 echo >&2 "*" 21 - echo >&2 "* Could not find Qt5 via pkg-config." 21 + echo >&2 "* Could not find Qt5 via ${HOSTPKG_CONFIG}." 22 22 echo >&2 "* Please install Qt5 and make sure it's in PKG_CONFIG_PATH" 23 23 echo >&2 "*" 24 24 exit 1
+213
scripts/mod/list.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef LIST_H 3 + #define LIST_H 4 + 5 + #include <stdbool.h> 6 + #include <stddef.h> 7 + 8 + /* Are two types/vars the same type (ignoring qualifiers)? */ 9 + #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) 10 + 11 + /** 12 + * container_of - cast a member of a structure out to the containing structure 13 + * @ptr: the pointer to the member. 14 + * @type: the type of the container struct this is embedded in. 15 + * @member: the name of the member within the struct. 16 + * 17 + */ 18 + #define container_of(ptr, type, member) ({ \ 19 + void *__mptr = (void *)(ptr); \ 20 + _Static_assert(__same_type(*(ptr), ((type *)0)->member) || \ 21 + __same_type(*(ptr), void), \ 22 + "pointer type mismatch in container_of()"); \ 23 + ((type *)(__mptr - offsetof(type, member))); }) 24 + 25 + #define LIST_POISON1 ((void *) 0x100) 26 + #define LIST_POISON2 ((void *) 0x122) 27 + 28 + /* 29 + * Circular doubly linked list implementation. 30 + * 31 + * Some of the internal functions ("__xxx") are useful when 32 + * manipulating whole lists rather than single entries, as 33 + * sometimes we already know the next/prev entries and we can 34 + * generate better code by using them directly rather than 35 + * using the generic single-entry routines. 36 + */ 37 + 38 + struct list_head { 39 + struct list_head *next, *prev; 40 + }; 41 + 42 + #define LIST_HEAD_INIT(name) { &(name), &(name) } 43 + 44 + #define LIST_HEAD(name) \ 45 + struct list_head name = LIST_HEAD_INIT(name) 46 + 47 + /** 48 + * INIT_LIST_HEAD - Initialize a list_head structure 49 + * @list: list_head structure to be initialized. 50 + * 51 + * Initializes the list_head to point to itself. If it is a list header, 52 + * the result is an empty list. 53 + */ 54 + static inline void INIT_LIST_HEAD(struct list_head *list) 55 + { 56 + list->next = list; 57 + list->prev = list; 58 + } 59 + 60 + /* 61 + * Insert a new entry between two known consecutive entries. 62 + * 63 + * This is only for internal list manipulation where we know 64 + * the prev/next entries already! 65 + */ 66 + static inline void __list_add(struct list_head *new, 67 + struct list_head *prev, 68 + struct list_head *next) 69 + { 70 + next->prev = new; 71 + new->next = next; 72 + new->prev = prev; 73 + prev->next = new; 74 + } 75 + 76 + /** 77 + * list_add - add a new entry 78 + * @new: new entry to be added 79 + * @head: list head to add it after 80 + * 81 + * Insert a new entry after the specified head. 82 + * This is good for implementing stacks. 83 + */ 84 + static inline void list_add(struct list_head *new, struct list_head *head) 85 + { 86 + __list_add(new, head, head->next); 87 + } 88 + 89 + /** 90 + * list_add_tail - add a new entry 91 + * @new: new entry to be added 92 + * @head: list head to add it before 93 + * 94 + * Insert a new entry before the specified head. 95 + * This is useful for implementing queues. 96 + */ 97 + static inline void list_add_tail(struct list_head *new, struct list_head *head) 98 + { 99 + __list_add(new, head->prev, head); 100 + } 101 + 102 + /* 103 + * Delete a list entry by making the prev/next entries 104 + * point to each other. 105 + * 106 + * This is only for internal list manipulation where we know 107 + * the prev/next entries already! 108 + */ 109 + static inline void __list_del(struct list_head *prev, struct list_head *next) 110 + { 111 + next->prev = prev; 112 + prev->next = next; 113 + } 114 + 115 + static inline void __list_del_entry(struct list_head *entry) 116 + { 117 + __list_del(entry->prev, entry->next); 118 + } 119 + 120 + /** 121 + * list_del - deletes entry from list. 122 + * @entry: the element to delete from the list. 123 + * Note: list_empty() on entry does not return true after this, the entry is 124 + * in an undefined state. 125 + */ 126 + static inline void list_del(struct list_head *entry) 127 + { 128 + __list_del_entry(entry); 129 + entry->next = LIST_POISON1; 130 + entry->prev = LIST_POISON2; 131 + } 132 + 133 + /** 134 + * list_is_head - tests whether @list is the list @head 135 + * @list: the entry to test 136 + * @head: the head of the list 137 + */ 138 + static inline int list_is_head(const struct list_head *list, const struct list_head *head) 139 + { 140 + return list == head; 141 + } 142 + 143 + /** 144 + * list_empty - tests whether a list is empty 145 + * @head: the list to test. 146 + */ 147 + static inline int list_empty(const struct list_head *head) 148 + { 149 + return head->next == head; 150 + } 151 + 152 + /** 153 + * list_entry - get the struct for this entry 154 + * @ptr: the &struct list_head pointer. 155 + * @type: the type of the struct this is embedded in. 156 + * @member: the name of the list_head within the struct. 157 + */ 158 + #define list_entry(ptr, type, member) \ 159 + container_of(ptr, type, member) 160 + 161 + /** 162 + * list_first_entry - get the first element from a list 163 + * @ptr: the list head to take the element from. 164 + * @type: the type of the struct this is embedded in. 165 + * @member: the name of the list_head within the struct. 166 + * 167 + * Note, that list is expected to be not empty. 168 + */ 169 + #define list_first_entry(ptr, type, member) \ 170 + list_entry((ptr)->next, type, member) 171 + 172 + /** 173 + * list_next_entry - get the next element in list 174 + * @pos: the type * to cursor 175 + * @member: the name of the list_head within the struct. 176 + */ 177 + #define list_next_entry(pos, member) \ 178 + list_entry((pos)->member.next, typeof(*(pos)), member) 179 + 180 + /** 181 + * list_entry_is_head - test if the entry points to the head of the list 182 + * @pos: the type * to cursor 183 + * @head: the head for your list. 184 + * @member: the name of the list_head within the struct. 185 + */ 186 + #define list_entry_is_head(pos, head, member) \ 187 + (&pos->member == (head)) 188 + 189 + /** 190 + * list_for_each_entry - iterate over list of given type 191 + * @pos: the type * to use as a loop cursor. 192 + * @head: the head for your list. 193 + * @member: the name of the list_head within the struct. 194 + */ 195 + #define list_for_each_entry(pos, head, member) \ 196 + for (pos = list_first_entry(head, typeof(*pos), member); \ 197 + !list_entry_is_head(pos, head, member); \ 198 + pos = list_next_entry(pos, member)) 199 + 200 + /** 201 + * list_for_each_entry_safe - iterate over list of given type. Safe against removal of list entry 202 + * @pos: the type * to use as a loop cursor. 203 + * @n: another type * to use as temporary storage 204 + * @head: the head for your list. 205 + * @member: the name of the list_head within the struct. 206 + */ 207 + #define list_for_each_entry_safe(pos, n, head, member) \ 208 + for (pos = list_first_entry(head, typeof(*pos), member), \ 209 + n = list_next_entry(pos, member); \ 210 + !list_entry_is_head(pos, head, member); \ 211 + pos = n, n = list_next_entry(n, member)) 212 + 213 + #endif /* LIST_H */
+360 -318
scripts/mod/modpost.c
··· 23 23 #include "../../include/linux/license.h" 24 24 25 25 /* Are we using CONFIG_MODVERSIONS? */ 26 - static int modversions = 0; 26 + static bool modversions; 27 27 /* Is CONFIG_MODULE_SRCVERSION_ALL set? */ 28 - static int all_versions = 0; 28 + static bool all_versions; 29 29 /* If we are modposting external module set to 1 */ 30 - static int external_module = 0; 30 + static bool external_module; 31 31 /* Only warn about unresolved symbols */ 32 - static int warn_unresolved = 0; 33 - /* How a symbol is exported */ 34 - static int sec_mismatch_count = 0; 35 - static int sec_mismatch_warn_only = true; 32 + static bool warn_unresolved; 33 + 34 + static int sec_mismatch_count; 35 + static bool sec_mismatch_warn_only = true; 36 36 /* ignore missing files */ 37 - static int ignore_missing_files; 37 + static bool ignore_missing_files; 38 38 /* If set to 1, only warn (instead of error) about missing ns imports */ 39 - static int allow_missing_ns_imports; 39 + static bool allow_missing_ns_imports; 40 40 41 41 static bool error_occurred; 42 42 ··· 46 46 */ 47 47 #define MAX_UNRESOLVED_REPORTS 10 48 48 static unsigned int nr_unresolved; 49 - 50 - enum export { 51 - export_plain, 52 - export_gpl, 53 - export_unknown 54 - }; 55 49 56 50 /* In kernel, this size is defined in linux/module.h; 57 51 * here we use Elf_Addr instead of long for covering cross-compile ··· 159 165 } 160 166 161 167 /* A list of all modules we processed */ 162 - static struct module *modules; 168 + LIST_HEAD(modules); 163 169 164 170 static struct module *find_module(const char *modname) 165 171 { 166 172 struct module *mod; 167 173 168 - for (mod = modules; mod; mod = mod->next) 174 + list_for_each_entry(mod, &modules, list) { 169 175 if (strcmp(mod->name, modname) == 0) 170 - break; 171 - return mod; 176 + return mod; 177 + } 178 + return NULL; 172 179 } 173 180 174 181 static struct module *new_module(const char *modname) ··· 179 184 mod = NOFAIL(malloc(sizeof(*mod) + strlen(modname) + 1)); 180 185 memset(mod, 0, sizeof(*mod)); 181 186 182 - /* add to list */ 187 + INIT_LIST_HEAD(&mod->exported_symbols); 188 + INIT_LIST_HEAD(&mod->unresolved_symbols); 189 + INIT_LIST_HEAD(&mod->missing_namespaces); 190 + INIT_LIST_HEAD(&mod->imported_namespaces); 191 + 183 192 strcpy(mod->name, modname); 184 193 mod->is_vmlinux = (strcmp(modname, "vmlinux") == 0); 185 - mod->gpl_compatible = -1; 186 - mod->next = modules; 187 - modules = mod; 194 + 195 + /* 196 + * Set mod->is_gpl_compatible to true by default. If MODULE_LICENSE() 197 + * is missing, do not check the use for EXPORT_SYMBOL_GPL() becasue 198 + * modpost will exit wiht error anyway. 199 + */ 200 + mod->is_gpl_compatible = true; 201 + 202 + list_add_tail(&mod->list, &modules); 188 203 189 204 return mod; 190 205 } ··· 206 201 207 202 struct symbol { 208 203 struct symbol *next; 204 + struct list_head list; /* link to module::exported_symbols or module::unresolved_symbols */ 209 205 struct module *module; 210 - unsigned int crc; 211 - int crc_valid; 212 206 char *namespace; 213 - unsigned int weak:1; 214 - unsigned int is_static:1; /* 1 if symbol is not global */ 215 - enum export export; /* Type of export */ 207 + unsigned int crc; 208 + bool crc_valid; 209 + bool weak; 210 + bool is_static; /* true if symbol is not global */ 211 + bool is_gpl_only; /* exported by EXPORT_SYMBOL_GPL */ 216 212 char name[]; 217 213 }; 218 214 ··· 236 230 * Allocate a new symbols for use in the hash of exported symbols or 237 231 * the list of unresolved symbols per module 238 232 **/ 239 - static struct symbol *alloc_symbol(const char *name, unsigned int weak, 240 - struct symbol *next) 233 + static struct symbol *alloc_symbol(const char *name) 241 234 { 242 235 struct symbol *s = NOFAIL(malloc(sizeof(*s) + strlen(name) + 1)); 243 236 244 237 memset(s, 0, sizeof(*s)); 245 238 strcpy(s->name, name); 246 - s->weak = weak; 247 - s->next = next; 248 - s->is_static = 1; 239 + s->is_static = true; 249 240 return s; 250 241 } 251 242 252 243 /* For the hash of exported symbols */ 253 - static struct symbol *new_symbol(const char *name, struct module *module, 254 - enum export export) 244 + static void hash_add_symbol(struct symbol *sym) 255 245 { 256 246 unsigned int hash; 257 247 258 - hash = tdb_hash(name) % SYMBOL_HASH_SIZE; 259 - symbolhash[hash] = alloc_symbol(name, 0, symbolhash[hash]); 260 - 261 - return symbolhash[hash]; 248 + hash = tdb_hash(sym->name) % SYMBOL_HASH_SIZE; 249 + sym->next = symbolhash[hash]; 250 + symbolhash[hash] = sym; 262 251 } 263 252 264 - static struct symbol *find_symbol(const char *name) 253 + static void sym_add_unresolved(const char *name, struct module *mod, bool weak) 254 + { 255 + struct symbol *sym; 256 + 257 + sym = alloc_symbol(name); 258 + sym->weak = weak; 259 + 260 + list_add_tail(&sym->list, &mod->unresolved_symbols); 261 + } 262 + 263 + static struct symbol *sym_find_with_module(const char *name, struct module *mod) 265 264 { 266 265 struct symbol *s; 267 266 ··· 275 264 name++; 276 265 277 266 for (s = symbolhash[tdb_hash(name) % SYMBOL_HASH_SIZE]; s; s = s->next) { 278 - if (strcmp(s->name, name) == 0) 267 + if (strcmp(s->name, name) == 0 && (!mod || s->module == mod)) 279 268 return s; 280 269 } 281 270 return NULL; 282 271 } 283 272 284 - static bool contains_namespace(struct namespace_list *list, 285 - const char *namespace) 273 + static struct symbol *find_symbol(const char *name) 286 274 { 287 - for (; list; list = list->next) 275 + return sym_find_with_module(name, NULL); 276 + } 277 + 278 + struct namespace_list { 279 + struct list_head list; 280 + char namespace[]; 281 + }; 282 + 283 + static bool contains_namespace(struct list_head *head, const char *namespace) 284 + { 285 + struct namespace_list *list; 286 + 287 + list_for_each_entry(list, head, list) { 288 288 if (!strcmp(list->namespace, namespace)) 289 289 return true; 290 + } 290 291 291 292 return false; 292 293 } 293 294 294 - static void add_namespace(struct namespace_list **list, const char *namespace) 295 + static void add_namespace(struct list_head *head, const char *namespace) 295 296 { 296 297 struct namespace_list *ns_entry; 297 298 298 - if (!contains_namespace(*list, namespace)) { 299 - ns_entry = NOFAIL(malloc(sizeof(struct namespace_list) + 299 + if (!contains_namespace(head, namespace)) { 300 + ns_entry = NOFAIL(malloc(sizeof(*ns_entry) + 300 301 strlen(namespace) + 1)); 301 302 strcpy(ns_entry->namespace, namespace); 302 - ns_entry->next = *list; 303 - *list = ns_entry; 303 + list_add_tail(&ns_entry->list, head); 304 304 } 305 - } 306 - 307 - static bool module_imports_namespace(struct module *module, 308 - const char *namespace) 309 - { 310 - return contains_namespace(module->imported_namespaces, namespace); 311 - } 312 - 313 - static const struct { 314 - const char *str; 315 - enum export export; 316 - } export_list[] = { 317 - { .str = "EXPORT_SYMBOL", .export = export_plain }, 318 - { .str = "EXPORT_SYMBOL_GPL", .export = export_gpl }, 319 - { .str = "(unknown)", .export = export_unknown }, 320 - }; 321 - 322 - 323 - static const char *export_str(enum export ex) 324 - { 325 - return export_list[ex].str; 326 - } 327 - 328 - static enum export export_no(const char *s) 329 - { 330 - int i; 331 - 332 - if (!s) 333 - return export_unknown; 334 - for (i = 0; export_list[i].export != export_unknown; i++) { 335 - if (strcmp(export_list[i].str, s) == 0) 336 - return export_list[i].export; 337 - } 338 - return export_unknown; 339 305 } 340 306 341 307 static void *sym_get_data_by_offset(const struct elf_info *info, ··· 345 357 346 358 #define strstarts(str, prefix) (strncmp(str, prefix, strlen(prefix)) == 0) 347 359 348 - static enum export export_from_secname(struct elf_info *elf, unsigned int sec) 349 - { 350 - const char *secname = sec_name(elf, sec); 351 - 352 - if (strstarts(secname, "___ksymtab+")) 353 - return export_plain; 354 - else if (strstarts(secname, "___ksymtab_gpl+")) 355 - return export_gpl; 356 - else 357 - return export_unknown; 358 - } 359 - 360 - static enum export export_from_sec(struct elf_info *elf, unsigned int sec) 361 - { 362 - if (sec == elf->export_sec) 363 - return export_plain; 364 - else if (sec == elf->export_gpl_sec) 365 - return export_gpl; 366 - else 367 - return export_unknown; 368 - } 369 - 370 - static const char *namespace_from_kstrtabns(const struct elf_info *info, 371 - const Elf_Sym *sym) 372 - { 373 - const char *value = sym_get_data(info, sym); 374 - return value[0] ? value : NULL; 375 - } 376 - 377 360 static void sym_update_namespace(const char *symname, const char *namespace) 378 361 { 379 362 struct symbol *s = find_symbol(symname); ··· 360 401 } 361 402 362 403 free(s->namespace); 363 - s->namespace = 364 - namespace && namespace[0] ? NOFAIL(strdup(namespace)) : NULL; 404 + s->namespace = namespace[0] ? NOFAIL(strdup(namespace)) : NULL; 365 405 } 366 406 367 - /** 368 - * Add an exported symbol - it may have already been added without a 369 - * CRC, in this case just update the CRC 370 - **/ 371 407 static struct symbol *sym_add_exported(const char *name, struct module *mod, 372 - enum export export) 408 + bool gpl_only) 373 409 { 374 410 struct symbol *s = find_symbol(name); 375 411 376 - if (!s) { 377 - s = new_symbol(name, mod, export); 378 - } else if (!external_module || s->module->is_vmlinux || 379 - s->module == mod) { 380 - warn("%s: '%s' exported twice. Previous export was in %s%s\n", 381 - mod->name, name, s->module->name, 382 - s->module->is_vmlinux ? "" : ".ko"); 383 - return s; 412 + if (s && (!external_module || s->module->is_vmlinux || s->module == mod)) { 413 + error("%s: '%s' exported twice. Previous export was in %s%s\n", 414 + mod->name, name, s->module->name, 415 + s->module->is_vmlinux ? "" : ".ko"); 384 416 } 385 417 418 + s = alloc_symbol(name); 386 419 s->module = mod; 387 - s->export = export; 420 + s->is_gpl_only = gpl_only; 421 + list_add_tail(&s->list, &mod->exported_symbols); 422 + hash_add_symbol(s); 423 + 388 424 return s; 389 425 } 390 426 391 - static void sym_set_crc(const char *name, unsigned int crc) 427 + static void sym_set_crc(struct symbol *sym, unsigned int crc) 392 428 { 393 - struct symbol *s = find_symbol(name); 394 - 395 - /* 396 - * Ignore stand-alone __crc_*, which might be auto-generated symbols 397 - * such as __*_veneer in ARM ELF. 398 - */ 399 - if (!s) 400 - return; 401 - 402 - s->crc = crc; 403 - s->crc_valid = 1; 429 + sym->crc = crc; 430 + sym->crc_valid = true; 404 431 } 405 432 406 433 static void *grab_file(const char *filename, size_t *size) ··· 521 576 fatal("%s has NOBITS .modinfo\n", filename); 522 577 info->modinfo = (void *)hdr + sechdrs[i].sh_offset; 523 578 info->modinfo_len = sechdrs[i].sh_size; 524 - } else if (strcmp(secname, "__ksymtab") == 0) 525 - info->export_sec = i; 526 - else if (strcmp(secname, "__ksymtab_gpl") == 0) 527 - info->export_gpl_sec = i; 579 + } 528 580 529 581 if (sechdrs[i].sh_type == SHT_SYMTAB) { 530 582 unsigned int sh_link_idx; ··· 609 667 return 0; 610 668 } 611 669 612 - static void handle_modversion(const struct module *mod, 613 - const struct elf_info *info, 614 - const Elf_Sym *sym, const char *symname) 615 - { 616 - unsigned int crc; 617 - 618 - if (sym->st_shndx == SHN_UNDEF) { 619 - warn("EXPORT symbol \"%s\" [%s%s] version generation failed, symbol will not be versioned.\n" 620 - "Is \"%s\" prototyped in <asm/asm-prototypes.h>?\n", 621 - symname, mod->name, mod->is_vmlinux ? "" : ".ko", 622 - symname); 623 - 624 - return; 625 - } 626 - 627 - if (sym->st_shndx == SHN_ABS) { 628 - crc = sym->st_value; 629 - } else { 630 - unsigned int *crcp; 631 - 632 - /* symbol points to the CRC in the ELF object */ 633 - crcp = sym_get_data(info, sym); 634 - crc = TO_NATIVE(*crcp); 635 - } 636 - sym_set_crc(symname, crc); 637 - } 638 - 639 670 static void handle_symbol(struct module *mod, struct elf_info *info, 640 671 const Elf_Sym *sym, const char *symname) 641 672 { 642 - enum export export; 643 - const char *name; 644 - 645 - if (strstarts(symname, "__ksymtab")) 646 - export = export_from_secname(info, get_secindex(info, sym)); 647 - else 648 - export = export_from_sec(info, get_secindex(info, sym)); 649 - 650 673 switch (sym->st_shndx) { 651 674 case SHN_COMMON: 652 675 if (strstarts(symname, "__gnu_lto_")) { ··· 639 732 } 640 733 } 641 734 642 - mod->unres = alloc_symbol(symname, 643 - ELF_ST_BIND(sym->st_info) == STB_WEAK, 644 - mod->unres); 735 + sym_add_unresolved(symname, mod, 736 + ELF_ST_BIND(sym->st_info) == STB_WEAK); 645 737 break; 646 738 default: 647 739 /* All exported symbols */ 648 740 if (strstarts(symname, "__ksymtab_")) { 741 + const char *name, *secname; 742 + 649 743 name = symname + strlen("__ksymtab_"); 650 - sym_add_exported(name, mod, export); 744 + secname = sec_name(info, get_secindex(info, sym)); 745 + 746 + if (strstarts(secname, "___ksymtab_gpl+")) 747 + sym_add_exported(name, mod, true); 748 + else if (strstarts(secname, "___ksymtab+")) 749 + sym_add_exported(name, mod, false); 651 750 } 652 751 if (strcmp(symname, "init_module") == 0) 653 - mod->has_init = 1; 752 + mod->has_init = true; 654 753 if (strcmp(symname, "cleanup_module") == 0) 655 - mod->has_cleanup = 1; 754 + mod->has_cleanup = true; 656 755 break; 657 756 } 658 757 } ··· 1916 2003 return s; 1917 2004 } 1918 2005 2006 + /* 2007 + * The CRCs are recorded in .*.cmd files in the form of: 2008 + * #SYMVER <name> <crc> 2009 + */ 2010 + static void extract_crcs_for_object(const char *object, struct module *mod) 2011 + { 2012 + char cmd_file[PATH_MAX]; 2013 + char *buf, *p; 2014 + const char *base; 2015 + int dirlen, ret; 2016 + 2017 + base = strrchr(object, '/'); 2018 + if (base) { 2019 + base++; 2020 + dirlen = base - object; 2021 + } else { 2022 + dirlen = 0; 2023 + base = object; 2024 + } 2025 + 2026 + ret = snprintf(cmd_file, sizeof(cmd_file), "%.*s.%s.cmd", 2027 + dirlen, object, base); 2028 + if (ret >= sizeof(cmd_file)) { 2029 + error("%s: too long path was truncated\n", cmd_file); 2030 + return; 2031 + } 2032 + 2033 + buf = read_text_file(cmd_file); 2034 + p = buf; 2035 + 2036 + while ((p = strstr(p, "\n#SYMVER "))) { 2037 + char *name; 2038 + size_t namelen; 2039 + unsigned int crc; 2040 + struct symbol *sym; 2041 + 2042 + name = p + strlen("\n#SYMVER "); 2043 + 2044 + p = strchr(name, ' '); 2045 + if (!p) 2046 + break; 2047 + 2048 + namelen = p - name; 2049 + p++; 2050 + 2051 + if (!isdigit(*p)) 2052 + continue; /* skip this line */ 2053 + 2054 + crc = strtol(p, &p, 0); 2055 + if (*p != '\n') 2056 + continue; /* skip this line */ 2057 + 2058 + name[namelen] = '\0'; 2059 + 2060 + /* 2061 + * sym_find_with_module() may return NULL here. 2062 + * It typically occurs when CONFIG_TRIM_UNUSED_KSYMS=y. 2063 + * Since commit e1327a127703, genksyms calculates CRCs of all 2064 + * symbols, including trimmed ones. Ignore orphan CRCs. 2065 + */ 2066 + sym = sym_find_with_module(name, mod); 2067 + if (sym) 2068 + sym_set_crc(sym, crc); 2069 + } 2070 + 2071 + free(buf); 2072 + } 2073 + 2074 + /* 2075 + * The symbol versions (CRC) are recorded in the .*.cmd files. 2076 + * Parse them to retrieve CRCs for the current module. 2077 + */ 2078 + static void mod_set_crcs(struct module *mod) 2079 + { 2080 + char objlist[PATH_MAX]; 2081 + char *buf, *p, *obj; 2082 + int ret; 2083 + 2084 + if (mod->is_vmlinux) { 2085 + strcpy(objlist, ".vmlinux.objs"); 2086 + } else { 2087 + /* objects for a module are listed in the *.mod file. */ 2088 + ret = snprintf(objlist, sizeof(objlist), "%s.mod", mod->name); 2089 + if (ret >= sizeof(objlist)) { 2090 + error("%s: too long path was truncated\n", objlist); 2091 + return; 2092 + } 2093 + } 2094 + 2095 + buf = read_text_file(objlist); 2096 + p = buf; 2097 + 2098 + while ((obj = strsep(&p, "\n")) && obj[0]) 2099 + extract_crcs_for_object(obj, mod); 2100 + 2101 + free(buf); 2102 + } 2103 + 1919 2104 static void read_symbols(const char *modname) 1920 2105 { 1921 2106 const char *symname; ··· 2045 2034 if (!license) 2046 2035 error("missing MODULE_LICENSE() in %s\n", modname); 2047 2036 while (license) { 2048 - if (license_is_gpl_compatible(license)) 2049 - mod->gpl_compatible = 1; 2050 - else { 2051 - mod->gpl_compatible = 0; 2037 + if (!license_is_gpl_compatible(license)) { 2038 + mod->is_gpl_compatible = false; 2052 2039 break; 2053 2040 } 2054 2041 license = get_next_modinfo(&info, "license", license); ··· 2073 2064 /* Apply symbol namespaces from __kstrtabns_<symbol> entries. */ 2074 2065 if (strstarts(symname, "__kstrtabns_")) 2075 2066 sym_update_namespace(symname + strlen("__kstrtabns_"), 2076 - namespace_from_kstrtabns(&info, 2077 - sym)); 2078 - 2079 - if (strstarts(symname, "__crc_")) 2080 - handle_modversion(mod, &info, sym, 2081 - symname + strlen("__crc_")); 2067 + sym_get_data(&info, sym)); 2082 2068 } 2083 2069 2084 2070 // check for static EXPORT_SYMBOL_* functions && global vars ··· 2086 2082 sym->st_name)); 2087 2083 2088 2084 if (s) 2089 - s->is_static = 0; 2085 + s->is_static = false; 2090 2086 } 2091 2087 } 2092 2088 ··· 2101 2097 2102 2098 parse_elf_finish(&info); 2103 2099 2104 - /* Our trick to get versioning for module struct etc. - it's 2105 - * never passed as an argument to an exported function, so 2106 - * the automatic versioning doesn't pick it up, but it's really 2107 - * important anyhow */ 2108 - if (modversions) 2109 - mod->unres = alloc_symbol("module_layout", 0, mod->unres); 2100 + if (modversions) { 2101 + /* 2102 + * Our trick to get versioning for module struct etc. - it's 2103 + * never passed as an argument to an exported function, so 2104 + * the automatic versioning doesn't pick it up, but it's really 2105 + * important anyhow. 2106 + */ 2107 + sym_add_unresolved("module_layout", mod, false); 2108 + 2109 + mod_set_crcs(mod); 2110 + } 2110 2111 } 2111 2112 2112 2113 static void read_symbols_from_files(const char *filename) ··· 2164 2155 buf->pos += len; 2165 2156 } 2166 2157 2167 - static void check_for_gpl_usage(enum export exp, const char *m, const char *s) 2168 - { 2169 - switch (exp) { 2170 - case export_gpl: 2171 - error("GPL-incompatible module %s.ko uses GPL-only symbol '%s'\n", 2172 - m, s); 2173 - break; 2174 - case export_plain: 2175 - case export_unknown: 2176 - /* ignore */ 2177 - break; 2178 - } 2179 - } 2180 - 2181 2158 static void check_exports(struct module *mod) 2182 2159 { 2183 2160 struct symbol *s, *exp; 2184 2161 2185 - for (s = mod->unres; s; s = s->next) { 2162 + list_for_each_entry(s, &mod->unresolved_symbols, list) { 2186 2163 const char *basename; 2187 2164 exp = find_symbol(s->name); 2188 - if (!exp || exp->module == mod) { 2165 + if (!exp) { 2189 2166 if (!s->weak && nr_unresolved++ < MAX_UNRESOLVED_REPORTS) 2190 2167 modpost_log(warn_unresolved ? LOG_WARN : LOG_ERROR, 2191 2168 "\"%s\" [%s.ko] undefined!\n", 2192 2169 s->name, mod->name); 2193 2170 continue; 2194 2171 } 2172 + if (exp->module == mod) { 2173 + error("\"%s\" [%s.ko] was exported without definition\n", 2174 + s->name, mod->name); 2175 + continue; 2176 + } 2177 + 2178 + s->module = exp->module; 2179 + s->crc_valid = exp->crc_valid; 2180 + s->crc = exp->crc; 2181 + 2195 2182 basename = strrchr(mod->name, '/'); 2196 2183 if (basename) 2197 2184 basename++; ··· 2195 2190 basename = mod->name; 2196 2191 2197 2192 if (exp->namespace && 2198 - !module_imports_namespace(mod, exp->namespace)) { 2193 + !contains_namespace(&mod->imported_namespaces, exp->namespace)) { 2199 2194 modpost_log(allow_missing_ns_imports ? LOG_WARN : LOG_ERROR, 2200 2195 "module %s uses symbol %s from namespace %s, but does not import it.\n", 2201 2196 basename, exp->name, exp->namespace); 2202 2197 add_namespace(&mod->missing_namespaces, exp->namespace); 2203 2198 } 2204 2199 2205 - if (!mod->gpl_compatible) 2206 - check_for_gpl_usage(exp->export, basename, exp->name); 2200 + if (!mod->is_gpl_compatible && exp->is_gpl_only) 2201 + error("GPL-incompatible module %s.ko uses GPL-only symbol '%s'\n", 2202 + basename, exp->name); 2207 2203 } 2208 2204 } 2209 2205 ··· 2234 2228 buf_printf(b, "#define INCLUDE_VERMAGIC\n"); 2235 2229 buf_printf(b, "#include <linux/build-salt.h>\n"); 2236 2230 buf_printf(b, "#include <linux/elfnote-lto.h>\n"); 2231 + buf_printf(b, "#include <linux/export-internal.h>\n"); 2237 2232 buf_printf(b, "#include <linux/vermagic.h>\n"); 2238 2233 buf_printf(b, "#include <linux/compiler.h>\n"); 2239 2234 buf_printf(b, "\n"); ··· 2255 2248 "#endif\n"); 2256 2249 buf_printf(b, "\t.arch = MODULE_ARCH_INIT,\n"); 2257 2250 buf_printf(b, "};\n"); 2258 - } 2259 2251 2260 - static void add_intree_flag(struct buffer *b, int is_intree) 2261 - { 2262 - if (is_intree) 2252 + if (!external_module) 2263 2253 buf_printf(b, "\nMODULE_INFO(intree, \"Y\");\n"); 2264 - } 2265 2254 2266 - /* Cannot check for assembler */ 2267 - static void add_retpoline(struct buffer *b) 2268 - { 2269 - buf_printf(b, "\n#ifdef CONFIG_RETPOLINE\n"); 2270 - buf_printf(b, "MODULE_INFO(retpoline, \"Y\");\n"); 2271 - buf_printf(b, "#endif\n"); 2272 - } 2255 + buf_printf(b, 2256 + "\n" 2257 + "#ifdef CONFIG_RETPOLINE\n" 2258 + "MODULE_INFO(retpoline, \"Y\");\n" 2259 + "#endif\n"); 2273 2260 2274 - static void add_staging_flag(struct buffer *b, const char *name) 2275 - { 2276 - if (strstarts(name, "drivers/staging")) 2261 + if (strstarts(mod->name, "drivers/staging")) 2277 2262 buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n"); 2263 + } 2264 + 2265 + static void add_exported_symbols(struct buffer *buf, struct module *mod) 2266 + { 2267 + struct symbol *sym; 2268 + 2269 + if (!modversions) 2270 + return; 2271 + 2272 + /* record CRCs for exported symbols */ 2273 + buf_printf(buf, "\n"); 2274 + list_for_each_entry(sym, &mod->exported_symbols, list) { 2275 + if (!sym->crc_valid) { 2276 + warn("EXPORT symbol \"%s\" [%s%s] version generation failed, symbol will not be versioned.\n" 2277 + "Is \"%s\" prototyped in <asm/asm-prototypes.h>?\n", 2278 + sym->name, mod->name, mod->is_vmlinux ? "" : ".ko", 2279 + sym->name); 2280 + continue; 2281 + } 2282 + 2283 + buf_printf(buf, "SYMBOL_CRC(%s, 0x%08x, \"%s\");\n", 2284 + sym->name, sym->crc, sym->is_gpl_only ? "_gpl" : ""); 2285 + } 2278 2286 } 2279 2287 2280 2288 /** ··· 2297 2275 **/ 2298 2276 static void add_versions(struct buffer *b, struct module *mod) 2299 2277 { 2300 - struct symbol *s, *exp; 2301 - 2302 - for (s = mod->unres; s; s = s->next) { 2303 - exp = find_symbol(s->name); 2304 - if (!exp || exp->module == mod) 2305 - continue; 2306 - s->module = exp->module; 2307 - s->crc_valid = exp->crc_valid; 2308 - s->crc = exp->crc; 2309 - } 2278 + struct symbol *s; 2310 2279 2311 2280 if (!modversions) 2312 2281 return; ··· 2306 2293 buf_printf(b, "static const struct modversion_info ____versions[]\n"); 2307 2294 buf_printf(b, "__used __section(\"__versions\") = {\n"); 2308 2295 2309 - for (s = mod->unres; s; s = s->next) { 2296 + list_for_each_entry(s, &mod->unresolved_symbols, list) { 2310 2297 if (!s->module) 2311 2298 continue; 2312 2299 if (!s->crc_valid) { ··· 2332 2319 int first = 1; 2333 2320 2334 2321 /* Clear ->seen flag of modules that own symbols needed by this. */ 2335 - for (s = mod->unres; s; s = s->next) 2322 + list_for_each_entry(s, &mod->unresolved_symbols, list) { 2336 2323 if (s->module) 2337 2324 s->module->seen = s->module->is_vmlinux; 2325 + } 2338 2326 2339 2327 buf_printf(b, "\n"); 2340 2328 buf_printf(b, "MODULE_INFO(depends, \""); 2341 - for (s = mod->unres; s; s = s->next) { 2329 + list_for_each_entry(s, &mod->unresolved_symbols, list) { 2342 2330 const char *p; 2343 2331 if (!s->module) 2344 2332 continue; ··· 2347 2333 if (s->module->seen) 2348 2334 continue; 2349 2335 2350 - s->module->seen = 1; 2336 + s->module->seen = true; 2351 2337 p = strrchr(s->module->name, '/'); 2352 2338 if (p) 2353 2339 p++; ··· 2371 2357 static void write_buf(struct buffer *b, const char *fname) 2372 2358 { 2373 2359 FILE *file; 2360 + 2361 + if (error_occurred) 2362 + return; 2374 2363 2375 2364 file = fopen(fname, "w"); 2376 2365 if (!file) { ··· 2425 2408 write_buf(b, fname); 2426 2409 } 2427 2410 2411 + static void write_vmlinux_export_c_file(struct module *mod) 2412 + { 2413 + struct buffer buf = { }; 2414 + 2415 + buf_printf(&buf, 2416 + "#include <linux/export-internal.h>\n"); 2417 + 2418 + add_exported_symbols(&buf, mod); 2419 + write_if_changed(&buf, ".vmlinux.export.c"); 2420 + free(buf.p); 2421 + } 2422 + 2423 + /* do sanity checks, and generate *.mod.c file */ 2424 + static void write_mod_c_file(struct module *mod) 2425 + { 2426 + struct buffer buf = { }; 2427 + char fname[PATH_MAX]; 2428 + int ret; 2429 + 2430 + check_modname_len(mod); 2431 + check_exports(mod); 2432 + 2433 + add_header(&buf, mod); 2434 + add_exported_symbols(&buf, mod); 2435 + add_versions(&buf, mod); 2436 + add_depends(&buf, mod); 2437 + add_moddevtable(&buf, mod); 2438 + add_srcversion(&buf, mod); 2439 + 2440 + ret = snprintf(fname, sizeof(fname), "%s.mod.c", mod->name); 2441 + if (ret >= sizeof(fname)) { 2442 + error("%s: too long path was truncated\n", fname); 2443 + goto free; 2444 + } 2445 + 2446 + write_if_changed(&buf, fname); 2447 + 2448 + free: 2449 + free(buf.p); 2450 + } 2451 + 2428 2452 /* parse Module.symvers file. line format: 2429 2453 * 0x12345678<tab>symbol<tab>module<tab>export<tab>namespace 2430 2454 **/ ··· 2485 2427 unsigned int crc; 2486 2428 struct module *mod; 2487 2429 struct symbol *s; 2430 + bool gpl_only; 2488 2431 2489 2432 if (!(symname = strchr(line, '\t'))) 2490 2433 goto fail; ··· 2503 2444 crc = strtoul(line, &d, 16); 2504 2445 if (*symname == '\0' || *modname == '\0' || *d != '\0') 2505 2446 goto fail; 2447 + 2448 + if (!strcmp(export, "EXPORT_SYMBOL_GPL")) { 2449 + gpl_only = true; 2450 + } else if (!strcmp(export, "EXPORT_SYMBOL")) { 2451 + gpl_only = false; 2452 + } else { 2453 + error("%s: unknown license %s. skip", symname, export); 2454 + continue; 2455 + } 2456 + 2506 2457 mod = find_module(modname); 2507 2458 if (!mod) { 2508 2459 mod = new_module(modname); 2509 - mod->from_dump = 1; 2460 + mod->from_dump = true; 2510 2461 } 2511 - s = sym_add_exported(symname, mod, export_no(export)); 2512 - s->is_static = 0; 2513 - sym_set_crc(symname, crc); 2462 + s = sym_add_exported(symname, mod, gpl_only); 2463 + s->is_static = false; 2464 + sym_set_crc(s, crc); 2514 2465 sym_update_namespace(symname, namespace); 2515 2466 } 2516 2467 free(buf); ··· 2533 2464 static void write_dump(const char *fname) 2534 2465 { 2535 2466 struct buffer buf = { }; 2536 - struct symbol *symbol; 2537 - const char *namespace; 2538 - int n; 2467 + struct module *mod; 2468 + struct symbol *sym; 2539 2469 2540 - for (n = 0; n < SYMBOL_HASH_SIZE ; n++) { 2541 - symbol = symbolhash[n]; 2542 - while (symbol) { 2543 - if (!symbol->module->from_dump) { 2544 - namespace = symbol->namespace; 2545 - buf_printf(&buf, "0x%08x\t%s\t%s\t%s\t%s\n", 2546 - symbol->crc, symbol->name, 2547 - symbol->module->name, 2548 - export_str(symbol->export), 2549 - namespace ? namespace : ""); 2550 - } 2551 - symbol = symbol->next; 2470 + list_for_each_entry(mod, &modules, list) { 2471 + if (mod->from_dump) 2472 + continue; 2473 + list_for_each_entry(sym, &mod->exported_symbols, list) { 2474 + buf_printf(&buf, "0x%08x\t%s\t%s\tEXPORT_SYMBOL%s\t%s\n", 2475 + sym->crc, sym->name, mod->name, 2476 + sym->is_gpl_only ? "_GPL" : "", 2477 + sym->namespace ?: ""); 2552 2478 } 2553 2479 } 2554 2480 write_buf(&buf, fname); ··· 2556 2492 struct namespace_list *ns; 2557 2493 struct buffer ns_deps_buf = {}; 2558 2494 2559 - for (mod = modules; mod; mod = mod->next) { 2495 + list_for_each_entry(mod, &modules, list) { 2560 2496 2561 - if (mod->from_dump || !mod->missing_namespaces) 2497 + if (mod->from_dump || list_empty(&mod->missing_namespaces)) 2562 2498 continue; 2563 2499 2564 2500 buf_printf(&ns_deps_buf, "%s.ko:", mod->name); 2565 2501 2566 - for (ns = mod->missing_namespaces; ns; ns = ns->next) 2502 + list_for_each_entry(ns, &mod->missing_namespaces, list) 2567 2503 buf_printf(&ns_deps_buf, " %s", ns->namespace); 2568 2504 2569 2505 buf_printf(&ns_deps_buf, "\n"); ··· 2574 2510 } 2575 2511 2576 2512 struct dump_list { 2577 - struct dump_list *next; 2513 + struct list_head list; 2578 2514 const char *file; 2579 2515 }; 2580 2516 2581 2517 int main(int argc, char **argv) 2582 2518 { 2583 2519 struct module *mod; 2584 - struct buffer buf = { }; 2585 2520 char *missing_namespace_deps = NULL; 2586 2521 char *dump_write = NULL, *files_source = NULL; 2587 2522 int opt; 2588 2523 int n; 2589 - struct dump_list *dump_read_start = NULL; 2590 - struct dump_list **dump_read_iter = &dump_read_start; 2524 + LIST_HEAD(dump_lists); 2525 + struct dump_list *dl, *dl2; 2591 2526 2592 2527 while ((opt = getopt(argc, argv, "ei:mnT:o:awENd:")) != -1) { 2593 2528 switch (opt) { 2594 2529 case 'e': 2595 - external_module = 1; 2530 + external_module = true; 2596 2531 break; 2597 2532 case 'i': 2598 - *dump_read_iter = 2599 - NOFAIL(calloc(1, sizeof(**dump_read_iter))); 2600 - (*dump_read_iter)->file = optarg; 2601 - dump_read_iter = &(*dump_read_iter)->next; 2533 + dl = NOFAIL(malloc(sizeof(*dl))); 2534 + dl->file = optarg; 2535 + list_add_tail(&dl->list, &dump_lists); 2602 2536 break; 2603 2537 case 'm': 2604 - modversions = 1; 2538 + modversions = true; 2605 2539 break; 2606 2540 case 'n': 2607 - ignore_missing_files = 1; 2541 + ignore_missing_files = true; 2608 2542 break; 2609 2543 case 'o': 2610 2544 dump_write = optarg; 2611 2545 break; 2612 2546 case 'a': 2613 - all_versions = 1; 2547 + all_versions = true; 2614 2548 break; 2615 2549 case 'T': 2616 2550 files_source = optarg; 2617 2551 break; 2618 2552 case 'w': 2619 - warn_unresolved = 1; 2553 + warn_unresolved = true; 2620 2554 break; 2621 2555 case 'E': 2622 2556 sec_mismatch_warn_only = false; 2623 2557 break; 2624 2558 case 'N': 2625 - allow_missing_ns_imports = 1; 2559 + allow_missing_ns_imports = true; 2626 2560 break; 2627 2561 case 'd': 2628 2562 missing_namespace_deps = optarg; ··· 2630 2568 } 2631 2569 } 2632 2570 2633 - while (dump_read_start) { 2634 - struct dump_list *tmp; 2635 - 2636 - read_dump(dump_read_start->file); 2637 - tmp = dump_read_start->next; 2638 - free(dump_read_start); 2639 - dump_read_start = tmp; 2571 + list_for_each_entry_safe(dl, dl2, &dump_lists, list) { 2572 + read_dump(dl->file); 2573 + list_del(&dl->list); 2574 + free(dl); 2640 2575 } 2641 2576 2642 2577 while (optind < argc) ··· 2642 2583 if (files_source) 2643 2584 read_symbols_from_files(files_source); 2644 2585 2645 - for (mod = modules; mod; mod = mod->next) { 2646 - char fname[PATH_MAX]; 2647 - 2648 - if (mod->is_vmlinux || mod->from_dump) 2586 + list_for_each_entry(mod, &modules, list) { 2587 + if (mod->from_dump) 2649 2588 continue; 2650 2589 2651 - buf.pos = 0; 2652 - 2653 - check_modname_len(mod); 2654 - check_exports(mod); 2655 - 2656 - add_header(&buf, mod); 2657 - add_intree_flag(&buf, !external_module); 2658 - add_retpoline(&buf); 2659 - add_staging_flag(&buf, mod->name); 2660 - add_versions(&buf, mod); 2661 - add_depends(&buf, mod); 2662 - add_moddevtable(&buf, mod); 2663 - add_srcversion(&buf, mod); 2664 - 2665 - sprintf(fname, "%s.mod.c", mod->name); 2666 - write_if_changed(&buf, fname); 2590 + if (mod->is_vmlinux) 2591 + write_vmlinux_export_c_file(mod); 2592 + else 2593 + write_mod_c_file(mod); 2667 2594 } 2668 2595 2669 2596 if (missing_namespace_deps) ··· 2665 2620 2666 2621 for (s = symbolhash[n]; s; s = s->next) { 2667 2622 if (s->is_static) 2668 - error("\"%s\" [%s] is a static %s\n", 2669 - s->name, s->module->name, 2670 - export_str(s->export)); 2623 + error("\"%s\" [%s] is a static EXPORT_SYMBOL\n", 2624 + s->name, s->module->name); 2671 2625 } 2672 2626 } 2673 2627 2674 2628 if (nr_unresolved > MAX_UNRESOLVED_REPORTS) 2675 2629 warn("suppressed %u unresolved symbol warnings because there were too many)\n", 2676 2630 nr_unresolved - MAX_UNRESOLVED_REPORTS); 2677 - 2678 - free(buf.p); 2679 2631 2680 2632 return error_occurred ? 1 : 0; 2681 2633 }
+13 -18
scripts/mod/modpost.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 + #include <stdbool.h> 2 3 #include <stdio.h> 3 4 #include <stdlib.h> 4 5 #include <stdarg.h> ··· 11 10 #include <unistd.h> 12 11 #include <elf.h> 13 12 13 + #include "list.h" 14 14 #include "elfconfig.h" 15 15 16 16 /* On BSD-alike OSes elf.h defines these according to host's word size */ ··· 111 109 void 112 110 buf_write(struct buffer *buf, const char *s, int len); 113 111 114 - struct namespace_list { 115 - struct namespace_list *next; 116 - char namespace[]; 117 - }; 118 - 119 112 struct module { 120 - struct module *next; 121 - int gpl_compatible; 122 - struct symbol *unres; 123 - int from_dump; /* 1 if module was loaded from *.symvers */ 124 - int is_vmlinux; 125 - int seen; 126 - int has_init; 127 - int has_cleanup; 113 + struct list_head list; 114 + struct list_head exported_symbols; 115 + struct list_head unresolved_symbols; 116 + bool is_gpl_compatible; 117 + bool from_dump; /* true if module was loaded from *.symvers */ 118 + bool is_vmlinux; 119 + bool seen; 120 + bool has_init; 121 + bool has_cleanup; 128 122 struct buffer dev_table_buf; 129 123 char srcversion[25]; 130 124 // Missing namespace dependencies 131 - struct namespace_list *missing_namespaces; 125 + struct list_head missing_namespaces; 132 126 // Actual imported namespaces 133 - struct namespace_list *imported_namespaces; 127 + struct list_head imported_namespaces; 134 128 char name[]; 135 129 }; 136 130 ··· 136 138 Elf_Shdr *sechdrs; 137 139 Elf_Sym *symtab_start; 138 140 Elf_Sym *symtab_stop; 139 - Elf_Section export_sec; 140 - Elf_Section export_gpl_sec; 141 141 char *strtab; 142 142 char *modinfo; 143 143 unsigned int modinfo_len; ··· 174 178 } 175 179 176 180 /* file2alias.c */ 177 - extern unsigned int cross_build; 178 181 void handle_moddevtable(struct module *mod, struct elf_info *info, 179 182 Elf_Sym *sym, const char *symname); 180 183 void add_moddevtable(struct buffer *buf, struct module *mod);
+5 -14
scripts/mod/sumversion.c
··· 290 290 return 1; 291 291 } 292 292 /* Check whether the file is a static library or not */ 293 - static int is_static_library(const char *objfile) 293 + static bool is_static_library(const char *objfile) 294 294 { 295 295 int len = strlen(objfile); 296 - if (objfile[len - 2] == '.' && objfile[len - 1] == 'a') 297 - return 1; 298 - else 299 - return 0; 296 + 297 + return objfile[len - 2] == '.' && objfile[len - 1] == 'a'; 300 298 } 301 299 302 300 /* We have dir/file.o. Open dir/.file.o.cmd, look for source_ and deps_ line ··· 385 387 /* Calc and record src checksum. */ 386 388 void get_src_version(const char *modname, char sum[], unsigned sumlen) 387 389 { 388 - char *buf, *pos, *firstline; 390 + char *buf; 389 391 struct md4_ctx md; 390 392 char *fname; 391 393 char filelist[PATH_MAX + 1]; ··· 395 397 396 398 buf = read_text_file(filelist); 397 399 398 - pos = buf; 399 - firstline = get_line(&pos); 400 - if (!firstline) { 401 - warn("bad ending versions file for %s\n", modname); 402 - goto free; 403 - } 404 - 405 400 md4_init(&md); 406 - while ((fname = strsep(&firstline, " "))) { 401 + while ((fname = strsep(&buf, "\n"))) { 407 402 if (!*fname) 408 403 continue; 409 404 if (!(is_static_library(fname)) &&
+5 -1
scripts/prune-kernel
··· 16 16 rm -f "/boot/initramfs-$f.img" "/boot/System.map-$f" 17 17 rm -f "/boot/vmlinuz-$f" "/boot/config-$f" 18 18 rm -rf "/lib/modules/$f" 19 - new-kernel-pkg --remove $f 19 + if [ -x "$(command -v new-kernel-pkg)" ]; then 20 + new-kernel-pkg --remove $f 21 + elif [ -x "$(command -v kernel-install)" ]; then 22 + kernel-install remove $f 23 + fi 20 24 fi 21 25 done
+2 -2
tools/objtool/Makefile
··· 19 19 OBJTOOL := $(OUTPUT)objtool 20 20 OBJTOOL_IN := $(OBJTOOL)-in.o 21 21 22 - LIBELF_FLAGS := $(shell pkg-config libelf --cflags 2>/dev/null) 23 - LIBELF_LIBS := $(shell pkg-config libelf --libs 2>/dev/null || echo -lelf) 22 + LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null) 23 + LIBELF_LIBS := $(shell $(HOSTPKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf) 24 24 25 25 all: $(OBJTOOL) 26 26
+1 -1
usr/include/Makefile
··· 82 82 # Include the header twice to detect missing include guard. 83 83 quiet_cmd_hdrtest = HDRTEST $< 84 84 cmd_hdrtest = \ 85 - $(CC) $(c_flags) -S -o /dev/null -x c /dev/null \ 85 + $(CC) $(c_flags) -fsyntax-only -x c /dev/null \ 86 86 $(if $(filter-out $(no-header-test), $*.h), -include $< -include $<); \ 87 87 $(PERL) $(srctree)/$(src)/headers_check.pl $(obj) $(SRCARCH) $<; \ 88 88 touch $@