From ae0c553c24c009596c3a3e903433824fe050c547 Mon Sep 17 00:00:00 2001 From: Sami Tolvanen Date: Thu, 30 Nov 2017 15:38:26 -0800 Subject: [PATCH 01/29] kbuild: add clang-version.sh Based on gcc-version.sh, clang-version.sh prints out the correct version of clang. Signed-off-by: Sami Tolvanen Tested-by: Nick Desaulniers Signed-off-by: Masahiro Yamada --- scripts/clang-version.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 scripts/clang-version.sh diff --git a/scripts/clang-version.sh b/scripts/clang-version.sh new file mode 100755 index 000000000000..9780efa56980 --- /dev/null +++ b/scripts/clang-version.sh @@ -0,0 +1,33 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# clang-version [-p] clang-command +# +# Prints the compiler version of `clang-command' in a canonical 4-digit form +# such as `0500' for clang-5.0 etc. +# +# With the -p option, prints the patchlevel as well, for example `050001' for +# clang-5.0.1 etc. +# + +if [ "$1" = "-p" ] ; then + with_patchlevel=1; + shift; +fi + +compiler="$*" + +if [ ${#compiler} -eq 0 ]; then + echo "Error: No compiler specified." + printf "Usage:\n\t$0 \n" + exit 1 +fi + +MAJOR=$(echo __clang_major__ | $compiler -E -x c - | tail -n 1) +MINOR=$(echo __clang_minor__ | $compiler -E -x c - | tail -n 1) +if [ "x$with_patchlevel" != "x" ] ; then + PATCHLEVEL=$(echo __clang_patchlevel__ | $compiler -E -x c - | tail -n 1) + printf "%02d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL +else + printf "%02d%02d\\n" $MAJOR $MINOR +fi From 1fe7d2bb24d7db6175e0b0a31d8fe03dc6ffb16e Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Tue, 6 Feb 2018 22:41:17 -0800 Subject: [PATCH 02/29] kbuild: Improve portability of some sed invocations * Use BREs where EREs aren't necessary. * Pass -E instead of -r to use EREs. This will be standardized in the next POSIX revision[0]. GNU sed supports this since 4.2 (May 2009), and busybox since 1.22.0 (Jan 2014). * Use the [:space:] character class instead of ` \t` in bracket expressions. In bracket expressions, POSIX says that loses its special meaning, so a conforming implementation cannot expand \t to [1]. * In BREs, use interval expressions (\{n,m\}) instead of non-standard features like \+ and \?. * Use a loop instead of -s flag. There are still plenty of other cases of non-standard sed invocations (use of ERE features in BREs, in-place editing), but this fixes some core ones. [0] http://austingroupbugs.net/view.php?id=528 [1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_03_05 Signed-off-by: Michael Forney Signed-off-by: Masahiro Yamada --- scripts/Kbuild.include | 2 +- scripts/Makefile.build | 2 +- scripts/adjust_autoksyms.sh | 4 +++- scripts/gen_initramfs_list.sh | 2 +- scripts/headers_install.sh | 10 +++++----- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 065324a8046f..34cbd81024b0 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -368,7 +368,7 @@ ksym_dep_filter = \ $(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 -rn 's/^.*=== __KSYM_(.*) ===.*$$/KSYM_\1/p' + esac | tr ";" "\n" | sed -n 's/^.*=== __KSYM_\(.*\) ===.*$$/KSYM_\1/p' cmd_and_fixdep = \ $(echo-cmd) $(cmd_$(1)); \ diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 4f2b25d43ec9..fff770983960 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -314,7 +314,7 @@ endef # List module undefined symbols (or empty line if not enabled) ifdef CONFIG_TRIM_UNUSED_KSYMS -cmd_undef_syms = $(NM) $@ | sed -n 's/^ \+U //p' | xargs echo +cmd_undef_syms = $(NM) $@ | sed -n 's/^ *U //p' | xargs echo else cmd_undef_syms = echo endif diff --git a/scripts/adjust_autoksyms.sh b/scripts/adjust_autoksyms.sh index 513da1a4a2da..a162258ab606 100755 --- a/scripts/adjust_autoksyms.sh +++ b/scripts/adjust_autoksyms.sh @@ -60,7 +60,9 @@ cat > "$new_ksyms_file" << EOT EOT [ "$(ls -A "$MODVERDIR")" ] && -sed -ns -e '3{s/ /\n/g;/^$/!p;}' "$MODVERDIR"/*.mod | sort -u | +for mod in "$MODVERDIR"/*.mod; do + sed -n -e '3{s/ /\n/g;/^$/!p;}' "$mod" +done | sort -u | while read sym; do if [ -n "$CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX" ]; then sym="${sym#_}" diff --git a/scripts/gen_initramfs_list.sh b/scripts/gen_initramfs_list.sh index 86a3c0e5cfbc..10e528b3a08f 100755 --- a/scripts/gen_initramfs_list.sh +++ b/scripts/gen_initramfs_list.sh @@ -194,7 +194,7 @@ input_file() { source="$1" if [ -f "$1" ]; then ${dep_list}header "$1" - is_cpio="$(echo "$1" | sed 's/^.*\.cpio\(\..*\)\?/cpio/')" + is_cpio="$(echo "$1" | sed 's/^.*\.cpio\(\..*\)\{0,1\}/cpio/')" if [ $2 -eq 0 -a ${is_cpio} = "cpio" ]; then cpio_file=$1 echo "$1" | grep -q '^.*\.cpio\..*' && is_cpio_compressed="compressed" diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh index a18bca720995..593f8879c641 100755 --- a/scripts/headers_install.sh +++ b/scripts/headers_install.sh @@ -31,13 +31,13 @@ trap 'rm -f "$OUTDIR/$FILE" "$OUTDIR/$FILE.sed"' EXIT for i in "$@" do FILE="$(basename "$i")" - sed -r \ - -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \ - -e 's/__attribute_const__([ \t]|$)/\1/g' \ + sed -E \ + -e 's/([[:space:](])(__user|__force|__iomem)[[:space:]]/\1/g' \ + -e 's/__attribute_const__([[:space:]]|$)/\1/g' \ -e 's@^#include @@' \ -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \ - -e 's/(^|[ \t(])(inline|asm|volatile)([ \t(]|$)/\1__\2__\3/g' \ - -e 's@#(ifndef|define|endif[ \t]*/[*])[ \t]*_UAPI@#\1 @' \ + -e 's/(^|[[:space:](])(inline|asm|volatile)([[:space:](]|$)/\1__\2__\3/g' \ + -e 's@#(ifndef|define|endif[[:space:]]*/[*])[[:space:]]*_UAPI@#\1 @' \ "$SRCDIR/$i" > "$OUTDIR/$FILE.sed" || exit 1 scripts/unifdef -U__KERNEL__ -D__EXPORTED_HEADERS__ "$OUTDIR/$FILE.sed" \ > "$OUTDIR/$FILE" From 6358d6e8b9846c2ff6fd1d4ad2809145635dd813 Mon Sep 17 00:00:00 2001 From: Nicholas Piggin Date: Sun, 11 Feb 2018 00:25:03 +1000 Subject: [PATCH 03/29] kbuild: remove incremental linking option This removes the old `ld -r` incremental link option, which has not been selected by any architecture since June 2017. Signed-off-by: Nicholas Piggin Signed-off-by: Masahiro Yamada --- Documentation/kbuild/makefiles.txt | 10 +++- arch/Kconfig | 6 --- scripts/Makefile.build | 32 ++++------- scripts/link-vmlinux.sh | 87 +++++++++++------------------- 4 files changed, 49 insertions(+), 86 deletions(-) diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt index 71e9feefb63c..750aea9edd35 100644 --- a/Documentation/kbuild/makefiles.txt +++ b/Documentation/kbuild/makefiles.txt @@ -153,8 +153,14 @@ more details, with real examples. configuration. Kbuild compiles all the $(obj-y) files. It then calls - "$(LD) -r" to merge these files into one built-in.o file. - built-in.o is later linked into vmlinux by the parent Makefile. + "$(AR) rcSTP" to merge these files into one built-in.o file. + This is a thin archive without a symbol table, which makes it + unsuitable as a linker input. + + The scripts/link-vmlinux.sh script later makes an aggregate + built-in.o with "${AR} rcsTP", which creates the thin archive + with a symbol table and an index, making it a valid input for + the final vmlinux link passes. The order of files in $(obj-y) is significant. Duplicates in the lists are allowed: the first instance will be linked into diff --git a/arch/Kconfig b/arch/Kconfig index 76c0b54443b1..8e0d665c8d53 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -596,12 +596,6 @@ config CC_STACKPROTECTOR_AUTO endchoice -config THIN_ARCHIVES - def_bool y - help - Select this if the architecture wants to use thin archives - instead of ld -r to create the built-in.o files. - config LD_DEAD_CODE_DATA_ELIMINATION bool help diff --git a/scripts/Makefile.build b/scripts/Makefile.build index fff770983960..672cf5bfd724 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -458,15 +458,13 @@ $(sort $(subdir-obj-y)): $(subdir-ym) ; # ifdef builtin-target -ifdef CONFIG_THIN_ARCHIVES - cmd_make_builtin = rm -f $@; $(AR) rcSTP$(KBUILD_ARFLAGS) - cmd_make_empty_builtin = rm -f $@; $(AR) rcSTP$(KBUILD_ARFLAGS) - quiet_cmd_link_o_target = AR $@ -else - cmd_make_builtin = $(LD) $(ld_flags) -r -o - cmd_make_empty_builtin = rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) - quiet_cmd_link_o_target = LD $@ -endif +# built-in.o archives are made with no symbol table or index which +# makes them small and fast, but unable to be used by the linker. +# scripts/link-vmlinux.sh builds an aggregate built-in.o with a symbol +# table and index. +cmd_make_builtin = rm -f $@; $(AR) rcSTP$(KBUILD_ARFLAGS) +cmd_make_empty_builtin = rm -f $@; $(AR) rcSTP$(KBUILD_ARFLAGS) +quiet_cmd_link_o_target = AR $@ # If the list of objects to link is empty, just create an empty built-in.o cmd_link_o_target = $(if $(strip $(obj-y)),\ @@ -499,11 +497,8 @@ $(modorder-target): $(subdir-ym) FORCE ifdef lib-target quiet_cmd_link_l_target = AR $@ -ifdef CONFIG_THIN_ARCHIVES - cmd_link_l_target = rm -f $@; $(AR) rcsTP$(KBUILD_ARFLAGS) $@ $(lib-y) -else - cmd_link_l_target = rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@ $(lib-y) -endif +# lib target archives do get a symbol table and index +cmd_link_l_target = rm -f $@; $(AR) rcsTP$(KBUILD_ARFLAGS) $@ $(lib-y) $(lib-target): $(lib-y) FORCE $(call if_changed,link_l_target) @@ -551,13 +546,8 @@ $($(subst $(obj)/,,$(@:.o=-m)))), $^) cmd_link_multi-link = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps) $(cmd_secanalysis) -ifdef CONFIG_THIN_ARCHIVES - quiet_cmd_link_multi-y = AR $@ - cmd_link_multi-y = rm -f $@; $(AR) rcSTP$(KBUILD_ARFLAGS) $@ $(link_multi_deps) -else - quiet_cmd_link_multi-y = LD $@ - cmd_link_multi-y = $(cmd_link_multi-link) -endif +quiet_cmd_link_multi-y = AR $@ +cmd_link_multi-y = rm -f $@; $(AR) rcSTP$(KBUILD_ARFLAGS) $@ $(link_multi_deps) quiet_cmd_link_multi-m = LD [M] $@ cmd_link_multi-m = $(cmd_link_multi-link) diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index be56a1153014..601ca8b528b3 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -55,13 +55,11 @@ info() # archive_builtin() { - if [ -n "${CONFIG_THIN_ARCHIVES}" ]; then - info AR built-in.o - rm -f built-in.o; - ${AR} rcsTP${KBUILD_ARFLAGS} built-in.o \ - ${KBUILD_VMLINUX_INIT} \ - ${KBUILD_VMLINUX_MAIN} - fi + info AR built-in.o + rm -f built-in.o; + ${AR} rcsTP${KBUILD_ARFLAGS} built-in.o \ + ${KBUILD_VMLINUX_INIT} \ + ${KBUILD_VMLINUX_MAIN} } # Link of vmlinux.o used for section mismatch analysis @@ -70,20 +68,13 @@ modpost_link() { local objects - if [ -n "${CONFIG_THIN_ARCHIVES}" ]; then - objects="--whole-archive \ - built-in.o \ - --no-whole-archive \ - --start-group \ - ${KBUILD_VMLINUX_LIBS} \ - --end-group" - else - objects="${KBUILD_VMLINUX_INIT} \ - --start-group \ - ${KBUILD_VMLINUX_MAIN} \ - ${KBUILD_VMLINUX_LIBS} \ - --end-group" - fi + objects="--whole-archive \ + built-in.o \ + --no-whole-archive \ + --start-group \ + ${KBUILD_VMLINUX_LIBS} \ + --end-group" + ${LD} ${LDFLAGS} -r -o ${1} ${objects} } @@ -96,46 +87,28 @@ vmlinux_link() local objects if [ "${SRCARCH}" != "um" ]; then - if [ -n "${CONFIG_THIN_ARCHIVES}" ]; then - objects="--whole-archive \ - built-in.o \ - --no-whole-archive \ - --start-group \ - ${KBUILD_VMLINUX_LIBS} \ - --end-group \ - ${1}" - else - objects="${KBUILD_VMLINUX_INIT} \ - --start-group \ - ${KBUILD_VMLINUX_MAIN} \ - ${KBUILD_VMLINUX_LIBS} \ - --end-group \ - ${1}" - fi + objects="--whole-archive \ + built-in.o \ + --no-whole-archive \ + --start-group \ + ${KBUILD_VMLINUX_LIBS} \ + --end-group \ + ${1}" - ${LD} ${LDFLAGS} ${LDFLAGS_vmlinux} -o ${2} \ + ${LD} ${LDFLAGS} ${LDFLAGS_vmlinux} -o ${2} \ -T ${lds} ${objects} else - if [ -n "${CONFIG_THIN_ARCHIVES}" ]; then - objects="-Wl,--whole-archive \ - built-in.o \ - -Wl,--no-whole-archive \ - -Wl,--start-group \ - ${KBUILD_VMLINUX_LIBS} \ - -Wl,--end-group \ - ${1}" - else - objects="${KBUILD_VMLINUX_INIT} \ - -Wl,--start-group \ - ${KBUILD_VMLINUX_MAIN} \ - ${KBUILD_VMLINUX_LIBS} \ - -Wl,--end-group \ - ${1}" - fi + objects="-Wl,--whole-archive \ + built-in.o \ + -Wl,--no-whole-archive \ + -Wl,--start-group \ + ${KBUILD_VMLINUX_LIBS} \ + -Wl,--end-group \ + ${1}" - ${CC} ${CFLAGS_vmlinux} -o ${2} \ - -Wl,-T,${lds} \ - ${objects} \ + ${CC} ${CFLAGS_vmlinux} -o ${2} \ + -Wl,-T,${lds} \ + ${objects} \ -lutil -lrt -lpthread rm -f linux fi From f49821ee32b76b1a356fab17316eb62430182ecf Mon Sep 17 00:00:00 2001 From: Nicholas Piggin Date: Sun, 11 Feb 2018 00:25:04 +1000 Subject: [PATCH 04/29] kbuild: rename built-in.o to built-in.a Incremental linking is gone, so rename built-in.o to built-in.a, which is the usual extension for archive files. This patch does two things, first is a simple search/replace: git grep -l 'built-in\.o' | xargs sed -i 's/built-in\.o/built-in\.a/g' The second is to invert nesting of nested text manipulations to avoid filtering built-in.a out from libs-y2: -libs-y2 := $(filter-out %.a, $(patsubst %/, %/built-in.a, $(libs-y))) +libs-y2 := $(patsubst %/, %/built-in.a, $(filter-out %.a, $(libs-y))) Signed-off-by: Nicholas Piggin Signed-off-by: Masahiro Yamada --- Documentation/kbuild/makefiles.txt | 16 ++++++++-------- Documentation/process/changes.rst | 2 +- Makefile | 14 +++++++------- arch/blackfin/kernel/bfin_ksyms.c | 2 +- arch/powerpc/kernel/Makefile | 2 +- drivers/s390/Makefile | 2 +- lib/Kconfig.debug | 4 ++-- scripts/Makefile.build | 10 +++++----- scripts/Makefile.lib | 6 +++--- scripts/link-vmlinux.sh | 20 ++++++++++---------- scripts/namespace.pl | 2 +- usr/initramfs_data.S | 2 +- 12 files changed, 41 insertions(+), 41 deletions(-) diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt index 750aea9edd35..667cd899ada8 100644 --- a/Documentation/kbuild/makefiles.txt +++ b/Documentation/kbuild/makefiles.txt @@ -153,18 +153,18 @@ more details, with real examples. configuration. Kbuild compiles all the $(obj-y) files. It then calls - "$(AR) rcSTP" to merge these files into one built-in.o file. + "$(AR) rcSTP" to merge these files into one built-in.a file. This is a thin archive without a symbol table, which makes it unsuitable as a linker input. The scripts/link-vmlinux.sh script later makes an aggregate - built-in.o with "${AR} rcsTP", which creates the thin archive + built-in.a with "${AR} rcsTP", which creates the thin archive with a symbol table and an index, making it a valid input for the final vmlinux link passes. The order of files in $(obj-y) is significant. Duplicates in the lists are allowed: the first instance will be linked into - built-in.o and succeeding instances will be ignored. + built-in.a and succeeding instances will be ignored. Link order is significant, because certain functions (module_init() / __initcall) will be called during boot in the @@ -228,7 +228,7 @@ more details, with real examples. Note: Of course, when you are building objects into the kernel, the syntax above will also work. So, if you have CONFIG_EXT2_FS=y, kbuild will build an ext2.o file for you out of the individual - parts and then link this into built-in.o, as you would expect. + parts and then link this into built-in.a, as you would expect. --- 3.4 Objects which export symbols @@ -238,7 +238,7 @@ more details, with real examples. --- 3.5 Library file goals - lib-y Objects listed with obj-* are used for modules, or - combined in a built-in.o for that specific directory. + combined in a built-in.a for that specific directory. There is also the possibility to list objects that will be included in a library, lib.a. All objects listed with lib-y are combined in a single @@ -250,7 +250,7 @@ more details, with real examples. Note that the same kbuild makefile may list files to be built-in and to be part of a library. Therefore the same directory - may contain both a built-in.o and a lib.a file. + may contain both a built-in.a and a lib.a file. Example: #arch/x86/lib/Makefile @@ -992,7 +992,7 @@ When kbuild executes, the following steps are followed (roughly): $(head-y) lists objects to be linked first in vmlinux. $(libs-y) lists directories where a lib.a archive can be located. - The rest list directories where a built-in.o object file can be + The rest list directories where a built-in.a object file can be located. $(init-y) objects will be located after $(head-y). @@ -1077,7 +1077,7 @@ When kbuild executes, the following steps are followed (roughly): extra-y := head.o init_task.o In this example, extra-y is used to list object files that - shall be built, but shall not be linked as part of built-in.o. + shall be built, but shall not be linked as part of built-in.a. --- 6.7 Commands useful for building a boot image diff --git a/Documentation/process/changes.rst b/Documentation/process/changes.rst index 81cdb528ad46..4f19a9725f76 100644 --- a/Documentation/process/changes.rst +++ b/Documentation/process/changes.rst @@ -78,7 +78,7 @@ Binutils -------- The build system has, as of 4.13, switched to using thin archives (`ar T`) -rather than incremental linking (`ld -r`) for built-in.o intermediate steps. +rather than incremental linking (`ld -r`) for built-in.a intermediate steps. This requires binutils 2.20 or newer. Flex diff --git a/Makefile b/Makefile index e02d092bc2d6..3cb5d10c7aa9 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ unexport GREP_OPTIONS # Most importantly: sub-Makefiles should only ever modify files in # their own directory. If in some directory we have a dependency on # a file in another dir (which doesn't happen often, but it's often -# unavoidable when linking the built-in.o targets which finally +# unavoidable when linking the built-in.a targets which finally # turn into vmlinux), we will call a sub make in that other dir, and # after that we are sure that everything which is in that other dir # is now up to date. @@ -982,13 +982,13 @@ vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \ vmlinux-alldirs := $(sort $(vmlinux-dirs) $(patsubst %/,%,$(filter %/, \ $(init-) $(core-) $(drivers-) $(net-) $(libs-) $(virt-)))) -init-y := $(patsubst %/, %/built-in.o, $(init-y)) -core-y := $(patsubst %/, %/built-in.o, $(core-y)) -drivers-y := $(patsubst %/, %/built-in.o, $(drivers-y)) -net-y := $(patsubst %/, %/built-in.o, $(net-y)) +init-y := $(patsubst %/, %/built-in.a, $(init-y)) +core-y := $(patsubst %/, %/built-in.a, $(core-y)) +drivers-y := $(patsubst %/, %/built-in.a, $(drivers-y)) +net-y := $(patsubst %/, %/built-in.a, $(net-y)) libs-y1 := $(patsubst %/, %/lib.a, $(libs-y)) -libs-y2 := $(filter-out %.a, $(patsubst %/, %/built-in.o, $(libs-y))) -virt-y := $(patsubst %/, %/built-in.o, $(virt-y)) +libs-y2 := $(patsubst %/, %/built-in.a, $(filter-out %.a, $(libs-y))) +virt-y := $(patsubst %/, %/built-in.a, $(virt-y)) # Externally visible symbols (used by link-vmlinux.sh) export KBUILD_VMLINUX_INIT := $(head-y) $(init-y) diff --git a/arch/blackfin/kernel/bfin_ksyms.c b/arch/blackfin/kernel/bfin_ksyms.c index 68096e8f787f..c0038eeb9e29 100644 --- a/arch/blackfin/kernel/bfin_ksyms.c +++ b/arch/blackfin/kernel/bfin_ksyms.c @@ -36,7 +36,7 @@ EXPORT_SYMBOL(memchr); /* * Because string functions are both inline and exported functions and * folder arch/blackfin/lib is configured as a library path in Makefile, - * symbols exported in folder lib is not linked into built-in.o but + * symbols exported in folder lib is not linked into built-in.a but * inlined only. In order to export string symbols to kernel module * properly, they should be exported here. */ diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile index 1b6bc7fba996..2358f97d62ec 100644 --- a/arch/powerpc/kernel/Makefile +++ b/arch/powerpc/kernel/Makefile @@ -165,7 +165,7 @@ systbl_chk: $(src)/systbl_chk.sh $(obj)/systbl_chk.i $(call cmd,systbl_chk) ifeq ($(CONFIG_PPC_OF_BOOT_TRAMPOLINE),y) -$(obj)/built-in.o: prom_init_check +$(obj)/built-in.a: prom_init_check quiet_cmd_prom_init_check = CALL $< cmd_prom_init_check = $(CONFIG_SHELL) $< "$(NM)" "$(obj)/prom_init.o" diff --git a/drivers/s390/Makefile b/drivers/s390/Makefile index 2fdab400c1fe..a863b0462b43 100644 --- a/drivers/s390/Makefile +++ b/drivers/s390/Makefile @@ -5,5 +5,5 @@ obj-y += cio/ block/ char/ crypto/ net/ scsi/ virtio/ -drivers-y += drivers/s390/built-in.o +drivers-y += drivers/s390/built-in.a diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 64155e310a9f..5be22e406f96 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -324,11 +324,11 @@ config DEBUG_SECTION_MISMATCH the analysis would not catch the illegal reference. This option tells gcc to inline less (but it does result in a larger kernel). - - Run the section mismatch analysis for each module/built-in.o file. + - Run the section mismatch analysis for each module/built-in.a file. When we run the section mismatch analysis on vmlinux.o, we lose valuable information about where the mismatch was introduced. - Running the analysis for each module/built-in.o file + Running the analysis for each module/built-in.a file tells where the mismatch happens much closer to the source. The drawback is that the same mismatch is reported at least twice. diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 672cf5bfd724..7cd2f4a6c2ac 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -77,7 +77,7 @@ obj-y += $(obj)/lib-ksyms.o endif ifneq ($(strip $(obj-y) $(need-builtin)),) -builtin-target := $(obj)/built-in.o +builtin-target := $(obj)/built-in.a endif modorder-target := $(obj)/modules.order @@ -104,7 +104,7 @@ ifneq ($(KBUILD_ENABLE_EXTRA_GCC_CHECKS),) cmd_checkdoc = $(srctree)/scripts/kernel-doc -none $< ; endif -# Do section mismatch analysis for each module/built-in.o +# Do section mismatch analysis for each module/built-in.a ifdef CONFIG_DEBUG_SECTION_MISMATCH cmd_secanalysis = ; scripts/mod/modpost $@ endif @@ -458,15 +458,15 @@ $(sort $(subdir-obj-y)): $(subdir-ym) ; # ifdef builtin-target -# built-in.o archives are made with no symbol table or index which +# built-in.a archives are made with no symbol table or index which # makes them small and fast, but unable to be used by the linker. -# scripts/link-vmlinux.sh builds an aggregate built-in.o with a symbol +# scripts/link-vmlinux.sh builds an aggregate built-in.a with a symbol # table and index. cmd_make_builtin = rm -f $@; $(AR) rcSTP$(KBUILD_ARFLAGS) cmd_make_empty_builtin = rm -f $@; $(AR) rcSTP$(KBUILD_ARFLAGS) quiet_cmd_link_o_target = AR $@ -# If the list of objects to link is empty, just create an empty built-in.o +# If the list of objects to link is empty, just create an empty built-in.a cmd_link_o_target = $(if $(strip $(obj-y)),\ $(cmd_make_builtin) $@ $(filter $(obj-y), $^) \ $(cmd_secanalysis),\ diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index a6f538b31ad6..5fd60af76d98 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -27,7 +27,7 @@ modorder := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m:.o=.ko # Handle objects in subdirs # --------------------------------------------------------------------------- -# o if we encounter foo/ in $(obj-y), replace it by foo/built-in.o +# o if we encounter foo/ in $(obj-y), replace it by foo/built-in.a # and add the directory to the list of dirs to descend into: $(subdir-y) # o if we encounter foo/ in $(obj-m), remove it from $(obj-m) # and add the directory to the list of dirs to descend into: $(subdir-m) @@ -35,7 +35,7 @@ __subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y))) subdir-y += $(__subdir-y) __subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m))) subdir-m += $(__subdir-m) -obj-y := $(patsubst %/, %/built-in.o, $(obj-y)) +obj-y := $(patsubst %/, %/built-in.a, $(obj-y)) obj-m := $(filter-out %/, $(obj-m)) # Subdirectories we need to descend into @@ -54,7 +54,7 @@ multi-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)) $($(m:.o=-y))) # $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to # tell kbuild to descend -subdir-obj-y := $(filter %/built-in.o, $(obj-y)) +subdir-obj-y := $(filter %/built-in.a, $(obj-y)) # Replace multi-part objects by their individual parts, look at local dir only real-objs-y := $(foreach m, $(filter-out $(subdir-obj-y), $(obj-y)), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 601ca8b528b3..08ca08e9105c 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -4,7 +4,7 @@ # link vmlinux # # vmlinux is linked from the objects selected by $(KBUILD_VMLINUX_INIT) and -# $(KBUILD_VMLINUX_MAIN) and $(KBUILD_VMLINUX_LIBS). Most are built-in.o files +# $(KBUILD_VMLINUX_MAIN) and $(KBUILD_VMLINUX_LIBS). Most are built-in.a files # from top-level directories in the kernel tree, others are specified in # arch/$(ARCH)/Makefile. Ordering when linking is important, and # $(KBUILD_VMLINUX_INIT) must be first. $(KBUILD_VMLINUX_LIBS) are archives @@ -18,7 +18,7 @@ # | +--< init/version.o + more # | # +--< $(KBUILD_VMLINUX_MAIN) -# | +--< drivers/built-in.o mm/built-in.o + more +# | +--< drivers/built-in.a mm/built-in.a + more # | # +--< $(KBUILD_VMLINUX_LIBS) # | +--< lib/lib.a + more @@ -51,13 +51,13 @@ info() # # Traditional incremental style of link does not require this step # -# built-in.o output file +# built-in.a output file # archive_builtin() { - info AR built-in.o - rm -f built-in.o; - ${AR} rcsTP${KBUILD_ARFLAGS} built-in.o \ + info AR built-in.a + rm -f built-in.a; + ${AR} rcsTP${KBUILD_ARFLAGS} built-in.a \ ${KBUILD_VMLINUX_INIT} \ ${KBUILD_VMLINUX_MAIN} } @@ -69,7 +69,7 @@ modpost_link() local objects objects="--whole-archive \ - built-in.o \ + built-in.a \ --no-whole-archive \ --start-group \ ${KBUILD_VMLINUX_LIBS} \ @@ -88,7 +88,7 @@ vmlinux_link() if [ "${SRCARCH}" != "um" ]; then objects="--whole-archive \ - built-in.o \ + built-in.a \ --no-whole-archive \ --start-group \ ${KBUILD_VMLINUX_LIBS} \ @@ -99,7 +99,7 @@ vmlinux_link() -T ${lds} ${objects} else objects="-Wl,--whole-archive \ - built-in.o \ + built-in.a \ -Wl,--no-whole-archive \ -Wl,--start-group \ ${KBUILD_VMLINUX_LIBS} \ @@ -164,7 +164,7 @@ cleanup() rm -f .tmp_System.map rm -f .tmp_kallsyms* rm -f .tmp_vmlinux* - rm -f built-in.o + rm -f built-in.a rm -f System.map rm -f vmlinux rm -f vmlinux.o diff --git a/scripts/namespace.pl b/scripts/namespace.pl index 729c547fc9e1..6135574a6f39 100755 --- a/scripts/namespace.pl +++ b/scripts/namespace.pl @@ -164,7 +164,7 @@ sub linux_objects s:^\./::; if (/.*\.o$/ && ! ( - m:/built-in.o$: + m:/built-in.a$: || m:arch/x86/vdso/: || m:arch/x86/boot/: || m:arch/ia64/ia32/ia32.o$: diff --git a/usr/initramfs_data.S b/usr/initramfs_data.S index 10d325e24566..b28da799f6a6 100644 --- a/usr/initramfs_data.S +++ b/usr/initramfs_data.S @@ -10,7 +10,7 @@ ld -m elf_i386 --format binary --oformat elf32-i386 -r \ -T initramfs_data.scr initramfs_data.cpio.gz -o initramfs_data.o - ld -m elf_i386 -r -o built-in.o initramfs_data.o + ld -m elf_i386 -r -o built-in.a initramfs_data.o For including the .init.ramfs sections, see include/asm-generic/vmlinux.lds. From 22340a06534a10296209bc2d02365a2770ded8fc Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 11 Feb 2018 17:40:29 +0900 Subject: [PATCH 05/29] kbuild: process mixture of clean/build targets one by one Support parallel building of clean, config, and build targets in a single command. For example, make -j clean all or make -j mrproper defconfig all They should be handled one by one. Signed-off-by: Masahiro Yamada --- Makefile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3cb5d10c7aa9..bfd09bc0da91 100644 --- a/Makefile +++ b/Makefile @@ -220,7 +220,8 @@ export srctree objtree VPATH version_h := include/generated/uapi/linux/version.h old_version_h := include/linux/version.h -no-dot-config-targets := clean mrproper distclean \ +clean-targets := %clean mrproper cleandocs +no-dot-config-targets := $(clean-targets) \ cscope gtags TAGS tags help% %docs check% coccicheck \ $(version_h) headers_% archheaders archscripts \ kernelversion %src-pkg @@ -243,6 +244,14 @@ ifeq ($(KBUILD_EXTMOD),) endif endif endif + +# For "make -j clean all", "make -j mrproper defconfig all", etc. +ifneq ($(filter $(clean-targets),$(MAKECMDGOALS)),) + ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),) + mixed-targets := 1 + endif +endif + # install and modules_install need also be processed one by one ifneq ($(filter install,$(MAKECMDGOALS)),) ifneq ($(filter modules_install,$(MAKECMDGOALS)),) From 0294e6f4a0006856e1f36b8cd8fa088d9e499e98 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 23 Feb 2018 13:56:53 +0900 Subject: [PATCH 06/29] kbuild: simplify ld-option implementation Currently, linker options are tested by the coordination of $(CC) and $(LD) because $(LD) needs some object to link. As commit 86a9df597cdd ("kbuild: fix linker feature test macros when cross compiling with Clang") addressed, we need to make sure $(CC) and $(LD) agree the underlying architecture of the passed object. This could be a bit complex when we combine tools from different groups. For example, we can use clang for $(CC), but we still need to rely on GCC toolchain for $(LD). So, I was searching for a way of standalone testing of linker options. A trick I found is to use '-v'; this not only prints the version string, but also tests if the given option is recognized. If a given option is supported, $ aarch64-linux-gnu-ld -v --fix-cortex-a53-843419 GNU ld (Linaro_Binutils-2017.11) 2.28.2.20170706 $ echo $? 0 If unsupported, $ aarch64-linux-gnu-ld -v --fix-cortex-a53-843419 GNU ld (crosstool-NG linaro-1.13.1-4.7-2013.04-20130415 - Linaro GCC 2013.04) 2.23.1 aarch64-linux-gnu-ld: unrecognized option '--fix-cortex-a53-843419' aarch64-linux-gnu-ld: use the --help option for usage information $ echo $? 1 Gold works likewise. $ aarch64-linux-gnu-ld.gold -v --fix-cortex-a53-843419 GNU gold (Linaro_Binutils-2017.11 2.28.2.20170706) 1.14 masahiro@pug:~/ref/linux$ echo $? 0 $ aarch64-linux-gnu-ld.gold -v --fix-cortex-a53-999999 GNU gold (Linaro_Binutils-2017.11 2.28.2.20170706) 1.14 aarch64-linux-gnu-ld.gold: --fix-cortex-a53-999999: unknown option aarch64-linux-gnu-ld.gold: use the --help option for usage information $ echo $? 1 LLD too. $ ld.lld -v --gc-sections LLD 7.0.0 (http://llvm.org/git/lld.git 4a0e4190e74cea19f8a8dc625ccaebdf8b5d1585) (compatible with GNU linkers) $ echo $? 0 $ ld.lld -v --fix-cortex-a53-843419 LLD 7.0.0 (http://llvm.org/git/lld.git 4a0e4190e74cea19f8a8dc625ccaebdf8b5d1585) (compatible with GNU linkers) $ echo $? 0 $ ld.lld -v --fix-cortex-a53-999999 ld.lld: error: unknown argument: --fix-cortex-a53-999999 LLD 7.0.0 (http://llvm.org/git/lld.git 4a0e4190e74cea19f8a8dc625ccaebdf8b5d1585) (compatible with GNU linkers) $ echo $? 1 Signed-off-by: Masahiro Yamada Tested-by: Nick Desaulniers --- scripts/Kbuild.include | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 34cbd81024b0..f9c2f07442c5 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -237,9 +237,7 @@ cc-ldoption = $(call try-run-cached,\ # ld-option # Usage: LDFLAGS += $(call ld-option, -X) -ld-option = $(call try-run-cached,\ - $(CC) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -x c /dev/null -c -o "$$TMPO"; \ - $(LD) $(LDFLAGS) $(1) "$$TMPO" -o "$$TMP",$(1),$(2)) +ld-option = $(call try-run-cached, $(LD) $(LDFLAGS) $(1) -v,$(1),$(2)) # ar-option # Usage: KBUILD_ARFLAGS := $(call ar-option,D) From 35cd02bee6e3f2825ce254159102b788116872d9 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 28 Feb 2018 19:14:23 +0900 Subject: [PATCH 07/29] kbuild: remove command line interface LDFLAGS_MODULE from makefiles.txt Documentation/kbuild/makefiles.txt lists variables used in Makefile whereas Documentation/kbuild/kbuild.txt describes user assignable parameters given via environments or the command line. LDFLAGS_MODULE is a command line interface, so it should be dropped from makefiles.txt. Some lines below in this file, it is clearly explained that KBUILD_LDFLAGS_MODULE is the right one for the internal use: KBUILD_LDFLAGS_MODULE Options for $(LD) when linking modules $(KBUILD_LDFLAGS_MODULE) is used to add arch-specific options used when linking modules. This is often a linker script. From commandline LDFLAGS_MODULE shall be used (see kbuild.txt). Then, kbuild.txt explains LDFLAGS_MODULE, like follows: LDFLAGS_MODULE -------------------------------------------------- Additional options used for $(LD) when linking modules. Signed-off-by: Masahiro Yamada --- Documentation/kbuild/makefiles.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt index 667cd899ada8..048fc39a6b91 100644 --- a/Documentation/kbuild/makefiles.txt +++ b/Documentation/kbuild/makefiles.txt @@ -837,12 +837,6 @@ When kbuild executes, the following steps are followed (roughly): Note: ldflags-y can be used to further customise the flags used. See chapter 3.7. - LDFLAGS_MODULE Options for $(LD) when linking modules - - LDFLAGS_MODULE is used to set specific flags for $(LD) when - linking the .ko files used for modules. - Default is "-r", for relocatable output. - LDFLAGS_vmlinux Options for $(LD) when linking vmlinux LDFLAGS_vmlinux is used to specify additional flags to pass to From bd0f98eba6840d99b791b36a01b83fc62d55235f Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 28 Feb 2018 19:14:24 +0900 Subject: [PATCH 08/29] kbuild: remove internally used LDFLAGS_vmlinux from kbuild.txt Documentation/kbuild/makefiles.txt lists variables used in Makefile whereas Documentation/kbuild/kbuild.txt describes user assignable parameters given via environments or the command line. The top Makefile and arch/*/Makefile accumulate proper linker flags to LDFLAGS_vmlinux. So, users can not override it from the command line. Generally, per-file options are not supposed to be user-assignable. Remove the misleading entry from kbuild.txt. If we need a way to append user-specific flags for linking the kernel, LDFLAGS_KERNEL would be a consistent choice because we already expose LDFLAGS_MODULE counter-part to users. Signed-off-by: Masahiro Yamada --- Documentation/kbuild/kbuild.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Documentation/kbuild/kbuild.txt b/Documentation/kbuild/kbuild.txt index ac2363ea05c5..6c9c69ec3986 100644 --- a/Documentation/kbuild/kbuild.txt +++ b/Documentation/kbuild/kbuild.txt @@ -50,10 +50,6 @@ LDFLAGS_MODULE -------------------------------------------------- Additional options used for $(LD) when linking modules. -LDFLAGS_vmlinux --------------------------------------------------- -Additional options passed to final link of vmlinux. - KBUILD_VERBOSE -------------------------------------------------- Set the kbuild verbosity. Can be assigned same values as "V=...". From ce99d0bf312daf0178e640da9e3c93b773a67e7d Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 16 Mar 2018 16:37:09 +0900 Subject: [PATCH 09/29] kbuild: clear LDFLAGS in the top Makefile Currently LDFLAGS is not cleared, so same flags are accumulated in LDFLAGS when the top Makefile is recursively invoked. I found unneeded rebuild for ARCH=arm64 when CONFIG_TRIM_UNUSED_KSYMS is enabled. If include/generated/autoksyms.h is updated, the top Makefile is recursively invoked, then arch/arm64/Makefile adds one more '-maarch64linux'. Due to the command line change, modules are rebuilt needlessly. Signed-off-by: Masahiro Yamada Acked-by: Nicolas Pitre --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index bfd09bc0da91..37574e3d21fe 100644 --- a/Makefile +++ b/Makefile @@ -435,6 +435,7 @@ KBUILD_CFLAGS_KERNEL := KBUILD_AFLAGS_MODULE := -DMODULE KBUILD_CFLAGS_MODULE := -DMODULE KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds +LDFLAGS := GCC_PLUGINS_CFLAGS := export ARCH SRCARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC From baa16684b0eb4e590c7e0e65fff4d348c877bc4e Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 16 Mar 2018 16:37:10 +0900 Subject: [PATCH 10/29] kbuild: remove wrong 'touch' in adjust_autoksyms.sh The comment mentions it creates autoksyms.h in case it is missing, but the actual code touches it when it does exists. The build system creates it anyway because and need it. The code would not have worked as intended, and people have not noticed it. This is a proof that we can simply remove it. Signed-off-by: Masahiro Yamada Acked-by: Nicolas Pitre --- scripts/adjust_autoksyms.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/adjust_autoksyms.sh b/scripts/adjust_autoksyms.sh index a162258ab606..e0dd0d5148ec 100755 --- a/scripts/adjust_autoksyms.sh +++ b/scripts/adjust_autoksyms.sh @@ -48,9 +48,6 @@ case "${KCONFIG_CONFIG}" in . "./${KCONFIG_CONFIG}" esac -# In case it doesn't exist yet... -if [ -e "$cur_ksyms_file" ]; then touch "$cur_ksyms_file"; fi - # Generate a new ksym list file with symbols needed by the current # set of modules. cat > "$new_ksyms_file" << EOT From d8821622c889d9dbc1a31b16e726717394954596 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 16 Mar 2018 16:37:11 +0900 Subject: [PATCH 11/29] kbuild: move 'scripts' target below Just a trivial change to prepare for the next commit. This target is still invisible from external module building. Signed-off-by: Masahiro Yamada --- Makefile | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 37574e3d21fe..5aa07da475bc 100644 --- a/Makefile +++ b/Makefile @@ -565,14 +565,6 @@ endif export KBUILD_MODULES KBUILD_BUILTIN ifeq ($(KBUILD_EXTMOD),) -# Additional helpers built in scripts/ -# Carefully list dependencies so we do not try to build scripts twice -# in parallel -PHONY += scripts -scripts: scripts_basic include/config/auto.conf include/config/tristate.conf \ - asm-generic gcc-plugins - $(Q)$(MAKE) $(build)=$(@) - # Objects we will link into vmlinux / subdirs we need to visit init-y := init/ drivers-y := drivers/ sound/ firmware/ @@ -1068,6 +1060,13 @@ endef include/config/kernel.release: include/config/auto.conf FORCE $(call filechk,kernel.release) +# Additional helpers built in scripts/ +# Carefully list dependencies so we do not try to build scripts twice +# in parallel +PHONY += scripts +scripts: scripts_basic include/config/auto.conf include/config/tristate.conf \ + asm-generic gcc-plugins + $(Q)$(MAKE) $(build)=$(@) # Things we need to do before we recursively start building the kernel # or the modules are listed in "prepare". From 07a422bb213adb7ee1afbb2347ce6922c60a558a Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 16 Mar 2018 16:37:12 +0900 Subject: [PATCH 12/29] kbuild: restore autoksyms.h touch to the top Makefile Commit d3fc425e819b ("kbuild: make sure autoksyms.h exists early") moved the code that touches autoksyms.h to scripts/kconfig/Makefile with obscure reason. From Nicolas' comment [1], he did not seem to be sure about the root cause. I guess I figured it out, so here is a fix-up I think is more correct. According to the error log in the original post [2], the build failed in scripts/mod/devicetable-offsets.c scripts/mod/Makefile is descended from scripts/Makefile, which is invoked from the top-level Makefile by the 'scripts' target. To build vmlinux and/or modules, Kbuild descend into $(vmlinux-dirs). This depends on 'prepare' and 'scripts' as follows: $(vmlinux-dirs): prepare scripts Because there is no dependency between 'prepare' and 'scripts', the parallel building can execute them simultaneously. 'prepare' depends on 'prepare1', which touched autoksyms.h, while 'scripts' descends into script/, then scripts/mod/, which needs if CONFIG_TRIM_UNUSED_KSYMS. It was the reason of the race. I am not happy to have unrelated code in the Kconfig Makefile, so getting it back to the top Makefile. I removed the standalone test target because I want to use it to create an empty autoksyms.h file. Here is a little improvement; unnecessary autoksyms.h is not created when CONFIG_TRIM_UNUSED_KSYMS is disabled. [1] https://lkml.org/lkml/2016/11/30/734 [2] https://lkml.org/lkml/2016/11/30/531 Signed-off-by: Masahiro Yamada Acked-by: Nicolas Pitre --- Makefile | 12 +++++++----- scripts/kconfig/Makefile | 2 -- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 5aa07da475bc..b65cfe3bcba8 100644 --- a/Makefile +++ b/Makefile @@ -1019,9 +1019,11 @@ ifdef CONFIG_TRIM_UNUSED_KSYMS "$(MAKE) -f $(srctree)/Makefile vmlinux" endif -# standalone target for easier testing -include/generated/autoksyms.h: FORCE - $(Q)$(CONFIG_SHELL) $(srctree)/scripts/adjust_autoksyms.sh true +autoksyms_h := $(if $(CONFIG_TRIM_UNUSED_KSYMS), include/generated/autoksyms.h) + +$(autoksyms_h): + $(Q)mkdir -p $(dir $@) + $(Q)touch $@ ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) @@ -1065,7 +1067,7 @@ include/config/kernel.release: include/config/auto.conf FORCE # in parallel PHONY += scripts scripts: scripts_basic include/config/auto.conf include/config/tristate.conf \ - asm-generic gcc-plugins + asm-generic gcc-plugins $(autoksyms_h) $(Q)$(MAKE) $(build)=$(@) # Things we need to do before we recursively start building the kernel @@ -1095,7 +1097,7 @@ endif # that need to depend on updated CONFIG_* values can be checked here. prepare2: prepare3 prepare-compiler-check outputmakefile asm-generic -prepare1: prepare2 $(version_h) include/generated/utsrelease.h \ +prepare1: prepare2 $(version_h) $(autoksyms_h) include/generated/utsrelease.h \ include/config/auto.conf $(cmd_crmodverdir) diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile index cb3ec53a7c29..eb139a17383c 100644 --- a/scripts/kconfig/Makefile +++ b/scripts/kconfig/Makefile @@ -38,8 +38,6 @@ nconfig: $(obj)/nconf # for external use. silentoldconfig: $(obj)/conf $(Q)mkdir -p include/config include/generated - $(Q)test -e include/generated/autoksyms.h || \ - touch include/generated/autoksyms.h $< $(silent) --$@ $(Kconfig) localyesconfig localmodconfig: $(obj)/streamline_config.pl $(obj)/conf From 1f50b80a093836743b5b579b3fab33eb2f6834f2 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 16 Mar 2018 16:37:13 +0900 Subject: [PATCH 13/29] kbuild: move CONFIG_TRIM_UNUSED_KSYMS code unneeded for external module The external module building does not need to parse this code because KBUILD_MODULES is always set anyway. Move this code inside the "ifeq ($(KBUILD_EXTMOD),) ... endif" block. Signed-off-by: Masahiro Yamada Acked-by: Nicolas Pitre --- Makefile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index b65cfe3bcba8..1e7f134dac0d 100644 --- a/Makefile +++ b/Makefile @@ -612,13 +612,6 @@ else include/config/auto.conf: ; endif # $(dot-config) -# For the kernel to actually contain only the needed exported symbols, -# we have to build modules as well to determine what those symbols are. -# (this can be evaluated only once include/config/auto.conf has been included) -ifdef CONFIG_TRIM_UNUSED_KSYMS - KBUILD_MODULES := 1 -endif - # The all: target is the default when no target is given on the # command line. # This allow a user to issue only 'make' to build a kernel including modules @@ -1019,6 +1012,13 @@ ifdef CONFIG_TRIM_UNUSED_KSYMS "$(MAKE) -f $(srctree)/Makefile vmlinux" endif +# For the kernel to actually contain only the needed exported symbols, +# we have to build modules as well to determine what those symbols are. +# (this can be evaluated only once include/config/auto.conf has been included) +ifdef CONFIG_TRIM_UNUSED_KSYMS + KBUILD_MODULES := 1 +endif + autoksyms_h := $(if $(CONFIG_TRIM_UNUSED_KSYMS), include/generated/autoksyms.h) $(autoksyms_h): From fbfa9be9904e2c0d0c97d860fd071089d21dd9be Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 16 Mar 2018 16:37:14 +0900 Subject: [PATCH 14/29] kbuild: move include/config/ksym/* to include/ksym/* The idea of using fixdep was inspired by Kconfig, but autoksyms belongs to a different group. So, I want to move those touched files under include/config/ksym/ to include/ksym/. The directory include/ksym/ can be removed by 'make clean' because it is meaningless for the external module building. Signed-off-by: Masahiro Yamada Acked-by: Nicolas Pitre --- .gitignore | 1 + Makefile | 2 +- scripts/Kbuild.include | 2 +- scripts/adjust_autoksyms.sh | 2 +- scripts/basic/fixdep.c | 8 ++++---- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 1be78fd8163b..85bcc2696442 100644 --- a/.gitignore +++ b/.gitignore @@ -87,6 +87,7 @@ modules.builtin # include/config include/generated +include/ksym arch/*/include/generated # stgit generated dirs diff --git a/Makefile b/Makefile index 1e7f134dac0d..416e6b1eb4b8 100644 --- a/Makefile +++ b/Makefile @@ -1336,7 +1336,7 @@ endif # CONFIG_MODULES # make distclean Remove editor backup files, patch leftover files and the like # Directories & files removed with 'make clean' -CLEAN_DIRS += $(MODVERDIR) +CLEAN_DIRS += $(MODVERDIR) include/ksym # Directories & files removed with 'make mrproper' MRPROPER_DIRS += include/config usr/include include/generated \ diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index f9c2f07442c5..cce31ee876b6 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -366,7 +366,7 @@ ksym_dep_filter = \ $(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_\(.*\) ===.*$$/KSYM_\1/p' + esac | tr ";" "\n" | sed -n 's/^.*=== __KSYM_\(.*\) ===.*$$/_\1/p' cmd_and_fixdep = \ $(echo-cmd) $(cmd_$(1)); \ diff --git a/scripts/adjust_autoksyms.sh b/scripts/adjust_autoksyms.sh index e0dd0d5148ec..f11cae6a041b 100755 --- a/scripts/adjust_autoksyms.sh +++ b/scripts/adjust_autoksyms.sh @@ -80,7 +80,7 @@ sort "$cur_ksyms_file" "$new_ksyms_file" | uniq -u | sed -n 's/^#define __KSYM_\(.*\) 1/\1/p' | tr "A-Z_" "a-z/" | while read sympath; do if [ -z "$sympath" ]; then continue; fi - depfile="include/config/ksym/${sympath}.h" + depfile="include/ksym/${sympath}.h" mkdir -p "$(dirname "$depfile")" touch "$depfile" echo $((count += 1)) diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index 449b68c4c90c..f387538c58bc 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -113,11 +113,11 @@ static void usage(void) /* * Print out a dependency path from a symbol name */ -static void print_config(const char *m, int slen) +static void print_dep(const char *m, int slen, const char *dir) { int c, i; - printf(" $(wildcard include/config/"); + printf(" $(wildcard %s/", dir); for (i = 0; i < slen; i++) { c = m[i]; if (c == '_') @@ -140,7 +140,7 @@ static void do_extra_deps(void) fprintf(stderr, "fixdep: bad data on stdin\n"); exit(1); } - print_config(buf, len - 1); + print_dep(buf, len - 1, "include/ksym"); } } @@ -208,7 +208,7 @@ static void use_config(const char *m, int slen) return; define_config(m, slen, hash); - print_config(m, slen); + print_dep(m, slen, "include/config"); } /* test if s ends in sub */ From 3fdc7d3fe4c04bab0305838cf662ae30051cc192 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 16 Mar 2018 16:37:15 +0900 Subject: [PATCH 15/29] kbuild: link vmlinux only once for CONFIG_TRIM_UNUSED_KSYMS If CONFIG_TRIM_UNUSED_KSYMS is enabled and the kernel is built from a pristine state, the vmlinux is linked twice. [1] A user runs 'make' [2] First build with empty autoksyms.h [3] adjust_autoksyms.sh updates autoksyms.h and recurses 'make vmlinux' --------(begin sub-make)-------- [4] Second build with new autoksyms.h [5] link-vmlinux.sh is invoked because vmlinux is missing ---------(end sub-make)--------- [6] link-vmlinux.sh is invoked again despite vmlinux is up-to-date. The reason of [6] is probably because Make already decided to update vmlinux at the time of [2] because vmlinux was missing when Make built up the dependency graph. Because if_changed is implemented based on $?, this issue can be narrowed down to how Make handles $?. You can test it with the following simple code: [Test Makefile] A: B @echo newer prerequisite: $? cp B A B: C cp C B touch A [Result] $ rm -f A B $ touch C $ make cp C B touch A newer prerequisite: B cp B A Here, 'A' has been touched in the recipe of 'B'. So, the dependency 'A: B' has already been met before the recipe of 'A' is executed. However, Make does not notice the fact that the recipe of 'B' also updates 'A' as a side-effect. The situation is similar in this case; the vmlinux has actually been updated in the vmlinux_prereq target. Make cannot predict this, so judges the vmlinux is old. link-vmlinux.sh is costly, so it is better to not run it when unneeded. Split CONFIG_TRIM_UNUSED_KSYMS recursion to a dedicated target. The reason of commit 2441e78b1919 ("kbuild: better abstract vmlinux sequential prerequisites") was to cater to CONFIG_BUILD_DOCSRC, but it was later removed by commit 184892925118 ("samples: move blackfin gptimers-example from Documentation"). Signed-off-by: Masahiro Yamada Acked-by: Nicolas Pitre --- Makefile | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 416e6b1eb4b8..646c5d99d7df 100644 --- a/Makefile +++ b/Makefile @@ -996,17 +996,9 @@ export KBUILD_ALLDIRS := $(sort $(filter-out arch/%,$(vmlinux-alldirs)) arch Doc vmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_INIT) $(KBUILD_VMLINUX_MAIN) $(KBUILD_VMLINUX_LIBS) -# Include targets which we want to execute sequentially if the rest of the -# kernel build went well. If CONFIG_TRIM_UNUSED_KSYMS is set, this might be -# evaluated more than once. -PHONY += vmlinux_prereq -vmlinux_prereq: $(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 +# Recurse until adjust_autoksyms.sh is satisfied +PHONY += autoksyms_recursive +autoksyms_recursive: $(vmlinux-deps) ifdef CONFIG_TRIM_UNUSED_KSYMS $(Q)$(CONFIG_SHELL) $(srctree)/scripts/adjust_autoksyms.sh \ "$(MAKE) -f $(srctree)/Makefile vmlinux" @@ -1032,7 +1024,13 @@ cmd_link-vmlinux = \ $(CONFIG_SHELL) $< $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) ; \ $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) -vmlinux: scripts/link-vmlinux.sh vmlinux_prereq $(vmlinux-deps) FORCE +vmlinux: scripts/link-vmlinux.sh autoksyms_recursive $(vmlinux-deps) FORCE +ifdef CONFIG_HEADERS_CHECK + $(Q)$(MAKE) -f $(srctree)/Makefile headers_check +endif +ifdef CONFIG_GDB_SCRIPTS + $(Q)ln -fsn $(abspath $(srctree)/scripts/gdb/vmlinux-gdb.py) +endif +$(call if_changed,link-vmlinux) # Build samples along the rest of the kernel From a670b0b4aed129dc11b465c1c330bfe9202023e5 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Sun, 18 Mar 2018 17:54:02 -0700 Subject: [PATCH 16/29] kbuild: Use ls(1) instead of stat(1) to obtain file size stat(1) is not standardized and different implementations have their own (conflicting) flags for querying the size of a file. ls(1) provides the same information (value of st.st_size) in the 5th column, except when the file is a character or block device. This output is standardized[0]. The -n option turns on -l, which writes lines formatted like "%s %u %s %s %u %s %s\n", , , , , , , but instead of writing the and , it writes the numeric owner and group IDs (this avoids /etc/passwd and /etc/group lookups as well as potential field splitting issues). The field is specified as "the value that would be returned for the file in the st_size field of struct stat". To avoid duplicating logic in several locations in the tree, create scripts/file-size.sh and update callers to use that instead of stat(1). [0] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html#tag_20_73_10 Signed-off-by: Michael Forney Signed-off-by: Masahiro Yamada --- arch/arm/boot/deflate_xip_data.sh | 2 +- arch/powerpc/boot/wrapper | 2 +- scripts/Makefile.lib | 2 +- scripts/file-size.sh | 4 ++++ scripts/link-vmlinux.sh | 4 ++-- 5 files changed, 9 insertions(+), 5 deletions(-) create mode 100755 scripts/file-size.sh diff --git a/arch/arm/boot/deflate_xip_data.sh b/arch/arm/boot/deflate_xip_data.sh index 1189598a25eb..07adfc734fa3 100755 --- a/arch/arm/boot/deflate_xip_data.sh +++ b/arch/arm/boot/deflate_xip_data.sh @@ -45,7 +45,7 @@ data_start=$(($__data_loc - $base_offset)) data_end=$(($_edata_loc - $base_offset)) # Make sure data occupies the last part of the file. -file_end=$(stat -c "%s" "$XIPIMAGE") +file_end=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" "$XIPIMAGE") if [ "$file_end" != "$data_end" ]; then printf "end of xipImage doesn't match with _edata_loc (%#x vs %#x)\n" \ $(($file_end + $base_offset)) $_edata_loc 2>&1 diff --git a/arch/powerpc/boot/wrapper b/arch/powerpc/boot/wrapper index 76fe3ccfd381..f9141eaec6ff 100755 --- a/arch/powerpc/boot/wrapper +++ b/arch/powerpc/boot/wrapper @@ -355,7 +355,7 @@ vmz="$tmpdir/`basename \"$kernel\"`.$ext" # Calculate the vmlinux.strip size ${CROSS}objcopy $objflags "$kernel" "$vmz.$$" -strip_size=$(stat -c %s $vmz.$$) +strip_size=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" "$vmz.$$") if [ -z "$cacheit" -o ! -f "$vmz$compression" -o "$vmz$compression" -ot "$kernel" ]; then # recompress the image if we need to diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 5fd60af76d98..ef592e993e92 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -329,7 +329,7 @@ dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp) size_append = printf $(shell \ dec_size=0; \ for F in $1; do \ - fsize=$$(stat -c "%s" $$F); \ + fsize=$$($(CONFIG_SHELL) $(srctree)/scripts/file-size.sh $$F); \ dec_size=$$(expr $$dec_size + $$fsize); \ done; \ printf "%08x\n" $$dec_size | \ diff --git a/scripts/file-size.sh b/scripts/file-size.sh new file mode 100755 index 000000000000..7eb7423416b5 --- /dev/null +++ b/scripts/file-size.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +set -- $(ls -dn "$1") +printf '%s\n' "$5" diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 08ca08e9105c..9045823c7be7 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -269,8 +269,8 @@ if [ -n "${CONFIG_KALLSYMS}" ]; then kallsyms .tmp_vmlinux2 .tmp_kallsyms2.o # step 3 - size1=$(stat -c "%s" .tmp_kallsyms1.o) - size2=$(stat -c "%s" .tmp_kallsyms2.o) + size1=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" .tmp_kallsyms1.o) + size2=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" .tmp_kallsyms2.o) if [ $size1 -ne $size2 ] || [ -n "${KALLSYMS_EXTRA_PASS}" ]; then kallsymso=.tmp_kallsyms3.o From 8cd0e46d3f0ce730a5c7d1e9e75765b24b72013a Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 19 Mar 2018 18:01:23 +0900 Subject: [PATCH 17/29] kbuild: remove unnecessary $(subst $(obj)/, , ...) in modname-multi In the context ... $(obj)/%.s: $(src)/%.c FORCE $(call if_changed_dep,cc_s_c) $(obj)/%.i: $(src)/%.c FORCE $(call if_changed_dep,cpp_i_c) $(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_dep) FORCE $(call cmd,force_checksrc) $(call if_changed_rule,cc_o_c) $(obj)/%.lst: $(src)/%.c FORCE $(call if_changed_dep,cc_lst_c) '$*' returns the stem of the target (the part of '%'), so $(obj)/ has already been ripped off. $(subst $(obj)/,,$*.o) is the same as $*.o Signed-off-by: Masahiro Yamada Reviewed-by: Cao jin --- scripts/Makefile.lib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index ef592e993e92..ca5b587c9c42 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -175,7 +175,7 @@ dtc_cpp_flags = -Wp,-MD,$(depfile).pre.tmp -nostdinc \ # Finds the multi-part object the current object will be linked into modname-multi = $(sort $(foreach m,$(multi-used),\ - $(if $(filter $(subst $(obj)/,,$*.o), $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=)))) + $(if $(filter $*.o, $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=)))) # Useful for describing the dependency of composite objects # Usage: From aeacb019b61c4ea7689085574bd03d2c0810f119 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 19 Mar 2018 18:01:24 +0900 Subject: [PATCH 18/29] kbuild: define KBUILD_MODNAME even if multiple modules share objects Currently, KBUILD_MODNAME is defined only when $(modname) contains just one word. If an object is shared among multiple modules, undefined KBUILD_MODNAME could cause a build error. For example, if CONFIG_DYNAMIC_DEBUG is enabled, any call of printk() populates .modname, then fails to build due to undefined KBUILD_MODNAME. Take the following code as an example: obj-m += foo.o obj-m += bar.o foo-objs := foo-bar-common.o foo-only.o bar-objs := foo-bar-common.o bar-only.o In this case, there is room for argument what to define for KBUILD_MODNAME when foo-bar-common.o is being compiled. "foo", "bar", or what else? One idea is to define colon-separated modules that share the object, in this case, "bar:foo" (modules are sorted alphabetically by $(sort ...)). Signed-off-by: Masahiro Yamada Reviewed-by: Cao jin --- scripts/Makefile.lib | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index ca5b587c9c42..5bdfb740047e 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -87,13 +87,9 @@ subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) # These flags are needed for modversions and compiling, so we define them here # $(modname_flags) defines KBUILD_MODNAME as the name of the module it will # end up in (or would, if it gets compiled in) -# Note: Files that end up in two or more modules are compiled without the -# KBUILD_MODNAME definition. The reason is that any made-up name would -# differ in different configs. name-fix = $(squote)$(quote)$(subst $(comma),_,$(subst -,_,$1))$(quote)$(squote) basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget)) -modname_flags = $(if $(filter 1,$(words $(modname))),\ - -DKBUILD_MODNAME=$(call name-fix,$(modname))) +modname_flags = -DKBUILD_MODNAME=$(call name-fix,$(modname)) orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \ $(ccflags-y) $(CFLAGS_$(basetarget).o) @@ -174,8 +170,10 @@ dtc_cpp_flags = -Wp,-MD,$(depfile).pre.tmp -nostdinc \ -undef -D__DTS__ # Finds the multi-part object the current object will be linked into -modname-multi = $(sort $(foreach m,$(multi-used),\ - $(if $(filter $*.o, $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=)))) +# If the object belongs to two or more multi-part objects, all of them are +# concatenated with a colon separator. +modname-multi = $(subst $(space),:,$(sort $(foreach m,$(multi-used),\ + $(if $(filter $*.o, $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=))))) # Useful for describing the dependency of composite objects # Usage: From c96a294eb6972742ed9d55f8d4afa7e0051c0942 Mon Sep 17 00:00:00 2001 From: Cao jin Date: Mon, 19 Mar 2018 18:01:25 +0900 Subject: [PATCH 19/29] kbuild: fix modname for composite modules Commit cf4f21938e13 ("kbuild: Allow to specify composite modules with modname-m") added modname-m support, but missed to update the corresponding multi-objs-m & modname-multi definition. Signed-off-by: Cao jin Signed-off-by: Masahiro Yamada --- scripts/Makefile.lib | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 5bdfb740047e..f855c2353b42 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -50,7 +50,7 @@ single-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m))) # Build list of the parts of our composite objects, our composite # objects depend on those (obviously) multi-objs-y := $(foreach m, $(multi-used-y), $($(m:.o=-objs)) $($(m:.o=-y))) -multi-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)) $($(m:.o=-y))) +multi-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))) # $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to # tell kbuild to descend @@ -173,7 +173,7 @@ dtc_cpp_flags = -Wp,-MD,$(depfile).pre.tmp -nostdinc \ # If the object belongs to two or more multi-part objects, all of them are # concatenated with a colon separator. modname-multi = $(subst $(space),:,$(sort $(foreach m,$(multi-used),\ - $(if $(filter $*.o, $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=))))) + $(if $(filter $*.o, $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$(m:.o=))))) # Useful for describing the dependency of composite objects # Usage: From fe852ac200311bcbbb0a8c84096e4cd44ea623d9 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 19 Mar 2018 18:01:26 +0900 Subject: [PATCH 20/29] kbuild: simplify modname calculation modname can be calculated much more simply. If modname-multi is empty, it is a single-used object. So, modname = $(basetarget). Otherwise, modname = $(modname-multi). Signed-off-by: Masahiro Yamada Reviewed-by: Cao jin --- scripts/Makefile.build | 12 +----------- scripts/Makefile.lib | 7 ------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 7cd2f4a6c2ac..f5858f609210 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -131,17 +131,7 @@ $(real-objs-m:.o=.lst): quiet_modtag := [M] $(obj-m) : quiet_modtag := [M] -# Default for not multi-part modules -modname = $(basetarget) - -$(multi-objs-m) : modname = $(modname-multi) -$(multi-objs-m:.o=.i) : modname = $(modname-multi) -$(multi-objs-m:.o=.s) : modname = $(modname-multi) -$(multi-objs-m:.o=.lst) : modname = $(modname-multi) -$(multi-objs-y) : modname = $(modname-multi) -$(multi-objs-y:.o=.i) : modname = $(modname-multi) -$(multi-objs-y:.o=.s) : modname = $(modname-multi) -$(multi-objs-y:.o=.lst) : modname = $(modname-multi) +modname = $(if $(modname-multi),$(modname-multi),$(basetarget)) quiet_cmd_cc_s_c = CC $(quiet_modtag) $@ cmd_cc_s_c = $(CC) $(c_flags) $(DISABLE_LTO) -fverbose-asm -S -o $@ $< diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index f855c2353b42..b5fa80a07c26 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -47,11 +47,6 @@ multi-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m multi-used := $(multi-used-y) $(multi-used-m) single-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m))) -# Build list of the parts of our composite objects, our composite -# objects depend on those (obviously) -multi-objs-y := $(foreach m, $(multi-used-y), $($(m:.o=-objs)) $($(m:.o=-y))) -multi-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))) - # $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to # tell kbuild to descend subdir-obj-y := $(filter %/built-in.a, $(obj-y)) @@ -80,8 +75,6 @@ real-objs-m := $(addprefix $(obj)/,$(real-objs-m)) single-used-m := $(addprefix $(obj)/,$(single-used-m)) multi-used-y := $(addprefix $(obj)/,$(multi-used-y)) multi-used-m := $(addprefix $(obj)/,$(multi-used-m)) -multi-objs-y := $(addprefix $(obj)/,$(multi-objs-y)) -multi-objs-m := $(addprefix $(obj)/,$(multi-objs-m)) subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) # These flags are needed for modversions and compiling, so we define them here From c0152e9a6b4484b44e77e0cc49c6c3b2e3417782 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 19 Mar 2018 18:01:27 +0900 Subject: [PATCH 21/29] kbuild: move modname and modname-multi close to modname_flags Just a cosmetic change to put related code close together. Signed-off-by: Masahiro Yamada Reviewed-by: Cao jin --- scripts/Makefile.build | 2 -- scripts/Makefile.lib | 14 ++++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index f5858f609210..93d05e30bdb1 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -131,8 +131,6 @@ $(real-objs-m:.o=.lst): quiet_modtag := [M] $(obj-m) : quiet_modtag := [M] -modname = $(if $(modname-multi),$(modname-multi),$(basetarget)) - quiet_cmd_cc_s_c = CC $(quiet_modtag) $@ cmd_cc_s_c = $(CC) $(c_flags) $(DISABLE_LTO) -fverbose-asm -S -o $@ $< diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index b5fa80a07c26..1e35c8bb11e0 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -77,6 +77,14 @@ multi-used-y := $(addprefix $(obj)/,$(multi-used-y)) multi-used-m := $(addprefix $(obj)/,$(multi-used-m)) subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) +# Finds the multi-part object the current object will be linked into. +# If the object belongs to two or more multi-part objects, all of them are +# concatenated with a colon separator. +modname-multi = $(subst $(space),:,$(sort $(foreach m,$(multi-used),\ + $(if $(filter $*.o, $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$(m:.o=))))) + +modname = $(if $(modname-multi),$(modname-multi),$(basetarget)) + # These flags are needed for modversions and compiling, so we define them here # $(modname_flags) defines KBUILD_MODNAME as the name of the module it will # end up in (or would, if it gets compiled in) @@ -162,12 +170,6 @@ dtc_cpp_flags = -Wp,-MD,$(depfile).pre.tmp -nostdinc \ $(addprefix -I,$(DTC_INCLUDE)) \ -undef -D__DTS__ -# Finds the multi-part object the current object will be linked into -# If the object belongs to two or more multi-part objects, all of them are -# concatenated with a colon separator. -modname-multi = $(subst $(space),:,$(sort $(foreach m,$(multi-used),\ - $(if $(filter $*.o, $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$(m:.o=))))) - # Useful for describing the dependency of composite objects # Usage: # $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add) From f5f336812c233976ad84995110c2266cd94c5cd0 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 19 Mar 2018 20:26:07 +0900 Subject: [PATCH 22/29] kbuild: rename real-objs-y/m to real-obj-y/m When I was refactoring Makefiles, I stupidly mistook 'real-obj-y' for 'real-objs-y' over and over again. Finally, I decide to rename it to 'real-obj-y'. This is consistent with 'obj-y', 'subdir-obj-y'. Signed-off-by: Masahiro Yamada --- scripts/Makefile.build | 24 ++++++++++++------------ scripts/Makefile.lib | 8 ++++---- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 93d05e30bdb1..8c1287f04bed 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -119,17 +119,17 @@ modkern_cflags = \ $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL)) quiet_modtag := $(empty) $(empty) -$(real-objs-m) : part-of-module := y -$(real-objs-m:.o=.i) : part-of-module := y -$(real-objs-m:.o=.s) : part-of-module := y -$(real-objs-m:.o=.lst): part-of-module := y +$(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-objs-m) : quiet_modtag := [M] -$(real-objs-m:.o=.i) : quiet_modtag := [M] -$(real-objs-m:.o=.s) : quiet_modtag := [M] -$(real-objs-m:.o=.lst): quiet_modtag := [M] +$(real-obj-m) : quiet_modtag := [M] +$(real-obj-m:.o=.i) : quiet_modtag := [M] +$(real-obj-m:.o=.s) : quiet_modtag := [M] +$(real-obj-m:.o=.lst): quiet_modtag := [M] -$(obj-m) : quiet_modtag := [M] +$(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 $@ $< @@ -333,8 +333,8 @@ $(obj)/%.lst: $(src)/%.c FORCE modkern_aflags := $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL) -$(real-objs-m) : modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE) -$(real-objs-m:.o=.s): modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE) +$(real-obj-m) : modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE) +$(real-obj-m:.o=.s): modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE) # .S file exports must have their C prototypes defined in asm/asm-prototypes.h # or a file that it includes, in order to get versioned symbols. We build a @@ -412,7 +412,7 @@ endif $(obj)/%.o: $(src)/%.S $(objtool_dep) FORCE $(call if_changed_rule,as_o_S) -targets += $(real-objs-y) $(real-objs-m) $(lib-y) +targets += $(real-obj-y) $(real-obj-m) $(lib-y) targets += $(extra-y) $(MAKECMDGOALS) $(always) # Linker scripts preprocessor (.lds.S -> .lds) diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 1e35c8bb11e0..975d436046bb 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -52,8 +52,8 @@ single-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m))) subdir-obj-y := $(filter %/built-in.a, $(obj-y)) # Replace multi-part objects by their individual parts, look at local dir only -real-objs-y := $(foreach m, $(filter-out $(subdir-obj-y), $(obj-y)), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) -real-objs-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)),$(m))) +real-obj-y := $(foreach m, $(filter-out $(subdir-obj-y), $(obj-y)), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) +real-obj-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)),$(m))) # DTB # If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built @@ -70,8 +70,8 @@ obj-y := $(addprefix $(obj)/,$(obj-y)) obj-m := $(addprefix $(obj)/,$(obj-m)) lib-y := $(addprefix $(obj)/,$(lib-y)) subdir-obj-y := $(addprefix $(obj)/,$(subdir-obj-y)) -real-objs-y := $(addprefix $(obj)/,$(real-objs-y)) -real-objs-m := $(addprefix $(obj)/,$(real-objs-m)) +real-obj-y := $(addprefix $(obj)/,$(real-obj-y)) +real-obj-m := $(addprefix $(obj)/,$(real-obj-m)) single-used-m := $(addprefix $(obj)/,$(single-used-m)) multi-used-y := $(addprefix $(obj)/,$(multi-used-y)) multi-used-m := $(addprefix $(obj)/,$(multi-used-m)) From f98fe47ce51dee6d97dd91bbeccdde23f043c754 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 19 Mar 2018 20:26:08 +0900 Subject: [PATCH 23/29] kbuild: link $(real-obj-y) instead of $(obj-y) into built-in.a In Kbuild, Makefiles can add the same object to obj-y multiple times. So, obj-y += foo.o obj-y += foo.o is fine. However, this is not true when the same object is added multiple times via composite objects. For example, obj-y += foo.o bar.o foo-objs := foo-bar-common.o foo-only.o bar-objs := foo-bar-common.o bar-only.o causes build error because two instances of foo-bar-common.o are linked into the vmlinux. Makefiles tend to invent ugly work-around, for example - lib/zstd/Makefile - drivers/net/ethernet/cavium/liquidio/Makefile The technique used in Kbuild to avoid the multiple definition error is to use $(filter $(obj-y), $^). Here, $^ lists the names of all the prerequisites with duplicated names removed. By replacing it with $(filter $(real-obj-y), $^) we can do likewise for composite objects. For built-in objects, we do not need to keep the composite object structure. We can simply expand them, and link $(real-obj-y) to built-in.a. Signed-off-by: Masahiro Yamada --- scripts/Makefile.build | 21 +++++++-------------- scripts/Makefile.lib | 7 +++---- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 8c1287f04bed..316cb95d7ff2 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -73,10 +73,10 @@ endif ifneq ($(strip $(lib-y) $(lib-m) $(lib-)),) lib-target := $(obj)/lib.a -obj-y += $(obj)/lib-ksyms.o +real-obj-y += $(obj)/lib-ksyms.o endif -ifneq ($(strip $(obj-y) $(need-builtin)),) +ifneq ($(strip $(real-obj-y) $(need-builtin)),) builtin-target := $(obj)/built-in.a endif @@ -412,7 +412,7 @@ endif $(obj)/%.o: $(src)/%.S $(objtool_dep) FORCE $(call if_changed_rule,as_o_S) -targets += $(real-obj-y) $(real-obj-m) $(lib-y) +targets += $(filter-out $(subdir-obj-y), $(real-obj-y)) $(real-obj-m) $(lib-y) targets += $(extra-y) $(MAKECMDGOALS) $(always) # Linker scripts preprocessor (.lds.S -> .lds) @@ -455,12 +455,12 @@ cmd_make_empty_builtin = rm -f $@; $(AR) rcSTP$(KBUILD_ARFLAGS) quiet_cmd_link_o_target = AR $@ # If the list of objects to link is empty, just create an empty built-in.a -cmd_link_o_target = $(if $(strip $(obj-y)),\ - $(cmd_make_builtin) $@ $(filter $(obj-y), $^) \ +cmd_link_o_target = $(if $(strip $(real-obj-y)),\ + $(cmd_make_builtin) $@ $(filter $(real-obj-y), $^) \ $(cmd_secanalysis),\ $(cmd_make_empty_builtin) $@) -$(builtin-target): $(obj-y) FORCE +$(builtin-target): $(real-obj-y) FORCE $(call if_changed,link_o_target) targets += $(builtin-target) @@ -534,23 +534,16 @@ $($(subst $(obj)/,,$(@:.o=-m)))), $^) cmd_link_multi-link = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps) $(cmd_secanalysis) -quiet_cmd_link_multi-y = AR $@ -cmd_link_multi-y = rm -f $@; $(AR) rcSTP$(KBUILD_ARFLAGS) $@ $(link_multi_deps) - quiet_cmd_link_multi-m = LD [M] $@ cmd_link_multi-m = $(cmd_link_multi-link) -$(multi-used-y): FORCE - $(call if_changed,link_multi-y) -$(call multi_depend, $(multi-used-y), .o, -objs -y) - $(multi-used-m): FORCE $(call if_changed,link_multi-m) @{ echo $(@:.o=.ko); echo $(link_multi_deps); \ $(cmd_undef_syms); } > $(MODVERDIR)/$(@F:.o=.mod) $(call multi_depend, $(multi-used-m), .o, -objs -y -m) -targets += $(multi-used-y) $(multi-used-m) +targets += $(multi-used-m) targets := $(filter-out $(PHONY), $(targets)) # Descending diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 975d436046bb..194ae707167d 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -51,8 +51,9 @@ single-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m))) # tell kbuild to descend subdir-obj-y := $(filter %/built-in.a, $(obj-y)) -# Replace multi-part objects by their individual parts, look at local dir only -real-obj-y := $(foreach m, $(filter-out $(subdir-obj-y), $(obj-y)), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) +# Replace multi-part objects by their individual parts, +# including built-in.a from subdirectories +real-obj-y := $(foreach m, $(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) real-obj-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)),$(m))) # DTB @@ -66,14 +67,12 @@ extra-y := $(addprefix $(obj)/,$(extra-y)) always := $(addprefix $(obj)/,$(always)) targets := $(addprefix $(obj)/,$(targets)) modorder := $(addprefix $(obj)/,$(modorder)) -obj-y := $(addprefix $(obj)/,$(obj-y)) obj-m := $(addprefix $(obj)/,$(obj-m)) lib-y := $(addprefix $(obj)/,$(lib-y)) subdir-obj-y := $(addprefix $(obj)/,$(subdir-obj-y)) real-obj-y := $(addprefix $(obj)/,$(real-obj-y)) real-obj-m := $(addprefix $(obj)/,$(real-obj-m)) single-used-m := $(addprefix $(obj)/,$(single-used-m)) -multi-used-y := $(addprefix $(obj)/,$(multi-used-y)) multi-used-m := $(addprefix $(obj)/,$(multi-used-m)) subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) From dc35da16a2e23db04822f0129cd5b28b7b0e72b4 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 19 Mar 2018 20:26:09 +0900 Subject: [PATCH 24/29] lib: zstd: clean up Makefile for simpler composite object handling Now, Kbuild nicely handles composite objects to avoid multiple definition. Makefiles can simply add the same objects multiple times across composite objects. Signed-off-by: Masahiro Yamada --- lib/zstd/Makefile | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/lib/zstd/Makefile b/lib/zstd/Makefile index dd0a359c135b..7920cbbfeae9 100644 --- a/lib/zstd/Makefile +++ b/lib/zstd/Makefile @@ -3,16 +3,7 @@ obj-$(CONFIG_ZSTD_DECOMPRESS) += zstd_decompress.o ccflags-y += -O3 -# Object files unique to zstd_compress and zstd_decompress -zstd_compress-y := fse_compress.o huf_compress.o compress.o -zstd_decompress-y := huf_decompress.o decompress.o - -# These object files are shared between the modules. -# Always add them to zstd_compress. -# Unless both zstd_compress and zstd_decompress are built in -# then also add them to zstd_decompress. -zstd_compress-y += entropy_common.o fse_decompress.o zstd_common.o - -ifneq ($(CONFIG_ZSTD_COMPRESS)$(CONFIG_ZSTD_DECOMPRESS),yy) - zstd_decompress-y += entropy_common.o fse_decompress.o zstd_common.o -endif +zstd_compress-y := fse_compress.o huf_compress.o compress.o \ + entropy_common.o fse_decompress.o zstd_common.o +zstd_decompress-y := huf_decompress.o decompress.o \ + entropy_common.o fse_decompress.o zstd_common.o From f605005a50fc1443a14b4e8c9c1727881f8f96ae Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 19 Mar 2018 20:26:10 +0900 Subject: [PATCH 25/29] net: liquidio: clean up Makefile for simpler composite object handling Now, Kbuild nicely handles composite objects to avoid multiple definition. Makefiles can simply add the same objects multiple times across composite objects. Signed-off-by: Masahiro Yamada --- drivers/net/ethernet/cavium/liquidio/Makefile | 53 ++++++------------- 1 file changed, 17 insertions(+), 36 deletions(-) diff --git a/drivers/net/ethernet/cavium/liquidio/Makefile b/drivers/net/ethernet/cavium/liquidio/Makefile index e3fc4645cd8a..bc9937502043 100644 --- a/drivers/net/ethernet/cavium/liquidio/Makefile +++ b/drivers/net/ethernet/cavium/liquidio/Makefile @@ -2,42 +2,23 @@ # # Cavium Liquidio ethernet device driver # + +common-objs := lio_ethtool.o \ + lio_core.o \ + request_manager.o \ + response_manager.o \ + octeon_device.o \ + cn66xx_device.o \ + cn68xx_device.o \ + cn23xx_pf_device.o \ + cn23xx_vf_device.o \ + octeon_mailbox.o \ + octeon_mem_ops.o \ + octeon_droq.o \ + octeon_nic.o + obj-$(CONFIG_LIQUIDIO) += liquidio.o - -liquidio-$(CONFIG_LIQUIDIO) += lio_ethtool.o \ - lio_core.o \ - request_manager.o \ - response_manager.o \ - octeon_device.o \ - cn66xx_device.o \ - cn68xx_device.o \ - cn23xx_pf_device.o \ - cn23xx_vf_device.o \ - octeon_mailbox.o \ - octeon_mem_ops.o \ - octeon_droq.o \ - octeon_nic.o - -liquidio-objs := lio_main.o octeon_console.o lio_vf_rep.o $(liquidio-y) +liquidio-y := lio_main.o octeon_console.o lio_vf_rep.o $(common-objs) obj-$(CONFIG_LIQUIDIO_VF) += liquidio_vf.o - -ifeq ($(CONFIG_LIQUIDIO)$(CONFIG_LIQUIDIO_VF), yy) - liquidio_vf-objs := lio_vf_main.o -else -liquidio_vf-$(CONFIG_LIQUIDIO_VF) += lio_ethtool.o \ - lio_core.o \ - request_manager.o \ - response_manager.o \ - octeon_device.o \ - cn66xx_device.o \ - cn68xx_device.o \ - cn23xx_pf_device.o \ - cn23xx_vf_device.o \ - octeon_mailbox.o \ - octeon_mem_ops.o \ - octeon_droq.o \ - octeon_nic.o - -liquidio_vf-objs := lio_vf_main.o $(liquidio_vf-y) -endif +liquidio_vf-y := lio_vf_main.o $(common-objs) From 7657f60e8ffad587fabc74873b5f42083a60c3cf Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 19 Mar 2018 20:26:11 +0900 Subject: [PATCH 26/29] kbuild: remove partial section mismatch detection for built-in.a When built-in.o was incrementally linked with 'ld -r', the section mismatch analysis for the individual built-in.o was possible when CONFIG_DEBUG_SECTION_MISMATCH was enabled. With the migration to the thin archive, built-in.a (former, built-in.o) is no longer an ELF file. So, the modpost does nothing useful. scripts/mod/modpost.c just checks the header to bail out, as follows: /* Is this a valid ELF file? */ if ((hdr->e_ident[EI_MAG0] != ELFMAG0) || (hdr->e_ident[EI_MAG1] != ELFMAG1) || (hdr->e_ident[EI_MAG2] != ELFMAG2) || (hdr->e_ident[EI_MAG3] != ELFMAG3)) { /* Not an ELF file - silently ignore it */ return 0; } We have the full analysis in the final link stage anyway, so we would not miss the section mismatching. I do not see a good reason to require extra linking only for the purpose of the per-directory analysis. Just get rid of this part. Signed-off-by: Masahiro Yamada --- scripts/Makefile.build | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 316cb95d7ff2..66461e9323b4 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -456,8 +456,7 @@ quiet_cmd_link_o_target = AR $@ # If the list of objects to link is empty, just create an empty built-in.a cmd_link_o_target = $(if $(strip $(real-obj-y)),\ - $(cmd_make_builtin) $@ $(filter $(real-obj-y), $^) \ - $(cmd_secanalysis),\ + $(cmd_make_builtin) $@ $(filter $(real-obj-y), $^), \ $(cmd_make_empty_builtin) $@) $(builtin-target): $(real-obj-y) FORCE From 5e18f0290f2eccb0f64e87fbfca6395f11985b4b Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 19 Mar 2018 20:26:12 +0900 Subject: [PATCH 27/29] kbuild: clean up archive rule of built-in.a With the incremental linking entirely dropped, we can simplify the Makefile. While I am here, I renamed cmd_link_o_target to cmd_ar_builtin. Signed-off-by: Masahiro Yamada --- scripts/Makefile.build | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 66461e9323b4..e5c1aa347554 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -450,17 +450,12 @@ ifdef builtin-target # makes them small and fast, but unable to be used by the linker. # scripts/link-vmlinux.sh builds an aggregate built-in.a with a symbol # table and index. -cmd_make_builtin = rm -f $@; $(AR) rcSTP$(KBUILD_ARFLAGS) -cmd_make_empty_builtin = rm -f $@; $(AR) rcSTP$(KBUILD_ARFLAGS) -quiet_cmd_link_o_target = AR $@ - -# If the list of objects to link is empty, just create an empty built-in.a -cmd_link_o_target = $(if $(strip $(real-obj-y)),\ - $(cmd_make_builtin) $@ $(filter $(real-obj-y), $^), \ - $(cmd_make_empty_builtin) $@) +quiet_cmd_ar_builtin = AR $@ + cmd_ar_builtin = rm -f $@; \ + $(AR) rcSTP$(KBUILD_ARFLAGS) $@ $(filter $(real-obj-y), $^) $(builtin-target): $(real-obj-y) FORCE - $(call if_changed,link_o_target) + $(call if_changed,ar_builtin) targets += $(builtin-target) endif # builtin-target From 127668cf766d0ede207457f9f5f26f5e40ce4127 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 19 Mar 2018 20:26:13 +0900 Subject: [PATCH 28/29] kbuild: clean up link rule of composite modules cmd_link_multi-link is used only for cmd_link_multi-m. Signed-off-by: Masahiro Yamada --- scripts/Makefile.build | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index e5c1aa347554..77cce68c4d63 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -526,10 +526,8 @@ $($(subst $(obj)/,,$(@:.o=-objs))) \ $($(subst $(obj)/,,$(@:.o=-y))) \ $($(subst $(obj)/,,$(@:.o=-m)))), $^) -cmd_link_multi-link = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps) $(cmd_secanalysis) - quiet_cmd_link_multi-m = LD [M] $@ -cmd_link_multi-m = $(cmd_link_multi-link) +cmd_link_multi-m = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps) $(cmd_secanalysis) $(multi-used-m): FORCE $(call if_changed,link_multi-m) From a95b37e20db9a2b05354eec009b2188523a21c8e Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 27 Mar 2018 21:52:50 +0900 Subject: [PATCH 29/29] kbuild: get out of Since commit 28128c61e08e ("kconfig.h: Include compiler types to avoid missed struct attributes"), pulls in kernel-space headers to unrelated places. Commit 0f9da844d877 ("MIPS: boot: Define __ASSEMBLY__ for its.S build") suppress the build error by defining __ASSEMBLY__, but ITS (i.e. DTS) is not assembly, and should not include in the first place. Looking at arch/s390/tools/Makefile, host programs gen_facilities and gen_opcode_table now pull in as well. The motivation for that commit was to define necessary attributes before any struct is defined. Obviously, this happens only in C. It is enough to include only when compiling C files, and only when compiling kernel space. Move the include to c_flags. Signed-off-by: Masahiro Yamada --- include/linux/kconfig.h | 3 --- scripts/Makefile.lib | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/include/linux/kconfig.h b/include/linux/kconfig.h index dcde9471897d..cc8fa109cfa3 100644 --- a/include/linux/kconfig.h +++ b/include/linux/kconfig.h @@ -70,7 +70,4 @@ */ #define IS_ENABLED(option) __or(IS_BUILTIN(option), IS_MODULE(option)) -/* Make sure we always have all types and struct attributes defined. */ -#include - #endif /* __LINUX_KCONFIG_H */ diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 194ae707167d..e3215b7652ee 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -152,6 +152,7 @@ __cpp_flags = $(call flags,_cpp_flags) endif c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ + -include $(srctree)/include/linux/compiler_types.h \ $(__c_flags) $(modkern_cflags) \ $(basename_flags) $(modname_flags)