From dbe27a002ef8573168cb64e181458ea23a74e2b6 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 6 Nov 2018 12:04:54 +0900 Subject: kbuild: add -no-integrated-as Clang option unconditionally We are still a way off the Clang's integrated assembler support for the kernel. Hence, -no-integrated-as is mandatory to build the kernel with Clang. If you had an ancient version of Clang that does not recognize this option, you would not be able to compile the kernel anyway. Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers Tested-by: Nick Desaulniers --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 2f36db897895..b71b9c70496c 100644 --- a/Makefile +++ b/Makefile @@ -497,8 +497,8 @@ CLANG_GCC_TC := --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) +KBUILD_CFLAGS += -no-integrated-as +KBUILD_AFLAGS += -no-integrated-as endif RETPOLINE_CFLAGS_GCC := -mindirect-branch=thunk-extern -mindirect-branch-register -- cgit v1.2.3-59-g8ed1b From 238bcbc4e07fad2fff99c5b157d0c37ccd4d093c Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 6 Nov 2018 12:04:55 +0900 Subject: kbuild: consolidate Clang compiler flags Collect basic Clang options such as --target, --prefix, --gcc-toolchain, -no-integrated-as into a single variable CLANG_FLAGS so that it can be easily reused in other parts of Makefile. Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers Tested-by: Nick Desaulniers Acked-by: Greg Hackmann --- Makefile | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index b71b9c70496c..c300ac16c895 100644 --- a/Makefile +++ b/Makefile @@ -487,18 +487,17 @@ 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 += -no-integrated-as -KBUILD_AFLAGS += -no-integrated-as +CLANG_FLAGS += -no-integrated-as +KBUILD_CFLAGS += $(CLANG_FLAGS) +KBUILD_AFLAGS += $(CLANG_FLAGS) endif RETPOLINE_CFLAGS_GCC := -mindirect-branch=thunk-extern -mindirect-branch-register -- cgit v1.2.3-59-g8ed1b From 3bd9805090af843b25f97ffe5049f20ade1d86d6 Mon Sep 17 00:00:00 2001 From: Joel Stanley Date: Mon, 12 Nov 2018 14:51:15 +1030 Subject: Makefile: Export clang toolchain variables The powerpc makefile will use these in it's boot wrapper. Signed-off-by: Joel Stanley Signed-off-by: Masahiro Yamada --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index c300ac16c895..96b4ea5adf91 100644 --- a/Makefile +++ b/Makefile @@ -498,6 +498,7 @@ endif 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 -- cgit v1.2.3-59-g8ed1b From 813af51f5d30a2da6a2523c08465f9726e51772e Mon Sep 17 00:00:00 2001 From: Joel Stanley Date: Mon, 12 Nov 2018 14:51:16 +1030 Subject: powerpc/boot: Set target when cross-compiling for clang Clang needs to be told which target it is building for when cross compiling. Link: https://github.com/ClangBuiltLinux/linux/issues/259 Signed-off-by: Joel Stanley Tested-by: Daniel Axtens # powerpc 64-bit BE Acked-by: Michael Ellerman Reviewed-by: Nick Desaulniers Signed-off-by: Masahiro Yamada --- arch/powerpc/boot/Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile index 39354365f54a..111f97b1ccec 100644 --- a/arch/powerpc/boot/Makefile +++ b/arch/powerpc/boot/Makefile @@ -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 -- cgit v1.2.3-59-g8ed1b From 5818c683a619c534c113e1f66d24f636defc29bc Mon Sep 17 00:00:00 2001 From: Sami Tolvanen Date: Tue, 23 Oct 2018 15:15:35 -0700 Subject: modpost: validate symbol names also in find_elf_symbol If an ARM mapping symbol shares an address with a valid symbol, find_elf_symbol can currently return the mapping symbol instead, as the symbol is not validated. This can result in confusing warnings: WARNING: vmlinux.o(.text+0x18f4028): Section mismatch in reference from the function set_reset_devices() to the variable .init.text:$x.0 This change adds a call to is_valid_name to find_elf_symbol, similarly to how it's already used in find_elf_symbol2. Signed-off-by: Sami Tolvanen Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 0d998c54564d..b709b2e623d6 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1204,6 +1204,30 @@ static int secref_whitelist(const struct sectioncheck *mismatch, 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 +1253,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 +1273,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. -- cgit v1.2.3-59-g8ed1b From ff64dd4857303dd5550faed9fd598ac90f0f2238 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Wed, 14 Nov 2018 18:11:18 -0800 Subject: scripts/setlocalversion: Improve -dirty check with git-status --no-optional-locks git-diff-index does not refresh the index for you, so using it for a "-dirty" check can give misleading results. Commit 6147b1cf19651 ("scripts/setlocalversion: git: Make -dirty check more robust") tried to fix this by switching to git-status, but it overlooked the fact that git-status also writes to the .git directory of the source tree, which is definitely not kosher for an out-of-tree (O=) build. That is getting reverted. Fortunately, git-status now supports avoiding writing to the index via the --no-optional-locks flag, as of git 2.14. It still calculates an up-to-date index, but it avoids writing it out to the .git directory. So, let's retry the solution from commit 6147b1cf19651 using this new flag first, and if it fails, we assume this is an older version of git and just use the old git-diff-index method. It's hairy to get the 'grep -vq' (inverted matching) correct by stashing the output of git-status (you have to be careful about the difference betwen "empty stdin" and "blank line on stdin"), so just pipe the output directly to grep and use a regex that's good enough for both the git-status and git-diff-index version. Cc: Christian Kujau Cc: Guenter Roeck Suggested-by: Alexander Kapshuk Signed-off-by: Brian Norris Tested-by: Genki Sky Signed-off-by: Masahiro Yamada --- scripts/setlocalversion | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/setlocalversion b/scripts/setlocalversion index 71f39410691b..365b3c2b8f43 100755 --- a/scripts/setlocalversion +++ b/scripts/setlocalversion @@ -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 -- cgit v1.2.3-59-g8ed1b From 0987abcbeea4c87aef80a6138efc13ed0798fcf2 Mon Sep 17 00:00:00 2001 From: Paul Walmsley Date: Wed, 14 Nov 2018 16:56:01 -0800 Subject: modpost: drop unused command line switches Drop modpost command line switches that are no longer used by makefile.modpost, upon request from Sam Ravnborg , who wrote: modpost is not supposed to be used outside the kernel build. [...] I checked if there were any options supported by modpost that was not configurable in Makefile.modpost. And I could see that the -M and -K options in getopt() were leftovers. The code that used these option was dropped in: commit a8773769d1a1 ("Kbuild: clear marker out of modpost") Could you add a patch that delete these on top of what you already have. https://lore.kernel.org/lkml/20181020140835.GA3351@ravnborg.org/ Suggested-by: Sam Ravnborg Signed-off-by: Paul Walmsley Signed-off-by: Paul Walmsley Acked-by: Sam Ravnborg Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index b709b2e623d6..c64066dcd2e4 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -2418,7 +2418,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; -- cgit v1.2.3-59-g8ed1b From 0126be38d98815d25d9ec4573541ed4315bf6a88 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 21 Nov 2018 00:04:18 +0900 Subject: kbuild: announce removal of SUBDIRS if used SUBDIRS has been kept as a backward compatibility since commit ("[PATCH] kbuild: external module support") in 2002. We do not need multiple ways to do the same thing, so I will remove SUBDIRS after the Linux 5.3 release. I cleaned up in-tree code, and updated the document so that nobody would try to use it. Meanwhile, display the following warning if SUBDIRS is used. Makefile:189: ================= WARNING ================ Makefile:190: 'SUBDIRS' will be removed after Linux 5.3 Makefile:191: Please use 'M=' or 'KBUILD_EXTMOD' instead Makefile:192: ========================================== Signed-off-by: Masahiro Yamada Acked-by: Boris Brezillon # for scx200_docflash.c Acked-by: Guenter Roeck # for scx200_wdt.c --- Documentation/kbuild/kbuild.txt | 7 +------ Makefile | 4 ++++ drivers/mtd/maps/scx200_docflash.c | 7 ------- drivers/watchdog/scx200_wdt.c | 7 ------- samples/connector/Makefile | 2 +- 5 files changed, 6 insertions(+), 21 deletions(-) diff --git a/Documentation/kbuild/kbuild.txt b/Documentation/kbuild/kbuild.txt index 8390c360d4b3..c9e3d93e7a89 100644 --- a/Documentation/kbuild/kbuild.txt +++ b/Documentation/kbuild/kbuild.txt @@ -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/Makefile b/Makefile index 96b4ea5adf91..9fcd8f81809c 100644 --- 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 diff --git a/drivers/mtd/maps/scx200_docflash.c b/drivers/mtd/maps/scx200_docflash.c index f1c1f737d0d7..7f1a0e690c4f 100644 --- a/drivers/mtd/maps/scx200_docflash.c +++ b/drivers/mtd/maps/scx200_docflash.c @@ -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: -*/ diff --git a/drivers/watchdog/scx200_wdt.c b/drivers/watchdog/scx200_wdt.c index 836377cf9271..ec4063ebb41a 100644 --- a/drivers/watchdog/scx200_wdt.c +++ b/drivers/watchdog/scx200_wdt.c @@ -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: -*/ diff --git a/samples/connector/Makefile b/samples/connector/Makefile index fe3c8542ae4a..6ad71620e503 100644 --- a/samples/connector/Makefile +++ b/samples/connector/Makefile @@ -14,4 +14,4 @@ HOSTCFLAGS_ucon.o += -I$(objtree)/usr/include all: modules modules clean: - $(MAKE) -C ../.. SUBDIRS=$(CURDIR) $@ + $(MAKE) -C ../.. M=$(CURDIR) $@ -- cgit v1.2.3-59-g8ed1b From a4d26f1a0958bb1c2b60c6f1e67c6f5d43e2647b Mon Sep 17 00:00:00 2001 From: Paul Walmsley Date: Wed, 21 Nov 2018 13:14:13 -0800 Subject: modpost: skip ELF local symbols during section mismatch check During development of a serial console driver with a gcc 8.2.0 toolchain for RISC-V, the following modpost warning appeared: ---- WARNING: vmlinux.o(.data+0x19b10): Section mismatch in reference from the variable .LANCHOR1 to the function .init.text:sifive_serial_console_setup() The variable .LANCHOR1 references the function __init sifive_serial_console_setup() If the reference is valid then annotate the variable with __init* or __refdata (see linux/init.h) or name the variable: *_template, *_timer, *_sht, *_ops, *_probe, *_probe_one, *_console ---- ".LANCHOR1" is an ELF local symbol, automatically created by gcc's section anchor generation code: https://gcc.gnu.org/onlinedocs/gccint/Anchored-Addresses.html https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/varasm.c;h=cd9591a45617464946dcf9a126dde277d9de9804;hb=9fb89fa845c1b2e0a18d85ada0b077c84508ab78#l7473 This was verified by compiling the kernel with -fno-section-anchors and observing that the ".LANCHOR1" ELF local symbol disappeared, and modpost no longer warned about the section mismatch. The serial driver code idiom triggering the warning is standard Linux serial driver practice that has a specific whitelist inclusion in modpost.c. I'm neither a modpost nor an ELF expert, but naively, it doesn't seem useful for modpost to report section mismatch warnings caused by ELF local symbols by default. Local symbols have compiler-generated names, and thus bypass modpost's whitelisting algorithm, which relies on the presence of a non-autogenerated symbol name. This increases the likelihood that false positive warnings will be generated (as in the above case). Thus, disable section mismatch reporting on ELF local symbols. The rationale here is similar to that of commit 2e3a10a1551d ("ARM: avoid ARM binutils leaking ELF local symbols") and of similar code already present in modpost.c: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/mod/modpost.c?h=v4.19-rc4&id=7876320f88802b22d4e2daf7eb027dd14175a0f8#n1256 This third version of the patch implements a suggestion from Masahiro Yamada to restructure the code as an additional pattern matching step inside secref_whitelist(), and further improves the patch description. Signed-off-by: Paul Walmsley Signed-off-by: Paul Walmsley Acked-by: Sam Ravnborg Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index c64066dcd2e4..3aab410f020e 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -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,6 +1209,10 @@ 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; } -- cgit v1.2.3-59-g8ed1b From e07db28eea38ed4e332b3a89f3995c86b713cb5b Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 22 Nov 2018 08:11:54 +0900 Subject: kbuild: fix single target build for external module Building a single target in an external module fails due to missing .tmp_versions directory. For example, $ make -C /lib/modules/$(uname -r)/build M=$PWD foo.o will fail in the following way: CC [M] /home/masahiro/foo/foo.o /bin/sh: 1: cannot create /home/masahiro/foo/.tmp_versions/foo.mod: Directory nonexistent This is because $(cmd_crmodverdir) is executed only before building /, %/, %.ko single targets of external modules. Create .tmp_versions in the 'prepare' target. Signed-off-by: Masahiro Yamada --- Makefile | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 9fcd8f81809c..b2519b9b3599 100644 --- a/Makefile +++ b/Makefile @@ -1551,9 +1551,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 +1562,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) @@ -1606,7 +1603,8 @@ help: # Dummies... PHONY += prepare scripts -prepare: ; +prepare: + $(cmd_crmodverdir) scripts: ; endif # KBUILD_EXTMOD @@ -1730,17 +1728,14 @@ endif # Modules /: prepare scripts FORCE - $(cmd_crmodverdir) $(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) $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \ $(build)=$(build-dir) %.ko: prepare scripts FORCE - $(cmd_crmodverdir) $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \ $(build)=$(build-dir) $(@:.ko=.o) $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost -- cgit v1.2.3-59-g8ed1b From ec91e78d378cc5d4b43805a1227d8e04e5dfa17d Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 22 Nov 2018 13:28:41 +0900 Subject: modpost: file2alias: go back to simple devtable lookup Commit e49ce14150c6 ("modpost: use linker section to generate table.") was not so cool as we had expected first; it ended up with ugly section hacks when commit dd2a3acaecd7 ("mod/file2alias: make modpost compile on darwin again") came in. Given a certain degree of unknowledge about the link stage of host programs, I really want to see simple, stupid table lookup so that this works in the same way regardless of the underlying executable format. Signed-off-by: Masahiro Yamada Acked-by: Mathieu Malaterre --- scripts/mod/file2alias.c | 144 ++++++++++++++++------------------------------- 1 file changed, 49 insertions(+), 95 deletions(-) diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index 28a61665bb9c..7e4aededfd37 100644 --- a/scripts/mod/file2alias.c +++ b/scripts/mod/file2alias.c @@ -50,46 +50,6 @@ struct devtable { void *function; }; -#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 - -#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) @@ -1407,6 +1318,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 +1413,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->function, mod); break; } } -- cgit v1.2.3-59-g8ed1b From f880eea68fe593342fa6e09be9bb661f3c297aec Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 22 Nov 2018 13:28:42 +0900 Subject: modpost: file2alias: check prototype of handler Use specific prototype instead of an opaque pointer so that the compiler can catch function prototype mismatch. Signed-off-by: Masahiro Yamada Reviewed-by: Mathieu Malaterre --- scripts/mod/file2alias.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index 7e4aededfd37..a37af7d71973 100644 --- a/scripts/mod/file2alias.c +++ b/scripts/mod/file2alias.c @@ -47,7 +47,7 @@ typedef struct { struct devtable { const char *device_id; /* name of table, __mod___*_device_table. */ unsigned long id_size; - void *function; + int (*do_entry)(const char *filename, void *symval, char *alias); }; /* Define a variable f that holds the value of field f of struct devid @@ -1299,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. */ @@ -1420,7 +1419,7 @@ void handle_moddevtable(struct module *mod, struct elf_info *info, if (sym_is(name, namelen, p->device_id)) { do_table(symval, sym->st_size, p->id_size, - p->device_id, p->function, mod); + p->device_id, p->do_entry, mod); break; } } -- cgit v1.2.3-59-g8ed1b From d2665ca8e3310d045b62397590ab54dc485e035e Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 23 Nov 2018 16:57:21 +0900 Subject: modpost: refactor seen flag clearing in add_depends() You do not need to iterate over all modules for resetting ->seen flag because add_depends() is only interested in modules that export symbols referenced from the given 'mod'. This also avoids shadowing the 'modules' parameter of add_depends(). Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 3aab410f020e..eedc2742dc8e 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -2241,15 +2241,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"); @@ -2518,7 +2518,7 @@ int main(int argc, char **argv) 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); -- cgit v1.2.3-59-g8ed1b From c6826ad8a49f1230dcbc45dac26b54d492b13280 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 23 Nov 2018 16:57:22 +0900 Subject: modpost: merge module iterations Probably, this is just a matter of the order of error/warning messages. Merge the two for-loops. Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index eedc2742dc8e..963a0b69b9a3 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -2496,12 +2496,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) { @@ -2513,6 +2507,7 @@ int main(int argc, char **argv) buf.pos = 0; err |= check_modname_len(mod); + check_exports(mod); add_header(&buf, mod); add_intree_flag(&buf, !external_module); add_retpoline(&buf); -- cgit v1.2.3-59-g8ed1b From 3b4152880348287b6b3d9a0708f1e2f4c540f3d0 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 23 Nov 2018 16:57:23 +0900 Subject: modpost: move unresolved symbol checks to check_exports() This will fit better in check_exports() than add_versions(). Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 963a0b69b9a3..0de2fb236640 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -2097,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++; @@ -2115,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) @@ -2192,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; @@ -2507,7 +2510,7 @@ int main(int argc, char **argv) buf.pos = 0; err |= check_modname_len(mod); - check_exports(mod); + err |= check_exports(mod); add_header(&buf, mod); add_intree_flag(&buf, !external_module); add_retpoline(&buf); -- cgit v1.2.3-59-g8ed1b From 65bba0423ecf89fb291d2269e0087707888a1cef Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 29 Nov 2018 11:58:50 +0900 Subject: kbuild: fix UML build error with CONFIG_GCC_PLUGINS UML fails to build with CONFIG_GCC_PLUGINS=y. $ make -s ARCH=um mrproper $ make -s ARCH=um allmodconfig $ make ARCH=um UPD include/generated/uapi/linux/version.h WRAP arch/x86/include/generated/uapi/asm/bpf_perf_event.h WRAP arch/x86/include/generated/uapi/asm/poll.h WRAP arch/x86/include/generated/asm/dma-contiguous.h WRAP arch/x86/include/generated/asm/early_ioremap.h WRAP arch/x86/include/generated/asm/export.h WRAP arch/x86/include/generated/asm/mcs_spinlock.h WRAP arch/x86/include/generated/asm/mm-arch-hooks.h SYSTBL arch/x86/include/generated/asm/syscalls_32.h SYSHDR arch/x86/include/generated/asm/unistd_32_ia32.h SYSHDR arch/x86/include/generated/asm/unistd_64_x32.h SYSTBL arch/x86/include/generated/asm/syscalls_64.h SYSHDR arch/x86/include/generated/uapi/asm/unistd_32.h SYSHDR arch/x86/include/generated/uapi/asm/unistd_64.h SYSHDR arch/x86/include/generated/uapi/asm/unistd_x32.h HOSTCC scripts/unifdef CC arch/x86/um/user-offsets.s cc1: error: cannot load plugin ./scripts/gcc-plugins/cyc_complexity_plugin.so ./scripts/gcc-plugins/cyc_complexity_plugin.so: cannot open shared object file: No such file or directory cc1: error: cannot load plugin ./scripts/gcc-plugins/structleak_plugin.so ./scripts/gcc-plugins/structleak_plugin.so: cannot open shared object file: No such file or directory cc1: error: cannot load plugin ./scripts/gcc-plugins/latent_entropy_plugin.so ./scripts/gcc-plugins/latent_entropy_plugin.so: cannot open shared object file: No such file or directory cc1: error: cannot load plugin ./scripts/gcc-plugins/randomize_layout_plugin.so ./scripts/gcc-plugins/randomize_layout_plugin.so: cannot open shared object file: No such file or directory make[1]: *** [scripts/Makefile.build;119: arch/x86/um/user-offsets.s] Error 1 make: *** [arch/um/Makefile;152: arch/x86/um/user-offsets.s] Error 2 Reorder the preparation stage (with cleanups) to make sure gcc-plugins is built before descending to arch/x86/um/. Fixes: 6b90bd4ba40b ("GCC plugin infrastructure") Reported-by: kbuild test robot Signed-off-by: Masahiro Yamada --- Makefile | 4 ++-- arch/um/Makefile | 24 ++---------------------- arch/x86/um/Makefile | 4 +++- 3 files changed, 7 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index b2519b9b3599..bfab340453c6 100644 --- a/Makefile +++ b/Makefile @@ -1110,9 +1110,9 @@ prepare1: prepare2 $(version_h) $(autoksyms_h) include/generated/utsrelease.h macroprepare: prepare1 archmacros -archprepare: archheaders archscripts macroprepare scripts_basic +archprepare: archheaders archscripts macroprepare scripts_basic gcc-plugins -prepare0: archprepare gcc-plugins +prepare0: archprepare $(Q)$(MAKE) $(build)=. # All the preparing.. diff --git a/arch/um/Makefile b/arch/um/Makefile index ab1066c38944..c08035904849 100644 --- a/arch/um/Makefile +++ b/arch/um/Makefile @@ -116,7 +116,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 +147,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 diff --git a/arch/x86/um/Makefile b/arch/x86/um/Makefile index c2d3d7c51e9e..17924646467c 100644 --- a/arch/x86/um/Makefile +++ b/arch/x86/um/Makefile @@ -36,10 +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 +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) -- cgit v1.2.3-59-g8ed1b From 60df1aee2aecb53efb4218b4dfdf7d6c80a5a3de Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 29 Nov 2018 12:13:24 +0900 Subject: kbuild: move modpost out of 'scripts' target I am eagar to build under the scripts/ directory only with $(HOSTCC), but scripts/mod/ highly depends on the $(CC) and target arch headers. That it why the 'scripts' target must depend on 'asm-generic', 'gcc-plugins', and $(autoksyms_h). Move it to the 'prepare0' stage. I know this is a cheesy workaround, but better than the current situation. Signed-off-by: Masahiro Yamada --- Makefile | 3 ++- scripts/Makefile | 3 +-- scripts/mod/Makefile | 2 -- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index bfab340453c6..6da46310a662 100644 --- a/Makefile +++ b/Makefile @@ -1075,7 +1075,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 @@ -1113,6 +1113,7 @@ macroprepare: prepare1 archmacros archprepare: archheaders archscripts macroprepare scripts_basic gcc-plugins prepare0: archprepare + $(Q)$(MAKE) $(build)=scripts/mod $(Q)$(MAKE) $(build)=. # All the preparing.. diff --git a/scripts/Makefile b/scripts/Makefile index ece52ff20171..b48259d30280 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -37,9 +37,8 @@ build_unifdef: $(obj)/unifdef @: 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 gcc-plugins diff --git a/scripts/mod/Makefile b/scripts/mod/Makefile index a5b4af47987a..42c5d50f2bcc 100644 --- a/scripts/mod/Makefile +++ b/scripts/mod/Makefile @@ -4,8 +4,6 @@ OBJECT_FILES_NON_STANDARD := y hostprogs-y := modpost mk_elfconfig always := $(hostprogs-y) empty.o -CFLAGS_REMOVE_empty.o := $(ASM_MACRO_FLAGS) - modpost-objs := modpost.o file2alias.o sumversion.o devicetable-offsets-file := devicetable-offsets.h -- cgit v1.2.3-59-g8ed1b From 059bc9fc375e00f159f9d7c5ca9d18ab843f95de Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 29 Nov 2018 12:56:30 +0900 Subject: kbuild: make 'archprepare' depend on 'scripts' Before start descending, Kbuild needs to run 'prepare' and 'scripts', which has been orthogonal to each other. Going forward, let's consider 'scripts' is a part of the preparation. This will allow more cleanups. Move 'scripts' to the prerequisite of 'archprepare', where UML starts compiling target *.c files. Signed-off-by: Masahiro Yamada --- Makefile | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 6da46310a662..06b6424d519a 100644 --- a/Makefile +++ b/Makefile @@ -1060,7 +1060,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 @@ -1110,7 +1110,7 @@ prepare1: prepare2 $(version_h) $(autoksyms_h) include/generated/utsrelease.h macroprepare: prepare1 archmacros -archprepare: archheaders archscripts macroprepare scripts_basic gcc-plugins +archprepare: archheaders archscripts macroprepare scripts gcc-plugins prepare0: archprepare $(Q)$(MAKE) $(build)=scripts/mod @@ -1284,7 +1284,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 @@ -1602,11 +1602,9 @@ help: @echo ' clean - remove generated files in module directory only' @echo '' -# Dummies... -PHONY += prepare scripts +PHONY += prepare prepare: $(cmd_crmodverdir) -scripts: ; endif # KBUILD_EXTMOD clean: $(clean-dirs) @@ -1710,33 +1708,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 +/: 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 +%/: prepare FORCE $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \ $(build)=$(build-dir) -%.ko: prepare scripts FORCE +%.ko: prepare FORCE $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \ $(build)=$(build-dir) $(@:.ko=.o) $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost -- cgit v1.2.3-59-g8ed1b From ce2fd53a10c7d17934c005029382f8310e565504 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 29 Nov 2018 12:56:31 +0900 Subject: kbuild: descend into scripts/gcc-plugins/ via scripts/Makefile Now that 'archprepare' depends on 'scripts', Kbuild can descend into scripts/gcc-plugins in a more standard way. Signed-off-by: Masahiro Yamada Reviewed-by: Kees Cook --- Makefile | 2 +- scripts/Makefile | 3 ++- scripts/Makefile.gcc-plugins | 8 -------- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 06b6424d519a..861d9d48c7df 100644 --- a/Makefile +++ b/Makefile @@ -1110,7 +1110,7 @@ prepare1: prepare2 $(version_h) $(autoksyms_h) include/generated/utsrelease.h macroprepare: prepare1 archmacros -archprepare: archheaders archscripts macroprepare scripts gcc-plugins +archprepare: archheaders archscripts macroprepare scripts prepare0: archprepare $(Q)$(MAKE) $(build)=scripts/mod diff --git a/scripts/Makefile b/scripts/Makefile index b48259d30280..feb1f71381d7 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -36,9 +36,10 @@ PHONY += build_unifdef build_unifdef: $(obj)/unifdef @: +subdir-$(CONFIG_GCC_PLUGINS) += gcc-plugins subdir-$(CONFIG_MODVERSIONS) += genksyms subdir-$(CONFIG_SECURITY_SELINUX) += selinux subdir-$(CONFIG_GDB_SCRIPTS) += gdb # Let clean descend into subdirs -subdir- += basic dtc kconfig mod package gcc-plugins +subdir- += basic dtc kconfig mod package diff --git a/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins index 46c5c6809806..c36f19959619 100644 --- a/scripts/Makefile.gcc-plugins +++ b/scripts/Makefile.gcc-plugins @@ -49,11 +49,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 - @: -- cgit v1.2.3-59-g8ed1b From 392885ee82d35d515ba2af7b72c5e357c3002113 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 30 Nov 2018 10:05:22 +0900 Subject: kbuild: let fixdep directly write to .*.cmd files Currently, fixdep writes dependencies to .*.tmp, which is renamed to .*.cmd after everything succeeds. This is a very safe way to avoid corrupted .*.cmd files. The if_changed_dep has carried this safety mechanism since it was added in 2002. If fixdep fails for some reasons or a user terminates the build while fixdep is running, the incomplete output from the fixdep could be troublesome. This is my insight about some bad scenarios: [1] If the compiler succeeds to generate *.o file, but fixdep fails to write necessary dependencies to .*.cmd file, Make will miss to rebuild the object when headers or CONFIG options are changed. In this case, fixdep should not generate .*.cmd file at all so that 'arg-check' will surely trigger the rebuild of the object. [2] A partially constructed .*.cmd file may not be a syntactically correct makefile. The next time Make runs, it would include it, then fail to parse it. Once this happens, 'make clean' is be the only way to fix it. In fact, [1] is no longer a problem since commit 9c2af1c7377a ("kbuild: add .DELETE_ON_ERROR special target"). Make deletes a target file on any failure in its recipe. Because fixdep is a part of the recipe of *.o target, if it fails, the *.o is deleted anyway. However, I am a bit worried about the slight possibility of [2]. So, here is a solution. Let fixdep directly write to a .*.cmd file, but allow makefiles to include it only when its corresponding target exists. This effectively reverts commit 2982c953570b ("kbuild: remove redundant $(wildcard ...) for cmd_files calculation"), and commit 00d78ab2ba75 ("kbuild: remove dead code in cmd_files calculation in top Makefile") because now we must check the presence of targets. Signed-off-by: Masahiro Yamada --- Makefile | 13 +++++++------ scripts/Kbuild.include | 10 ++++------ scripts/Makefile.build | 12 +++++------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 861d9d48c7df..d4ac3cb9256c 100644 --- a/Makefile +++ b/Makefile @@ -1043,6 +1043,8 @@ ifdef CONFIG_GDB_SCRIPTS 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 @@ -1758,13 +1760,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) diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index bb015551c2d9..6cf6a8b83b97 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -264,9 +264,8 @@ ifndef CONFIG_TRIM_UNUSED_KSYMS 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; + scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).cmd;\ + rm -f $(depfile); else @@ -289,9 +288,8 @@ 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; + > $(dot-target).cmd; \ + rm -f $(depfile); endif diff --git a/scripts/Makefile.build b/scripts/Makefile.build index a8e7ba9f73e8..6835f98e2070 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -529,18 +529,16 @@ 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 -- cgit v1.2.3-59-g8ed1b From f3fd4a3f3a388041fe5f1ef74fdd461900513f1e Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 30 Nov 2018 10:05:23 +0900 Subject: kbuild: remove redundant 'set -e' from filechk_offsets The filechk macro in scripts/Kbuild.include already sets 'set -e'. Signed-off-by: Masahiro Yamada --- scripts/Makefile.lib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 8fe4468f9bda..ae3ae97f0d5e 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -406,7 +406,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 "/*"; \ -- cgit v1.2.3-59-g8ed1b From 4317ee3b6a5e8bd0f62780591df6424ef9397fbd Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 30 Nov 2018 10:05:24 +0900 Subject: kbuild: remove redundant 'set -e' from sub_cmd_record_mcount This is executed inside the if_changed_rule, which already sets 'set -e'. Signed-off-by: Masahiro Yamada --- scripts/Makefile.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 6835f98e2070..91b63ba926fc 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -204,7 +204,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)" \ -- cgit v1.2.3-59-g8ed1b From ee3e46b7efd2954479f87030d31fda3c22bbc763 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 30 Nov 2018 10:05:25 +0900 Subject: kbuild: refactor modversions build rules Let $(CC) compile objects into normal files *.o instead of .tmp_*.o whether CONFIG_MODVERSIONS is enabled or not. With this, the input file for objtool is always *.o so objtool_o can go away. I guess the reason of using .tmp_*.o for intermediate objects was to avoid leaving incomplete *.o file (, whose timestamp says it is up-to-date) when the genksyms tool failed for some reasons. It no longer matters because any targets are deleted on errors since commit 9c2af1c7377a ("kbuild: add .DELETE_ON_ERROR special target"). Signed-off-by: Masahiro Yamada --- scripts/Makefile.build | 54 ++++++++++++++++---------------------------------- 1 file changed, 17 insertions(+), 37 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 91b63ba926fc..cdb25d163b42 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -154,35 +154,30 @@ $(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_.o from .c -# o if .tmp_.o doesn't contain a __ksymtab version, i.e. does -# not export symbols, we just rename .tmp_.o to .o and -# are done. +# o compile a .o from .c +# o if .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 .o from .tmp_.o using the linker to +# o generate .tmp_.o from .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_.o to .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) $@; \ + rm -f $(@D)/.tmp_$(@F:.o=.ver); \ fi; endif @@ -241,19 +236,12 @@ ifneq ($(RETPOLINE_CFLAGS),) endif 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)) @@ -357,34 +345,26 @@ $(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) $@; \ + rm -f $(@D)/.tmp_$(@F:.o=.ver); \ fi; endif endif -- cgit v1.2.3-59-g8ed1b From bbda5ec671d3fe62faefa1cab7270aa586042a4b Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 30 Nov 2018 10:05:26 +0900 Subject: kbuild: simplify dependency generation for CONFIG_TRIM_UNUSED_KSYMS My main motivation of this commit is to clean up scripts/Kbuild.include and scripts/Makefile.build. Currently, CONFIG_TRIM_UNUSED_KSYMS works with a tricky gimmick; possibly exported symbols are detected by letting $(CPP) replace EXPORT_SYMBOL* with a special string '=== __KSYM_*===', which is post-processed by sed, and passed to fixdep. The extra preprocessing is costly, and hacking cmd_and_fixdep is ugly. I came up with a new way to find exported symbols; insert a dummy symbol __ksym_marker_* to each potentially exported symbol. Those dummy symbols are picked up by $(NM), post-processed by sed, then appended to .*.cmd files. I collected the post-process part to a new shell script scripts/gen_ksymdeps.sh for readability. The dummy symbols are put into the .discard.* section so that the linker script rips them off the final vmlinux or modules. A nice side-effect is building with CONFIG_TRIM_UNUSED_KSYMS will be much faster. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Pitre --- include/asm-generic/export.h | 13 ++++++++----- include/linux/export.h | 18 +++++++++--------- scripts/Kbuild.include | 28 ---------------------------- scripts/Makefile.build | 7 +++++++ scripts/basic/fixdep.c | 31 ++++--------------------------- scripts/gen_ksymdeps.sh | 25 +++++++++++++++++++++++++ 6 files changed, 53 insertions(+), 69 deletions(-) create mode 100755 scripts/gen_ksymdeps.sh diff --git a/include/asm-generic/export.h b/include/asm-generic/export.h index 4d73e6e3c66c..294d6ae785d4 100644 --- a/include/asm-generic/export.h +++ b/include/asm-generic/export.h @@ -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 #include +.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) diff --git a/include/linux/export.h b/include/linux/export.h index ce764a5d2ee4..fd8711ed9ac4 100644 --- a/include/linux/export.h +++ b/include/linux/export.h @@ -92,22 +92,22 @@ struct kernel_symbol { */ #define __EXPORT_SYMBOL(sym, sec) -#elif defined(__KSYM_DEPS__) +#elif defined(CONFIG_TRIM_UNUSED_KSYMS) + +#include /* * 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_ 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 +#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) diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 6cf6a8b83b97..4b943f4d2226 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -260,39 +260,11 @@ if_changed_dep = $(if $(strip $(any-prereq) $(arg-check) ), \ @set -e; \ $(cmd_and_fixdep), @:) -ifndef CONFIG_TRIM_UNUSED_KSYMS - cmd_and_fixdep = \ $(echo-cmd) $(cmd_$(1)); \ scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).cmd;\ rm -f $(depfile); -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).cmd; \ - rm -f $(depfile); - -endif - # Usage: $(call if_changed_rule,foo) # Will check if $(cmd_foo) or any of the prerequisites changed, # and if so will execute $(rule_foo). diff --git a/scripts/Makefile.build b/scripts/Makefile.build index cdb25d163b42..23ebf2508234 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -254,9 +254,15 @@ 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_gen_ksymdeps) \ $(cmd_checkdoc) \ $(call echo-cmd,objtool) $(cmd_objtool) \ $(cmd_modversions_c) \ @@ -265,6 +271,7 @@ endef define rule_as_o_S $(call cmd_and_fixdep,as_o_S) \ + $(cmd_gen_ksymdeps) \ $(call echo-cmd,objtool) $(cmd_objtool) \ $(cmd_modversions_S) endef diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index 850966f3d602..facbd603adf6 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -105,8 +105,7 @@ static void usage(void) { - fprintf(stderr, "Usage: fixdep [-e] \n"); - fprintf(stderr, " -e insert extra dependencies given on stdin\n"); + fprintf(stderr, "Usage: fixdep \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; diff --git a/scripts/gen_ksymdeps.sh b/scripts/gen_ksymdeps.sh new file mode 100755 index 000000000000..1324986e1362 --- /dev/null +++ b/scripts/gen_ksymdeps.sh @@ -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):" -- cgit v1.2.3-59-g8ed1b From 3a2429e1faf40b2aaa481aa4b001a74d222c7e8b Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 30 Nov 2018 10:05:27 +0900 Subject: kbuild: change if_changed_rule for multi-line recipe The 'define' ... 'endef' directive is useful to confine a series of shell commands into a single macro: define foo [action1] [action2] [action3] endif Each action is executed in a separate subshell. However, rule_cc_o_c and rule_as_o_S in scripts/Makefile.build are written as follows (with a trailing semicolon in each cmd_*): define rule_cc_o_c [action1] ; \ [action2] ; \ [action3] ; endef All shell commands are concatenated with '; \' so that it looks like a single command from the Makefile point of view. This does not exploit the benefits of 'define' ... 'endef' form because a single shell command can be more simply written, like this: rule_cc_o_c = \ [action1] ; \ [action2] ; \ [action3] ; I guess the intention for the command concatenation was to let the '@set -e' in if_changed_rule cover all the commands. We can improve the readability by moving '@set -e' to the 'cmd' macro. The combo of $(call echo-cmd,*) $(cmd_*) in rule_cc_o_c and rule_as_o_S have been replaced with $(call cmd,*). The trailing back-slashes have been removed. Here is a note about the performance: the commands in rule_cc_o_c and rule_as_o_S were previously executed all together in a single subshell, but now each line in a separate subshell. This means Make will spawn extra subshells [1]. I measured the build performance for x86_64_defconfig + CONFIG_MODVERSIONS + CONFIG_TRIM_UNUSED_KSYMS and I saw slight performance regression, but I believe code readability and maintainability wins. [1] Precisely, GNU Make may optimize this by executing the command directly instead of forking a subshell, if no shell special characters are found in the command line and omitting the subshell will not change the behavior. Signed-off-by: Masahiro Yamada --- scripts/Kbuild.include | 12 ++++-------- scripts/Makefile.build | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 4b943f4d2226..6bbbe7533d6f 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -215,7 +215,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))) @@ -256,21 +256,17 @@ if_changed = $(if $(strip $(any-prereq) $(arg-check)), \ 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), @:) +if_changed_dep = $(if $(strip $(any-prereq) $(arg-check)),$(cmd_and_fixdep),@:) cmd_and_fixdep = \ - $(echo-cmd) $(cmd_$(1)); \ + $(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 diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 23ebf2508234..a0002246366b 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -260,20 +260,20 @@ cmd_gen_ksymdeps = \ endif define rule_cc_o_c - $(call echo-cmd,checksrc) $(cmd_checksrc) \ - $(call cmd_and_fixdep,cc_o_c) \ - $(cmd_gen_ksymdeps) \ - $(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) \ - $(cmd_gen_ksymdeps) \ - $(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) -- cgit v1.2.3-59-g8ed1b From e5d289100d3aef3e83dc1b8303999e26d86acb7b Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 30 Nov 2018 10:05:28 +0900 Subject: kbuild: remove trailing semicolon from cmd_* passed to if_changed_rule With the change of rule_cc_o_c / rule_as_o_S in the last commit, each command is executed in a separate subshell. Rip off unneeded semicolons. Signed-off-by: Masahiro Yamada --- scripts/Kbuild.include | 2 +- scripts/Makefile.build | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 6bbbe7533d6f..ba297fdd7c52 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -261,7 +261,7 @@ if_changed_dep = $(if $(strip $(any-prereq) $(arg-check)),$(cmd_and_fixdep),@:) cmd_and_fixdep = \ $(cmd); \ scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).cmd;\ - rm -f $(depfile); + rm -f $(depfile) # Usage: $(call if_changed_rule,foo) # Will check if $(cmd_foo) or any of the prerequisites changed, diff --git a/scripts/Makefile.build b/scripts/Makefile.build index a0002246366b..912198d9ef33 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -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 @@ -178,7 +178,7 @@ cmd_modversions_c = \ -T $(@D)/.tmp_$(@F:.o=.ver); \ mv -f $(@D)/.tmp_$(@F) $@; \ rm -f $(@D)/.tmp_$(@F:.o=.ver); \ - fi; + fi endif ifdef CONFIG_FTRACE_MCOUNT_RECORD @@ -211,7 +211,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 @@ -241,7 +241,7 @@ endif # '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_obj) $(objtool_args) $@) objtool_obj = $(if $(patsubst y%,, \ $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \ $(__objtool_obj)) @@ -256,7 +256,7 @@ objtool_dep = $(objtool_obj) \ ifdef CONFIG_TRIM_UNUSED_KSYMS cmd_gen_ksymdeps = \ - $(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ >> $(dot-target).cmd; + $(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ >> $(dot-target).cmd endif define rule_cc_o_c @@ -372,7 +372,7 @@ cmd_modversions_S = \ -T $(@D)/.tmp_$(@F:.o=.ver); \ mv -f $(@D)/.tmp_$(@F) $@; \ rm -f $(@D)/.tmp_$(@F:.o=.ver); \ - fi; + fi endif endif -- cgit v1.2.3-59-g8ed1b From 67126965ee0856f0d1cdb10792a36eaf4b2f13c0 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 30 Nov 2018 10:05:29 +0900 Subject: kbuild: refactor if_changed '@set -e; $(echo-cmd) $(cmd_$(1)' can be replaced with '$(cmd)'. Signed-off-by: Masahiro Yamada --- scripts/Kbuild.include | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index ba297fdd7c52..87e188609ef7 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -251,8 +251,7 @@ 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. -- cgit v1.2.3-59-g8ed1b From 5439f09f488f291a9493455c24b197c99025764d Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 30 Nov 2018 10:05:30 +0900 Subject: kbuild: remove redundant 'set -e' from cmd_* defines These three cmd_* are invoked in the $(call cmd,*) form. Now that 'set -e' moved to the 'cmd' macro, they do not need to explicitly give 'set -e'. Signed-off-by: Masahiro Yamada --- scripts/Makefile.build | 2 -- scripts/package/Makefile | 1 - 2 files changed, 3 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 912198d9ef33..ed9b6467ebde 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -134,7 +134,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 $@ @@ -337,7 +336,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 $@ diff --git a/scripts/package/Makefile b/scripts/package/Makefile index 73503ebce632..453fecee62f0 100644 --- a/scripts/package/Makefile +++ b/scripts/package/Makefile @@ -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:"; \ -- cgit v1.2.3-59-g8ed1b From 8e9b61b293d98f878cf1e6d1ae164e41c0219959 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 1 Dec 2018 09:27:15 +0900 Subject: kbuild: move .SECONDARY special target to Kbuild.include In commit 54a702f70589 ("kbuild: mark $(targets) as .SECONDARY and remove .PRECIOUS markers"), I missed one important feature of the .SECONDARY target: .SECONDARY with no prerequisites causes all targets to be treated as secondary. ... which agrees with the policy of Kbuild. Let's move it to scripts/Kbuild.include, with no prerequisites. Note: If an intermediate file is generated by $(call if_changed,...), you still need to add it to "targets" so its .*.cmd file is included. The arm/arm64 crypto files are generated by $(call cmd,shipped), so they do not need to be added to "targets", but need to be added to "clean-files" so "make clean" can properly clean them away. Signed-off-by: Masahiro Yamada --- arch/arm/crypto/Makefile | 2 +- arch/arm64/crypto/Makefile | 2 +- scripts/Kbuild.include | 3 +++ scripts/Makefile.build | 4 ---- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/arch/arm/crypto/Makefile b/arch/arm/crypto/Makefile index bd5bceef0605..89f88abba698 100644 --- a/arch/arm/crypto/Makefile +++ b/arch/arm/crypto/Makefile @@ -65,4 +65,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 diff --git a/arch/arm64/crypto/Makefile b/arch/arm64/crypto/Makefile index f476fede09ba..860d9312ccf9 100644 --- a/arch/arm64/crypto/Makefile +++ b/arch/arm64/crypto/Makefile @@ -75,4 +75,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 diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 87e188609ef7..4f138620865b 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -358,3 +358,6 @@ endef # delete partially updated (i.e. corrupted) files on error .DELETE_ON_ERROR: + +# do not delete intermediate files automatically +.SECONDARY: diff --git a/scripts/Makefile.build b/scripts/Makefile.build index ed9b6467ebde..aa05423c8418 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -529,8 +529,4 @@ $(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) -- cgit v1.2.3-59-g8ed1b From 5e34bd1d548d440015d5bee3326e9d74cdebecd6 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 5 Dec 2018 16:37:53 +0900 Subject: kbuild: remove a special handling for *.agh in Makefile.headersinst scripts/Makefile.headersinst takes care of *.agh just for arch/cris/include/uapi/arch-v10/arch/sv_addr.agh because renaming exported headers is difficult (or impossible). This code is no longer necessary thanks to commit c690eddc2f3b ("CRIS: Drop support for the CRIS port"). Signed-off-by: Masahiro Yamada --- scripts/Makefile.headersinst | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/Makefile.headersinst b/scripts/Makefile.headersinst index d5e131471131..45927fcddbc0 100644 --- a/scripts/Makefile.headersinst +++ b/scripts/Makefile.headersinst @@ -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)) -- cgit v1.2.3-59-g8ed1b From 257edce66d31a345dff8ca9f1fd30c46e0f14058 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 5 Dec 2018 16:38:35 +0900 Subject: kbuild: exploit parallel building for CONFIG_HEADERS_CHECK When CONFIG_HEADERS_CHECK is enabled, the headers_check is executed as a serialized task in the vmlinux recipe. Make it independent of vmlinux so that parallel building can process the headers_check and other build targets simultaneously. Signed-off-by: Masahiro Yamada --- Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index d4ac3cb9256c..00630cf04d84 100644 --- a/Makefile +++ b/Makefile @@ -1035,9 +1035,6 @@ 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 @@ -1208,6 +1205,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 -- cgit v1.2.3-59-g8ed1b From c7fe060885c4c0b78934c3d7507aa5e68de4099f Mon Sep 17 00:00:00 2001 From: Eugen Cazacu Date: Sat, 1 Dec 2018 17:03:22 +0100 Subject: user/Makefile: Fix typo and capitalization in comment section Signed-off-by: Eugen Cazacu Signed-off-by: Masahiro Yamada --- usr/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usr/Makefile b/usr/Makefile index 748f6a60bb1e..4a70ae43c9cb 100644 --- a/usr/Makefile +++ b/usr/Makefile @@ -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) -- cgit v1.2.3-59-g8ed1b From 7d0e5c2056c70ff443188b6e603b6254af1304cc Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 5 Dec 2018 20:28:04 +0900 Subject: kbuild: refactor Makefile.asm-generic - Use conventional $(MAKE) $(asm-generic)= style for directory descending - Remove unneeded FORCE since "all" is a phony target - Remove unneeded "_dummy :=" assignment - Skip $(shell mkdir ...) when headers exist in the directory - Misc cleanups Signed-off-by: Masahiro Yamada Acked-by: Sam Ravnborg --- Makefile | 8 ++++---- scripts/Makefile.asm-generic | 37 +++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index 00630cf04d84..6f3df2d786dd 100644 --- a/Makefile +++ b/Makefile @@ -1119,13 +1119,13 @@ prepare0: archprepare 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) diff --git a/scripts/Makefile.asm-generic b/scripts/Makefile.asm-generic index 32ad8e93fbe1..760323e70ebc 100644 --- a/scripts/Makefile.asm-generic +++ b/scripts/Makefile.asm-generic @@ -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 " >$@ + cmd_wrap = echo "\#include " > $@ 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: ; -- cgit v1.2.3-59-g8ed1b From b39a691617e4a7ba83bb33386e09206e60261a22 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 11 Dec 2018 21:01:53 +0900 Subject: kbuild: remove redundant quiet_modtag for $(obj-m) All objects in $(obj-m) are contained in $(real-obj-m) as well. It is true composite objects are only contained in $(obj-m), but [M] is hard-coded in quiet_cmd_link_multi-m. This line is redundant. Signed-off-by: Masahiro Yamada --- scripts/Makefile.build | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index aa05423c8418..29d02ed21552 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -110,8 +110,6 @@ $(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_cmd_cc_s_c = CC $(quiet_modtag) $@ cmd_cc_s_c = $(CC) $(c_flags) $(DISABLE_LTO) -fverbose-asm -S -o $@ $< -- cgit v1.2.3-59-g8ed1b From 45c4372d002bbf7342ea0426af896691ebc3a2f7 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 11 Dec 2018 21:01:54 +0900 Subject: kbuild: refactor quiet_modtag part-of-module and quiet_modtag are set for the same targets. Define quiet_modtag based on part-of-module. Signed-off-by: Masahiro Yamada --- scripts/Makefile.build | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 29d02ed21552..f83942b40ad1 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -98,18 +98,13 @@ modkern_cflags = \ $(if $(part-of-module), \ $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \ $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL)) -quiet_modtag := $(empty) $(empty) +quiet_modtag = $(if $(part-of-module),[M], ) $(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] - quiet_cmd_cc_s_c = CC $(quiet_modtag) $@ cmd_cc_s_c = $(CC) $(c_flags) $(DISABLE_LTO) -fverbose-asm -S -o $@ $< -- cgit v1.2.3-59-g8ed1b From 96c0a9180a1279c8ca5d9ea3096f2944828194d3 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 11 Dec 2018 21:01:55 +0900 Subject: kbuild: refactor part-of-module Use $(foreach ...) to make it shorter. Signed-off-by: Masahiro Yamada --- scripts/Makefile.build | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index f83942b40ad1..c09fe9099f58 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -94,17 +94,15 @@ endif # --------------------------------------------------------------------------- # Default is built-in, unless we know otherwise +$(foreach x, i lst o s, $(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 = $(if $(part-of-module),[M], ) -$(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 - quiet_cmd_cc_s_c = CC $(quiet_modtag) $@ cmd_cc_s_c = $(CC) $(c_flags) $(DISABLE_LTO) -fverbose-asm -S -o $@ $< -- cgit v1.2.3-59-g8ed1b From 1d467bb8a8b95caa01a240362589215739505233 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 11 Dec 2018 21:01:56 +0900 Subject: kbuild: handle part-of-module correctly for *.ll and *.symtypes The single targets *.ll and *.symtypes have never been treated as a module. Fix it. Signed-off-by: Masahiro Yamada --- scripts/Makefile.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index c09fe9099f58..0f2b5f07926b 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -94,7 +94,7 @@ endif # --------------------------------------------------------------------------- # Default is built-in, unless we know otherwise -$(foreach x, i lst o s, $(patsubst %.o,%.$(x),$(real-obj-m))): \ +$(foreach x, i ll lst o s symtypes, $(patsubst %.o,%.$(x),$(real-obj-m))): \ part-of-module := y modkern_cflags = \ -- cgit v1.2.3-59-g8ed1b From b825b4325354db65fd632b26ba585ced85f33902 Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Wed, 12 Dec 2018 12:55:56 +0100 Subject: scripts: coccinelle: only suggest true/false in files that already use them Some code may overall use 0 and 1, so don't introduce occasional uses of true and false in these cases. Signed-off-by: Julia Lawall Signed-off-by: Masahiro Yamada --- scripts/coccinelle/misc/boolinit.cocci | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/scripts/coccinelle/misc/boolinit.cocci b/scripts/coccinelle/misc/boolinit.cocci index b9abed49cd95..1b44feb7926c 100644 --- a/scripts/coccinelle/misc/boolinit.cocci +++ b/scripts/coccinelle/misc/boolinit.cocci @@ -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; @@ @@ -148,7 +159,7 @@ p1 << r3.p1; cocci.print_main("WARNING: Assignment of bool to 0/1",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) @@ -172,7 +183,7 @@ p1 << r3.p1; coccilib.report.print_report(p1[0],"WARNING: Assignment of bool to 0/1") @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") -- cgit v1.2.3-59-g8ed1b From 518d8a5644197abd3d5efb23c71afff25194da7e Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Wed, 12 Dec 2018 12:55:57 +0100 Subject: scripts: coccinelle: Correct warning message "Assignment" requires the assigned value before the place that value is stored into. Signed-off-by: Julia Lawall Signed-off-by: Masahiro Yamada --- scripts/coccinelle/misc/boolinit.cocci | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/coccinelle/misc/boolinit.cocci b/scripts/coccinelle/misc/boolinit.cocci index 1b44feb7926c..b0584a33c921 100644 --- a/scripts/coccinelle/misc/boolinit.cocci +++ b/scripts/coccinelle/misc/boolinit.cocci @@ -150,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 << 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; @@ -174,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 << 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") -- cgit v1.2.3-59-g8ed1b From 42a92bccd213ce4b7198d2e943ac0efe88cbe1aa Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 14 Dec 2018 17:05:37 +0900 Subject: kbuild: add -fno-PIE flag unconditionally This flag is documented in the GCC 4.6 manual, and recognized by Clang as well. Let's rip off the cc-option switch. Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers --- Makefile | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 6f3df2d786dd..2d15726fb546 100644 --- a/Makefile +++ b/Makefile @@ -426,9 +426,9 @@ LINUXINCLUDE := \ -I$(objtree)/include \ $(USERINCLUDE) -KBUILD_AFLAGS := -D__ASSEMBLY__ +KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \ - -fno-strict-aliasing -fno-common -fshort-wchar \ + -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \ -Werror-implicit-function-declaration \ -Wno-format-security \ -std=gnu89 @@ -514,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 -- cgit v1.2.3-59-g8ed1b From eeb5687a7139649e1724674441580b778f5ff7ab Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 14 Dec 2018 17:05:38 +0900 Subject: kbuild: add -Werror=strict-prototypes flag unconditionally -Wstrict-prototypes is added to KBUILD_CFLAGS first, then overridden by -Werror=strict-prototypes later. Let's add -Werror=strict-prototypes unconditionally because it is supported by GCC 4.6, and also by Clang. Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers --- Makefile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 2d15726fb546..1ec5289a871f 100644 --- a/Makefile +++ b/Makefile @@ -427,7 +427,7 @@ LINUXINCLUDE := \ $(USERINCLUDE) KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE -KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \ +KBUILD_CFLAGS := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \ -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \ -Werror-implicit-function-declaration \ -Wno-format-security \ @@ -832,9 +832,6 @@ 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) -- cgit v1.2.3-59-g8ed1b From 61a0902a06d602377cb6526deacfe4f0a7eade73 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 14 Dec 2018 17:05:39 +0900 Subject: kbuild: add -Werror=implicit-int flag unconditionally This flag is documented in the GCC 4.6 manual, and recognized by Clang as well. Let's rip off the cc-option switch. Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers --- Makefile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 1ec5289a871f..b9e902e8e382 100644 --- a/Makefile +++ b/Makefile @@ -429,7 +429,7 @@ LINUXINCLUDE := \ 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-function-declaration -Werror=implicit-int \ -Wno-format-security \ -std=gnu89 KBUILD_CPPFLAGS := -D__KERNEL__ @@ -829,9 +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) - # Prohibit date/time macros, which would make the build non-deterministic KBUILD_CFLAGS += $(call cc-option,-Werror=date-time) -- cgit v1.2.3-59-g8ed1b From b30204640192234d18f9168f19f9cd693485b86d Mon Sep 17 00:00:00 2001 From: Tom Roeder Date: Tue, 18 Dec 2018 14:49:07 -0800 Subject: scripts: add a tool to produce a compile_commands.json file The LLVM/Clang project provides many tools for analyzing C source code. Many of these tools are based on LibTooling (https://clang.llvm.org/docs/LibTooling.html), which depends on a database of compiler flags. The standard container for this database is compile_commands.json, which consists of a list of JSON objects, each with "directory", "file", and "command" fields. Some build systems, like cmake or bazel, produce this compilation information directly. Naturally, Makefiles don't. However, the kernel makefiles already create ..o.cmd files that contain all the information needed to build a compile_commands.json file. So, this commit adds scripts/gen_compile_commands.py, which recursively searches through a directory for ..o.cmd files and extracts appropriate compile commands from them. It writes a compile_commands.json file that LibTooling-based tools can use. By default, gen_compile_commands.py starts its search in its working directory and (over)writes compile_commands.json in the working directory. However, it also supports --output and --directory flags for out-of-tree use. Note that while gen_compile_commands.py enables the use of clang-based tools, it does not require the kernel to be compiled with clang. E.g., the following sequence of commands produces a compile_commands.json file that works correctly with LibTooling. make defconfig make scripts/gen_compile_commands.py Also note that this script is written to work correctly in both Python 2 and Python 3, so it does not specify the Python version in its first line. For an example of the utility of this script: after running gen_compile_commands.json on the latest kernel version, I was able to use Vim + the YouCompleteMe pluging + clangd to automatically jump to definitions and declarations. Obviously, cscope and ctags provide some of this functionality; the advantage of supporting LibTooling is that it opens the door to many other clang-based tools that understand the code directly and do not rely on regular expressions and heuristics. Tested: Built several recent kernel versions and ran the script against them, testing tools like clangd (for editor/LSP support) and clang-check (for static analysis). Also extracted some test .cmd files from a kernel build and wrote a test script to check that the script behaved correctly with all permutations of the --output and --directory flags. Signed-off-by: Tom Roeder Signed-off-by: Masahiro Yamada --- scripts/gen_compile_commands.py | 151 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100755 scripts/gen_compile_commands.py diff --git a/scripts/gen_compile_commands.py b/scripts/gen_compile_commands.py new file mode 100755 index 000000000000..7915823b92a5 --- /dev/null +++ b/scripts/gen_compile_commands.py @@ -0,0 +1,151 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) Google LLC, 2018 +# +# Author: Tom Roeder +# +"""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() -- cgit v1.2.3-59-g8ed1b From 733f4ef46d3ea31e44cebfec851528089a783f0f Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 20 Dec 2018 18:27:26 +0900 Subject: um: remove unused filechk_gen_header in Makefile This is a leftover of commit ecba97d4aacf ("[PATCH] uml makefiles sanitized"). Signed-off-by: Masahiro Yamada --- arch/um/Makefile | 2 -- 1 file changed, 2 deletions(-) diff --git a/arch/um/Makefile b/arch/um/Makefile index c08035904849..273130cf91d1 100644 --- a/arch/um/Makefile +++ b/arch/um/Makefile @@ -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)/ -- cgit v1.2.3-59-g8ed1b From 3c78c77bafb18bbbd22f6bda6f508699431ceb11 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 21 Dec 2018 12:12:39 +0900 Subject: scripts: remove unnecessary ihex2fw and check-lc_ctypes from .gitignore Commit c512d2544c68 ("gitignore: ignore scripts/ihex2fw") was unneeded. ihex2fw was generated in firmware/ instead of scripts/ at that time although ihex2fw.c was pushed back and forth between those directories in the past. check-lc_ctype was removed by commit cb43fb5775df ("docs: remove DocBook from the building system"). Signed-off-by: Masahiro Yamada --- scripts/.gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/.gitignore b/scripts/.gitignore index 12d302d70128..17f8cef88fa8 100644 --- a/scripts/.gitignore +++ b/scripts/.gitignore @@ -6,9 +6,7 @@ conmakehash kallsyms pnmtologo unifdef -ihex2fw recordmcount -check-lc_ctype sortextable asn1_compiler extract-cert -- cgit v1.2.3-59-g8ed1b From b239b4d65d6442fabd6db694f9d014268b8711c1 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 21 Dec 2018 12:12:40 +0900 Subject: firmware: remove unnecessary patterns from .gitignore Commit df85b2d767aa ("firmware: Restore support for built-in firmware") should not have restored this .gitignore blindly. *.gen.S is only pattern that should be ignored by git. Signed-off-by: Masahiro Yamada --- firmware/.gitignore | 5 ----- 1 file changed, 5 deletions(-) diff --git a/firmware/.gitignore b/firmware/.gitignore index d9c69017bc9a..9c8bdb9fdcc3 100644 --- a/firmware/.gitignore +++ b/firmware/.gitignore @@ -1,6 +1 @@ *.gen.S -*.fw -*.bin -*.csp -*.dsp -ihex2fw -- cgit v1.2.3-59-g8ed1b From 3470d9eb638722212ac44787eaf13486823fa011 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 21 Dec 2018 12:12:41 +0900 Subject: firmware: refactor firmware/Makefile Clean up the Makefile. Equivalent *.gen.S files are still produced. - Use filechk to remove ugly wordsize_deps - Get FWNAME, FWSTR, ASM_WORD, ASM_ALIGN, and PROGBITS out of the recipe for readability - Remove 'mkdir' because filechk takes care of it Signed-off-by: Masahiro Yamada --- firmware/Makefile | 84 +++++++++++++++++++++---------------------------------- 1 file changed, 32 insertions(+), 52 deletions(-) diff --git a/firmware/Makefile b/firmware/Makefile index 29641383e136..e2f7dd2f30e0 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -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)) -- cgit v1.2.3-59-g8ed1b From 4d4b5c2e3b6e6137c36cc13fe0d03404205afbd0 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Dec 2018 18:50:33 +0900 Subject: treewide: remove explicit rules for *offsets.s These explicit rules are unneeded because scripts/Makefile.build provides a pattern rule to create %.s from %.c Signed-off-by: Masahiro Yamada --- Kbuild | 9 +-------- arch/arm/mach-at91/Makefile | 3 --- arch/arm/mach-omap2/Makefile | 3 --- arch/ia64/kernel/Makefile | 5 ----- drivers/memory/Makefile.asm-offsets | 3 --- samples/bpf/Makefile | 3 --- 6 files changed, 1 insertion(+), 25 deletions(-) diff --git a/Kbuild b/Kbuild index 005304205482..b24210cb4dfe 100644 --- a/Kbuild +++ b/Kbuild @@ -16,10 +16,6 @@ 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 $(call filechk,offsets,__LINUX_BOUNDS_H__) @@ -50,10 +46,7 @@ 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: $(obj)/$(timeconst-file) $(obj)/$(bounds-file) $(obj)/$(offsets-file): arch/$(SRCARCH)/kernel/asm-offsets.s FORCE $(call filechk,offsets,__ASM_OFFSETS_H__) diff --git a/arch/arm/mach-at91/Makefile b/arch/arm/mach-at91/Makefile index 7415f181907b..f87066b60836 100644 --- a/arch/arm/mach-at91/Makefile +++ b/arch/arm/mach-at91/Makefile @@ -19,9 +19,6 @@ 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__) diff --git a/arch/arm/mach-omap2/Makefile b/arch/arm/mach-omap2/Makefile index 01377c292db4..55c482c2bab1 100644 --- a/arch/arm/mach-omap2/Makefile +++ b/arch/arm/mach-omap2/Makefile @@ -236,9 +236,6 @@ 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__) diff --git a/arch/ia64/kernel/Makefile b/arch/ia64/kernel/Makefile index d0c0ccdd656a..7372d994b44e 100644 --- a/arch/ia64/kernel/Makefile +++ b/arch/ia64/kernel/Makefile @@ -50,10 +50,5 @@ 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__) diff --git a/drivers/memory/Makefile.asm-offsets b/drivers/memory/Makefile.asm-offsets index 843ff60ccb5a..f968dfa71d8e 100644 --- a/drivers/memory/Makefile.asm-offsets +++ b/drivers/memory/Makefile.asm-offsets @@ -1,5 +1,2 @@ -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__) diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile index be0a961450bc..100a49d35c77 100644 --- a/samples/bpf/Makefile +++ b/samples/bpf/Makefile @@ -227,9 +227,6 @@ $(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__) -- cgit v1.2.3-59-g8ed1b From 2c667d77fc02dd453c49b9c29d08a8bb55d60ebe Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Dec 2018 18:50:34 +0900 Subject: treewide: add intermediate .s files to targets Avoid unneeded recreation of these in the incremental build. Signed-off-by: Masahiro Yamada --- arch/arm/mach-at91/Makefile | 2 ++ arch/arm/mach-omap2/Makefile | 2 ++ arch/ia64/kernel/Makefile | 2 ++ arch/x86/um/Makefile | 1 + drivers/memory/Makefile.asm-offsets | 2 ++ samples/bpf/Makefile | 1 + 6 files changed, 10 insertions(+) diff --git a/arch/arm/mach-at91/Makefile b/arch/arm/mach-at91/Makefile index f87066b60836..31b61f0e1c07 100644 --- a/arch/arm/mach-at91/Makefile +++ b/arch/arm/mach-at91/Makefile @@ -23,3 +23,5 @@ include/generated/at91_pm_data-offsets.h: arch/arm/mach-at91/pm_data-offsets.s F $(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 diff --git a/arch/arm/mach-omap2/Makefile b/arch/arm/mach-omap2/Makefile index 55c482c2bab1..4afdf56964c9 100644 --- a/arch/arm/mach-omap2/Makefile +++ b/arch/arm/mach-omap2/Makefile @@ -240,3 +240,5 @@ include/generated/ti-pm-asm-offsets.h: arch/arm/mach-omap2/pm-asm-offsets.s FORC $(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 diff --git a/arch/ia64/kernel/Makefile b/arch/ia64/kernel/Makefile index 7372d994b44e..4ba05140b249 100644 --- a/arch/ia64/kernel/Makefile +++ b/arch/ia64/kernel/Makefile @@ -52,3 +52,5 @@ include $(src)/Makefile.gate include/generated/nr-irqs.h: arch/$(SRCARCH)/kernel/nr-irqs.s FORCE $(call filechk,offsets,__ASM_NR_IRQS_H__) + +targets += nr-irqs.s diff --git a/arch/x86/um/Makefile b/arch/x86/um/Makefile index 17924646467c..2d686ae54681 100644 --- a/arch/x86/um/Makefile +++ b/arch/x86/um/Makefile @@ -38,6 +38,7 @@ USER_OBJS := bugs_$(BITS).o ptrace_user.o fault.o $(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__) diff --git a/drivers/memory/Makefile.asm-offsets b/drivers/memory/Makefile.asm-offsets index f968dfa71d8e..0447e174c752 100644 --- a/drivers/memory/Makefile.asm-offsets +++ b/drivers/memory/Makefile.asm-offsets @@ -1,2 +1,4 @@ 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 diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile index 100a49d35c77..82d5a3870460 100644 --- a/samples/bpf/Makefile +++ b/samples/bpf/Makefile @@ -230,6 +230,7 @@ $(LIBBPF): FORCE $(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: -- cgit v1.2.3-59-g8ed1b From 11fda148040bb987949f9b957aceb483407e32cb Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 22 Dec 2018 18:50:35 +0900 Subject: kbuild: remove $(obj)/ prefixes in ./Kbuild Adding $(obj)/ to file paths relative from the top objtree looks a bit redundant to me. This commit has no functional change since $(obj) is '.' in this file. Signed-off-by: Masahiro Yamada --- Kbuild | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Kbuild b/Kbuild index b24210cb4dfe..03cb8edfbafb 100644 --- a/Kbuild +++ b/Kbuild @@ -16,7 +16,7 @@ bounds-file := include/generated/bounds.h always := $(bounds-file) targets := kernel/bounds.s -$(obj)/$(bounds-file): kernel/bounds.s FORCE +$(bounds-file): kernel/bounds.s FORCE $(call filechk,offsets,__LINUX_BOUNDS_H__) ##### @@ -34,7 +34,7 @@ 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) ##### @@ -46,9 +46,9 @@ offsets-file := include/generated/asm-offsets.h always += $(offsets-file) targets += arch/$(SRCARCH)/kernel/asm-offsets.s -arch/$(SRCARCH)/kernel/asm-offsets.s: $(obj)/$(timeconst-file) $(obj)/$(bounds-file) +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__) ##### @@ -70,7 +70,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 -- cgit v1.2.3-59-g8ed1b From dec28d8ea2f731b7ec68a2c9421e99a165d47b57 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 24 Dec 2018 23:11:09 +0900 Subject: kbuild: remove unused cmd_gentimeconst filechk_gentimeconst is always used instead of cmd_gentimeconst. Signed-off-by: Masahiro Yamada --- Kbuild | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Kbuild b/Kbuild index 03cb8edfbafb..414ae6da1f50 100644 --- a/Kbuild +++ b/Kbuild @@ -26,10 +26,6 @@ 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 -- cgit v1.2.3-59-g8ed1b