Merge tag 'kbuild-v4.21' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy...
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 29 Dec 2018 20:03:17 +0000 (12:03 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 29 Dec 2018 20:03:17 +0000 (12:03 -0800)
Pull Kbuild updates from Masahiro Yamada:
 "Kbuild core:
   - remove unneeded $(call cc-option,...) switches
   - consolidate Clang compiler flags into CLANG_FLAGS
   - announce the deprecation of SUBDIRS
   - fix single target build for external module
   - simplify the dependencies of 'prepare' stage targets
   - allow fixdep to directly write to .*.cmd files
   - simplify dependency generation for CONFIG_TRIM_UNUSED_KSYMS
   - change if_changed_rule to accept multi-line recipe
   - move .SECONDARY special target to scripts/Kbuild.include
   - remove redundant 'set -e'
   - improve parallel execution for CONFIG_HEADERS_CHECK
   - misc cleanups

  Treewide fixes and cleanups
   - set Clang flags correctly for PowerPC boot images
   - fix UML build error with CONFIG_GCC_PLUGINS
   - remove unneeded patterns from .gitignore files
   - refactor firmware/Makefile
   - remove unneeded rules for *offsets.s
   - avoid unneeded regeneration of intermediate .s files
   - clean up ./Kbuild

  Modpost:
   - remove unused -M, -K options
   - fix false positive warnings about section mismatch
   - use simple devtable lookup instead of linker magic
   - misc cleanups

  Coccinelle:
   - relax boolinit.cocci checks for overall consistency
   - fix warning messages of boolinit.cocci

  Other tools:
   - improve -dirty check of scripts/setlocalversion
   - add a tool to generate compile_commands.json from .*.cmd files"

* tag 'kbuild-v4.21' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: (51 commits)
  kbuild: remove unused cmd_gentimeconst
  kbuild: remove $(obj)/ prefixes in ./Kbuild
  treewide: add intermediate .s files to targets
  treewide: remove explicit rules for *offsets.s
  firmware: refactor firmware/Makefile
  firmware: remove unnecessary patterns from .gitignore
  scripts: remove unnecessary ihex2fw and check-lc_ctypes from .gitignore
  um: remove unused filechk_gen_header in Makefile
  scripts: add a tool to produce a compile_commands.json file
  kbuild: add -Werror=implicit-int flag unconditionally
  kbuild: add -Werror=strict-prototypes flag unconditionally
  kbuild: add -fno-PIE flag unconditionally
  scripts: coccinelle: Correct warning message
  scripts: coccinelle: only suggest true/false in files that already use them
  kbuild: handle part-of-module correctly for *.ll and *.symtypes
  kbuild: refactor part-of-module
  kbuild: refactor quiet_modtag
  kbuild: remove redundant quiet_modtag for $(obj-m)
  kbuild: refactor Makefile.asm-generic
  user/Makefile: Fix typo and capitalization in comment section
  ...

37 files changed:
Documentation/kbuild/kbuild.txt
Kbuild
Makefile
arch/arm/crypto/Makefile
arch/arm/mach-at91/Makefile
arch/arm/mach-omap2/Makefile
arch/arm64/crypto/Makefile
arch/ia64/kernel/Makefile
arch/powerpc/boot/Makefile
arch/um/Makefile
arch/x86/um/Makefile
drivers/memory/Makefile.asm-offsets
drivers/mtd/maps/scx200_docflash.c
drivers/watchdog/scx200_wdt.c
firmware/.gitignore
firmware/Makefile
include/asm-generic/export.h
include/linux/export.h
samples/bpf/Makefile
samples/connector/Makefile
scripts/.gitignore
scripts/Kbuild.include
scripts/Makefile
scripts/Makefile.asm-generic
scripts/Makefile.build
scripts/Makefile.gcc-plugins
scripts/Makefile.headersinst
scripts/Makefile.lib
scripts/basic/fixdep.c
scripts/coccinelle/misc/boolinit.cocci
scripts/gen_compile_commands.py [new file with mode: 0755]
scripts/gen_ksymdeps.sh [new file with mode: 0755]
scripts/mod/file2alias.c
scripts/mod/modpost.c
scripts/package/Makefile
scripts/setlocalversion
usr/Makefile

index 8390c360d4b350c960f1eebaeaeec6012dacb9b5..c9e3d93e7a89030118b7c22548108e7622e06491 100644 (file)
@@ -81,12 +81,7 @@ KBUILD_EXTMOD
 --------------------------------------------------
 Set the directory to look for the kernel source when building external
 modules.
-The directory can be specified in several ways:
-1) Use "M=..." on the command line
-2) Environment variable KBUILD_EXTMOD
-3) Environment variable SUBDIRS
-The possibilities are listed in the order they take precedence.
-Using "M=..." will always override the others.
+Setting "M=..." takes precedence over KBUILD_EXTMOD.
 
 KBUILD_OUTPUT
 --------------------------------------------------
diff --git a/Kbuild b/Kbuild
index 00530420548225a8b26a36f504d9aa00468ddb42..414ae6da1f50dea68fd044ca2d09d682c308fab4 100644 (file)
--- a/Kbuild
+++ b/Kbuild
@@ -16,11 +16,7 @@ bounds-file := include/generated/bounds.h
 always  := $(bounds-file)
 targets := kernel/bounds.s
 
-# We use internal kbuild rules to avoid the "is up to date" message from make
-kernel/bounds.s: kernel/bounds.c FORCE
-       $(call if_changed_dep,cc_s_c)
-
-$(obj)/$(bounds-file): kernel/bounds.s FORCE
+$(bounds-file): kernel/bounds.s FORCE
        $(call filechk,offsets,__LINUX_BOUNDS_H__)
 
 #####
@@ -30,15 +26,11 @@ timeconst-file := include/generated/timeconst.h
 
 targets += $(timeconst-file)
 
-quiet_cmd_gentimeconst = GEN     $@
-define cmd_gentimeconst
-       (echo $(CONFIG_HZ) | bc -q $< ) > $@
-endef
 define filechk_gentimeconst
        (echo $(CONFIG_HZ) | bc -q $< )
 endef
 
-$(obj)/$(timeconst-file): kernel/time/timeconst.bc FORCE
+$(timeconst-file): kernel/time/timeconst.bc FORCE
        $(call filechk,gentimeconst)
 
 #####
@@ -50,12 +42,9 @@ offsets-file := include/generated/asm-offsets.h
 always  += $(offsets-file)
 targets += arch/$(SRCARCH)/kernel/asm-offsets.s
 
-# We use internal kbuild rules to avoid the "is up to date" message from make
-arch/$(SRCARCH)/kernel/asm-offsets.s: arch/$(SRCARCH)/kernel/asm-offsets.c \
-                                      $(obj)/$(timeconst-file) $(obj)/$(bounds-file) FORCE
-       $(call if_changed_dep,cc_s_c)
+arch/$(SRCARCH)/kernel/asm-offsets.s: $(timeconst-file) $(bounds-file)
 
-$(obj)/$(offsets-file): arch/$(SRCARCH)/kernel/asm-offsets.s FORCE
+$(offsets-file): arch/$(SRCARCH)/kernel/asm-offsets.s FORCE
        $(call filechk,offsets,__ASM_OFFSETS_H__)
 
 #####
@@ -77,7 +66,7 @@ missing-syscalls: scripts/checksyscalls.sh $(offsets-file) FORCE
 
 extra-$(CONFIG_GDB_SCRIPTS) += build_constants_py
 
-build_constants_py: $(obj)/$(timeconst-file) $(obj)/$(bounds-file)
+build_constants_py: $(timeconst-file) $(bounds-file)
        @$(MAKE) $(build)=scripts/gdb/linux $@
 
 # Keep these three files during make clean
index 7b4cfa42c28598da7143d80120346450a0c9c788..60a4732476576b04bdaca1ffa2e5ce4b422944f8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -186,6 +186,10 @@ endif
 # Old syntax make ... SUBDIRS=$PWD is still supported
 # Setting the environment variable KBUILD_EXTMOD take precedence
 ifdef SUBDIRS
+  $(warning ================= WARNING ================)
+  $(warning 'SUBDIRS' will be removed after Linux 5.3)
+  $(warning Please use 'M=' or 'KBUILD_EXTMOD' instead)
+  $(warning ==========================================)
   KBUILD_EXTMOD ?= $(SUBDIRS)
 endif
 
@@ -422,10 +426,10 @@ LINUXINCLUDE    := \
                -I$(objtree)/include \
                $(USERINCLUDE)
 
-KBUILD_AFLAGS   := -D__ASSEMBLY__
-KBUILD_CFLAGS   := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
-                  -fno-strict-aliasing -fno-common -fshort-wchar \
-                  -Werror-implicit-function-declaration \
+KBUILD_AFLAGS   := -D__ASSEMBLY__ -fno-PIE
+KBUILD_CFLAGS   := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
+                  -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \
+                  -Werror-implicit-function-declaration -Werror=implicit-int \
                   -Wno-format-security \
                   -std=gnu89
 KBUILD_CPPFLAGS := -D__KERNEL__
@@ -487,18 +491,18 @@ endif
 
 ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
 ifneq ($(CROSS_COMPILE),)
-CLANG_TARGET   := --target=$(notdir $(CROSS_COMPILE:%-=%))
+CLANG_FLAGS    := --target=$(notdir $(CROSS_COMPILE:%-=%))
 GCC_TOOLCHAIN_DIR := $(dir $(shell which $(LD)))
-CLANG_PREFIX   := --prefix=$(GCC_TOOLCHAIN_DIR)
+CLANG_FLAGS    += --prefix=$(GCC_TOOLCHAIN_DIR)
 GCC_TOOLCHAIN  := $(realpath $(GCC_TOOLCHAIN_DIR)/..)
 endif
 ifneq ($(GCC_TOOLCHAIN),)
-CLANG_GCC_TC   := --gcc-toolchain=$(GCC_TOOLCHAIN)
+CLANG_FLAGS    += --gcc-toolchain=$(GCC_TOOLCHAIN)
 endif
-KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) $(CLANG_PREFIX)
-KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) $(CLANG_PREFIX)
-KBUILD_CFLAGS += $(call cc-option, -no-integrated-as)
-KBUILD_AFLAGS += $(call cc-option, -no-integrated-as)
+CLANG_FLAGS    += -no-integrated-as
+KBUILD_CFLAGS  += $(CLANG_FLAGS)
+KBUILD_AFLAGS  += $(CLANG_FLAGS)
+export CLANG_FLAGS
 endif
 
 RETPOLINE_CFLAGS_GCC := -mindirect-branch=thunk-extern -mindirect-branch-register
@@ -510,9 +514,6 @@ RETPOLINE_VDSO_CFLAGS := $(call cc-option,$(RETPOLINE_VDSO_CFLAGS_GCC),$(call cc
 export RETPOLINE_CFLAGS
 export RETPOLINE_VDSO_CFLAGS
 
-KBUILD_CFLAGS  += $(call cc-option,-fno-PIE)
-KBUILD_AFLAGS  += $(call cc-option,-fno-PIE)
-
 # check for 'asm goto'
 ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC) $(KBUILD_CFLAGS)), y)
   CC_HAVE_ASM_GOTO := 1
@@ -828,12 +829,6 @@ KBUILD_CFLAGS  += $(call cc-option,-fno-stack-check,)
 # conserve stack if available
 KBUILD_CFLAGS   += $(call cc-option,-fconserve-stack)
 
-# disallow errors like 'EXPORT_GPL(foo);' with missing header
-KBUILD_CFLAGS   += $(call cc-option,-Werror=implicit-int)
-
-# require functions to have arguments in prototypes, not empty 'int foo()'
-KBUILD_CFLAGS   += $(call cc-option,-Werror=strict-prototypes)
-
 # Prohibit date/time macros, which would make the build non-deterministic
 KBUILD_CFLAGS   += $(call cc-option,-Werror=date-time)
 
@@ -1026,14 +1021,13 @@ cmd_link-vmlinux =                                                 \
        $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
 
 vmlinux: scripts/link-vmlinux.sh autoksyms_recursive $(vmlinux-deps) FORCE
-ifdef CONFIG_HEADERS_CHECK
-       $(Q)$(MAKE) -f $(srctree)/Makefile headers_check
-endif
 ifdef CONFIG_GDB_SCRIPTS
        $(Q)ln -fsn $(abspath $(srctree)/scripts/gdb/vmlinux-gdb.py)
 endif
        +$(call if_changed,link-vmlinux)
 
+targets := vmlinux
+
 # Build samples along the rest of the kernel. This needs headers_install.
 ifdef CONFIG_SAMPLES
 vmlinux-dirs += samples
@@ -1051,7 +1045,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
 # Error messages still appears in the original language
 
 PHONY += $(vmlinux-dirs)
-$(vmlinux-dirs): prepare scripts
+$(vmlinux-dirs): prepare
        $(Q)$(MAKE) $(build)=$@ need-builtin=1
 
 define filechk_kernel.release
@@ -1066,7 +1060,7 @@ include/config/kernel.release: $(srctree)/Makefile FORCE
 # Carefully list dependencies so we do not try to build scripts twice
 # in parallel
 PHONY += scripts
-scripts: scripts_basic scripts_dtc asm-generic gcc-plugins $(autoksyms_h)
+scripts: scripts_basic scripts_dtc
        $(Q)$(MAKE) $(build)=$(@)
 
 # Things we need to do before we recursively start building the kernel
@@ -1099,22 +1093,23 @@ prepare2: prepare3 outputmakefile asm-generic
 prepare1: prepare2 $(version_h) $(autoksyms_h) include/generated/utsrelease.h
        $(cmd_crmodverdir)
 
-archprepare: archheaders archscripts prepare1 scripts_basic
+archprepare: archheaders archscripts prepare1 scripts
 
-prepare0: archprepare gcc-plugins
+prepare0: archprepare
+       $(Q)$(MAKE) $(build)=scripts/mod
        $(Q)$(MAKE) $(build)=.
 
 # All the preparing..
 prepare: prepare0 prepare-objtool
 
 # Support for using generic headers in asm-generic
+asm-generic := -f $(srctree)/scripts/Makefile.asm-generic obj
+
 PHONY += asm-generic uapi-asm-generic
 asm-generic: uapi-asm-generic
-       $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.asm-generic \
-                   src=asm obj=arch/$(SRCARCH)/include/generated/asm
+       $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/asm
 uapi-asm-generic:
-       $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.asm-generic \
-                   src=uapi/asm obj=arch/$(SRCARCH)/include/generated/uapi/asm
+       $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/uapi/asm
 
 PHONY += prepare-objtool
 prepare-objtool: $(objtool_target)
@@ -1199,6 +1194,10 @@ headers_check: headers_install
        $(Q)$(MAKE) $(hdr-inst)=include/uapi dst=include HDRCHECK=1
        $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi $(hdr-dst) HDRCHECK=1
 
+ifdef CONFIG_HEADERS_CHECK
+all: headers_check
+endif
+
 # ---------------------------------------------------------------------------
 # Kernel selftest
 
@@ -1283,7 +1282,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
 
 # Target to prepare building external modules
 PHONY += modules_prepare
-modules_prepare: prepare scripts
+modules_prepare: prepare
 
 # Target to install modules
 PHONY += modules_install
@@ -1551,9 +1550,6 @@ else # KBUILD_EXTMOD
 
 # We are always building modules
 KBUILD_MODULES := 1
-PHONY += crmodverdir
-crmodverdir:
-       $(cmd_crmodverdir)
 
 PHONY += $(objtree)/Module.symvers
 $(objtree)/Module.symvers:
@@ -1565,7 +1561,7 @@ $(objtree)/Module.symvers:
 
 module-dirs := $(addprefix _module_,$(KBUILD_EXTMOD))
 PHONY += $(module-dirs) modules
-$(module-dirs): crmodverdir $(objtree)/Module.symvers
+$(module-dirs): prepare $(objtree)/Module.symvers
        $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
 
 modules: $(module-dirs)
@@ -1604,10 +1600,9 @@ help:
        @echo  '  clean           - remove generated files in module directory only'
        @echo  ''
 
-# Dummies...
-PHONY += prepare scripts
-prepare: ;
-scripts: ;
+PHONY += prepare
+prepare:
+       $(cmd_crmodverdir)
 endif # KBUILD_EXTMOD
 
 clean: $(clean-dirs)
@@ -1712,36 +1707,33 @@ else
         target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
 endif
 
-%.s: %.c prepare scripts FORCE
+%.s: %.c prepare FORCE
        $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
-%.i: %.c prepare scripts FORCE
+%.i: %.c prepare FORCE
        $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
-%.o: %.c prepare scripts FORCE
+%.o: %.c prepare FORCE
        $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
-%.lst: %.c prepare scripts FORCE
+%.lst: %.c prepare FORCE
        $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
-%.s: %.S prepare scripts FORCE
+%.s: %.S prepare FORCE
        $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
-%.o: %.S prepare scripts FORCE
+%.o: %.S prepare FORCE
        $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
-%.symtypes: %.c prepare scripts FORCE
+%.symtypes: %.c prepare FORCE
        $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
-%.ll: %.c prepare scripts FORCE
+%.ll: %.c prepare FORCE
        $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
 
 # Modules
-/: prepare scripts FORCE
-       $(cmd_crmodverdir)
+/: prepare FORCE
        $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
        $(build)=$(build-dir)
 # Make sure the latest headers are built for Documentation
 Documentation/ samples/: headers_install
-%/: prepare scripts FORCE
-       $(cmd_crmodverdir)
+%/: prepare FORCE
        $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
        $(build)=$(build-dir)
-%.ko: prepare scripts FORCE
-       $(cmd_crmodverdir)
+%.ko: prepare FORCE
        $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1)   \
        $(build)=$(build-dir) $(@:.ko=.o)
        $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
@@ -1765,13 +1757,12 @@ quiet_cmd_depmod = DEPMOD  $(KERNELRELEASE)
 cmd_crmodverdir = $(Q)mkdir -p $(MODVERDIR) \
                   $(if $(KBUILD_MODULES),; rm -f $(MODVERDIR)/*)
 
-# read all saved command lines
-cmd_files := $(wildcard .*.cmd)
+# read saved command lines for existing targets
+existing-targets := $(wildcard $(sort $(targets)))
 
-ifneq ($(cmd_files),)
-  $(cmd_files): ;      # Do not try to update included dependency files
-  include $(cmd_files)
-endif
+cmd_files := $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
+$(cmd_files): ;        # Do not try to update included dependency files
+-include $(cmd_files)
 
 endif   # ifeq ($(config-targets),1)
 endif   # ifeq ($(mixed-targets),1)
index b65d6bfab8e6b7e483d75b7129e72eb44c9a5668..4180f3a13512cf4d284a67eff636972b0f0ece86 100644 (file)
@@ -67,4 +67,4 @@ $(src)/sha512-core.S_shipped: $(src)/sha512-armv4.pl
        $(call cmd,perl)
 endif
 
-targets += sha256-core.S sha512-core.S
+clean-files += sha256-core.S sha512-core.S
index 7415f181907b854aff92fb303ea7ea391a9ce922..31b61f0e1c077e707a96590ee7b9f40c4b5a230e 100644 (file)
@@ -19,10 +19,9 @@ ifeq ($(CONFIG_PM_DEBUG),y)
 CFLAGS_pm.o += -DDEBUG
 endif
 
-arch/arm/mach-at91/pm_data-offsets.s: arch/arm/mach-at91/pm_data-offsets.c
-       $(call if_changed_dep,cc_s_c)
-
 include/generated/at91_pm_data-offsets.h: arch/arm/mach-at91/pm_data-offsets.s FORCE
        $(call filechk,offsets,__PM_DATA_OFFSETS_H__)
 
 arch/arm/mach-at91/pm_suspend.o: include/generated/at91_pm_data-offsets.h
+
+targets += pm_data-offsets.s
index 899c60fac15938c1c2d839280ab8abd3de3672c5..85d1b13c9215b89da7087e19b2aefe0ceb68e515 100644 (file)
@@ -236,10 +236,9 @@ obj-y                                      += omap_phy_internal.o
 
 obj-$(CONFIG_MACH_OMAP2_TUSB6010)      += usb-tusb6010.o
 
-arch/arm/mach-omap2/pm-asm-offsets.s: arch/arm/mach-omap2/pm-asm-offsets.c
-       $(call if_changed_dep,cc_s_c)
-
 include/generated/ti-pm-asm-offsets.h: arch/arm/mach-omap2/pm-asm-offsets.s FORCE
        $(call filechk,offsets,__TI_PM_ASM_OFFSETS_H__)
 
 $(obj)/sleep33xx.o $(obj)/sleep43xx.o: include/generated/ti-pm-asm-offsets.h
+
+targets += pm-asm-offsets.s
index a4ffd9fe32650c0310cc12ac735fb087a8eede6b..e766daf43b7cf5c39a2caaee1a23f76f2dc01841 100644 (file)
@@ -78,4 +78,4 @@ $(src)/sha512-core.S_shipped: $(src)/sha512-armv8.pl
        $(call cmd,perlasm)
 endif
 
-targets += sha256-core.S sha512-core.S
+clean-files += sha256-core.S sha512-core.S
index d0c0ccdd656a04bbcc20b8fa31b44756a552bc1e..4ba05140b249ba10afe8b0f7655d5deff3748b38 100644 (file)
@@ -50,10 +50,7 @@ CFLAGS_traps.o  += -mfixed-range=f2-f5,f16-f31
 # The gate DSO image is built using a special linker script.
 include $(src)/Makefile.gate
 
-# We use internal kbuild rules to avoid the "is up to date" message from make
-arch/$(SRCARCH)/kernel/nr-irqs.s: arch/$(SRCARCH)/kernel/nr-irqs.c
-       $(Q)mkdir -p $(dir $@)
-       $(call if_changed_dep,cc_s_c)
-
 include/generated/nr-irqs.h: arch/$(SRCARCH)/kernel/nr-irqs.s FORCE
        $(call filechk,offsets,__ASM_NR_IRQS_H__)
+
+targets += nr-irqs.s
index ed9883169190577f86bc77059eaefdd5d1f3caff..0e8dadd011bc493ea7d5caf6a3a917b50fcb0946 100644 (file)
@@ -55,6 +55,11 @@ BOOTAFLAGS   := -D__ASSEMBLY__ $(BOOTCFLAGS) -traditional -nostdinc
 
 BOOTARFLAGS    := -cr$(KBUILD_ARFLAGS)
 
+ifdef CONFIG_CC_IS_CLANG
+BOOTCFLAGS += $(CLANG_FLAGS)
+BOOTAFLAGS += $(CLANG_FLAGS)
+endif
+
 ifdef CONFIG_DEBUG_INFO
 BOOTCFLAGS     += -g
 endif
index ab1066c38944ee40bae5d76ca5d0da2d966bccea..273130cf91d1203ffcfef0662b515cc06ad1c066 100644 (file)
@@ -23,8 +23,6 @@ OS := $(shell uname -s)
 # features.
 SHELL := /bin/bash
 
-filechk_gen_header = $<
-
 core-y                 += $(ARCH_DIR)/kernel/          \
                           $(ARCH_DIR)/drivers/         \
                           $(ARCH_DIR)/os-$(OS)/
@@ -116,7 +114,8 @@ endef
 archheaders:
        $(Q)$(MAKE) -f $(srctree)/Makefile ARCH=$(HEADER_ARCH) asm-generic archheaders
 
-archprepare: include/generated/user_constants.h
+archprepare:
+       $(Q)$(MAKE) $(build)=$(HOST_DIR)/um include/generated/user_constants.h
 
 LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static
 LINK-$(CONFIG_LD_SCRIPT_DYN) += -Wl,-rpath,/lib $(call cc-option, -no-pie)
@@ -146,25 +145,4 @@ archclean:
        @find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \
                -o -name '*.gcov' \) -type f -print | xargs rm -f
 
-# Generated files
-
-$(HOST_DIR)/um/user-offsets.s: __headers FORCE
-       $(Q)$(MAKE) $(build)=$(HOST_DIR)/um $@
-
-define filechk_gen-asm-offsets
-        (set -e; \
-         echo "/*"; \
-         echo " * DO NOT MODIFY."; \
-         echo " *"; \
-         echo " * This file was generated by arch/$(ARCH)/Makefile"; \
-         echo " *"; \
-         echo " */"; \
-         echo ""; \
-         sed -ne "/^->/{s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; s:->::; p;}" < $<; \
-         echo ""; )
-endef
-
-include/generated/user_constants.h: $(HOST_DIR)/um/user-offsets.s
-       $(call filechk,gen-asm-offsets)
-
 export HEADER_ARCH SUBARCH USER_CFLAGS CFLAGS_NO_HARDENING OS DEV_NULL_PATH
index c2d3d7c51e9e8f938accd4b695ea0dd8a5bf6957..2d686ae54681d5a8991d22b69b1673f70e8522d1 100644 (file)
@@ -36,9 +36,12 @@ subarch-$(CONFIG_MODULES) += ../kernel/module.o
 
 USER_OBJS := bugs_$(BITS).o ptrace_user.o fault.o
 
-extra-y += user-offsets.s
 $(obj)/user-offsets.s: c_flags = -Wp,-MD,$(depfile) $(USER_CFLAGS) \
        -Iarch/x86/include/generated
+targets += user-offsets.s
+
+include/generated/user_constants.h: $(obj)/user-offsets.s
+       $(call filechk,offsets,__USER_CONSTANT_H__)
 
 UNPROFILE_OBJS := stub_segv.o
 CFLAGS_stub_segv.o := $(CFLAGS_NO_HARDENING)
index 843ff60ccb5a2eed716ef86654c43ae4d4053031..0447e174c7521b1a63b1ebc84481d5d4f7142478 100644 (file)
@@ -1,5 +1,4 @@
-drivers/memory/emif-asm-offsets.s: drivers/memory/emif-asm-offsets.c
-       $(call if_changed_dep,cc_s_c)
-
 include/generated/ti-emif-asm-offsets.h: drivers/memory/emif-asm-offsets.s FORCE
        $(call filechk,offsets,__TI_EMIF_ASM_OFFSETS_H__)
+
+targets += emif-asm-offsets.s
index f1c1f737d0d7ebdece52d97ac6590bacd7edb1b8..7f1a0e690c4f93399f551fad40ed80ad83a3b5db 100644 (file)
@@ -216,10 +216,3 @@ static void __exit cleanup_scx200_docflash(void)
 
 module_init(init_scx200_docflash);
 module_exit(cleanup_scx200_docflash);
-
-/*
-    Local variables:
-        compile-command: "make -k -C ../../.. SUBDIRS=drivers/mtd/maps modules"
-        c-basic-offset: 8
-    End:
-*/
index 836377cf92710a03af1a158cd69edfa94a67794b..ec4063ebb41a14d03a5c4961c3967ac51dc85f54 100644 (file)
@@ -262,10 +262,3 @@ static void __exit scx200_wdt_cleanup(void)
 
 module_init(scx200_wdt_init);
 module_exit(scx200_wdt_cleanup);
-
-/*
-    Local variables:
-       compile-command: "make -k -C ../.. SUBDIRS=drivers/char modules"
-       c-basic-offset: 8
-    End:
-*/
index d9c69017bc9affb03b2519d1dbb1e5cc88abfcdc..9c8bdb9fdcc31abd07c3dc50befec65b480a13dd 100644 (file)
@@ -1,6 +1 @@
 *.gen.S
-*.fw
-*.bin
-*.csp
-*.dsp
-ihex2fw
index 29641383e136024ec9f2993b1a29a7fc9c2fa94b..e2f7dd2f30e0dcc4b592ccafe960127f78f94818 100644 (file)
@@ -1,61 +1,41 @@
 # SPDX-License-Identifier: GPL-2.0
-#
-# kbuild file for firmware/
-#
 
-# Create $(fwabs) from $(CONFIG_EXTRA_FIRMWARE_DIR) -- if it doesn't have a
+# Create $(fwdir) from $(CONFIG_EXTRA_FIRMWARE_DIR) -- if it doesn't have a
 # leading /, it's relative to $(srctree).
 fwdir := $(subst $(quote),,$(CONFIG_EXTRA_FIRMWARE_DIR))
-fwabs := $(addprefix $(srctree)/,$(filter-out /%,$(fwdir)))$(filter /%,$(fwdir))
-
-fw-external-y := $(subst $(quote),,$(CONFIG_EXTRA_FIRMWARE))
-
-quiet_cmd_fwbin = MK_FW   $@
-      cmd_fwbin = FWNAME="$(patsubst firmware/%.gen.S,%,$@)";               \
-                 FWSTR="$(subst /,_,$(subst .,_,$(subst -,_,$(patsubst      \
-                               firmware/%.gen.S,%,$@))))";                  \
-                 ASM_WORD=$(if $(CONFIG_64BIT),.quad,.long);                \
-                 ASM_ALIGN=$(if $(CONFIG_64BIT),3,2);                       \
-                 PROGBITS=$(if $(CONFIG_ARM),%,@)progbits;                  \
-                 echo "/* Generated by firmware/Makefile */"           > $@;\
-                 echo "    .section .rodata"                           >>$@;\
-                 echo "    .p2align $${ASM_ALIGN}"                     >>$@;\
-                 echo "_fw_$${FWSTR}_bin:"                             >>$@;\
-                 echo "    .incbin \"$(2)\""                           >>$@;\
-                 echo "_fw_end:"                                       >>$@;\
-                 echo "   .section .rodata.str,\"aMS\",$${PROGBITS},1" >>$@;\
-                 echo "    .p2align $${ASM_ALIGN}"                     >>$@;\
-                 echo "_fw_$${FWSTR}_name:"                            >>$@;\
-                 echo "    .string \"$$FWNAME\""                       >>$@;\
-                 echo "    .section .builtin_fw,\"a\",$${PROGBITS}"    >>$@;\
-                 echo "    .p2align $${ASM_ALIGN}"                     >>$@;\
-                 echo "    $${ASM_WORD} _fw_$${FWSTR}_name"            >>$@;\
-                 echo "    $${ASM_WORD} _fw_$${FWSTR}_bin"             >>$@;\
-                 echo "    $${ASM_WORD} _fw_end - _fw_$${FWSTR}_bin"   >>$@;
-
-# One of these files will change, or come into existence, whenever
-# the configuration changes between 32-bit and 64-bit. The .S files
-# need to change when that happens.
-wordsize_deps := $(wildcard include/config/64bit.h include/config/32bit.h \
-               include/config/ppc32.h include/config/ppc64.h \
-               include/config/superh32.h include/config/superh64.h \
-               include/config/x86_32.h include/config/x86_64.h \
-               firmware/Makefile)
-
-$(patsubst %,$(obj)/%.gen.S, $(fw-external-y)): %: $(wordsize_deps) \
-               include/config/extra/firmware/dir.h
-       $(call cmd,fwbin,$(fwabs)/$(patsubst $(obj)/%.gen.S,%,$@))
+fwdir := $(addprefix $(srctree)/,$(filter-out /%,$(fwdir)))$(filter /%,$(fwdir))
+
+obj-y  := $(addsuffix .gen.o, $(subst $(quote),,$(CONFIG_EXTRA_FIRMWARE)))
+
+FWNAME    = $(patsubst $(obj)/%.gen.S,%,$@)
+FWSTR     = $(subst /,_,$(subst .,_,$(subst -,_,$(FWNAME))))
+ASM_WORD  = $(if $(CONFIG_64BIT),.quad,.long)
+ASM_ALIGN = $(if $(CONFIG_64BIT),3,2)
+PROGBITS  = $(if $(CONFIG_ARM),%,@)progbits
+
+filechk_fwbin = { \
+       echo "/* Generated by $(src)/Makefile */"               ;\
+       echo "    .section .rodata"                             ;\
+       echo "    .p2align $(ASM_ALIGN)"                        ;\
+       echo "_fw_$(FWSTR)_bin:"                                ;\
+       echo "    .incbin \"$(fwdir)/$(FWNAME)\""               ;\
+       echo "_fw_end:"                                         ;\
+       echo "    .section .rodata.str,\"aMS\",$(PROGBITS),1"   ;\
+       echo "    .p2align $(ASM_ALIGN)"                        ;\
+       echo "_fw_$(FWSTR)_name:"                               ;\
+       echo "    .string \"$(FWNAME)\""                        ;\
+       echo "    .section .builtin_fw,\"a\",$(PROGBITS)"       ;\
+       echo "    .p2align $(ASM_ALIGN)"                        ;\
+       echo "    $(ASM_WORD) _fw_$(FWSTR)_name"                ;\
+       echo "    $(ASM_WORD) _fw_$(FWSTR)_bin"                 ;\
+       echo "    $(ASM_WORD) _fw_end - _fw_$(FWSTR)_bin"       ;\
+}
+
+$(obj)/%.gen.S: FORCE
+       $(call filechk,fwbin)
 
 # The .o files depend on the binaries directly; the .S files don't.
-$(patsubst %,$(obj)/%.gen.o, $(fw-external-y)): $(obj)/%.gen.o: $(fwdir)/%
-
-obj-y                           += $(patsubst %,%.gen.o, $(fw-external-y))
-
-ifeq ($(KBUILD_SRC),)
-# Makefile.build only creates subdirectories for O= builds, but external
-# firmware might live outside the kernel source tree
-_dummy := $(foreach d,$(addprefix $(obj)/,$(dir $(fw-external-y))), $(shell [ -d $(d) ] || mkdir -p $(d)))
-endif
+$(addprefix $(obj)/, $(obj-y)): $(obj)/%.gen.o: $(fwdir)/%
 
 targets := $(patsubst $(obj)/%,%, \
                                 $(shell find $(obj) -name \*.gen.S 2>/dev/null))
index 4d73e6e3c66c6977acd08e97fa93e2e229a9b283..294d6ae785d4e9fed609ceb51d69975c0b51ed85 100644 (file)
@@ -59,16 +59,19 @@ __kcrctab_\name:
 .endm
 #undef __put
 
-#if defined(__KSYM_DEPS__)
-
-#define __EXPORT_SYMBOL(sym, val, sec) === __KSYM_##sym ===
-
-#elif defined(CONFIG_TRIM_UNUSED_KSYMS)
+#if defined(CONFIG_TRIM_UNUSED_KSYMS)
 
 #include <linux/kconfig.h>
 #include <generated/autoksyms.h>
 
+.macro __ksym_marker sym
+       .section ".discard.ksym","a"
+__ksym_marker_\sym:
+        .previous
+.endm
+
 #define __EXPORT_SYMBOL(sym, val, sec)                         \
+       __ksym_marker sym;                                      \
        __cond_export_sym(sym, val, sec, __is_defined(__KSYM_##sym))
 #define __cond_export_sym(sym, val, sec, conf)                 \
        ___cond_export_sym(sym, val, sec, conf)
index ce764a5d2ee45023c99da81485f77bd958480de7..fd8711ed9ac41de61efae43232c6e61983df93bc 100644 (file)
@@ -92,22 +92,22 @@ struct kernel_symbol {
  */
 #define __EXPORT_SYMBOL(sym, sec)
 
-#elif defined(__KSYM_DEPS__)
+#elif defined(CONFIG_TRIM_UNUSED_KSYMS)
+
+#include <generated/autoksyms.h>
 
 /*
  * For fine grained build dependencies, we want to tell the build system
  * about each possible exported symbol even if they're not actually exported.
- * We use a string pattern that is unlikely to be valid code that the build
- * system filters out from the preprocessor output (see ksym_dep_filter
- * in scripts/Kbuild.include).
+ * We use a symbol pattern __ksym_marker_<symbol> that the build system filters
+ * from the $(NM) output (see scripts/gen_ksymdeps.sh). These symbols are
+ * discarded in the final link stage.
  */
-#define __EXPORT_SYMBOL(sym, sec)      === __KSYM_##sym ===
-
-#elif defined(CONFIG_TRIM_UNUSED_KSYMS)
-
-#include <generated/autoksyms.h>
+#define __ksym_marker(sym)     \
+       static int __ksym_marker_##sym[0] __section(".discard.ksym") __used
 
 #define __EXPORT_SYMBOL(sym, sec)                              \
+       __ksym_marker(sym);                                     \
        __cond_export_sym(sym, sec, __is_defined(__KSYM_##sym))
 #define __cond_export_sym(sym, sec, conf)                      \
        ___cond_export_sym(sym, sec, conf)
index 35444f4a846bdfdbbadb836f8ccb48c9d34293d3..66ae15f27c70d8ecd7c52760e0c84d469b9faf0f 100644 (file)
@@ -235,12 +235,10 @@ $(LIBBPF): FORCE
 # Fix up variables inherited from Kbuild that tools/ build system won't like
        $(MAKE) -C $(dir $@) RM='rm -rf' LDFLAGS= srctree=$(BPF_SAMPLES_PATH)/../../ O=
 
-$(obj)/syscall_nrs.s:  $(src)/syscall_nrs.c
-       $(call if_changed_dep,cc_s_c)
-
 $(obj)/syscall_nrs.h:  $(obj)/syscall_nrs.s FORCE
        $(call filechk,offsets,__SYSCALL_NRS_H__)
 
+targets += syscall_nrs.s
 clean-files += syscall_nrs.h
 
 FORCE:
index fe3c8542ae4ab49b89c187d49aceec95666425c1..6ad71620e5034b9197c1ef936d08b93a9d5bfe85 100644 (file)
@@ -14,4 +14,4 @@ HOSTCFLAGS_ucon.o += -I$(objtree)/usr/include
 all: modules
 
 modules clean:
-       $(MAKE) -C ../.. SUBDIRS=$(CURDIR) $@
+       $(MAKE) -C ../.. M=$(CURDIR) $@
index 12d302d70128f8a9ee2909d12b4d666c77b74c42..17f8cef88fa8104beab09440a98598ca8b4d89b2 100644 (file)
@@ -6,9 +6,7 @@ conmakehash
 kallsyms
 pnmtologo
 unifdef
-ihex2fw
 recordmcount
-check-lc_ctype
 sortextable
 asn1_compiler
 extract-cert
index 3d09844405c923c2d1a7fa04d6e1c15b6567180d..46bf1a073f5dd44acb1c227fb55c86928ee21f43 100644 (file)
@@ -213,7 +213,7 @@ echo-cmd = $(if $($(quiet)cmd_$(1)),\
        echo '  $(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';)
 
 # printing commands
-cmd = @$(echo-cmd) $(cmd_$(1))
+cmd = @set -e; $(echo-cmd) $(cmd_$(1))
 
 # Add $(obj)/ for paths that are not absolute
 objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o)))
@@ -249,56 +249,21 @@ any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^)
 
 # Execute command if command has changed or prerequisite(s) are updated.
 if_changed = $(if $(strip $(any-prereq) $(arg-check)),                       \
-       @set -e;                                                             \
-       $(echo-cmd) $(cmd_$(1));                                             \
+       $(cmd);                                                              \
        printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:)
 
 # Execute the command and also postprocess generated .d dependencies file.
-if_changed_dep = $(if $(strip $(any-prereq) $(arg-check) ),                  \
-       @set -e;                                                             \
-       $(cmd_and_fixdep), @:)
-
-ifndef CONFIG_TRIM_UNUSED_KSYMS
+if_changed_dep = $(if $(strip $(any-prereq) $(arg-check)),$(cmd_and_fixdep),@:)
 
 cmd_and_fixdep =                                                             \
-       $(echo-cmd) $(cmd_$(1));                                             \
-       scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).tmp;\
-       rm -f $(depfile);                                                    \
-       mv -f $(dot-target).tmp $(dot-target).cmd;
-
-else
-
-# Filter out exported kernel symbol names from the preprocessor output.
-# See also __KSYM_DEPS__ in include/linux/export.h.
-# We disable the depfile generation here, so as not to overwrite the existing
-# depfile while fixdep is parsing it.
-flags_nodeps = $(filter-out -Wp$(comma)-M%, $($(1)))
-ksym_dep_filter =                                                            \
-       case "$(1)" in                                                       \
-         cc_*_c|cpp_i_c)                                                    \
-           $(CPP) $(call flags_nodeps,c_flags) -D__KSYM_DEPS__ $< ;;        \
-         as_*_S|cpp_s_S)                                                    \
-           $(CPP) $(call flags_nodeps,a_flags) -D__KSYM_DEPS__ $< ;;        \
-         boot*|build*|cpp_its_S|*cpp_lds_S|dtc|host*|vdso*) : ;;            \
-         *) echo "Don't know how to preprocess $(1)" >&2; false ;;          \
-       esac | tr ";" "\n" | sed -n 's/^.*=== __KSYM_\(.*\) ===.*$$/_\1/p'
-
-cmd_and_fixdep =                                                             \
-       $(echo-cmd) $(cmd_$(1));                                             \
-       $(ksym_dep_filter) |                                                 \
-               scripts/basic/fixdep -e $(depfile) $@ '$(make-cmd)'          \
-                       > $(dot-target).tmp;                                 \
-       rm -f $(depfile);                                                    \
-       mv -f $(dot-target).tmp $(dot-target).cmd;
-
-endif
+       $(cmd);                                                              \
+       scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).cmd;\
+       rm -f $(depfile)
 
 # Usage: $(call if_changed_rule,foo)
 # Will check if $(cmd_foo) or any of the prerequisites changed,
 # and if so will execute $(rule_foo).
-if_changed_rule = $(if $(strip $(any-prereq) $(arg-check) ),                 \
-       @set -e;                                                             \
-       $(rule_$(1)), @:)
+if_changed_rule = $(if $(strip $(any-prereq) $(arg-check)),$(rule_$(1)),@:)
 
 ###
 # why - tell why a target got built
@@ -391,3 +356,6 @@ endef
 
 # delete partially updated (i.e. corrupted) files on error
 .DELETE_ON_ERROR:
+
+# do not delete intermediate files automatically
+.SECONDARY:
index ece52ff2017147420059804915afbbbc374b2a3e..feb1f71381d73a083e42e457444a8b4d3a0896dd 100644 (file)
@@ -36,10 +36,10 @@ PHONY += build_unifdef
 build_unifdef: $(obj)/unifdef
        @:
 
+subdir-$(CONFIG_GCC_PLUGINS) += gcc-plugins
 subdir-$(CONFIG_MODVERSIONS) += genksyms
-subdir-y                     += mod
 subdir-$(CONFIG_SECURITY_SELINUX) += selinux
 subdir-$(CONFIG_GDB_SCRIPTS) += gdb
 
 # Let clean descend into subdirs
-subdir-        += basic dtc kconfig package gcc-plugins
+subdir-        += basic dtc kconfig mod package
index 32ad8e93fbe15c44216ea76c63fcbf87f687445e..760323e70ebc7c56e543f80fe4ce8c70ddd8d453 100644 (file)
@@ -2,41 +2,42 @@
 # include/asm-generic contains a lot of files that are used
 # verbatim by several architectures.
 #
-# This Makefile reads the file arch/$(SRCARCH)/include/$(src)/Kbuild
+# This Makefile reads the file arch/$(SRCARCH)/include/(uapi/)/asm/Kbuild
 # and for each file listed in this file with generic-y creates
-# a small wrapper file in $(obj) (arch/$(SRCARCH)/include/generated/$(src))
+# a small wrapper file in arch/$(SRCARCH)/include/generated/(uapi/)/asm.
 
 PHONY := all
 all:
 
-kbuild-file := $(srctree)/arch/$(SRCARCH)/include/$(src)/Kbuild
--include $(kbuild-file)
+src := $(subst /generated,,$(obj))
+-include $(src)/Kbuild
 
 include scripts/Kbuild.include
 
-# Create output directory if not already present
-_dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj))
+generic-y   := $(addprefix $(obj)/, $(generic-y))
+generated-y := $(addprefix $(obj)/, $(generated-y))
 
-# Stale wrappers when the corresponding files are removed from generic-y
-# need removing.
-generated-y   := $(generic-y) $(generated-y)
-all-files     := $(patsubst %, $(obj)/%, $(generated-y))
-old-headers   := $(wildcard $(obj)/*.h)
-unwanted      := $(filter-out $(all-files),$(old-headers))
+# Remove stale wrappers when the corresponding files are removed from generic-y
+old-headers := $(wildcard $(obj)/*.h)
+unwanted    := $(filter-out $(generic-y) $(generated-y),$(old-headers))
 
 quiet_cmd_wrap = WRAP    $@
-cmd_wrap = echo "\#include <asm-generic/$*.h>" >$@
+      cmd_wrap = echo "\#include <asm-generic/$*.h>" > $@
 
 quiet_cmd_remove = REMOVE  $(unwanted)
-cmd_remove = rm -f $(unwanted)
+      cmd_remove = rm -f $(unwanted)
 
-all: $(patsubst %, $(obj)/%, $(generic-y)) FORCE
-       $(if $(unwanted),$(call cmd,remove),)
+all: $(generic-y)
+       $(if $(unwanted),$(call cmd,remove))
        @:
 
 $(obj)/%.h:
        $(call cmd,wrap)
 
-PHONY += FORCE
+# Create output directory. Skip it if at least one old header exists
+# since we know the output directory already exists.
+ifeq ($(old-headers),)
+$(shell mkdir -p $(obj))
+endif
+
 .PHONY: $(PHONY)
-FORCE: ;
index 6a6be9f440cf940358a0236b6ad13360fed253ca..fd03d60f6c5aca50f94131f2d500cbcc4325c352 100644 (file)
@@ -75,14 +75,14 @@ __build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \
 # Linus' kernel sanity checking tool
 ifeq ($(KBUILD_CHECKSRC),1)
   quiet_cmd_checksrc       = CHECK   $<
-        cmd_checksrc       = $(CHECK) $(CHECKFLAGS) $(c_flags) $< ;
+        cmd_checksrc       = $(CHECK) $(CHECKFLAGS) $(c_flags) $<
 else ifeq ($(KBUILD_CHECKSRC),2)
   quiet_cmd_force_checksrc = CHECK   $<
-        cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< ;
+        cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $<
 endif
 
 ifneq ($(KBUILD_ENABLE_EXTRA_GCC_CHECKS),)
-  cmd_checkdoc = $(srctree)/scripts/kernel-doc -none $< ;
+  cmd_checkdoc = $(srctree)/scripts/kernel-doc -none $<
 endif
 
 # Do section mismatch analysis for each module/built-in.a
@@ -94,23 +94,14 @@ endif
 # ---------------------------------------------------------------------------
 
 # Default is built-in, unless we know otherwise
+$(foreach x, i ll lst o s symtypes, $(patsubst %.o,%.$(x),$(real-obj-m))): \
+       part-of-module := y
+
 modkern_cflags =                                          \
        $(if $(part-of-module),                           \
                $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \
                $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL))
-quiet_modtag := $(empty)   $(empty)
-
-$(real-obj-m)        : part-of-module := y
-$(real-obj-m:.o=.i)  : part-of-module := y
-$(real-obj-m:.o=.s)  : part-of-module := y
-$(real-obj-m:.o=.lst): part-of-module := y
-
-$(real-obj-m)        : quiet_modtag := [M]
-$(real-obj-m:.o=.i)  : quiet_modtag := [M]
-$(real-obj-m:.o=.s)  : quiet_modtag := [M]
-$(real-obj-m:.o=.lst): quiet_modtag := [M]
-
-$(obj-m)             : quiet_modtag := [M]
+quiet_modtag = $(if $(part-of-module),[M],   )
 
 quiet_cmd_cc_s_c = CC $(quiet_modtag)  $@
 cmd_cc_s_c       = $(CC) $(c_flags) $(DISABLE_LTO) -fverbose-asm -S -o $@ $<
@@ -134,7 +125,6 @@ cmd_gensymtypes_c =                                                         \
 
 quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@
 cmd_cc_symtypes_c =                                                         \
-    set -e;                                                                 \
     $(call cmd_gensymtypes_c,true,$@) >/dev/null;                           \
     test -s $@ || rm -f $@
 
@@ -154,36 +144,31 @@ $(obj)/%.ll: $(src)/%.c FORCE
 # (See cmd_cc_o_c + relevant part of rule_cc_o_c)
 
 quiet_cmd_cc_o_c = CC $(quiet_modtag)  $@
+      cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
 
-ifndef CONFIG_MODVERSIONS
-cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
-
-else
+ifdef CONFIG_MODVERSIONS
 # When module versioning is enabled the following steps are executed:
-# o compile a .tmp_<file>.o from <file>.c
-# o if .tmp_<file>.o doesn't contain a __ksymtab version, i.e. does
-#   not export symbols, we just rename .tmp_<file>.o to <file>.o and
-#   are done.
+# o compile a <file>.o from <file>.c
+# o if <file>.o doesn't contain a __ksymtab version, i.e. does
+#   not export symbols, it's done.
 # o otherwise, we calculate symbol versions using the good old
 #   genksyms on the preprocessed source and postprocess them in a way
 #   that they are usable as a linker script
-# o generate <file>.o from .tmp_<file>.o using the linker to
+# o generate .tmp_<file>.o from <file>.o using the linker to
 #   replace the unresolved symbols __crc_exported_symbol with
 #   the actual value of the checksum generated by genksyms
-
-cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) $<
+# o remove .tmp_<file>.o to <file>.o
 
 cmd_modversions_c =                                                            \
-       if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then             \
+       if $(OBJDUMP) -h $@ | grep -q __ksymtab; then                           \
                $(call cmd_gensymtypes_c,$(KBUILD_SYMTYPES),$(@:.o=.symtypes))  \
                    > $(@D)/.tmp_$(@F:.o=.ver);                                 \
                                                                                \
-               $(LD) $(KBUILD_LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F)               \
+               $(LD) $(KBUILD_LDFLAGS) -r -o $(@D)/.tmp_$(@F) $@               \
                        -T $(@D)/.tmp_$(@F:.o=.ver);                            \
-               rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver);                \
-       else                                                                    \
                mv -f $(@D)/.tmp_$(@F) $@;                                      \
-       fi;
+               rm -f $(@D)/.tmp_$(@F:.o=.ver);                                 \
+       fi
 endif
 
 ifdef CONFIG_FTRACE_MCOUNT_RECORD
@@ -204,7 +189,7 @@ sub_cmd_record_mcount =                                     \
 recordmcount_source := $(srctree)/scripts/recordmcount.c \
                    $(srctree)/scripts/recordmcount.h
 else
-sub_cmd_record_mcount = set -e ; perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \
+sub_cmd_record_mcount = perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \
        "$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \
        "$(if $(CONFIG_64BIT),64,32)" \
        "$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS)" \
@@ -216,7 +201,7 @@ cmd_record_mcount =                                         \
        if [ "$(findstring $(CC_FLAGS_FTRACE),$(_c_flags))" =   \
             "$(CC_FLAGS_FTRACE)" ]; then                       \
                $(sub_cmd_record_mcount)                        \
-       fi;
+       fi
 endif # CC_USING_RECORD_MCOUNT
 endif # CONFIG_FTRACE_MCOUNT_RECORD
 
@@ -239,19 +224,12 @@ ifdef CONFIG_RETPOLINE
   objtool_args += --retpoline
 endif
 
-
-ifdef CONFIG_MODVERSIONS
-objtool_o = $(@D)/.tmp_$(@F)
-else
-objtool_o = $(@)
-endif
-
 # 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory
 # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
 # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
 cmd_objtool = $(if $(patsubst y%,, \
        $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
-       $(__objtool_obj) $(objtool_args) "$(objtool_o)";)
+       $(__objtool_obj) $(objtool_args) $@)
 objtool_obj = $(if $(patsubst y%,, \
        $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
        $(__objtool_obj))
@@ -264,19 +242,26 @@ objtool_dep = $(objtool_obj)                                      \
              $(wildcard include/config/orc/unwinder.h          \
                         include/config/stack/validation.h)
 
+ifdef CONFIG_TRIM_UNUSED_KSYMS
+cmd_gen_ksymdeps = \
+       $(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ >> $(dot-target).cmd
+endif
+
 define rule_cc_o_c
-       $(call echo-cmd,checksrc) $(cmd_checksrc)                         \
-       $(call cmd_and_fixdep,cc_o_c)                                     \
-       $(cmd_checkdoc)                                                   \
-       $(call echo-cmd,objtool) $(cmd_objtool)                           \
-       $(cmd_modversions_c)                                              \
-       $(call echo-cmd,record_mcount) $(cmd_record_mcount)
+       $(call cmd,checksrc)
+       $(call cmd_and_fixdep,cc_o_c)
+       $(call cmd,gen_ksymdeps)
+       $(call cmd,checkdoc)
+       $(call cmd,objtool)
+       $(call cmd,modversions_c)
+       $(call cmd,record_mcount)
 endef
 
 define rule_as_o_S
-       $(call cmd_and_fixdep,as_o_S)                                     \
-       $(call echo-cmd,objtool) $(cmd_objtool)                           \
-       $(cmd_modversions_S)
+       $(call cmd_and_fixdep,as_o_S)
+       $(call cmd,gen_ksymdeps)
+       $(call cmd,objtool)
+       $(call cmd,modversions_S)
 endef
 
 # List module undefined symbols (or empty line if not enabled)
@@ -340,7 +325,6 @@ cmd_gensymtypes_S =                                                         \
 
 quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@
 cmd_cc_symtypes_S =                                                         \
-    set -e;                                                                 \
     $(call cmd_gensymtypes_S,true,$@) >/dev/null;                           \
     test -s $@ || rm -f $@
 
@@ -355,35 +339,27 @@ $(obj)/%.s: $(src)/%.S FORCE
        $(call if_changed_dep,cpp_s_S)
 
 quiet_cmd_as_o_S = AS $(quiet_modtag)  $@
+      cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
 
-ifndef CONFIG_MODVERSIONS
-cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
-
-else
+ifdef CONFIG_MODVERSIONS
 
 ASM_PROTOTYPES := $(wildcard $(srctree)/arch/$(SRCARCH)/include/asm/asm-prototypes.h)
 
-ifeq ($(ASM_PROTOTYPES),)
-cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
-
-else
+ifneq ($(ASM_PROTOTYPES),)
 
 # versioning matches the C process described above, with difference that
 # we parse asm-prototypes.h C header to get function definitions.
 
-cmd_as_o_S = $(CC) $(a_flags) -c -o $(@D)/.tmp_$(@F) $<
-
 cmd_modversions_S =                                                            \
-       if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then             \
+       if $(OBJDUMP) -h $@ | grep -q __ksymtab; then                           \
                $(call cmd_gensymtypes_S,$(KBUILD_SYMTYPES),$(@:.o=.symtypes))  \
                    > $(@D)/.tmp_$(@F:.o=.ver);                                 \
                                                                                \
-               $(LD) $(KBUILD_LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F)               \
+               $(LD) $(KBUILD_LDFLAGS) -r -o $(@D)/.tmp_$(@F) $@               \
                        -T $(@D)/.tmp_$(@F:.o=.ver);                            \
-               rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver);                \
-       else                                                                    \
                mv -f $(@D)/.tmp_$(@F) $@;                                      \
-       fi;
+               rm -f $(@D)/.tmp_$(@F:.o=.ver);                                 \
+       fi
 endif
 endif
 
@@ -527,25 +503,19 @@ FORCE:
 # optimization, we don't need to read them if the target does not
 # exist, we will rebuild anyway in that case.
 
-cmd_files := $(wildcard $(foreach f,$(sort $(targets)),$(dir $(f)).$(notdir $(f)).cmd))
+existing-targets := $(wildcard $(sort $(targets)))
 
-ifneq ($(cmd_files),)
-  include $(cmd_files)
-endif
+-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
 
 ifneq ($(KBUILD_SRC),)
 # Create directories for object files if they do not exist
 obj-dirs := $(sort $(obj) $(patsubst %/,%, $(dir $(targets))))
-# If cmd_files exist, their directories apparently exist.  Skip mkdir.
-exist-dirs := $(sort $(patsubst %/,%, $(dir $(cmd_files))))
-obj-dirs := $(strip $(filter-out $(exist-dirs), $(obj-dirs)))
+# If targets exist, their directories apparently exist. Skip mkdir.
+existing-dirs := $(sort $(patsubst %/,%, $(dir $(existing-targets))))
+obj-dirs := $(strip $(filter-out $(existing-dirs), $(obj-dirs)))
 ifneq ($(obj-dirs),)
 $(shell mkdir -p $(obj-dirs))
 endif
 endif
 
-# Some files contained in $(targets) are intermediate artifacts.
-# We never want them to be removed automatically.
-.SECONDARY: $(targets)
-
 .PHONY: $(PHONY)
index 048179d8c07fc1646e446b7d4fa550b257dcb396..35042d96cf5da42fb485d058b0a68083b878e5be 100644 (file)
@@ -55,11 +55,3 @@ KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
 # All enabled GCC plugins are collected here for building below.
 GCC_PLUGIN := $(gcc-plugin-y)
 export GCC_PLUGIN
-
-# Actually do the build, if requested.
-PHONY += gcc-plugins
-gcc-plugins: scripts_basic
-ifdef CONFIG_GCC_PLUGINS
-       $(Q)$(MAKE) $(build)=scripts/gcc-plugins
-endif
-       @:
index d5e1314711312c6572001170a506b022ac43f1fc..45927fcddbc0a5f69ec88b31aced34788abbb25e 100644 (file)
@@ -44,7 +44,6 @@ kbuild-file := $(srctree)/$(obj)/Kbuild
 installdir    := $(INSTALL_HDR_PATH)/$(dst)
 gendir        := $(objtree)/$(subst include/,include/generated/,$(obj))
 header-files  := $(notdir $(wildcard $(srcdir)/*.h))
-header-files  += $(notdir $(wildcard $(srcdir)/*.agh))
 header-files  := $(filter-out $(no-export-headers), $(header-files))
 genhdr-files  := $(notdir $(wildcard $(gendir)/*.h))
 genhdr-files  := $(filter-out $(header-files), $(genhdr-files))
index 0e78249ee77e8ac7d67d834b8700858523957e95..3ceaa2e2a6ced0298ca056c893d348eea4c08380 100644 (file)
@@ -426,7 +426,7 @@ endef
 # Use filechk to avoid rebuilds when a header changes, but the resulting file
 # does not
 define filechk_offsets
-       (set -e; \
+       ( \
         echo "#ifndef $2"; \
         echo "#define $2"; \
         echo "/*"; \
index 850966f3d6021bc1fb17472250ac7cf40bd42d0f..facbd603adf616aaa67a9b99456bd4b8f8be7177 100644 (file)
 
 static void usage(void)
 {
-       fprintf(stderr, "Usage: fixdep [-e] <depfile> <target> <cmdline>\n");
-       fprintf(stderr, " -e  insert extra dependencies given on stdin\n");
+       fprintf(stderr, "Usage: fixdep <depfile> <target> <cmdline>\n");
        exit(1);
 }
 
@@ -131,21 +130,6 @@ static void print_dep(const char *m, int slen, const char *dir)
        printf(".h) \\\n");
 }
 
-static void do_extra_deps(void)
-{
-       char buf[80];
-
-       while (fgets(buf, sizeof(buf), stdin)) {
-               int len = strlen(buf);
-
-               if (len < 2 || buf[len - 1] != '\n') {
-                       fprintf(stderr, "fixdep: bad data on stdin\n");
-                       exit(1);
-               }
-               print_dep(buf, len - 1, "include/ksym");
-       }
-}
-
 struct item {
        struct item     *next;
        unsigned int    len;
@@ -293,7 +277,7 @@ static int is_ignored_file(const char *s, int len)
  * assignments are parsed not only by make, but also by the rather simple
  * parser in scripts/mod/sumversion.c.
  */
-static void parse_dep_file(char *m, const char *target, int insert_extra_deps)
+static void parse_dep_file(char *m, const char *target)
 {
        char *p;
        int is_last, is_target;
@@ -369,9 +353,6 @@ static void parse_dep_file(char *m, const char *target, int insert_extra_deps)
                exit(1);
        }
 
-       if (insert_extra_deps)
-               do_extra_deps();
-
        printf("\n%s: $(deps_%s)\n\n", target, target);
        printf("$(deps_%s):\n", target);
 }
@@ -379,13 +360,9 @@ static void parse_dep_file(char *m, const char *target, int insert_extra_deps)
 int main(int argc, char *argv[])
 {
        const char *depfile, *target, *cmdline;
-       int insert_extra_deps = 0;
        void *buf;
 
-       if (argc == 5 && !strcmp(argv[1], "-e")) {
-               insert_extra_deps = 1;
-               argv++;
-       } else if (argc != 4)
+       if (argc != 4)
                usage();
 
        depfile = argv[1];
@@ -395,7 +372,7 @@ int main(int argc, char *argv[])
        printf("cmd_%s := %s\n\n", target, cmdline);
 
        buf = read_file(depfile);
-       parse_dep_file(buf, target, insert_extra_deps);
+       parse_dep_file(buf, target);
        free(buf);
 
        return 0;
index b9abed49cd95c5c99841a4e5016eb3c4fda4c1fb..b0584a33c921491026a01d019f8b77fc3e5fd151 100644 (file)
@@ -13,10 +13,17 @@ virtual context
 virtual org
 virtual report
 
+@boolok@
+symbol true,false;
+@@
+(
+true
+|
+false
+)
+
 @depends on patch@
 bool t;
-symbol true;
-symbol false;
 @@
 
 (
@@ -63,7 +70,7 @@ bool t;
 + t
 )
 
-@depends on patch@
+@depends on patch && boolok@
 bool b;
 @@
 (
@@ -116,19 +123,23 @@ position p;
 * t@p != 0
 )
 
-@r3 depends on !patch@
+@r3 depends on !patch && boolok@
 bool b;
-position p1,p2;
-constant c;
+position p1;
 @@
 (
 *b@p1 = 0
 |
 *b@p1 = 1
-|
-*b@p2 = c
 )
 
+@r4 depends on !patch@
+bool b;
+position p2;
+constant c != {0,1};
+@@
+*b@p2 = c
+
 @script:python depends on org@
 p << r1.p;
 @@
@@ -139,19 +150,19 @@ cocci.print_main("WARNING: Comparison to bool",p)
 p << r2.p;
 @@
 
-cocci.print_main("WARNING: Comparison of bool to 0/1",p)
+cocci.print_main("WARNING: Comparison of 0/1 to bool variable",p)
 
 @script:python depends on org@
 p1 << r3.p1;
 @@
 
-cocci.print_main("WARNING: Assignment of bool to 0/1",p1)
+cocci.print_main("WARNING: Assignment of 0/1 to bool variable",p1)
 
 @script:python depends on org@
-p2 << r3.p2;
+p2 << r4.p2;
 @@
 
-cocci.print_main("ERROR: Assignment of bool to non-0/1 constant",p2)
+cocci.print_main("ERROR: Assignment of non-0/1 constant to bool variable",p2)
 
 @script:python depends on report@
 p << r1.p;
@@ -163,16 +174,16 @@ coccilib.report.print_report(p[0],"WARNING: Comparison to bool")
 p << r2.p;
 @@
 
-coccilib.report.print_report(p[0],"WARNING: Comparison of bool to 0/1")
+coccilib.report.print_report(p[0],"WARNING: Comparison of 0/1 to bool variable")
 
 @script:python depends on report@
 p1 << r3.p1;
 @@
 
-coccilib.report.print_report(p1[0],"WARNING: Assignment of bool to 0/1")
+coccilib.report.print_report(p1[0],"WARNING: Assignment of 0/1 to bool variable")
 
 @script:python depends on report@
-p2 << r3.p2;
+p2 << r4.p2;
 @@
 
-coccilib.report.print_report(p2[0],"ERROR: Assignment of bool to non-0/1 constant")
+coccilib.report.print_report(p2[0],"ERROR: Assignment of non-0/1 constant to bool variable")
diff --git a/scripts/gen_compile_commands.py b/scripts/gen_compile_commands.py
new file mode 100755 (executable)
index 0000000..7915823
--- /dev/null
@@ -0,0 +1,151 @@
+#!/usr/bin/env python
+# SPDX-License-Identifier: GPL-2.0
+#
+# Copyright (C) Google LLC, 2018
+#
+# Author: Tom Roeder <tmroeder@google.com>
+#
+"""A tool for generating compile_commands.json in the Linux kernel."""
+
+import argparse
+import json
+import logging
+import os
+import re
+
+_DEFAULT_OUTPUT = 'compile_commands.json'
+_DEFAULT_LOG_LEVEL = 'WARNING'
+
+_FILENAME_PATTERN = r'^\..*\.cmd$'
+_LINE_PATTERN = r'^cmd_[^ ]*\.o := (.* )([^ ]*\.c)$'
+_VALID_LOG_LEVELS = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']
+
+# A kernel build generally has over 2000 entries in its compile_commands.json
+# database. If this code finds 500 or fewer, then warn the user that they might
+# not have all the .cmd files, and they might need to compile the kernel.
+_LOW_COUNT_THRESHOLD = 500
+
+
+def parse_arguments():
+    """Sets up and parses command-line arguments.
+
+    Returns:
+        log_level: A logging level to filter log output.
+        directory: The directory to search for .cmd files.
+        output: Where to write the compile-commands JSON file.
+    """
+    usage = 'Creates a compile_commands.json database from kernel .cmd files'
+    parser = argparse.ArgumentParser(description=usage)
+
+    directory_help = ('Path to the kernel source directory to search '
+                      '(defaults to the working directory)')
+    parser.add_argument('-d', '--directory', type=str, help=directory_help)
+
+    output_help = ('The location to write compile_commands.json (defaults to '
+                   'compile_commands.json in the search directory)')
+    parser.add_argument('-o', '--output', type=str, help=output_help)
+
+    log_level_help = ('The level of log messages to produce (one of ' +
+                      ', '.join(_VALID_LOG_LEVELS) + '; defaults to ' +
+                      _DEFAULT_LOG_LEVEL + ')')
+    parser.add_argument(
+        '--log_level', type=str, default=_DEFAULT_LOG_LEVEL,
+        help=log_level_help)
+
+    args = parser.parse_args()
+
+    log_level = args.log_level
+    if log_level not in _VALID_LOG_LEVELS:
+        raise ValueError('%s is not a valid log level' % log_level)
+
+    directory = args.directory or os.getcwd()
+    output = args.output or os.path.join(directory, _DEFAULT_OUTPUT)
+    directory = os.path.abspath(directory)
+
+    return log_level, directory, output
+
+
+def process_line(root_directory, file_directory, command_prefix, relative_path):
+    """Extracts information from a .cmd line and creates an entry from it.
+
+    Args:
+        root_directory: The directory that was searched for .cmd files. Usually
+            used directly in the "directory" entry in compile_commands.json.
+        file_directory: The path to the directory the .cmd file was found in.
+        command_prefix: The extracted command line, up to the last element.
+        relative_path: The .c file from the end of the extracted command.
+            Usually relative to root_directory, but sometimes relative to
+            file_directory and sometimes neither.
+
+    Returns:
+        An entry to append to compile_commands.
+
+    Raises:
+        ValueError: Could not find the extracted file based on relative_path and
+            root_directory or file_directory.
+    """
+    # The .cmd files are intended to be included directly by Make, so they
+    # escape the pound sign '#', either as '\#' or '$(pound)' (depending on the
+    # kernel version). The compile_commands.json file is not interepreted
+    # by Make, so this code replaces the escaped version with '#'.
+    prefix = command_prefix.replace('\#', '#').replace('$(pound)', '#')
+
+    cur_dir = root_directory
+    expected_path = os.path.join(cur_dir, relative_path)
+    if not os.path.exists(expected_path):
+        # Try using file_directory instead. Some of the tools have a different
+        # style of .cmd file than the kernel.
+        cur_dir = file_directory
+        expected_path = os.path.join(cur_dir, relative_path)
+        if not os.path.exists(expected_path):
+            raise ValueError('File %s not in %s or %s' %
+                             (relative_path, root_directory, file_directory))
+    return {
+        'directory': cur_dir,
+        'file': relative_path,
+        'command': prefix + relative_path,
+    }
+
+
+def main():
+    """Walks through the directory and finds and parses .cmd files."""
+    log_level, directory, output = parse_arguments()
+
+    level = getattr(logging, log_level)
+    logging.basicConfig(format='%(levelname)s: %(message)s', level=level)
+
+    filename_matcher = re.compile(_FILENAME_PATTERN)
+    line_matcher = re.compile(_LINE_PATTERN)
+
+    compile_commands = []
+    for dirpath, _, filenames in os.walk(directory):
+        for filename in filenames:
+            if not filename_matcher.match(filename):
+                continue
+            filepath = os.path.join(dirpath, filename)
+
+            with open(filepath, 'rt') as f:
+                for line in f:
+                    result = line_matcher.match(line)
+                    if not result:
+                        continue
+
+                    try:
+                        entry = process_line(directory, dirpath,
+                                             result.group(1), result.group(2))
+                        compile_commands.append(entry)
+                    except ValueError as err:
+                        logging.info('Could not add line from %s: %s',
+                                     filepath, err)
+
+    with open(output, 'wt') as f:
+        json.dump(compile_commands, f, indent=2, sort_keys=True)
+
+    count = len(compile_commands)
+    if count < _LOW_COUNT_THRESHOLD:
+        logging.warning(
+            'Found %s entries. Have you compiled the kernel?', count)
+
+
+if __name__ == '__main__':
+    main()
diff --git a/scripts/gen_ksymdeps.sh b/scripts/gen_ksymdeps.sh
new file mode 100755 (executable)
index 0000000..1324986
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+
+# List of exported symbols
+ksyms=$($NM $1 | sed -n 's/.*__ksym_marker_\(.*\)/\1/p' | tr A-Z a-z)
+
+if [ -z "$ksyms" ]; then
+       exit 0
+fi
+
+echo
+echo "ksymdeps_$1 := \\"
+
+for s in $ksyms
+do
+       echo $s | sed -e 's:^_*:    $(wildcard include/ksym/:' \
+                       -e 's:__*:/:g' -e 's/$/.h) \\/'
+done
+
+echo
+echo "$1: \$(ksymdeps_$1)"
+echo
+echo "\$(ksymdeps_$1):"
index 28a61665bb9c95648ef3bd123a67d5e79888c28a..a37af7d719732e2f3e9feab2fc78af4f9f13303a 100644 (file)
@@ -47,49 +47,9 @@ typedef struct {
 struct devtable {
        const char *device_id; /* name of table, __mod_<name>__*_device_table. */
        unsigned long id_size;
-       void *function;
+       int (*do_entry)(const char *filename, void *symval, char *alias);
 };
 
-#define ___cat(a,b) a ## b
-#define __cat(a,b) ___cat(a,b)
-
-/* we need some special handling for this host tool running eventually on
- * Darwin. The Mach-O section handling is a bit different than ELF section
- * handling. The differnces in detail are:
- *  a) we have segments which have sections
- *  b) we need a API call to get the respective section symbols */
-#if defined(__MACH__)
-#include <mach-o/getsect.h>
-
-#define INIT_SECTION(name)  do {                                       \
-               unsigned long name ## _len;                             \
-               char *__cat(pstart_,name) = getsectdata("__TEXT",       \
-                       #name, &__cat(name,_len));                      \
-               char *__cat(pstop_,name) = __cat(pstart_,name) +        \
-                       __cat(name, _len);                              \
-               __cat(__start_,name) = (void *)__cat(pstart_,name);     \
-               __cat(__stop_,name) = (void *)__cat(pstop_,name);       \
-       } while (0)
-#define SECTION(name)   __attribute__((section("__TEXT, " #name)))
-
-struct devtable **__start___devtable, **__stop___devtable;
-#else
-#define INIT_SECTION(name) /* no-op for ELF */
-#define SECTION(name)   __attribute__((section(#name)))
-
-/* We construct a table of pointers in an ELF section (pointers generally
- * go unpadded by gcc).  ld creates boundary syms for us. */
-extern struct devtable *__start___devtable[], *__stop___devtable[];
-#endif /* __MACH__ */
-
-#if !defined(__used)
-# if __GNUC__ == 3 && __GNUC_MINOR__ < 3
-#  define __used                       __attribute__((__unused__))
-# else
-#  define __used                       __attribute__((__used__))
-# endif
-#endif
-
 /* Define a variable f that holds the value of field f of struct devid
  * based at address m.
  */
@@ -110,16 +70,6 @@ extern struct devtable *__start___devtable[], *__stop___devtable[];
 #define DEF_FIELD_ADDR(m, devid, f) \
        DEF_FIELD_ADDR_VAR(m, devid, f, f)
 
-/* Add a table entry.  We test function type matches while we're here. */
-#define ADD_TO_DEVTABLE(device_id, type, function) \
-       static struct devtable __cat(devtable,__LINE__) = {     \
-               device_id + 0*sizeof((function)((const char *)NULL,     \
-                                               (void *)NULL,           \
-                                               (char *)NULL)),         \
-               SIZE_##type, (function) };                              \
-       static struct devtable *SECTION(__devtable) __used \
-               __cat(devtable_ptr,__LINE__) = &__cat(devtable,__LINE__)
-
 #define ADD(str, sep, cond, field)                              \
 do {                                                            \
         strcat(str, sep);                                       \
@@ -439,7 +389,6 @@ static int do_hid_entry(const char *filename,
 
        return 1;
 }
-ADD_TO_DEVTABLE("hid", hid_device_id, do_hid_entry);
 
 /* Looks like: ieee1394:venNmoNspNverN */
 static int do_ieee1394_entry(const char *filename,
@@ -464,7 +413,6 @@ static int do_ieee1394_entry(const char *filename,
        add_wildcard(alias);
        return 1;
 }
-ADD_TO_DEVTABLE("ieee1394", ieee1394_device_id, do_ieee1394_entry);
 
 /* Looks like: pci:vNdNsvNsdNbcNscNiN. */
 static int do_pci_entry(const char *filename,
@@ -508,7 +456,6 @@ static int do_pci_entry(const char *filename,
        add_wildcard(alias);
        return 1;
 }
-ADD_TO_DEVTABLE("pci", pci_device_id, do_pci_entry);
 
 /* looks like: "ccw:tNmNdtNdmN" */
 static int do_ccw_entry(const char *filename,
@@ -532,7 +479,6 @@ static int do_ccw_entry(const char *filename,
        add_wildcard(alias);
        return 1;
 }
-ADD_TO_DEVTABLE("ccw", ccw_device_id, do_ccw_entry);
 
 /* looks like: "ap:tN" */
 static int do_ap_entry(const char *filename,
@@ -543,7 +489,6 @@ static int do_ap_entry(const char *filename,
        sprintf(alias, "ap:t%02X*", dev_type);
        return 1;
 }
-ADD_TO_DEVTABLE("ap", ap_device_id, do_ap_entry);
 
 /* looks like: "css:tN" */
 static int do_css_entry(const char *filename,
@@ -554,7 +499,6 @@ static int do_css_entry(const char *filename,
        sprintf(alias, "css:t%01X", type);
        return 1;
 }
-ADD_TO_DEVTABLE("css", css_device_id, do_css_entry);
 
 /* Looks like: "serio:tyNprNidNexN" */
 static int do_serio_entry(const char *filename,
@@ -574,7 +518,6 @@ static int do_serio_entry(const char *filename,
        add_wildcard(alias);
        return 1;
 }
-ADD_TO_DEVTABLE("serio", serio_device_id, do_serio_entry);
 
 /* looks like: "acpi:ACPI0003" or "acpi:PNP0C0B" or "acpi:LNXVIDEO" or
  *             "acpi:bbsspp" (bb=base-class, ss=sub-class, pp=prog-if)
@@ -612,7 +555,6 @@ static int do_acpi_entry(const char *filename,
        }
        return 1;
 }
-ADD_TO_DEVTABLE("acpi", acpi_device_id, do_acpi_entry);
 
 /* looks like: "pnp:dD" */
 static void do_pnp_device_entry(void *symval, unsigned long size,
@@ -736,7 +678,6 @@ static int do_pcmcia_entry(const char *filename,
        add_wildcard(alias);
        return 1;
 }
-ADD_TO_DEVTABLE("pcmcia", pcmcia_device_id, do_pcmcia_entry);
 
 static int do_vio_entry(const char *filename, void *symval,
                char *alias)
@@ -756,7 +697,6 @@ static int do_vio_entry(const char *filename, void *symval,
        add_wildcard(alias);
        return 1;
 }
-ADD_TO_DEVTABLE("vio", vio_device_id, do_vio_entry);
 
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
@@ -829,7 +769,6 @@ static int do_input_entry(const char *filename, void *symval,
                do_input(alias, *swbit, 0, INPUT_DEVICE_ID_SW_MAX);
        return 1;
 }
-ADD_TO_DEVTABLE("input", input_device_id, do_input_entry);
 
 static int do_eisa_entry(const char *filename, void *symval,
                char *alias)
@@ -841,7 +780,6 @@ static int do_eisa_entry(const char *filename, void *symval,
                strcat(alias, "*");
        return 1;
 }
-ADD_TO_DEVTABLE("eisa", eisa_device_id, do_eisa_entry);
 
 /* Looks like: parisc:tNhvNrevNsvN */
 static int do_parisc_entry(const char *filename, void *symval,
@@ -861,7 +799,6 @@ static int do_parisc_entry(const char *filename, void *symval,
        add_wildcard(alias);
        return 1;
 }
-ADD_TO_DEVTABLE("parisc", parisc_device_id, do_parisc_entry);
 
 /* Looks like: sdio:cNvNdN. */
 static int do_sdio_entry(const char *filename,
@@ -878,7 +815,6 @@ static int do_sdio_entry(const char *filename,
        add_wildcard(alias);
        return 1;
 }
-ADD_TO_DEVTABLE("sdio", sdio_device_id, do_sdio_entry);
 
 /* Looks like: ssb:vNidNrevN. */
 static int do_ssb_entry(const char *filename,
@@ -895,7 +831,6 @@ static int do_ssb_entry(const char *filename,
        add_wildcard(alias);
        return 1;
 }
-ADD_TO_DEVTABLE("ssb", ssb_device_id, do_ssb_entry);
 
 /* Looks like: bcma:mNidNrevNclN. */
 static int do_bcma_entry(const char *filename,
@@ -914,7 +849,6 @@ static int do_bcma_entry(const char *filename,
        add_wildcard(alias);
        return 1;
 }
-ADD_TO_DEVTABLE("bcma", bcma_device_id, do_bcma_entry);
 
 /* Looks like: virtio:dNvN */
 static int do_virtio_entry(const char *filename, void *symval,
@@ -930,7 +864,6 @@ static int do_virtio_entry(const char *filename, void *symval,
        add_wildcard(alias);
        return 1;
 }
-ADD_TO_DEVTABLE("virtio", virtio_device_id, do_virtio_entry);
 
 /*
  * Looks like: vmbus:guid
@@ -953,7 +886,6 @@ static int do_vmbus_entry(const char *filename, void *symval,
 
        return 1;
 }
-ADD_TO_DEVTABLE("vmbus", hv_vmbus_device_id, do_vmbus_entry);
 
 /* Looks like: rpmsg:S */
 static int do_rpmsg_entry(const char *filename, void *symval,
@@ -964,7 +896,6 @@ static int do_rpmsg_entry(const char *filename, void *symval,
 
        return 1;
 }
-ADD_TO_DEVTABLE("rpmsg", rpmsg_device_id, do_rpmsg_entry);
 
 /* Looks like: i2c:S */
 static int do_i2c_entry(const char *filename, void *symval,
@@ -975,7 +906,6 @@ static int do_i2c_entry(const char *filename, void *symval,
 
        return 1;
 }
-ADD_TO_DEVTABLE("i2c", i2c_device_id, do_i2c_entry);
 
 /* Looks like: spi:S */
 static int do_spi_entry(const char *filename, void *symval,
@@ -986,7 +916,6 @@ static int do_spi_entry(const char *filename, void *symval,
 
        return 1;
 }
-ADD_TO_DEVTABLE("spi", spi_device_id, do_spi_entry);
 
 static const struct dmifield {
        const char *prefix;
@@ -1041,7 +970,6 @@ static int do_dmi_entry(const char *filename, void *symval,
        strcat(alias, ":");
        return 1;
 }
-ADD_TO_DEVTABLE("dmi", dmi_system_id, do_dmi_entry);
 
 static int do_platform_entry(const char *filename,
                             void *symval, char *alias)
@@ -1050,7 +978,6 @@ static int do_platform_entry(const char *filename,
        sprintf(alias, PLATFORM_MODULE_PREFIX "%s", *name);
        return 1;
 }
-ADD_TO_DEVTABLE("platform", platform_device_id, do_platform_entry);
 
 static int do_mdio_entry(const char *filename,
                         void *symval, char *alias)
@@ -1075,7 +1002,6 @@ static int do_mdio_entry(const char *filename,
 
        return 1;
 }
-ADD_TO_DEVTABLE("mdio", mdio_device_id, do_mdio_entry);
 
 /* Looks like: zorro:iN. */
 static int do_zorro_entry(const char *filename, void *symval,
@@ -1086,7 +1012,6 @@ static int do_zorro_entry(const char *filename, void *symval,
        ADD(alias, "i", id != ZORRO_WILDCARD, id);
        return 1;
 }
-ADD_TO_DEVTABLE("zorro", zorro_device_id, do_zorro_entry);
 
 /* looks like: "pnp:dD" */
 static int do_isapnp_entry(const char *filename,
@@ -1102,7 +1027,6 @@ static int do_isapnp_entry(const char *filename,
                (function >> 12) & 0x0f, (function >> 8) & 0x0f);
        return 1;
 }
-ADD_TO_DEVTABLE("isapnp", isapnp_device_id, do_isapnp_entry);
 
 /* Looks like: "ipack:fNvNdN". */
 static int do_ipack_entry(const char *filename,
@@ -1118,7 +1042,6 @@ static int do_ipack_entry(const char *filename,
        add_wildcard(alias);
        return 1;
 }
-ADD_TO_DEVTABLE("ipack", ipack_device_id, do_ipack_entry);
 
 /*
  * Append a match expression for a single masked hex digit.
@@ -1189,7 +1112,6 @@ static int do_amba_entry(const char *filename,
 
        return 1;
 }
-ADD_TO_DEVTABLE("amba", amba_id, do_amba_entry);
 
 /*
  * looks like: "mipscdmm:tN"
@@ -1205,7 +1127,6 @@ static int do_mips_cdmm_entry(const char *filename,
        sprintf(alias, "mipscdmm:t%02X*", type);
        return 1;
 }
-ADD_TO_DEVTABLE("mipscdmm", mips_cdmm_device_id, do_mips_cdmm_entry);
 
 /* LOOKS like cpu:type:x86,venVVVVfamFFFFmodMMMM:feature:*,FEAT,*
  * All fields are numbers. It would be nicer to use strings for vendor
@@ -1230,7 +1151,6 @@ static int do_x86cpu_entry(const char *filename, void *symval,
                sprintf(alias + strlen(alias), "%04X*", feature);
        return 1;
 }
-ADD_TO_DEVTABLE("x86cpu", x86_cpu_id, do_x86cpu_entry);
 
 /* LOOKS like cpu:type:*:feature:*FEAT* */
 static int do_cpu_entry(const char *filename, void *symval, char *alias)
@@ -1240,7 +1160,6 @@ static int do_cpu_entry(const char *filename, void *symval, char *alias)
        sprintf(alias, "cpu:type:*:feature:*%04X*", feature);
        return 1;
 }
-ADD_TO_DEVTABLE("cpu", cpu_feature, do_cpu_entry);
 
 /* Looks like: mei:S:uuid:N:* */
 static int do_mei_entry(const char *filename, void *symval,
@@ -1259,7 +1178,6 @@ static int do_mei_entry(const char *filename, void *symval,
 
        return 1;
 }
-ADD_TO_DEVTABLE("mei", mei_cl_device_id, do_mei_entry);
 
 /* Looks like: rapidio:vNdNavNadN */
 static int do_rio_entry(const char *filename,
@@ -1279,7 +1197,6 @@ static int do_rio_entry(const char *filename,
        add_wildcard(alias);
        return 1;
 }
-ADD_TO_DEVTABLE("rapidio", rio_device_id, do_rio_entry);
 
 /* Looks like: ulpi:vNpN */
 static int do_ulpi_entry(const char *filename, void *symval,
@@ -1292,7 +1209,6 @@ static int do_ulpi_entry(const char *filename, void *symval,
 
        return 1;
 }
-ADD_TO_DEVTABLE("ulpi", ulpi_device_id, do_ulpi_entry);
 
 /* Looks like: hdaudio:vNrNaN */
 static int do_hda_entry(const char *filename, void *symval, char *alias)
@@ -1309,7 +1225,6 @@ static int do_hda_entry(const char *filename, void *symval, char *alias)
        add_wildcard(alias);
        return 1;
 }
-ADD_TO_DEVTABLE("hdaudio", hda_device_id, do_hda_entry);
 
 /* Looks like: sdw:mNpN */
 static int do_sdw_entry(const char *filename, void *symval, char *alias)
@@ -1324,7 +1239,6 @@ static int do_sdw_entry(const char *filename, void *symval, char *alias)
        add_wildcard(alias);
        return 1;
 }
-ADD_TO_DEVTABLE("sdw", sdw_device_id, do_sdw_entry);
 
 /* Looks like: fsl-mc:vNdN */
 static int do_fsl_mc_entry(const char *filename, void *symval,
@@ -1336,7 +1250,6 @@ static int do_fsl_mc_entry(const char *filename, void *symval,
        sprintf(alias, "fsl-mc:v%08Xd%s", vendor, *obj_type);
        return 1;
 }
-ADD_TO_DEVTABLE("fslmc", fsl_mc_device_id, do_fsl_mc_entry);
 
 /* Looks like: tbsvc:kSpNvNrN */
 static int do_tbsvc_entry(const char *filename, void *symval, char *alias)
@@ -1361,7 +1274,6 @@ static int do_tbsvc_entry(const char *filename, void *symval, char *alias)
        add_wildcard(alias);
        return 1;
 }
-ADD_TO_DEVTABLE("tbsvc", tb_service_id, do_tbsvc_entry);
 
 /* Looks like: typec:idNmN */
 static int do_typec_entry(const char *filename, void *symval, char *alias)
@@ -1374,7 +1286,6 @@ static int do_typec_entry(const char *filename, void *symval, char *alias)
 
        return 1;
 }
-ADD_TO_DEVTABLE("typec", typec_device_id, do_typec_entry);
 
 /* Does namelen bytes of name exactly match the symbol? */
 static bool sym_is(const char *name, unsigned namelen, const char *symbol)
@@ -1388,12 +1299,11 @@ static bool sym_is(const char *name, unsigned namelen, const char *symbol)
 static void do_table(void *symval, unsigned long size,
                     unsigned long id_size,
                     const char *device_id,
-                    void *function,
+                    int (*do_entry)(const char *filename, void *symval, char *alias),
                     struct module *mod)
 {
        unsigned int i;
        char alias[500];
-       int (*do_entry)(const char *, void *entry, char *alias) = function;
 
        device_id_check(mod->name, device_id, size, id_size, symval);
        /* Leave last one: it's the terminator. */
@@ -1407,6 +1317,48 @@ static void do_table(void *symval, unsigned long size,
        }
 }
 
+static const struct devtable devtable[] = {
+       {"hid", SIZE_hid_device_id, do_hid_entry},
+       {"ieee1394", SIZE_ieee1394_device_id, do_ieee1394_entry},
+       {"pci", SIZE_pci_device_id, do_pci_entry},
+       {"ccw", SIZE_ccw_device_id, do_ccw_entry},
+       {"ap", SIZE_ap_device_id, do_ap_entry},
+       {"css", SIZE_css_device_id, do_css_entry},
+       {"serio", SIZE_serio_device_id, do_serio_entry},
+       {"acpi", SIZE_acpi_device_id, do_acpi_entry},
+       {"pcmcia", SIZE_pcmcia_device_id, do_pcmcia_entry},
+       {"vio", SIZE_vio_device_id, do_vio_entry},
+       {"input", SIZE_input_device_id, do_input_entry},
+       {"eisa", SIZE_eisa_device_id, do_eisa_entry},
+       {"parisc", SIZE_parisc_device_id, do_parisc_entry},
+       {"sdio", SIZE_sdio_device_id, do_sdio_entry},
+       {"ssb", SIZE_ssb_device_id, do_ssb_entry},
+       {"bcma", SIZE_bcma_device_id, do_bcma_entry},
+       {"virtio", SIZE_virtio_device_id, do_virtio_entry},
+       {"vmbus", SIZE_hv_vmbus_device_id, do_vmbus_entry},
+       {"rpmsg", SIZE_rpmsg_device_id, do_rpmsg_entry},
+       {"i2c", SIZE_i2c_device_id, do_i2c_entry},
+       {"spi", SIZE_spi_device_id, do_spi_entry},
+       {"dmi", SIZE_dmi_system_id, do_dmi_entry},
+       {"platform", SIZE_platform_device_id, do_platform_entry},
+       {"mdio", SIZE_mdio_device_id, do_mdio_entry},
+       {"zorro", SIZE_zorro_device_id, do_zorro_entry},
+       {"isapnp", SIZE_isapnp_device_id, do_isapnp_entry},
+       {"ipack", SIZE_ipack_device_id, do_ipack_entry},
+       {"amba", SIZE_amba_id, do_amba_entry},
+       {"mipscdmm", SIZE_mips_cdmm_device_id, do_mips_cdmm_entry},
+       {"x86cpu", SIZE_x86_cpu_id, do_x86cpu_entry},
+       {"cpu", SIZE_cpu_feature, do_cpu_entry},
+       {"mei", SIZE_mei_cl_device_id, do_mei_entry},
+       {"rapidio", SIZE_rio_device_id, do_rio_entry},
+       {"ulpi", SIZE_ulpi_device_id, do_ulpi_entry},
+       {"hdaudio", SIZE_hda_device_id, do_hda_entry},
+       {"sdw", SIZE_sdw_device_id, do_sdw_entry},
+       {"fslmc", SIZE_fsl_mc_device_id, do_fsl_mc_entry},
+       {"tbsvc", SIZE_tb_service_id, do_tbsvc_entry},
+       {"typec", SIZE_typec_device_id, do_typec_entry},
+};
+
 /* Create MODULE_ALIAS() statements.
  * At this time, we cannot write the actual output C source yet,
  * so we write into the mod->dev_table_buf buffer. */
@@ -1460,13 +1412,14 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
        else if (sym_is(name, namelen, "pnp_card"))
                do_pnp_card_entries(symval, sym->st_size, mod);
        else {
-               struct devtable **p;
-               INIT_SECTION(__devtable);
+               int i;
+
+               for (i = 0; i < ARRAY_SIZE(devtable); i++) {
+                       const struct devtable *p = &devtable[i];
 
-               for (p = __start___devtable; p < __stop___devtable; p++) {
-                       if (sym_is(name, namelen, (*p)->device_id)) {
-                               do_table(symval, sym->st_size, (*p)->id_size,
-                                        (*p)->device_id, (*p)->function, mod);
+                       if (sym_is(name, namelen, p->device_id)) {
+                               do_table(symval, sym->st_size, p->id_size,
+                                        p->device_id, p->do_entry, mod);
                                break;
                        }
                }
index 0d998c54564dfdc5793faa968f72e8e985bce6c8..0de2fb2366402a13c7f42e02c6f3912d180585d3 100644 (file)
@@ -1163,6 +1163,14 @@ static const struct sectioncheck *section_mismatch(
  *   fromsec = text section
  *   refsymname = *.constprop.*
  *
+ * Pattern 6:
+ *   Hide section mismatch warnings for ELF local symbols.  The goal
+ *   is to eliminate false positive modpost warnings caused by
+ *   compiler-generated ELF local symbol names such as ".LANCHOR1".
+ *   Autogenerated symbol names bypass modpost's "Pattern 2"
+ *   whitelisting, which relies on pattern-matching against symbol
+ *   names to work.  (One situation where gcc can autogenerate ELF
+ *   local symbols is when "-fsection-anchors" is used.)
  **/
 static int secref_whitelist(const struct sectioncheck *mismatch,
                            const char *fromsec, const char *fromsym,
@@ -1201,9 +1209,37 @@ static int secref_whitelist(const struct sectioncheck *mismatch,
            match(fromsym, optim_symbols))
                return 0;
 
+       /* Check for pattern 6 */
+       if (strstarts(fromsym, ".L"))
+               return 0;
+
        return 1;
 }
 
+static inline int is_arm_mapping_symbol(const char *str)
+{
+       return str[0] == '$' && strchr("axtd", str[1])
+              && (str[2] == '\0' || str[2] == '.');
+}
+
+/*
+ * If there's no name there, ignore it; likewise, ignore it if it's
+ * one of the magic symbols emitted used by current ARM tools.
+ *
+ * Otherwise if find_symbols_between() returns those symbols, they'll
+ * fail the whitelist tests and cause lots of false alarms ... fixable
+ * only by merging __exit and __init sections into __text, bloating
+ * the kernel (which is especially evil on embedded platforms).
+ */
+static inline int is_valid_name(struct elf_info *elf, Elf_Sym *sym)
+{
+       const char *name = elf->strtab + sym->st_name;
+
+       if (!name || !strlen(name))
+               return 0;
+       return !is_arm_mapping_symbol(name);
+}
+
 /**
  * Find symbol based on relocation record info.
  * In some cases the symbol supplied is a valid symbol so
@@ -1229,6 +1265,8 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
                        continue;
                if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
                        continue;
+               if (!is_valid_name(elf, sym))
+                       continue;
                if (sym->st_value == addr)
                        return sym;
                /* Find a symbol nearby - addr are maybe negative */
@@ -1247,30 +1285,6 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
                return NULL;
 }
 
-static inline int is_arm_mapping_symbol(const char *str)
-{
-       return str[0] == '$' && strchr("axtd", str[1])
-              && (str[2] == '\0' || str[2] == '.');
-}
-
-/*
- * If there's no name there, ignore it; likewise, ignore it if it's
- * one of the magic symbols emitted used by current ARM tools.
- *
- * Otherwise if find_symbols_between() returns those symbols, they'll
- * fail the whitelist tests and cause lots of false alarms ... fixable
- * only by merging __exit and __init sections into __text, bloating
- * the kernel (which is especially evil on embedded platforms).
- */
-static inline int is_valid_name(struct elf_info *elf, Elf_Sym *sym)
-{
-       const char *name = elf->strtab + sym->st_name;
-
-       if (!name || !strlen(name))
-               return 0;
-       return !is_arm_mapping_symbol(name);
-}
-
 /*
  * Find symbols before or equal addr and after addr - in the section sec.
  * If we find two symbols with equal offset prefer one with a valid name.
@@ -2083,15 +2097,27 @@ static void check_for_unused(enum export exp, const char *m, const char *s)
        }
 }
 
-static void check_exports(struct module *mod)
+static int check_exports(struct module *mod)
 {
        struct symbol *s, *exp;
+       int err = 0;
 
        for (s = mod->unres; s; s = s->next) {
                const char *basename;
                exp = find_symbol(s->name);
-               if (!exp || exp->module == mod)
+               if (!exp || exp->module == mod) {
+                       if (have_vmlinux && !s->weak) {
+                               if (warn_unresolved) {
+                                       warn("\"%s\" [%s.ko] undefined!\n",
+                                            s->name, mod->name);
+                               } else {
+                                       merror("\"%s\" [%s.ko] undefined!\n",
+                                              s->name, mod->name);
+                                       err = 1;
+                               }
+                       }
                        continue;
+               }
                basename = strrchr(mod->name, '/');
                if (basename)
                        basename++;
@@ -2101,6 +2127,8 @@ static void check_exports(struct module *mod)
                        check_for_gpl_usage(exp->export, basename, exp->name);
                check_for_unused(exp->export, basename, exp->name);
        }
+
+       return err;
 }
 
 static int check_modname_len(struct module *mod)
@@ -2178,19 +2206,8 @@ static int add_versions(struct buffer *b, struct module *mod)
 
        for (s = mod->unres; s; s = s->next) {
                exp = find_symbol(s->name);
-               if (!exp || exp->module == mod) {
-                       if (have_vmlinux && !s->weak) {
-                               if (warn_unresolved) {
-                                       warn("\"%s\" [%s.ko] undefined!\n",
-                                            s->name, mod->name);
-                               } else {
-                                       merror("\"%s\" [%s.ko] undefined!\n",
-                                              s->name, mod->name);
-                                       err = 1;
-                               }
-                       }
+               if (!exp || exp->module == mod)
                        continue;
-               }
                s->module = exp->module;
                s->crc_valid = exp->crc_valid;
                s->crc = exp->crc;
@@ -2227,15 +2244,15 @@ static int add_versions(struct buffer *b, struct module *mod)
        return err;
 }
 
-static void add_depends(struct buffer *b, struct module *mod,
-                       struct module *modules)
+static void add_depends(struct buffer *b, struct module *mod)
 {
        struct symbol *s;
-       struct module *m;
        int first = 1;
 
-       for (m = modules; m; m = m->next)
-               m->seen = is_vmlinux(m->name);
+       /* Clear ->seen flag of modules that own symbols needed by this. */
+       for (s = mod->unres; s; s = s->next)
+               if (s->module)
+                       s->module->seen = is_vmlinux(s->module->name);
 
        buf_printf(b, "\n");
        buf_printf(b, "static const char __module_depends[]\n");
@@ -2416,7 +2433,7 @@ int main(int argc, char **argv)
        struct ext_sym_list *extsym_iter;
        struct ext_sym_list *extsym_start = NULL;
 
-       while ((opt = getopt(argc, argv, "i:I:e:mnsST:o:awM:K:E")) != -1) {
+       while ((opt = getopt(argc, argv, "i:I:e:mnsST:o:awE")) != -1) {
                switch (opt) {
                case 'i':
                        kernel_read = optarg;
@@ -2482,12 +2499,6 @@ int main(int argc, char **argv)
        if (files_source)
                read_symbols_from_files(files_source);
 
-       for (mod = modules; mod; mod = mod->next) {
-               if (mod->skip)
-                       continue;
-               check_exports(mod);
-       }
-
        err = 0;
 
        for (mod = modules; mod; mod = mod->next) {
@@ -2499,12 +2510,13 @@ int main(int argc, char **argv)
                buf.pos = 0;
 
                err |= check_modname_len(mod);
+               err |= check_exports(mod);
                add_header(&buf, mod);
                add_intree_flag(&buf, !external_module);
                add_retpoline(&buf);
                add_staging_flag(&buf, mod->name);
                err |= add_versions(&buf, mod);
-               add_depends(&buf, mod, modules);
+               add_depends(&buf, mod);
                add_moddevtable(&buf, mod);
                add_srcversion(&buf, mod);
 
index 73503ebce6326ced505165feeec9e1a05233233d..453fecee62f0670e999f95a4a4e5f7f6c53e5a7d 100644 (file)
@@ -33,7 +33,6 @@ MKSPEC     := $(srctree)/scripts/package/mkspec
 
 quiet_cmd_src_tar = TAR     $(2).tar.gz
       cmd_src_tar = \
-set -e; \
 if test "$(objtree)" != "$(srctree)"; then \
        echo >&2; \
        echo >&2 "  ERROR:"; \
index 71f39410691b6be14774102000507c834c8ad493..365b3c2b8f431f28a83a6641ccf2da043dc05b55 100755 (executable)
@@ -73,8 +73,16 @@ scm_version()
                        printf -- '-svn%s' "`git svn find-rev $head`"
                fi
 
-               # Check for uncommitted changes
-               if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
+               # Check for uncommitted changes.
+               # First, with git-status, but --no-optional-locks is only
+               # supported in git >= 2.14, so fall back to git-diff-index if
+               # it fails. Note that git-diff-index does not refresh the
+               # index, so it may give misleading results. See
+               # git-update-index(1), git-diff-index(1), and git-status(1).
+               if {
+                       git --no-optional-locks status -uno --porcelain 2>/dev/null ||
+                       git diff-index --name-only HEAD
+               } | grep -qvE '^(.. )?scripts/package'; then
                        printf '%s' -dirty
                fi
 
index 748f6a60bb1e00070dbc61a895ba19e4370b476f..4a70ae43c9cb5366abbe135415de85c351fb4270 100644 (file)
@@ -49,10 +49,10 @@ $(deps_initramfs): ;
 
 $(deps_initramfs): klibcdirs
 # We rebuild initramfs_data.cpio if:
-# 1) Any included file is newer then initramfs_data.cpio
+# 1) Any included file is newer than initramfs_data.cpio
 # 2) There are changes in which files are included (added or deleted)
 # 3) If gen_init_cpio are newer than initramfs_data.cpio
-# 4) arguments to gen_initramfs.sh changes
+# 4) Arguments to gen_initramfs.sh changes
 $(obj)/$(datafile_y): $(obj)/gen_init_cpio $(deps_initramfs) klibcdirs
        $(Q)$(initramfs) -l $(ramfs-input) > $(obj)/$(datafile_d_y)
        $(call if_changed,initfs)