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

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

Pull Kbuild updates from Masahiro Yamada:

- Remove the support for -O3 (CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3)

- Fix error of rpm-pkg cross-builds

- Support riscv for checkstack tool

- Re-enable -Wformwat warnings for Clang

- Clean up modpost, Makefiles, and misc scripts

* tag 'kbuild-v5.20' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: (30 commits)
modpost: remove .symbol_white_list field entirely
modpost: remove unneeded .symbol_white_list initializers
modpost: add PATTERNS() helper macro
modpost: shorten warning messages in report_sec_mismatch()
Revert "Kbuild, lto, workaround: Don't warn for initcall_reference in modpost"
modpost: use more reliable way to get fromsec in section_rel(a)()
modpost: add array range check to sec_name()
modpost: refactor get_secindex()
kbuild: set EXIT trap before creating temporary directory
modpost: remove unused Elf_Sword macro
Makefile.extrawarn: re-enable -Wformat for clang
kbuild: add dtbs_prepare target
kconfig: Qt5: tell the user which packages are required
modpost: use sym_get_data() to get module device_table data
modpost: drop executable ELF support
checkstack: add riscv support for scripts/checkstack.pl
kconfig: shorten the temporary directory name for cc-option
scripts: headers_install.sh: Update config leak ignore entries
kbuild: error out if $(INSTALL_MOD_PATH) contains % or :
kbuild: error out if $(KBUILD_EXTMOD) contains % or :
...

+111 -313
+1 -1
Documentation/kbuild/kconfig-language.rst
··· 672 672 Work on kconfig is welcomed on both areas of clarifying semantics and on 673 673 evaluating the use of a full SAT solver for it. A full SAT solver can be 674 674 desirable to enable more complex dependency mappings and / or queries, 675 - for instance on possible use case for a SAT solver could be that of handling 675 + for instance one possible use case for a SAT solver could be that of handling 676 676 the current known recursive dependency issues. It is not known if this would 677 677 address such issues but such evaluation is desirable. If support for a full SAT 678 678 solver proves too complex or that it cannot address recursive dependency issues
-1
MAINTAINERS
··· 4783 4783 S: Maintained 4784 4784 F: Documentation/admin-guide/module-signing.rst 4785 4785 F: certs/ 4786 - F: scripts/check-blacklist-hashes.awk 4787 4786 F: scripts/sign-file.c 4788 4787 F: tools/certs/ 4789 4788
+12 -6
Makefile
··· 129 129 $(if $(word 2, $(KBUILD_EXTMOD)), \ 130 130 $(error building multiple external modules is not supported)) 131 131 132 + $(foreach x, % :, $(if $(findstring $x, $(KBUILD_EXTMOD)), \ 133 + $(error module directory path cannot contain '$x'))) 134 + 132 135 # Remove trailing slashes 133 136 ifneq ($(filter %/, $(KBUILD_EXTMOD)),) 134 137 KBUILD_EXTMOD := $(shell dirname $(KBUILD_EXTMOD).) ··· 758 755 759 756 ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE 760 757 KBUILD_CFLAGS += -O2 761 - else ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3 762 - KBUILD_CFLAGS += -O3 763 758 else ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE 764 759 KBUILD_CFLAGS += -Os 765 760 endif ··· 1371 1370 1372 1371 ifneq ($(dtstree),) 1373 1372 1374 - %.dtb: include/config/kernel.release scripts_dtc 1373 + %.dtb: dtbs_prepare 1375 1374 $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@ 1376 1375 1377 - %.dtbo: include/config/kernel.release scripts_dtc 1376 + %.dtbo: dtbs_prepare 1378 1377 $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@ 1379 1378 1380 - PHONY += dtbs dtbs_install dtbs_check 1381 - dtbs: include/config/kernel.release scripts_dtc 1379 + PHONY += dtbs dtbs_prepare dtbs_install dtbs_check 1380 + dtbs: dtbs_prepare 1382 1381 $(Q)$(MAKE) $(build)=$(dtstree) 1382 + 1383 + # include/config/kernel.release is actually needed when installing DTBs because 1384 + # INSTALL_DTBS_PATH contains $(KERNELRELEASE). However, we do not want to make 1385 + # dtbs_install depend on it as dtbs_install may run as root. 1386 + dtbs_prepare: include/config/kernel.release scripts_dtc 1383 1387 1384 1388 ifneq ($(filter dtbs_check, $(MAKECMDGOALS)),) 1385 1389 export CHECK_DTBS=y
-1
arch/arc/configs/axs101_defconfig
··· 9 9 # CONFIG_UTS_NS is not set 10 10 # CONFIG_PID_NS is not set 11 11 CONFIG_BLK_DEV_INITRD=y 12 - CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y 13 12 CONFIG_EMBEDDED=y 14 13 CONFIG_PERF_EVENTS=y 15 14 # CONFIG_VM_EVENT_COUNTERS is not set
-1
arch/arc/configs/axs103_defconfig
··· 9 9 # CONFIG_UTS_NS is not set 10 10 # CONFIG_PID_NS is not set 11 11 CONFIG_BLK_DEV_INITRD=y 12 - CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y 13 12 CONFIG_EMBEDDED=y 14 13 CONFIG_PERF_EVENTS=y 15 14 # CONFIG_VM_EVENT_COUNTERS is not set
-1
arch/arc/configs/axs103_smp_defconfig
··· 9 9 # CONFIG_UTS_NS is not set 10 10 # CONFIG_PID_NS is not set 11 11 CONFIG_BLK_DEV_INITRD=y 12 - CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y 13 12 CONFIG_EMBEDDED=y 14 13 CONFIG_PERF_EVENTS=y 15 14 # CONFIG_VM_EVENT_COUNTERS is not set
-1
arch/arc/configs/haps_hs_defconfig
··· 11 11 # CONFIG_UTS_NS is not set 12 12 # CONFIG_PID_NS is not set 13 13 CONFIG_BLK_DEV_INITRD=y 14 - CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y 15 14 CONFIG_EXPERT=y 16 15 CONFIG_PERF_EVENTS=y 17 16 # CONFIG_COMPAT_BRK is not set
-1
arch/arc/configs/haps_hs_smp_defconfig
··· 11 11 # CONFIG_UTS_NS is not set 12 12 # CONFIG_PID_NS is not set 13 13 CONFIG_BLK_DEV_INITRD=y 14 - CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y 15 14 CONFIG_EMBEDDED=y 16 15 CONFIG_PERF_EVENTS=y 17 16 # CONFIG_VM_EVENT_COUNTERS is not set
-1
arch/arc/configs/hsdk_defconfig
··· 9 9 # CONFIG_PID_NS is not set 10 10 CONFIG_BLK_DEV_INITRD=y 11 11 CONFIG_BLK_DEV_RAM=y 12 - CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y 13 12 CONFIG_EMBEDDED=y 14 13 CONFIG_PERF_EVENTS=y 15 14 # CONFIG_VM_EVENT_COUNTERS is not set
-1
arch/arc/configs/nsim_700_defconfig
··· 11 11 # CONFIG_UTS_NS is not set 12 12 # CONFIG_PID_NS is not set 13 13 CONFIG_BLK_DEV_INITRD=y 14 - CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y 15 14 CONFIG_KALLSYMS_ALL=y 16 15 CONFIG_EMBEDDED=y 17 16 CONFIG_PERF_EVENTS=y
-1
arch/arc/configs/nsimosci_defconfig
··· 10 10 # CONFIG_UTS_NS is not set 11 11 # CONFIG_PID_NS is not set 12 12 CONFIG_BLK_DEV_INITRD=y 13 - CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y 14 13 CONFIG_KALLSYMS_ALL=y 15 14 CONFIG_EMBEDDED=y 16 15 CONFIG_PERF_EVENTS=y
-1
arch/arc/configs/nsimosci_hs_defconfig
··· 10 10 # CONFIG_UTS_NS is not set 11 11 # CONFIG_PID_NS is not set 12 12 CONFIG_BLK_DEV_INITRD=y 13 - CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y 14 13 CONFIG_KALLSYMS_ALL=y 15 14 CONFIG_EMBEDDED=y 16 15 CONFIG_PERF_EVENTS=y
-1
arch/arc/configs/nsimosci_hs_smp_defconfig
··· 8 8 # CONFIG_UTS_NS is not set 9 9 # CONFIG_PID_NS is not set 10 10 CONFIG_BLK_DEV_INITRD=y 11 - CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y 12 11 CONFIG_PERF_EVENTS=y 13 12 # CONFIG_COMPAT_BRK is not set 14 13 CONFIG_KPROBES=y
-1
arch/arc/configs/tb10x_defconfig
··· 14 14 CONFIG_INITRAMFS_ROOT_UID=2100 15 15 CONFIG_INITRAMFS_ROOT_GID=501 16 16 # CONFIG_RD_GZIP is not set 17 - CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y 18 17 CONFIG_KALLSYMS_ALL=y 19 18 # CONFIG_AIO is not set 20 19 CONFIG_EMBEDDED=y
-1
arch/arc/configs/vdk_hs38_defconfig
··· 4 4 CONFIG_IKCONFIG=y 5 5 CONFIG_IKCONFIG_PROC=y 6 6 CONFIG_BLK_DEV_INITRD=y 7 - CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y 8 7 CONFIG_EMBEDDED=y 9 8 CONFIG_PERF_EVENTS=y 10 9 # CONFIG_VM_EVENT_COUNTERS is not set
-1
arch/arc/configs/vdk_hs38_smp_defconfig
··· 4 4 CONFIG_IKCONFIG=y 5 5 CONFIG_IKCONFIG_PROC=y 6 6 CONFIG_BLK_DEV_INITRD=y 7 - CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y 8 7 CONFIG_EMBEDDED=y 9 8 CONFIG_PERF_EVENTS=y 10 9 # CONFIG_VM_EVENT_COUNTERS is not set
+6 -8
certs/Makefile
··· 4 4 # 5 5 6 6 obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o 7 - obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o 7 + obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o blacklist_hashes.o 8 8 obj-$(CONFIG_SYSTEM_REVOCATION_LIST) += revocation_certificates.o 9 - ifneq ($(CONFIG_SYSTEM_BLACKLIST_HASH_LIST),) 10 9 11 10 $(obj)/blacklist_hashes.o: $(obj)/blacklist_hash_list 12 11 CFLAGS_blacklist_hashes.o := -I $(obj) 13 12 14 13 quiet_cmd_check_and_copy_blacklist_hash_list = GEN $@ 15 14 cmd_check_and_copy_blacklist_hash_list = \ 16 - $(AWK) -f $(srctree)/scripts/check-blacklist-hashes.awk $(CONFIG_SYSTEM_BLACKLIST_HASH_LIST) >&2; \ 17 - cat $(CONFIG_SYSTEM_BLACKLIST_HASH_LIST) > $@ 15 + $(if $(CONFIG_SYSTEM_BLACKLIST_HASH_LIST), \ 16 + $(AWK) -f $(srctree)/$(src)/check-blacklist-hashes.awk $(CONFIG_SYSTEM_BLACKLIST_HASH_LIST) >&2; \ 17 + { cat $(CONFIG_SYSTEM_BLACKLIST_HASH_LIST); echo $(comma) NULL; } > $@, \ 18 + echo NULL > $@) 18 19 19 20 $(obj)/blacklist_hash_list: $(CONFIG_SYSTEM_BLACKLIST_HASH_LIST) FORCE 20 21 $(call if_changed,check_and_copy_blacklist_hash_list) 21 - obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_hashes.o 22 - else 23 - obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_nohashes.o 24 - endif 22 + 25 23 targets += blacklist_hash_list 26 24 27 25 quiet_cmd_extract_certs = CERT $@
-1
certs/blacklist_hashes.c
··· 3 3 4 4 const char __initconst *const blacklist_hashes[] = { 5 5 #include "blacklist_hash_list" 6 - , NULL 7 6 };
-6
certs/blacklist_nohashes.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - #include "blacklist.h" 3 - 4 - const char __initconst *const blacklist_hashes[] = { 5 - NULL 6 - };
+5 -11
init/Kconfig
··· 1411 1411 with the "-O2" compiler flag for best performance and most 1412 1412 helpful compile-time warnings. 1413 1413 1414 - config CC_OPTIMIZE_FOR_PERFORMANCE_O3 1415 - bool "Optimize more for performance (-O3)" 1416 - depends on ARC 1417 - help 1418 - Choosing this option will pass "-O3" to your compiler to optimize 1419 - the kernel yet more for performance. 1420 - 1421 1414 config CC_OPTIMIZE_FOR_SIZE 1422 1415 bool "Optimize for size (-Os)" 1423 1416 help ··· 1726 1733 help 1727 1734 Normally kallsyms only contains the symbols of functions for nicer 1728 1735 OOPS messages and backtraces (i.e., symbols from the text and inittext 1729 - sections). This is sufficient for most cases. And only in very rare 1730 - cases (e.g., when a debugger is used) all symbols are required (e.g., 1731 - names of variables from the data sections, etc). 1736 + sections). This is sufficient for most cases. And only if you want to 1737 + enable kernel live patching, or other less common use cases (e.g., 1738 + when a debugger is used) all symbols are required (i.e., names of 1739 + variables from the data sections, etc). 1732 1740 1733 1741 This option makes sure that all symbols are loaded into the kernel 1734 1742 image (i.e., symbols from all sections) in cost of increased kernel 1735 1743 size (depending on the kernel configuration, it may be 300KiB or 1736 1744 something like this). 1737 1745 1738 - Say N unless you really need all symbols. 1746 + Say N unless you really need all symbols, or kernel live patching. 1739 1747 1740 1748 config KALLSYMS_ABSOLUTE_PERCPU 1741 1749 bool
+1 -1
scripts/Kconfig.include
··· 25 25 26 26 # $(cc-option,<flag>) 27 27 # Return y if the compiler supports <flag>, n otherwise 28 - cc-option = $(success,mkdir .tmp_$$$$; trap "rm -rf .tmp_$$$$" EXIT; $(CC) -Werror $(CLANG_FLAGS) $(1) -c -x c /dev/null -o .tmp_$$$$/tmp.o) 28 + cc-option = $(success,trap "rm -rf .tmp_$$" EXIT; mkdir .tmp_$$; $(CC) -Werror $(CLANG_FLAGS) $(1) -c -x c /dev/null -o .tmp_$$/tmp.o) 29 29 30 30 # $(ld-option,<flag>) 31 31 # Return y if the linker supports <flag>, n otherwise
+2 -3
scripts/Makefile.build
··· 358 358 359 359 quiet_cmd_ar_builtin = AR $@ 360 360 cmd_ar_builtin = rm -f $@; \ 361 - echo $(patsubst $(obj)/%,%,$(real-prereqs)) | \ 362 - sed -E 's:([^ ]+):$(obj)/\1:g' | \ 363 - xargs $(AR) cDPrST $@ 361 + $(if $(real-prereqs), printf "$(obj)/%s " $(patsubst $(obj)/%,%,$(real-prereqs)) | xargs) \ 362 + $(AR) cDPrST $@ 364 363 365 364 $(obj)/built-in.a: $(real-obj-y) FORCE 366 365 $(call if_changed,ar_builtin)
+1 -1
scripts/Makefile.compiler
··· 21 21 # automatically cleaned up. 22 22 try-run = $(shell set -e; \ 23 23 TMP=$(TMPOUT)/tmp; \ 24 - mkdir -p $(TMPOUT); \ 25 24 trap "rm -rf $(TMPOUT)" EXIT; \ 25 + mkdir -p $(TMPOUT); \ 26 26 if ($(1)) >/dev/null 2>&1; \ 27 27 then echo "$(2)"; \ 28 28 else echo "$(3)"; \
-1
scripts/Makefile.extrawarn
··· 47 47 48 48 ifdef CONFIG_CC_IS_CLANG 49 49 KBUILD_CFLAGS += -Wno-initializer-overrides 50 - KBUILD_CFLAGS += -Wno-format 51 50 KBUILD_CFLAGS += -Wno-sign-compare 52 51 KBUILD_CFLAGS += -Wno-format-zero-length 53 52 KBUILD_CFLAGS += $(call cc-disable-warning, pointer-to-enum-cast)
+3
scripts/Makefile.modinst
··· 18 18 dst := $(MODLIB)/$(INSTALL_MOD_DIR) 19 19 endif 20 20 21 + $(foreach x, % :, $(if $(findstring $x, $(dst)), \ 22 + $(error module installation path cannot contain '$x'))) 23 + 21 24 suffix-y := 22 25 suffix-$(CONFIG_MODULE_COMPRESS_GZIP) := .gz 23 26 suffix-$(CONFIG_MODULE_COMPRESS_XZ) := .xz
+2 -2
scripts/Makefile.package
··· 56 56 $(MAKE) clean 57 57 $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec 58 58 $(call cmd,src_tar,$(KERNELPATH),kernel.spec) 59 - +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE) -ta $(KERNELPATH).tar.gz \ 59 + +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -ta $(KERNELPATH).tar.gz \ 60 60 --define='_smp_mflags %{nil}' 61 61 62 62 # binrpm-pkg ··· 66 66 $(MAKE) -f $(srctree)/Makefile 67 67 $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec 68 68 +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \ 69 - $(UTS_MACHINE) -bb $(objtree)/binkernel.spec 69 + $(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec 70 70 71 71 PHONY += deb-pkg 72 72 deb-pkg:
scripts/check-blacklist-hashes.awk certs/check-blacklist-hashes.awk
+4
scripts/checkstack.pl
··· 16 16 # AArch64, PARISC ports by Kyle McMartin 17 17 # sparc port by Martin Habets <errandir_news@mph.eclipse.co.uk> 18 18 # ppc64le port by Breno Leitao <leitao@debian.org> 19 + # riscv port by Wadim Mueller <wafgo01@gmail.com> 19 20 # 20 21 # Usage: 21 22 # objdump -d vmlinux | scripts/checkstack.pl [arch] ··· 109 108 } elsif ($arch eq 'sparc' || $arch eq 'sparc64') { 110 109 # f0019d10: 9d e3 bf 90 save %sp, -112, %sp 111 110 $re = qr/.*save.*%sp, -(([0-9]{2}|[3-9])[0-9]{2}), %sp/o; 111 + } elsif ($arch =~ /^riscv(64)?$/) { 112 + #ffffffff8036e868: c2010113 addi sp,sp,-992 113 + $re = qr/.*addi.*sp,sp,-(([0-9]{2}|[3-9])[0-9]{2})/o; 112 114 } else { 113 115 print("wrong or unknown architecture \"$arch\"\n"); 114 116 exit
scripts/dummy-tools/dummy-plugin-dir/include/plugin-version.h
+2 -6
scripts/dummy-tools/gcc
··· 96 96 97 97 # To set GCC_PLUGINS 98 98 if arg_contain -print-file-name=plugin "$@"; then 99 - plugin_dir=$(mktemp -d) 100 - 101 - mkdir -p $plugin_dir/include 102 - touch $plugin_dir/include/plugin-version.h 103 - 104 - echo $plugin_dir 99 + # Use $0 to find the in-tree dummy directory 100 + echo "$(dirname "$(readlink -f "$0")")/dummy-plugin-dir" 105 101 exit 0 106 102 fi 107 103
-2
scripts/headers_install.sh
··· 70 70 # 71 71 # The format is <file-name>:<CONFIG-option> in each line. 72 72 config_leak_ignores=" 73 - arch/alpha/include/uapi/asm/setup.h:CONFIG_ALPHA_LEGACY_START_ADDRESS 74 73 arch/arc/include/uapi/asm/page.h:CONFIG_ARC_PAGE_SIZE_16K 75 74 arch/arc/include/uapi/asm/page.h:CONFIG_ARC_PAGE_SIZE_4K 76 75 arch/arc/include/uapi/asm/swab.h:CONFIG_ARC_HAS_SWAPE ··· 83 84 arch/x86/include/uapi/asm/auxvec.h:CONFIG_IA32_EMULATION 84 85 arch/x86/include/uapi/asm/auxvec.h:CONFIG_X86_64 85 86 arch/x86/include/uapi/asm/mman.h:CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS 86 - include/uapi/asm-generic/fcntl.h:CONFIG_64BIT 87 87 include/uapi/linux/atmdev.h:CONFIG_COMPAT 88 88 include/uapi/linux/eventpoll.h:CONFIG_PM_SLEEP 89 89 include/uapi/linux/hw_breakpoint.h:CONFIG_HAVE_MIXED_BREAKPOINTS_REGS
+1
scripts/kconfig/qconf-cfg.sh
··· 20 20 echo >&2 "*" 21 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 + echo >&2 "* You need $PKG" 23 24 echo >&2 "*" 24 25 exit 1
+1 -3
scripts/mod/file2alias.c
··· 1571 1571 zeros = calloc(1, sym->st_size); 1572 1572 symval = zeros; 1573 1573 } else { 1574 - symval = (void *)info->hdr 1575 - + info->sechdrs[get_secindex(info, sym)].sh_offset 1576 - + sym->st_value; 1574 + symval = sym_get_data(info, sym); 1577 1575 } 1578 1576 1579 1577 /* First handle the "special" cases */
+48 -233
scripts/mod/modpost.c
··· 321 321 { 322 322 Elf_Shdr *sechdr = &info->sechdrs[secindex]; 323 323 324 - if (info->hdr->e_type != ET_REL) 325 - offset -= sechdr->sh_addr; 326 - 327 324 return (void *)info->hdr + sechdr->sh_offset + offset; 328 325 } 329 326 330 - static void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym) 327 + void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym) 331 328 { 332 329 return sym_get_data_by_offset(info, get_secindex(info, sym), 333 330 sym->st_value); ··· 336 339 sechdr->sh_name); 337 340 } 338 341 339 - static const char *sec_name(const struct elf_info *info, int secindex) 342 + static const char *sec_name(const struct elf_info *info, unsigned int secindex) 340 343 { 344 + /* 345 + * If sym->st_shndx is a special section index, there is no 346 + * corresponding section header. 347 + * Return "" if the index is out of range of info->sechdrs[] array. 348 + */ 349 + if (secindex >= info->num_sections) 350 + return ""; 351 + 341 352 return sech_name(info, &info->sechdrs[secindex]); 342 353 } 343 354 ··· 470 465 hdr->e_shstrndx = TO_NATIVE(hdr->e_shstrndx); 471 466 sechdrs = (void *)hdr + hdr->e_shoff; 472 467 info->sechdrs = sechdrs; 468 + 469 + /* modpost only works for relocatable objects */ 470 + if (hdr->e_type != ET_REL) 471 + fatal("%s: not relocatable object.", filename); 473 472 474 473 /* Check if file offset is correct */ 475 474 if (hdr->e_shoff > info->size) { ··· 746 737 return false; 747 738 } 748 739 740 + /* useful to pass patterns to match() directly */ 741 + #define PATTERNS(...) \ 742 + ({ \ 743 + static const char *const patterns[] = {__VA_ARGS__, NULL}; \ 744 + patterns; \ 745 + }) 746 + 749 747 /* sections that we do not want to do full section mismatch check on */ 750 748 static const char *const section_white_list[] = 751 749 { 752 750 ".comment*", 753 751 ".debug*", 754 - ".cranges", /* sh64 */ 755 752 ".zdebug*", /* Compressed debug sections. */ 756 753 ".GCC.command.line", /* record-gcc-switches */ 757 754 ".mdebug*", /* alpha, score, mips etc. */ ··· 845 830 /* all init sections */ 846 831 static const char *const init_sections[] = { ALL_INIT_SECTIONS, NULL }; 847 832 848 - /* All init and exit sections (code + data) */ 849 - static const char *const init_exit_sections[] = 850 - {ALL_INIT_SECTIONS, ALL_EXIT_SECTIONS, NULL }; 851 - 852 833 /* all text sections */ 853 834 static const char *const text_sections[] = { ALL_TEXT_SECTIONS, NULL }; 854 835 855 836 /* data section */ 856 837 static const char *const data_sections[] = { DATA_SECTIONS, NULL }; 857 - 858 - 859 - /* symbols in .data that may refer to init/exit sections */ 860 - #define DEFAULT_SYMBOL_WHITE_LIST \ 861 - "*driver", \ 862 - "*_template", /* scsi uses *_template a lot */ \ 863 - "*_timer", /* arm uses ops structures named _timer a lot */ \ 864 - "*_sht", /* scsi also used *_sht to some extent */ \ 865 - "*_ops", \ 866 - "*_probe", \ 867 - "*_probe_one", \ 868 - "*_console" 869 838 870 839 static const char *const head_sections[] = { ".head.text*", NULL }; 871 840 static const char *const linker_symbols[] = ··· 882 883 * 883 884 * @mismatch: Type of mismatch. 884 885 * 885 - * @symbol_white_list: Do not match a relocation to a symbol in this list 886 - * even if it is targeting a section in @bad_to_sec. 887 - * 888 886 * @handler: Specific handler to call when a match is found. If NULL, 889 887 * default_mismatch_handler() will be called. 890 888 * ··· 891 895 const char *bad_tosec[20]; 892 896 const char *good_tosec[20]; 893 897 enum mismatch mismatch; 894 - const char *symbol_white_list[20]; 895 898 void (*handler)(const char *modname, struct elf_info *elf, 896 899 const struct sectioncheck* const mismatch, 897 900 Elf_Rela *r, Elf_Sym *sym, const char *fromsec); ··· 910 915 .fromsec = { TEXT_SECTIONS, NULL }, 911 916 .bad_tosec = { ALL_INIT_SECTIONS, NULL }, 912 917 .mismatch = TEXT_TO_ANY_INIT, 913 - .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, 914 918 }, 915 919 { 916 920 .fromsec = { DATA_SECTIONS, NULL }, 917 921 .bad_tosec = { ALL_XXXINIT_SECTIONS, NULL }, 918 922 .mismatch = DATA_TO_ANY_INIT, 919 - .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, 920 923 }, 921 924 { 922 925 .fromsec = { DATA_SECTIONS, NULL }, 923 926 .bad_tosec = { INIT_SECTIONS, NULL }, 924 927 .mismatch = DATA_TO_ANY_INIT, 925 - .symbol_white_list = { 926 - "*_template", "*_timer", "*_sht", "*_ops", 927 - "*_probe", "*_probe_one", "*_console", NULL 928 - }, 929 928 }, 930 929 { 931 930 .fromsec = { TEXT_SECTIONS, NULL }, 932 931 .bad_tosec = { ALL_EXIT_SECTIONS, NULL }, 933 932 .mismatch = TEXT_TO_ANY_EXIT, 934 - .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, 935 933 }, 936 934 { 937 935 .fromsec = { DATA_SECTIONS, NULL }, 938 936 .bad_tosec = { ALL_EXIT_SECTIONS, NULL }, 939 937 .mismatch = DATA_TO_ANY_EXIT, 940 - .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, 941 938 }, 942 939 /* Do not reference init code/data from meminit code/data */ 943 940 { 944 941 .fromsec = { ALL_XXXINIT_SECTIONS, NULL }, 945 942 .bad_tosec = { INIT_SECTIONS, NULL }, 946 943 .mismatch = XXXINIT_TO_SOME_INIT, 947 - .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, 948 944 }, 949 945 /* Do not reference exit code/data from memexit code/data */ 950 946 { 951 947 .fromsec = { ALL_XXXEXIT_SECTIONS, NULL }, 952 948 .bad_tosec = { EXIT_SECTIONS, NULL }, 953 949 .mismatch = XXXEXIT_TO_SOME_EXIT, 954 - .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, 955 950 }, 956 951 /* Do not use exit code/data from init code */ 957 952 { 958 953 .fromsec = { ALL_INIT_SECTIONS, NULL }, 959 954 .bad_tosec = { ALL_EXIT_SECTIONS, NULL }, 960 955 .mismatch = ANY_INIT_TO_ANY_EXIT, 961 - .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, 962 956 }, 963 957 /* Do not use init code/data from exit code */ 964 958 { 965 959 .fromsec = { ALL_EXIT_SECTIONS, NULL }, 966 960 .bad_tosec = { ALL_INIT_SECTIONS, NULL }, 967 961 .mismatch = ANY_EXIT_TO_ANY_INIT, 968 - .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, 969 962 }, 970 963 { 971 964 .fromsec = { ALL_PCI_INIT_SECTIONS, NULL }, 972 965 .bad_tosec = { INIT_SECTIONS, NULL }, 973 966 .mismatch = ANY_INIT_TO_ANY_EXIT, 974 - .symbol_white_list = { NULL }, 975 967 }, 976 968 /* Do not export init/exit functions or data */ 977 969 { 978 970 .fromsec = { "___ksymtab*", NULL }, 979 971 .bad_tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL }, 980 972 .mismatch = EXPORT_TO_INIT_EXIT, 981 - .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, 982 973 }, 983 974 { 984 975 .fromsec = { "__ex_table", NULL }, ··· 1025 1044 * fromsec = .data* 1026 1045 * atsym = __param_ops_* 1027 1046 * 1028 - * Pattern 2: 1029 - * Many drivers utilise a *driver container with references to 1030 - * add, remove, probe functions etc. 1031 - * the pattern is identified by: 1032 - * tosec = init or exit section 1033 - * fromsec = data section 1034 - * atsym = *driver, *_template, *_sht, *_ops, *_probe, 1035 - * *probe_one, *_console, *_timer 1036 - * 1037 1047 * Pattern 3: 1038 1048 * Whitelist all references from .head.text to any init section 1039 1049 * ··· 1073 1101 strstarts(fromsym, "__param_ops_")) 1074 1102 return 0; 1075 1103 1076 - /* Check for pattern 2 */ 1077 - if (match(tosec, init_exit_sections) && 1078 - match(fromsec, data_sections) && 1079 - match(fromsym, mismatch->symbol_white_list)) 1104 + /* symbols in data sections that may refer to any init/exit sections */ 1105 + if (match(fromsec, PATTERNS(DATA_SECTIONS)) && 1106 + match(tosec, PATTERNS(ALL_INIT_SECTIONS, ALL_EXIT_SECTIONS)) && 1107 + match(fromsym, PATTERNS("*_template", // scsi uses *_template a lot 1108 + "*_timer", // arm uses ops structures named _timer a lot 1109 + "*_sht", // scsi also used *_sht to some extent 1110 + "*_ops", 1111 + "*_probe", 1112 + "*_probe_one", 1113 + "*_console"))) 1114 + return 0; 1115 + 1116 + /* symbols in data sections that may refer to meminit/exit sections */ 1117 + if (match(fromsec, PATTERNS(DATA_SECTIONS)) && 1118 + match(tosec, PATTERNS(ALL_XXXINIT_SECTIONS, ALL_EXIT_SECTIONS)) && 1119 + match(fromsym, PATTERNS("*driver"))) 1080 1120 return 0; 1081 1121 1082 1122 /* Check for pattern 3 */ ··· 1214 1230 return near; 1215 1231 } 1216 1232 1217 - /* 1218 - * Convert a section name to the function/data attribute 1219 - * .init.text => __init 1220 - * .memexitconst => __memconst 1221 - * etc. 1222 - * 1223 - * The memory of returned value has been allocated on a heap. The user of this 1224 - * method should free it after usage. 1225 - */ 1226 - static char *sec2annotation(const char *s) 1227 - { 1228 - if (match(s, init_exit_sections)) { 1229 - char *p = NOFAIL(malloc(20)); 1230 - char *r = p; 1231 - 1232 - *p++ = '_'; 1233 - *p++ = '_'; 1234 - if (*s == '.') 1235 - s++; 1236 - while (*s && *s != '.') 1237 - *p++ = *s++; 1238 - *p = '\0'; 1239 - if (*s == '.') 1240 - s++; 1241 - if (strstr(s, "rodata") != NULL) 1242 - strcat(p, "const "); 1243 - else if (strstr(s, "data") != NULL) 1244 - strcat(p, "data "); 1245 - else 1246 - strcat(p, " "); 1247 - return r; 1248 - } else { 1249 - return NOFAIL(strdup("")); 1250 - } 1251 - } 1252 - 1253 1233 static int is_function(Elf_Sym *sym) 1254 1234 { 1255 1235 if (sym) 1256 1236 return ELF_ST_TYPE(sym->st_info) == STT_FUNC; 1257 1237 else 1258 1238 return -1; 1259 - } 1260 - 1261 - static void print_section_list(const char * const list[20]) 1262 - { 1263 - const char *const *s = list; 1264 - 1265 - while (*s) { 1266 - fprintf(stderr, "%s", *s); 1267 - s++; 1268 - if (*s) 1269 - fprintf(stderr, ", "); 1270 - } 1271 - fprintf(stderr, "\n"); 1272 1239 } 1273 1240 1274 1241 static inline void get_pretty_name(int is_func, const char** name, const char** name_p) ··· 1239 1304 static void report_sec_mismatch(const char *modname, 1240 1305 const struct sectioncheck *mismatch, 1241 1306 const char *fromsec, 1242 - unsigned long long fromaddr, 1243 1307 const char *fromsym, 1244 - int from_is_func, 1245 - const char *tosec, const char *tosym, 1246 - int to_is_func) 1308 + const char *tosec, const char *tosym) 1247 1309 { 1248 - const char *from, *from_p; 1249 - const char *to, *to_p; 1250 - char *prl_from; 1251 - char *prl_to; 1252 - 1253 1310 sec_mismatch_count++; 1254 - 1255 - get_pretty_name(from_is_func, &from, &from_p); 1256 - get_pretty_name(to_is_func, &to, &to_p); 1257 - 1258 - warn("%s(%s+0x%llx): Section mismatch in reference from the %s %s%s " 1259 - "to the %s %s:%s%s\n", 1260 - modname, fromsec, fromaddr, from, fromsym, from_p, to, tosec, 1261 - tosym, to_p); 1262 1311 1263 1312 switch (mismatch->mismatch) { 1264 1313 case TEXT_TO_ANY_INIT: 1265 - prl_from = sec2annotation(fromsec); 1266 - prl_to = sec2annotation(tosec); 1267 - fprintf(stderr, 1268 - "The function %s%s() references\n" 1269 - "the %s %s%s%s.\n" 1270 - "This is often because %s lacks a %s\n" 1271 - "annotation or the annotation of %s is wrong.\n", 1272 - prl_from, fromsym, 1273 - to, prl_to, tosym, to_p, 1274 - fromsym, prl_to, tosym); 1275 - free(prl_from); 1276 - free(prl_to); 1277 - break; 1278 - case DATA_TO_ANY_INIT: { 1279 - prl_to = sec2annotation(tosec); 1280 - fprintf(stderr, 1281 - "The variable %s references\n" 1282 - "the %s %s%s%s\n" 1283 - "If the reference is valid then annotate the\n" 1284 - "variable with __init* or __refdata (see linux/init.h) " 1285 - "or name the variable:\n", 1286 - fromsym, to, prl_to, tosym, to_p); 1287 - print_section_list(mismatch->symbol_white_list); 1288 - free(prl_to); 1289 - break; 1290 - } 1314 + case DATA_TO_ANY_INIT: 1291 1315 case TEXT_TO_ANY_EXIT: 1292 - prl_to = sec2annotation(tosec); 1293 - fprintf(stderr, 1294 - "The function %s() references a %s in an exit section.\n" 1295 - "Often the %s %s%s has valid usage outside the exit section\n" 1296 - "and the fix is to remove the %sannotation of %s.\n", 1297 - fromsym, to, to, tosym, to_p, prl_to, tosym); 1298 - free(prl_to); 1299 - break; 1300 - case DATA_TO_ANY_EXIT: { 1301 - prl_to = sec2annotation(tosec); 1302 - fprintf(stderr, 1303 - "The variable %s references\n" 1304 - "the %s %s%s%s\n" 1305 - "If the reference is valid then annotate the\n" 1306 - "variable with __exit* (see linux/init.h) or " 1307 - "name the variable:\n", 1308 - fromsym, to, prl_to, tosym, to_p); 1309 - print_section_list(mismatch->symbol_white_list); 1310 - free(prl_to); 1311 - break; 1312 - } 1316 + case DATA_TO_ANY_EXIT: 1313 1317 case XXXINIT_TO_SOME_INIT: 1314 1318 case XXXEXIT_TO_SOME_EXIT: 1315 - prl_from = sec2annotation(fromsec); 1316 - prl_to = sec2annotation(tosec); 1317 - fprintf(stderr, 1318 - "The %s %s%s%s references\n" 1319 - "a %s %s%s%s.\n" 1320 - "If %s is only used by %s then\n" 1321 - "annotate %s with a matching annotation.\n", 1322 - from, prl_from, fromsym, from_p, 1323 - to, prl_to, tosym, to_p, 1324 - tosym, fromsym, tosym); 1325 - free(prl_from); 1326 - free(prl_to); 1327 - break; 1328 1319 case ANY_INIT_TO_ANY_EXIT: 1329 - prl_from = sec2annotation(fromsec); 1330 - prl_to = sec2annotation(tosec); 1331 - fprintf(stderr, 1332 - "The %s %s%s%s references\n" 1333 - "a %s %s%s%s.\n" 1334 - "This is often seen when error handling " 1335 - "in the init function\n" 1336 - "uses functionality in the exit path.\n" 1337 - "The fix is often to remove the %sannotation of\n" 1338 - "%s%s so it may be used outside an exit section.\n", 1339 - from, prl_from, fromsym, from_p, 1340 - to, prl_to, tosym, to_p, 1341 - prl_to, tosym, to_p); 1342 - free(prl_from); 1343 - free(prl_to); 1344 - break; 1345 1320 case ANY_EXIT_TO_ANY_INIT: 1346 - prl_from = sec2annotation(fromsec); 1347 - prl_to = sec2annotation(tosec); 1348 - fprintf(stderr, 1349 - "The %s %s%s%s references\n" 1350 - "a %s %s%s%s.\n" 1351 - "This is often seen when error handling " 1352 - "in the exit function\n" 1353 - "uses functionality in the init path.\n" 1354 - "The fix is often to remove the %sannotation of\n" 1355 - "%s%s so it may be used outside an init section.\n", 1356 - from, prl_from, fromsym, from_p, 1357 - to, prl_to, tosym, to_p, 1358 - prl_to, tosym, to_p); 1359 - free(prl_from); 1360 - free(prl_to); 1321 + warn("%s: section mismatch in reference: %s (section: %s) -> %s (section: %s)\n", 1322 + modname, fromsym, fromsec, tosym, tosec); 1361 1323 break; 1362 1324 case EXPORT_TO_INIT_EXIT: 1363 - prl_to = sec2annotation(tosec); 1364 - fprintf(stderr, 1365 - "The symbol %s is exported and annotated %s\n" 1366 - "Fix this by removing the %sannotation of %s " 1367 - "or drop the export.\n", 1368 - tosym, prl_to, prl_to, tosym); 1369 - free(prl_to); 1325 + warn("%s: EXPORT_SYMBOL used for init/exit symbol: %s (section: %s)\n", 1326 + modname, tosym, tosec); 1370 1327 break; 1371 1328 case EXTABLE_TO_NON_TEXT: 1372 - fatal("There's a special handler for this mismatch type, " 1373 - "we should never get here."); 1329 + fatal("There's a special handler for this mismatch type, we should never get here.\n"); 1374 1330 break; 1375 1331 } 1376 - fprintf(stderr, "\n"); 1377 1332 } 1378 1333 1379 1334 static void default_mismatch_handler(const char *modname, struct elf_info *elf, ··· 1279 1454 from = find_elf_symbol2(elf, r->r_offset, fromsec); 1280 1455 fromsym = sym_name(elf, from); 1281 1456 1282 - if (strstarts(fromsym, "reference___initcall")) 1283 - return; 1284 - 1285 1457 tosec = sec_name(elf, get_secindex(elf, sym)); 1286 1458 to = find_elf_symbol(elf, r->r_addend, sym); 1287 1459 tosym = sym_name(elf, to); ··· 1287 1465 if (secref_whitelist(mismatch, 1288 1466 fromsec, fromsym, tosec, tosym)) { 1289 1467 report_sec_mismatch(modname, mismatch, 1290 - fromsec, r->r_offset, fromsym, 1291 - is_function(from), tosec, tosym, 1292 - is_function(to)); 1468 + fromsec, fromsym, tosec, tosym); 1293 1469 } 1294 1470 } 1295 1471 ··· 1443 1623 break; 1444 1624 case R_386_PC32: 1445 1625 r->r_addend = TO_NATIVE(*location) + 4; 1446 - /* For CONFIG_RELOCATABLE=y */ 1447 - if (elf->hdr->e_type == ET_EXEC) 1448 - r->r_addend += r->r_offset; 1449 1626 break; 1450 1627 } 1451 1628 return 0; ··· 1535 1718 Elf_Rela *start = (void *)elf->hdr + sechdr->sh_offset; 1536 1719 Elf_Rela *stop = (void *)start + sechdr->sh_size; 1537 1720 1538 - fromsec = sech_name(elf, sechdr); 1539 - fromsec += strlen(".rela"); 1721 + fromsec = sec_name(elf, sechdr->sh_info); 1540 1722 /* if from section (name) is know good then skip it */ 1541 1723 if (match(fromsec, section_white_list)) 1542 1724 return; ··· 1587 1771 Elf_Rel *start = (void *)elf->hdr + sechdr->sh_offset; 1588 1772 Elf_Rel *stop = (void *)start + sechdr->sh_size; 1589 1773 1590 - fromsec = sech_name(elf, sechdr); 1591 - fromsec += strlen(".rel"); 1774 + fromsec = sec_name(elf, sechdr->sh_info); 1592 1775 /* if from section (name) is know good then skip it */ 1593 1776 if (match(fromsec, section_white_list)) 1594 1777 return;
+19 -14
scripts/mod/modpost.h
··· 26 26 #define Elf_Shdr Elf32_Shdr 27 27 #define Elf_Sym Elf32_Sym 28 28 #define Elf_Addr Elf32_Addr 29 - #define Elf_Sword Elf64_Sword 30 29 #define Elf_Section Elf32_Half 31 30 #define ELF_ST_BIND ELF32_ST_BIND 32 31 #define ELF_ST_TYPE ELF32_ST_TYPE ··· 40 41 #define Elf_Shdr Elf64_Shdr 41 42 #define Elf_Sym Elf64_Sym 42 43 #define Elf_Addr Elf64_Addr 43 - #define Elf_Sword Elf64_Sxword 44 44 #define Elf_Section Elf64_Half 45 45 #define ELF_ST_BIND ELF64_ST_BIND 46 46 #define ELF_ST_TYPE ELF64_ST_TYPE ··· 156 158 return i != SHN_XINDEX && i >= SHN_LORESERVE && i <= SHN_HIRESERVE; 157 159 } 158 160 159 - /* 160 - * Move reserved section indices SHN_LORESERVE..SHN_HIRESERVE out of 161 - * the way to -256..-1, to avoid conflicting with real section 162 - * indices. 163 - */ 164 - #define SPECIAL(i) ((i) - (SHN_HIRESERVE + 1)) 165 - 166 161 /* Accessor for sym->st_shndx, hides ugliness of "64k sections" */ 167 162 static inline unsigned int get_secindex(const struct elf_info *info, 168 163 const Elf_Sym *sym) 169 164 { 170 - if (is_shndx_special(sym->st_shndx)) 171 - return SPECIAL(sym->st_shndx); 172 - if (sym->st_shndx != SHN_XINDEX) 173 - return sym->st_shndx; 174 - return info->symtab_shndx_start[sym - info->symtab_start]; 165 + unsigned int index = sym->st_shndx; 166 + 167 + /* 168 + * Elf{32,64}_Sym::st_shndx is 2 byte. Big section numbers are available 169 + * in the .symtab_shndx section. 170 + */ 171 + if (index == SHN_XINDEX) 172 + return info->symtab_shndx_start[sym - info->symtab_start]; 173 + 174 + /* 175 + * Move reserved section indices SHN_LORESERVE..SHN_HIRESERVE out of 176 + * the way to UINT_MAX-255..UINT_MAX, to avoid conflicting with real 177 + * section indices. 178 + */ 179 + if (index >= SHN_LORESERVE && index <= SHN_HIRESERVE) 180 + return index - SHN_HIRESERVE - 1; 181 + 182 + return index; 175 183 } 176 184 177 185 /* file2alias.c */ ··· 191 187 /* from modpost.c */ 192 188 char *read_text_file(const char *filename); 193 189 char *get_line(char **stringp); 190 + void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym); 194 191 195 192 enum loglevel { 196 193 LOG_WARN,
+3
scripts/package/mkspec
··· 49 49 URL: https://www.kernel.org 50 50 $S Source: kernel-$__KERNELRELEASE.tar.gz 51 51 Provides: $PROVIDES 52 + # $UTS_MACHINE as a fallback of _arch in case 53 + # /usr/lib/rpm/platform/*/macros was not included. 54 + %define _arch %{?_arch:$UTS_MACHINE} 52 55 %define __spec_install_post /usr/lib/rpm/brp-compress || : 53 56 %define debug_package %{nil} 54 57