Merge tag 'kbuild-v5.20' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy...
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 10 Aug 2022 17:40:41 +0000 (10:40 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 10 Aug 2022 17:40:41 +0000 (10:40 -0700)
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 :
  ...

37 files changed:
Documentation/kbuild/kconfig-language.rst
MAINTAINERS
Makefile
arch/arc/configs/axs101_defconfig
arch/arc/configs/axs103_defconfig
arch/arc/configs/axs103_smp_defconfig
arch/arc/configs/haps_hs_defconfig
arch/arc/configs/haps_hs_smp_defconfig
arch/arc/configs/hsdk_defconfig
arch/arc/configs/nsim_700_defconfig
arch/arc/configs/nsimosci_defconfig
arch/arc/configs/nsimosci_hs_defconfig
arch/arc/configs/nsimosci_hs_smp_defconfig
arch/arc/configs/tb10x_defconfig
arch/arc/configs/vdk_hs38_defconfig
arch/arc/configs/vdk_hs38_smp_defconfig
certs/Makefile
certs/blacklist_hashes.c
certs/blacklist_nohashes.c [deleted file]
certs/check-blacklist-hashes.awk [new file with mode: 0755]
init/Kconfig
scripts/Kconfig.include
scripts/Makefile.build
scripts/Makefile.compiler
scripts/Makefile.extrawarn
scripts/Makefile.modinst
scripts/Makefile.package
scripts/check-blacklist-hashes.awk [deleted file]
scripts/checkstack.pl
scripts/dummy-tools/dummy-plugin-dir/include/plugin-version.h [new file with mode: 0644]
scripts/dummy-tools/gcc
scripts/headers_install.sh
scripts/kconfig/qconf-cfg.sh
scripts/mod/file2alias.c
scripts/mod/modpost.c
scripts/mod/modpost.h
scripts/package/mkspec

index a717384..7fb3986 100644 (file)
@@ -672,7 +672,7 @@ Future kconfig work
 Work on kconfig is welcomed on both areas of clarifying semantics and on
 evaluating the use of a full SAT solver for it. A full SAT solver can be
 desirable to enable more complex dependency mappings and / or queries,
-for instance on possible use case for a SAT solver could be that of handling
+for instance one possible use case for a SAT solver could be that of handling
 the current known recursive dependency issues. It is not known if this would
 address such issues but such evaluation is desirable. If support for a full SAT
 solver proves too complex or that it cannot address recursive dependency issues
index b7221f4..31a856e 100644 (file)
@@ -4783,7 +4783,6 @@ L:        keyrings@vger.kernel.org
 S:     Maintained
 F:     Documentation/admin-guide/module-signing.rst
 F:     certs/
-F:     scripts/check-blacklist-hashes.awk
 F:     scripts/sign-file.c
 F:     tools/certs/
 
index dc6295f..60a7e3e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -129,6 +129,9 @@ endif
 $(if $(word 2, $(KBUILD_EXTMOD)), \
        $(error building multiple external modules is not supported))
 
+$(foreach x, % :, $(if $(findstring $x, $(KBUILD_EXTMOD)), \
+       $(error module directory path cannot contain '$x')))
+
 # Remove trailing slashes
 ifneq ($(filter %/, $(KBUILD_EXTMOD)),)
 KBUILD_EXTMOD := $(shell dirname $(KBUILD_EXTMOD).)
@@ -755,8 +758,6 @@ KBUILD_CFLAGS       += $(call cc-disable-warning, address-of-packed-member)
 
 ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE
 KBUILD_CFLAGS += -O2
-else ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3
-KBUILD_CFLAGS += -O3
 else ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
 KBUILD_CFLAGS += -Os
 endif
@@ -1370,16 +1371,21 @@ endif
 
 ifneq ($(dtstree),)
 
-%.dtb: include/config/kernel.release scripts_dtc
+%.dtb: dtbs_prepare
        $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@
 
-%.dtbo: include/config/kernel.release scripts_dtc
+%.dtbo: dtbs_prepare
        $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@
 
-PHONY += dtbs dtbs_install dtbs_check
-dtbs: include/config/kernel.release scripts_dtc
+PHONY += dtbs dtbs_prepare dtbs_install dtbs_check
+dtbs: dtbs_prepare
        $(Q)$(MAKE) $(build)=$(dtstree)
 
+# include/config/kernel.release is actually needed when installing DTBs because
+# INSTALL_DTBS_PATH contains $(KERNELRELEASE). However, we do not want to make
+# dtbs_install depend on it as dtbs_install may run as root.
+dtbs_prepare: include/config/kernel.release scripts_dtc
+
 ifneq ($(filter dtbs_check, $(MAKECMDGOALS)),)
 export CHECK_DTBS=y
 dtbs: dt_binding_check
index 0016149..e31a8eb 100644 (file)
@@ -9,7 +9,6 @@ CONFIG_NAMESPACES=y
 # CONFIG_UTS_NS is not set
 # CONFIG_PID_NS is not set
 CONFIG_BLK_DEV_INITRD=y
-CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y
 CONFIG_EMBEDDED=y
 CONFIG_PERF_EVENTS=y
 # CONFIG_VM_EVENT_COUNTERS is not set
index 5b03158..e0e8567 100644 (file)
@@ -9,7 +9,6 @@ CONFIG_NAMESPACES=y
 # CONFIG_UTS_NS is not set
 # CONFIG_PID_NS is not set
 CONFIG_BLK_DEV_INITRD=y
-CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y
 CONFIG_EMBEDDED=y
 CONFIG_PERF_EVENTS=y
 # CONFIG_VM_EVENT_COUNTERS is not set
index d4eec39..fcbc952 100644 (file)
@@ -9,7 +9,6 @@ CONFIG_NAMESPACES=y
 # CONFIG_UTS_NS is not set
 # CONFIG_PID_NS is not set
 CONFIG_BLK_DEV_INITRD=y
-CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y
 CONFIG_EMBEDDED=y
 CONFIG_PERF_EVENTS=y
 # CONFIG_VM_EVENT_COUNTERS is not set
index 7337cdf..d87ad7e 100644 (file)
@@ -11,7 +11,6 @@ CONFIG_NAMESPACES=y
 # CONFIG_UTS_NS is not set
 # CONFIG_PID_NS is not set
 CONFIG_BLK_DEV_INITRD=y
-CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y
 CONFIG_EXPERT=y
 CONFIG_PERF_EVENTS=y
 # CONFIG_COMPAT_BRK is not set
index bc92722..8d82cdb 100644 (file)
@@ -11,7 +11,6 @@ CONFIG_NAMESPACES=y
 # CONFIG_UTS_NS is not set
 # CONFIG_PID_NS is not set
 CONFIG_BLK_DEV_INITRD=y
-CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y
 CONFIG_EMBEDDED=y
 CONFIG_PERF_EVENTS=y
 # CONFIG_VM_EVENT_COUNTERS is not set
index aa00007..f856b03 100644 (file)
@@ -9,7 +9,6 @@ CONFIG_NAMESPACES=y
 # CONFIG_PID_NS is not set
 CONFIG_BLK_DEV_INITRD=y
 CONFIG_BLK_DEV_RAM=y
-CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y
 CONFIG_EMBEDDED=y
 CONFIG_PERF_EVENTS=y
 # CONFIG_VM_EVENT_COUNTERS is not set
index 326f6cd..a1ce12b 100644 (file)
@@ -11,7 +11,6 @@ CONFIG_NAMESPACES=y
 # CONFIG_UTS_NS is not set
 # CONFIG_PID_NS is not set
 CONFIG_BLK_DEV_INITRD=y
-CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y
 CONFIG_KALLSYMS_ALL=y
 CONFIG_EMBEDDED=y
 CONFIG_PERF_EVENTS=y
index bf39a00..ca10f4a 100644 (file)
@@ -10,7 +10,6 @@ CONFIG_NAMESPACES=y
 # CONFIG_UTS_NS is not set
 # CONFIG_PID_NS is not set
 CONFIG_BLK_DEV_INITRD=y
-CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y
 CONFIG_KALLSYMS_ALL=y
 CONFIG_EMBEDDED=y
 CONFIG_PERF_EVENTS=y
index 7121bd7..31b6ec3 100644 (file)
@@ -10,7 +10,6 @@ CONFIG_NAMESPACES=y
 # CONFIG_UTS_NS is not set
 # CONFIG_PID_NS is not set
 CONFIG_BLK_DEV_INITRD=y
-CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y
 CONFIG_KALLSYMS_ALL=y
 CONFIG_EMBEDDED=y
 CONFIG_PERF_EVENTS=y
index f9863b2..41a0037 100644 (file)
@@ -8,7 +8,6 @@ CONFIG_IKCONFIG_PROC=y
 # CONFIG_UTS_NS is not set
 # CONFIG_PID_NS is not set
 CONFIG_BLK_DEV_INITRD=y
-CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y
 CONFIG_PERF_EVENTS=y
 # CONFIG_COMPAT_BRK is not set
 CONFIG_KPROBES=y
index a12656e..d93b650 100644 (file)
@@ -14,7 +14,6 @@ CONFIG_INITRAMFS_SOURCE="../tb10x-rootfs.cpio"
 CONFIG_INITRAMFS_ROOT_UID=2100
 CONFIG_INITRAMFS_ROOT_GID=501
 # CONFIG_RD_GZIP is not set
-CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y
 CONFIG_KALLSYMS_ALL=y
 # CONFIG_AIO is not set
 CONFIG_EMBEDDED=y
index d7c858d..0c3b214 100644 (file)
@@ -4,7 +4,6 @@ CONFIG_HIGH_RES_TIMERS=y
 CONFIG_IKCONFIG=y
 CONFIG_IKCONFIG_PROC=y
 CONFIG_BLK_DEV_INITRD=y
-CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y
 CONFIG_EMBEDDED=y
 CONFIG_PERF_EVENTS=y
 # CONFIG_VM_EVENT_COUNTERS is not set
index 015c1d4..f9ad9d3 100644 (file)
@@ -4,7 +4,6 @@ CONFIG_HIGH_RES_TIMERS=y
 CONFIG_IKCONFIG=y
 CONFIG_IKCONFIG_PROC=y
 CONFIG_BLK_DEV_INITRD=y
-CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y
 CONFIG_EMBEDDED=y
 CONFIG_PERF_EVENTS=y
 # CONFIG_VM_EVENT_COUNTERS is not set
index 88a73b2..9486ed9 100644 (file)
@@ -4,24 +4,22 @@
 #
 
 obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o
-obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o
+obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o blacklist_hashes.o
 obj-$(CONFIG_SYSTEM_REVOCATION_LIST) += revocation_certificates.o
-ifneq ($(CONFIG_SYSTEM_BLACKLIST_HASH_LIST),)
 
 $(obj)/blacklist_hashes.o: $(obj)/blacklist_hash_list
 CFLAGS_blacklist_hashes.o := -I $(obj)
 
 quiet_cmd_check_and_copy_blacklist_hash_list = GEN     $@
       cmd_check_and_copy_blacklist_hash_list = \
-       $(AWK) -f $(srctree)/scripts/check-blacklist-hashes.awk $(CONFIG_SYSTEM_BLACKLIST_HASH_LIST) >&2; \
-       cat $(CONFIG_SYSTEM_BLACKLIST_HASH_LIST) > $@
+       $(if $(CONFIG_SYSTEM_BLACKLIST_HASH_LIST), \
+       $(AWK) -f $(srctree)/$(src)/check-blacklist-hashes.awk $(CONFIG_SYSTEM_BLACKLIST_HASH_LIST) >&2; \
+       { cat $(CONFIG_SYSTEM_BLACKLIST_HASH_LIST); echo $(comma) NULL; } > $@, \
+       echo NULL > $@)
 
 $(obj)/blacklist_hash_list: $(CONFIG_SYSTEM_BLACKLIST_HASH_LIST) FORCE
        $(call if_changed,check_and_copy_blacklist_hash_list)
-obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_hashes.o
-else
-obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_nohashes.o
-endif
+
 targets += blacklist_hash_list
 
 quiet_cmd_extract_certs  = CERT    $@
index 86d66fe..0c5476a 100644 (file)
@@ -3,5 +3,4 @@
 
 const char __initconst *const blacklist_hashes[] = {
 #include "blacklist_hash_list"
-       , NULL
 };
diff --git a/certs/blacklist_nohashes.c b/certs/blacklist_nohashes.c
deleted file mode 100644 (file)
index 753b703..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include "blacklist.h"
-
-const char __initconst *const blacklist_hashes[] = {
-       NULL
-};
diff --git a/certs/check-blacklist-hashes.awk b/certs/check-blacklist-hashes.awk
new file mode 100755 (executable)
index 0000000..107c1d3
--- /dev/null
@@ -0,0 +1,37 @@
+#!/usr/bin/awk -f
+# SPDX-License-Identifier: GPL-2.0
+#
+# Copyright Â© 2020, Microsoft Corporation. All rights reserved.
+#
+# Author: Mickaël Salaün <mic@linux.microsoft.com>
+#
+# Check that a CONFIG_SYSTEM_BLACKLIST_HASH_LIST file contains a valid array of
+# hash strings.  Such string must start with a prefix ("tbs" or "bin"), then a
+# colon (":"), and finally an even number of hexadecimal lowercase characters
+# (up to 128).
+
+BEGIN {
+       RS = ","
+}
+{
+       if (!match($0, "^[ \t\n\r]*\"([^\"]*)\"[ \t\n\r]*$", part1)) {
+               print "Not a string (item " NR "):", $0;
+               exit 1;
+       }
+       if (!match(part1[1], "^(tbs|bin):(.*)$", part2)) {
+               print "Unknown prefix (item " NR "):", part1[1];
+               exit 1;
+       }
+       if (!match(part2[2], "^([0-9a-f]+)$", part3)) {
+               print "Not a lowercase hexadecimal string (item " NR "):", part2[2];
+               exit 1;
+       }
+       if (length(part3[1]) > 128) {
+               print "Hash string too long (item " NR "):", part3[1];
+               exit 1;
+       }
+       if (length(part3[1]) % 2 == 1) {
+               print "Not an even number of hexadecimal characters (item " NR "):", part3[1];
+               exit 1;
+       }
+}
index 922848a..80fe60f 100644 (file)
@@ -1411,13 +1411,6 @@ config CC_OPTIMIZE_FOR_PERFORMANCE
          with the "-O2" compiler flag for best performance and most
          helpful compile-time warnings.
 
-config CC_OPTIMIZE_FOR_PERFORMANCE_O3
-       bool "Optimize more for performance (-O3)"
-       depends on ARC
-       help
-         Choosing this option will pass "-O3" to your compiler to optimize
-         the kernel yet more for performance.
-
 config CC_OPTIMIZE_FOR_SIZE
        bool "Optimize for size (-Os)"
        help
@@ -1733,16 +1726,17 @@ config KALLSYMS_ALL
        help
          Normally kallsyms only contains the symbols of functions for nicer
          OOPS messages and backtraces (i.e., symbols from the text and inittext
-         sections). This is sufficient for most cases. And only in very rare
-         cases (e.g., when a debugger is used) all symbols are required (e.g.,
-         names of variables from the data sections, etc).
+         sections). This is sufficient for most cases. And only if you want to
+         enable kernel live patching, or other less common use cases (e.g.,
+         when a debugger is used) all symbols are required (i.e., names of
+         variables from the data sections, etc).
 
          This option makes sure that all symbols are loaded into the kernel
          image (i.e., symbols from all sections) in cost of increased kernel
          size (depending on the kernel configuration, it may be 300KiB or
          something like this).
 
-         Say N unless you really need all symbols.
+         Say N unless you really need all symbols, or kernel live patching.
 
 config KALLSYMS_ABSOLUTE_PERCPU
        bool
index 0496efd..a0ccceb 100644 (file)
@@ -25,7 +25,7 @@ failure = $(if-success,$(1),n,y)
 
 # $(cc-option,<flag>)
 # Return y if the compiler supports <flag>, n otherwise
-cc-option = $(success,mkdir .tmp_$$$$; trap "rm -rf .tmp_$$$$" EXIT; $(CC) -Werror $(CLANG_FLAGS) $(1) -c -x c /dev/null -o .tmp_$$$$/tmp.o)
+cc-option = $(success,trap "rm -rf .tmp_$$" EXIT; mkdir .tmp_$$; $(CC) -Werror $(CLANG_FLAGS) $(1) -c -x c /dev/null -o .tmp_$$/tmp.o)
 
 # $(ld-option,<flag>)
 # Return y if the linker supports <flag>, n otherwise
index cac070a..784f46d 100644 (file)
@@ -358,9 +358,8 @@ $(subdir-modorder): $(obj)/%/modules.order: $(obj)/% ;
 
 quiet_cmd_ar_builtin = AR      $@
       cmd_ar_builtin = rm -f $@; \
-               echo $(patsubst $(obj)/%,%,$(real-prereqs)) | \
-               sed -E 's:([^ ]+):$(obj)/\1:g' | \
-               xargs $(AR) cDPrST $@
+       $(if $(real-prereqs), printf "$(obj)/%s " $(patsubst $(obj)/%,%,$(real-prereqs)) | xargs) \
+       $(AR) cDPrST $@
 
 $(obj)/built-in.a: $(real-obj-y) FORCE
        $(call if_changed,ar_builtin)
index 86ecd2a..94d0d40 100644 (file)
@@ -21,8 +21,8 @@ TMPOUT = $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_$$$$
 # automatically cleaned up.
 try-run = $(shell set -e;              \
        TMP=$(TMPOUT)/tmp;              \
-       mkdir -p $(TMPOUT);             \
        trap "rm -rf $(TMPOUT)" EXIT;   \
+       mkdir -p $(TMPOUT);             \
        if ($(1)) >/dev/null 2>&1;      \
        then echo "$(2)";               \
        else echo "$(3)";               \
index f5f0d6f..9bbaf71 100644 (file)
@@ -47,7 +47,6 @@ else
 
 ifdef CONFIG_CC_IS_CLANG
 KBUILD_CFLAGS += -Wno-initializer-overrides
-KBUILD_CFLAGS += -Wno-format
 KBUILD_CFLAGS += -Wno-sign-compare
 KBUILD_CFLAGS += -Wno-format-zero-length
 KBUILD_CFLAGS += $(call cc-disable-warning, pointer-to-enum-cast)
index 16a02e9..a4c987c 100644 (file)
@@ -18,6 +18,9 @@ INSTALL_MOD_DIR ?= extra
 dst := $(MODLIB)/$(INSTALL_MOD_DIR)
 endif
 
+$(foreach x, % :, $(if $(findstring $x, $(dst)), \
+       $(error module installation path cannot contain '$x')))
+
 suffix-y                               :=
 suffix-$(CONFIG_MODULE_COMPRESS_GZIP)  := .gz
 suffix-$(CONFIG_MODULE_COMPRESS_XZ)    := .xz
index 77b6121..5017f6b 100644 (file)
@@ -56,7 +56,7 @@ rpm-pkg:
        $(MAKE) clean
        $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
        $(call cmd,src_tar,$(KERNELPATH),kernel.spec)
-       +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE) -ta $(KERNELPATH).tar.gz \
+       +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -ta $(KERNELPATH).tar.gz \
        --define='_smp_mflags %{nil}'
 
 # binrpm-pkg
@@ -66,7 +66,7 @@ binrpm-pkg:
        $(MAKE) -f $(srctree)/Makefile
        $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec
        +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \
-               $(UTS_MACHINE) -bb $(objtree)/binkernel.spec
+               $(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec
 
 PHONY += deb-pkg
 deb-pkg:
diff --git a/scripts/check-blacklist-hashes.awk b/scripts/check-blacklist-hashes.awk
deleted file mode 100755 (executable)
index 107c1d3..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/awk -f
-# SPDX-License-Identifier: GPL-2.0
-#
-# Copyright Â© 2020, Microsoft Corporation. All rights reserved.
-#
-# Author: Mickaël Salaün <mic@linux.microsoft.com>
-#
-# Check that a CONFIG_SYSTEM_BLACKLIST_HASH_LIST file contains a valid array of
-# hash strings.  Such string must start with a prefix ("tbs" or "bin"), then a
-# colon (":"), and finally an even number of hexadecimal lowercase characters
-# (up to 128).
-
-BEGIN {
-       RS = ","
-}
-{
-       if (!match($0, "^[ \t\n\r]*\"([^\"]*)\"[ \t\n\r]*$", part1)) {
-               print "Not a string (item " NR "):", $0;
-               exit 1;
-       }
-       if (!match(part1[1], "^(tbs|bin):(.*)$", part2)) {
-               print "Unknown prefix (item " NR "):", part1[1];
-               exit 1;
-       }
-       if (!match(part2[2], "^([0-9a-f]+)$", part3)) {
-               print "Not a lowercase hexadecimal string (item " NR "):", part2[2];
-               exit 1;
-       }
-       if (length(part3[1]) > 128) {
-               print "Hash string too long (item " NR "):", part3[1];
-               exit 1;
-       }
-       if (length(part3[1]) % 2 == 1) {
-               print "Not an even number of hexadecimal characters (item " NR "):", part3[1];
-               exit 1;
-       }
-}
index d2c3858..d48dfed 100755 (executable)
@@ -16,6 +16,7 @@
 #      AArch64, PARISC ports by Kyle McMartin
 #      sparc port by Martin Habets <errandir_news@mph.eclipse.co.uk>
 #      ppc64le port by Breno Leitao <leitao@debian.org>
+#      riscv port by Wadim Mueller <wafgo01@gmail.com>
 #
 #      Usage:
 #      objdump -d vmlinux | scripts/checkstack.pl [arch]
@@ -108,6 +109,9 @@ my (@stack, $re, $dre, $sub, $x, $xs, $funcre, $min_stack);
        } elsif ($arch eq 'sparc' || $arch eq 'sparc64') {
                # f0019d10:       9d e3 bf 90     save  %sp, -112, %sp
                $re = qr/.*save.*%sp, -(([0-9]{2}|[3-9])[0-9]{2}), %sp/o;
+       } elsif ($arch =~ /^riscv(64)?$/) {
+               #ffffffff8036e868:      c2010113                addi    sp,sp,-992
+               $re = qr/.*addi.*sp,sp,-(([0-9]{2}|[3-9])[0-9]{2})/o;
        } else {
                print("wrong or unknown architecture \"$arch\"\n");
                exit
diff --git a/scripts/dummy-tools/dummy-plugin-dir/include/plugin-version.h b/scripts/dummy-tools/dummy-plugin-dir/include/plugin-version.h
new file mode 100644 (file)
index 0000000..e69de29
index b248314..7db8258 100755 (executable)
@@ -96,12 +96,8 @@ fi
 
 # To set GCC_PLUGINS
 if arg_contain -print-file-name=plugin "$@"; then
-       plugin_dir=$(mktemp -d)
-
-       mkdir -p $plugin_dir/include
-       touch $plugin_dir/include/plugin-version.h
-
-       echo $plugin_dir
+       # Use $0 to find the in-tree dummy directory
+       echo "$(dirname "$(readlink -f "$0")")/dummy-plugin-dir"
        exit 0
 fi
 
index dd554bd..4041881 100755 (executable)
@@ -70,7 +70,6 @@ configs=$(sed -e '
 #
 # The format is <file-name>:<CONFIG-option> in each line.
 config_leak_ignores="
-arch/alpha/include/uapi/asm/setup.h:CONFIG_ALPHA_LEGACY_START_ADDRESS
 arch/arc/include/uapi/asm/page.h:CONFIG_ARC_PAGE_SIZE_16K
 arch/arc/include/uapi/asm/page.h:CONFIG_ARC_PAGE_SIZE_4K
 arch/arc/include/uapi/asm/swab.h:CONFIG_ARC_HAS_SWAPE
@@ -84,7 +83,6 @@ arch/nios2/include/uapi/asm/swab.h:CONFIG_NIOS2_CI_SWAB_SUPPORT
 arch/x86/include/uapi/asm/auxvec.h:CONFIG_IA32_EMULATION
 arch/x86/include/uapi/asm/auxvec.h:CONFIG_X86_64
 arch/x86/include/uapi/asm/mman.h:CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
-include/uapi/asm-generic/fcntl.h:CONFIG_64BIT
 include/uapi/linux/atmdev.h:CONFIG_COMPAT
 include/uapi/linux/eventpoll.h:CONFIG_PM_SLEEP
 include/uapi/linux/hw_breakpoint.h:CONFIG_HAVE_MIXED_BREAKPOINTS_REGS
index 9b695e5..ad652cb 100755 (executable)
@@ -20,5 +20,6 @@ fi
 echo >&2 "*"
 echo >&2 "* Could not find Qt5 via ${HOSTPKG_CONFIG}."
 echo >&2 "* Please install Qt5 and make sure it's in PKG_CONFIG_PATH"
+echo >&2 "* You need $PKG"
 echo >&2 "*"
 exit 1
index cbd6b0f..80d9731 100644 (file)
@@ -1571,9 +1571,7 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
                zeros = calloc(1, sym->st_size);
                symval = zeros;
        } else {
-               symval = (void *)info->hdr
-                       + info->sechdrs[get_secindex(info, sym)].sh_offset
-                       + sym->st_value;
+               symval = sym_get_data(info, sym);
        }
 
        /* First handle the "special" cases */
index 29474ce..55e32af 100644 (file)
@@ -321,13 +321,10 @@ static void *sym_get_data_by_offset(const struct elf_info *info,
 {
        Elf_Shdr *sechdr = &info->sechdrs[secindex];
 
-       if (info->hdr->e_type != ET_REL)
-               offset -= sechdr->sh_addr;
-
        return (void *)info->hdr + sechdr->sh_offset + offset;
 }
 
-static void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym)
+void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym)
 {
        return sym_get_data_by_offset(info, get_secindex(info, sym),
                                      sym->st_value);
@@ -339,8 +336,16 @@ static const char *sech_name(const struct elf_info *info, Elf_Shdr *sechdr)
                                      sechdr->sh_name);
 }
 
-static const char *sec_name(const struct elf_info *info, int secindex)
+static const char *sec_name(const struct elf_info *info, unsigned int secindex)
 {
+       /*
+        * If sym->st_shndx is a special section index, there is no
+        * corresponding section header.
+        * Return "" if the index is out of range of info->sechdrs[] array.
+        */
+       if (secindex >= info->num_sections)
+               return "";
+
        return sech_name(info, &info->sechdrs[secindex]);
 }
 
@@ -466,6 +471,10 @@ static int parse_elf(struct elf_info *info, const char *filename)
        sechdrs = (void *)hdr + hdr->e_shoff;
        info->sechdrs = sechdrs;
 
+       /* modpost only works for relocatable objects */
+       if (hdr->e_type != ET_REL)
+               fatal("%s: not relocatable object.", filename);
+
        /* Check if file offset is correct */
        if (hdr->e_shoff > info->size) {
                fatal("section header offset=%lu in file '%s' is bigger than filesize=%zu\n",
@@ -737,12 +746,18 @@ static bool match(const char *string, const char *const patterns[])
        return false;
 }
 
+/* useful to pass patterns to match() directly */
+#define PATTERNS(...) \
+       ({ \
+               static const char *const patterns[] = {__VA_ARGS__, NULL}; \
+               patterns; \
+       })
+
 /* sections that we do not want to do full section mismatch check on */
 static const char *const section_white_list[] =
 {
        ".comment*",
        ".debug*",
-       ".cranges",             /* sh64 */
        ".zdebug*",             /* Compressed debug sections. */
        ".GCC.command.line",    /* record-gcc-switches */
        ".mdebug*",        /* alpha, score, mips etc. */
@@ -830,28 +845,12 @@ static const char *const init_data_sections[] =
 /* all init sections */
 static const char *const init_sections[] = { ALL_INIT_SECTIONS, NULL };
 
-/* All init and exit sections (code + data) */
-static const char *const init_exit_sections[] =
-       {ALL_INIT_SECTIONS, ALL_EXIT_SECTIONS, NULL };
-
 /* all text sections */
 static const char *const text_sections[] = { ALL_TEXT_SECTIONS, NULL };
 
 /* data section */
 static const char *const data_sections[] = { DATA_SECTIONS, NULL };
 
-
-/* symbols in .data that may refer to init/exit sections */
-#define DEFAULT_SYMBOL_WHITE_LIST                                      \
-       "*driver",                                                      \
-       "*_template", /* scsi uses *_template a lot */                  \
-       "*_timer",    /* arm uses ops structures named _timer a lot */  \
-       "*_sht",      /* scsi also used *_sht to some extent */         \
-       "*_ops",                                                        \
-       "*_probe",                                                      \
-       "*_probe_one",                                                  \
-       "*_console"
-
 static const char *const head_sections[] = { ".head.text*", NULL };
 static const char *const linker_symbols[] =
        { "__init_begin", "_sinittext", "_einittext", NULL };
@@ -883,9 +882,6 @@ enum mismatch {
  *
  * @mismatch: Type of mismatch.
  *
- * @symbol_white_list: Do not match a relocation to a symbol in this list
- * even if it is targeting a section in @bad_to_sec.
- *
  * @handler: Specific handler to call when a match is found.  If NULL,
  * default_mismatch_handler() will be called.
  *
@@ -895,7 +891,6 @@ struct sectioncheck {
        const char *bad_tosec[20];
        const char *good_tosec[20];
        enum mismatch mismatch;
-       const char *symbol_white_list[20];
        void (*handler)(const char *modname, struct elf_info *elf,
                        const struct sectioncheck* const mismatch,
                        Elf_Rela *r, Elf_Sym *sym, const char *fromsec);
@@ -915,75 +910,61 @@ static const struct sectioncheck sectioncheck[] = {
        .fromsec = { TEXT_SECTIONS, NULL },
        .bad_tosec = { ALL_INIT_SECTIONS, NULL },
        .mismatch = TEXT_TO_ANY_INIT,
-       .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
 },
 {
        .fromsec = { DATA_SECTIONS, NULL },
        .bad_tosec = { ALL_XXXINIT_SECTIONS, NULL },
        .mismatch = DATA_TO_ANY_INIT,
-       .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
 },
 {
        .fromsec = { DATA_SECTIONS, NULL },
        .bad_tosec = { INIT_SECTIONS, NULL },
        .mismatch = DATA_TO_ANY_INIT,
-       .symbol_white_list = {
-               "*_template", "*_timer", "*_sht", "*_ops",
-               "*_probe", "*_probe_one", "*_console", NULL
-       },
 },
 {
        .fromsec = { TEXT_SECTIONS, NULL },
        .bad_tosec = { ALL_EXIT_SECTIONS, NULL },
        .mismatch = TEXT_TO_ANY_EXIT,
-       .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
 },
 {
        .fromsec = { DATA_SECTIONS, NULL },
        .bad_tosec = { ALL_EXIT_SECTIONS, NULL },
        .mismatch = DATA_TO_ANY_EXIT,
-       .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
 },
 /* Do not reference init code/data from meminit code/data */
 {
        .fromsec = { ALL_XXXINIT_SECTIONS, NULL },
        .bad_tosec = { INIT_SECTIONS, NULL },
        .mismatch = XXXINIT_TO_SOME_INIT,
-       .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
 },
 /* Do not reference exit code/data from memexit code/data */
 {
        .fromsec = { ALL_XXXEXIT_SECTIONS, NULL },
        .bad_tosec = { EXIT_SECTIONS, NULL },
        .mismatch = XXXEXIT_TO_SOME_EXIT,
-       .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
 },
 /* Do not use exit code/data from init code */
 {
        .fromsec = { ALL_INIT_SECTIONS, NULL },
        .bad_tosec = { ALL_EXIT_SECTIONS, NULL },
        .mismatch = ANY_INIT_TO_ANY_EXIT,
-       .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
 },
 /* Do not use init code/data from exit code */
 {
        .fromsec = { ALL_EXIT_SECTIONS, NULL },
        .bad_tosec = { ALL_INIT_SECTIONS, NULL },
        .mismatch = ANY_EXIT_TO_ANY_INIT,
-       .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
 },
 {
        .fromsec = { ALL_PCI_INIT_SECTIONS, NULL },
        .bad_tosec = { INIT_SECTIONS, NULL },
        .mismatch = ANY_INIT_TO_ANY_EXIT,
-       .symbol_white_list = { NULL },
 },
 /* Do not export init/exit functions or data */
 {
        .fromsec = { "___ksymtab*", NULL },
        .bad_tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
        .mismatch = EXPORT_TO_INIT_EXIT,
-       .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
 },
 {
        .fromsec = { "__ex_table", NULL },
@@ -1044,15 +1025,6 @@ static const struct sectioncheck *section_mismatch(
  *   fromsec = .data*
  *   atsym   = __param_ops_*
  *
- * Pattern 2:
- *   Many drivers utilise a *driver container with references to
- *   add, remove, probe functions etc.
- *   the pattern is identified by:
- *   tosec   = init or exit section
- *   fromsec = data section
- *   atsym = *driver, *_template, *_sht, *_ops, *_probe,
- *           *probe_one, *_console, *_timer
- *
  * Pattern 3:
  *   Whitelist all references from .head.text to any init section
  *
@@ -1101,10 +1073,22 @@ static int secref_whitelist(const struct sectioncheck *mismatch,
            strstarts(fromsym, "__param_ops_"))
                return 0;
 
-       /* Check for pattern 2 */
-       if (match(tosec, init_exit_sections) &&
-           match(fromsec, data_sections) &&
-           match(fromsym, mismatch->symbol_white_list))
+       /* symbols in data sections that may refer to any init/exit sections */
+       if (match(fromsec, PATTERNS(DATA_SECTIONS)) &&
+           match(tosec, PATTERNS(ALL_INIT_SECTIONS, ALL_EXIT_SECTIONS)) &&
+           match(fromsym, PATTERNS("*_template", // scsi uses *_template a lot
+                                   "*_timer", // arm uses ops structures named _timer a lot
+                                   "*_sht", // scsi also used *_sht to some extent
+                                   "*_ops",
+                                   "*_probe",
+                                   "*_probe_one",
+                                   "*_console")))
+               return 0;
+
+       /* symbols in data sections that may refer to meminit/exit sections */
+       if (match(fromsec, PATTERNS(DATA_SECTIONS)) &&
+           match(tosec, PATTERNS(ALL_XXXINIT_SECTIONS, ALL_EXIT_SECTIONS)) &&
+           match(fromsym, PATTERNS("*driver")))
                return 0;
 
        /* Check for pattern 3 */
@@ -1230,42 +1214,6 @@ static Elf_Sym *find_elf_symbol2(struct elf_info *elf, Elf_Addr addr,
        return near;
 }
 
-/*
- * Convert a section name to the function/data attribute
- * .init.text => __init
- * .memexitconst => __memconst
- * etc.
- *
- * The memory of returned value has been allocated on a heap. The user of this
- * method should free it after usage.
-*/
-static char *sec2annotation(const char *s)
-{
-       if (match(s, init_exit_sections)) {
-               char *p = NOFAIL(malloc(20));
-               char *r = p;
-
-               *p++ = '_';
-               *p++ = '_';
-               if (*s == '.')
-                       s++;
-               while (*s && *s != '.')
-                       *p++ = *s++;
-               *p = '\0';
-               if (*s == '.')
-                       s++;
-               if (strstr(s, "rodata") != NULL)
-                       strcat(p, "const ");
-               else if (strstr(s, "data") != NULL)
-                       strcat(p, "data ");
-               else
-                       strcat(p, " ");
-               return r;
-       } else {
-               return NOFAIL(strdup(""));
-       }
-}
-
 static int is_function(Elf_Sym *sym)
 {
        if (sym)
@@ -1274,19 +1222,6 @@ static int is_function(Elf_Sym *sym)
                return -1;
 }
 
-static void print_section_list(const char * const list[20])
-{
-       const char *const *s = list;
-
-       while (*s) {
-               fprintf(stderr, "%s", *s);
-               s++;
-               if (*s)
-                       fprintf(stderr, ", ");
-       }
-       fprintf(stderr, "\n");
-}
-
 static inline void get_pretty_name(int is_func, const char** name, const char** name_p)
 {
        switch (is_func) {
@@ -1304,141 +1239,31 @@ static inline void get_pretty_name(int is_func, const char** name, const char**
 static void report_sec_mismatch(const char *modname,
                                const struct sectioncheck *mismatch,
                                const char *fromsec,
-                               unsigned long long fromaddr,
                                const char *fromsym,
-                               int from_is_func,
-                               const char *tosec, const char *tosym,
-                               int to_is_func)
+                               const char *tosec, const char *tosym)
 {
-       const char *from, *from_p;
-       const char *to, *to_p;
-       char *prl_from;
-       char *prl_to;
-
        sec_mismatch_count++;
 
-       get_pretty_name(from_is_func, &from, &from_p);
-       get_pretty_name(to_is_func, &to, &to_p);
-
-       warn("%s(%s+0x%llx): Section mismatch in reference from the %s %s%s "
-            "to the %s %s:%s%s\n",
-            modname, fromsec, fromaddr, from, fromsym, from_p, to, tosec,
-            tosym, to_p);
-
        switch (mismatch->mismatch) {
        case TEXT_TO_ANY_INIT:
-               prl_from = sec2annotation(fromsec);
-               prl_to = sec2annotation(tosec);
-               fprintf(stderr,
-               "The function %s%s() references\n"
-               "the %s %s%s%s.\n"
-               "This is often because %s lacks a %s\n"
-               "annotation or the annotation of %s is wrong.\n",
-               prl_from, fromsym,
-               to, prl_to, tosym, to_p,
-               fromsym, prl_to, tosym);
-               free(prl_from);
-               free(prl_to);
-               break;
-       case DATA_TO_ANY_INIT: {
-               prl_to = sec2annotation(tosec);
-               fprintf(stderr,
-               "The variable %s references\n"
-               "the %s %s%s%s\n"
-               "If the reference is valid then annotate the\n"
-               "variable with __init* or __refdata (see linux/init.h) "
-               "or name the variable:\n",
-               fromsym, to, prl_to, tosym, to_p);
-               print_section_list(mismatch->symbol_white_list);
-               free(prl_to);
-               break;
-       }
+       case DATA_TO_ANY_INIT:
        case TEXT_TO_ANY_EXIT:
-               prl_to = sec2annotation(tosec);
-               fprintf(stderr,
-               "The function %s() references a %s in an exit section.\n"
-               "Often the %s %s%s has valid usage outside the exit section\n"
-               "and the fix is to remove the %sannotation of %s.\n",
-               fromsym, to, to, tosym, to_p, prl_to, tosym);
-               free(prl_to);
-               break;
-       case DATA_TO_ANY_EXIT: {
-               prl_to = sec2annotation(tosec);
-               fprintf(stderr,
-               "The variable %s references\n"
-               "the %s %s%s%s\n"
-               "If the reference is valid then annotate the\n"
-               "variable with __exit* (see linux/init.h) or "
-               "name the variable:\n",
-               fromsym, to, prl_to, tosym, to_p);
-               print_section_list(mismatch->symbol_white_list);
-               free(prl_to);
-               break;
-       }
+       case DATA_TO_ANY_EXIT:
        case XXXINIT_TO_SOME_INIT:
        case XXXEXIT_TO_SOME_EXIT:
-               prl_from = sec2annotation(fromsec);
-               prl_to = sec2annotation(tosec);
-               fprintf(stderr,
-               "The %s %s%s%s references\n"
-               "a %s %s%s%s.\n"
-               "If %s is only used by %s then\n"
-               "annotate %s with a matching annotation.\n",
-               from, prl_from, fromsym, from_p,
-               to, prl_to, tosym, to_p,
-               tosym, fromsym, tosym);
-               free(prl_from);
-               free(prl_to);
-               break;
        case ANY_INIT_TO_ANY_EXIT:
-               prl_from = sec2annotation(fromsec);
-               prl_to = sec2annotation(tosec);
-               fprintf(stderr,
-               "The %s %s%s%s references\n"
-               "a %s %s%s%s.\n"
-               "This is often seen when error handling "
-               "in the init function\n"
-               "uses functionality in the exit path.\n"
-               "The fix is often to remove the %sannotation of\n"
-               "%s%s so it may be used outside an exit section.\n",
-               from, prl_from, fromsym, from_p,
-               to, prl_to, tosym, to_p,
-               prl_to, tosym, to_p);
-               free(prl_from);
-               free(prl_to);
-               break;
        case ANY_EXIT_TO_ANY_INIT:
-               prl_from = sec2annotation(fromsec);
-               prl_to = sec2annotation(tosec);
-               fprintf(stderr,
-               "The %s %s%s%s references\n"
-               "a %s %s%s%s.\n"
-               "This is often seen when error handling "
-               "in the exit function\n"
-               "uses functionality in the init path.\n"
-               "The fix is often to remove the %sannotation of\n"
-               "%s%s so it may be used outside an init section.\n",
-               from, prl_from, fromsym, from_p,
-               to, prl_to, tosym, to_p,
-               prl_to, tosym, to_p);
-               free(prl_from);
-               free(prl_to);
+               warn("%s: section mismatch in reference: %s (section: %s) -> %s (section: %s)\n",
+                    modname, fromsym, fromsec, tosym, tosec);
                break;
        case EXPORT_TO_INIT_EXIT:
-               prl_to = sec2annotation(tosec);
-               fprintf(stderr,
-               "The symbol %s is exported and annotated %s\n"
-               "Fix this by removing the %sannotation of %s "
-               "or drop the export.\n",
-               tosym, prl_to, prl_to, tosym);
-               free(prl_to);
+               warn("%s: EXPORT_SYMBOL used for init/exit symbol: %s (section: %s)\n",
+                    modname, tosym, tosec);
                break;
        case EXTABLE_TO_NON_TEXT:
-               fatal("There's a special handler for this mismatch type, "
-                     "we should never get here.");
+               fatal("There's a special handler for this mismatch type, we should never get here.\n");
                break;
        }
-       fprintf(stderr, "\n");
 }
 
 static void default_mismatch_handler(const char *modname, struct elf_info *elf,
@@ -1454,9 +1279,6 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf,
        from = find_elf_symbol2(elf, r->r_offset, fromsec);
        fromsym = sym_name(elf, from);
 
-       if (strstarts(fromsym, "reference___initcall"))
-               return;
-
        tosec = sec_name(elf, get_secindex(elf, sym));
        to = find_elf_symbol(elf, r->r_addend, sym);
        tosym = sym_name(elf, to);
@@ -1465,9 +1287,7 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf,
        if (secref_whitelist(mismatch,
                             fromsec, fromsym, tosec, tosym)) {
                report_sec_mismatch(modname, mismatch,
-                                   fromsec, r->r_offset, fromsym,
-                                   is_function(from), tosec, tosym,
-                                   is_function(to));
+                                   fromsec, fromsym, tosec, tosym);
        }
 }
 
@@ -1623,9 +1443,6 @@ static int addend_386_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
                break;
        case R_386_PC32:
                r->r_addend = TO_NATIVE(*location) + 4;
-               /* For CONFIG_RELOCATABLE=y */
-               if (elf->hdr->e_type == ET_EXEC)
-                       r->r_addend += r->r_offset;
                break;
        }
        return 0;
@@ -1718,8 +1535,7 @@ static void section_rela(const char *modname, struct elf_info *elf,
        Elf_Rela *start = (void *)elf->hdr + sechdr->sh_offset;
        Elf_Rela *stop  = (void *)start + sechdr->sh_size;
 
-       fromsec = sech_name(elf, sechdr);
-       fromsec += strlen(".rela");
+       fromsec = sec_name(elf, sechdr->sh_info);
        /* if from section (name) is know good then skip it */
        if (match(fromsec, section_white_list))
                return;
@@ -1771,8 +1587,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
        Elf_Rel *start = (void *)elf->hdr + sechdr->sh_offset;
        Elf_Rel *stop  = (void *)start + sechdr->sh_size;
 
-       fromsec = sech_name(elf, sechdr);
-       fromsec += strlen(".rel");
+       fromsec = sec_name(elf, sechdr->sh_info);
        /* if from section (name) is know good then skip it */
        if (match(fromsec, section_white_list))
                return;
index 044bdfb..1178f40 100644 (file)
@@ -26,7 +26,6 @@
 #define Elf_Shdr    Elf32_Shdr
 #define Elf_Sym     Elf32_Sym
 #define Elf_Addr    Elf32_Addr
-#define Elf_Sword   Elf64_Sword
 #define Elf_Section Elf32_Half
 #define ELF_ST_BIND ELF32_ST_BIND
 #define ELF_ST_TYPE ELF32_ST_TYPE
@@ -41,7 +40,6 @@
 #define Elf_Shdr    Elf64_Shdr
 #define Elf_Sym     Elf64_Sym
 #define Elf_Addr    Elf64_Addr
-#define Elf_Sword   Elf64_Sxword
 #define Elf_Section Elf64_Half
 #define ELF_ST_BIND ELF64_ST_BIND
 #define ELF_ST_TYPE ELF64_ST_TYPE
@@ -158,22 +156,28 @@ static inline int is_shndx_special(unsigned int i)
        return i != SHN_XINDEX && i >= SHN_LORESERVE && i <= SHN_HIRESERVE;
 }
 
-/*
- * Move reserved section indices SHN_LORESERVE..SHN_HIRESERVE out of
- * the way to -256..-1, to avoid conflicting with real section
- * indices.
- */
-#define SPECIAL(i) ((i) - (SHN_HIRESERVE + 1))
-
 /* Accessor for sym->st_shndx, hides ugliness of "64k sections" */
 static inline unsigned int get_secindex(const struct elf_info *info,
                                        const Elf_Sym *sym)
 {
-       if (is_shndx_special(sym->st_shndx))
-               return SPECIAL(sym->st_shndx);
-       if (sym->st_shndx != SHN_XINDEX)
-               return sym->st_shndx;
-       return info->symtab_shndx_start[sym - info->symtab_start];
+       unsigned int index = sym->st_shndx;
+
+       /*
+        * Elf{32,64}_Sym::st_shndx is 2 byte. Big section numbers are available
+        * in the .symtab_shndx section.
+        */
+       if (index == SHN_XINDEX)
+               return info->symtab_shndx_start[sym - info->symtab_start];
+
+       /*
+        * Move reserved section indices SHN_LORESERVE..SHN_HIRESERVE out of
+        * the way to UINT_MAX-255..UINT_MAX, to avoid conflicting with real
+        * section indices.
+        */
+       if (index >= SHN_LORESERVE && index <= SHN_HIRESERVE)
+               return index - SHN_HIRESERVE - 1;
+
+       return index;
 }
 
 /* file2alias.c */
@@ -187,6 +191,7 @@ void get_src_version(const char *modname, char sum[], unsigned sumlen);
 /* from modpost.c */
 char *read_text_file(const char *filename);
 char *get_line(char **stringp);
+void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym);
 
 enum loglevel {
        LOG_WARN,
index 7c477ca..8fa7c5b 100755 (executable)
@@ -49,6 +49,9 @@ sed -e '/^DEL/d' -e 's/^\t*//' <<EOF
        URL: https://www.kernel.org
 $S     Source: kernel-$__KERNELRELEASE.tar.gz
        Provides: $PROVIDES
+       # $UTS_MACHINE as a fallback of _arch in case
+       # /usr/lib/rpm/platform/*/macros was not included.
+       %define _arch %{?_arch:$UTS_MACHINE}
        %define __spec_install_post /usr/lib/rpm/brp-compress || :
        %define debug_package %{nil}