Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3b24b837 authored by Linus Torvalds's avatar Linus Torvalds
Browse files
Pull Kbuild updates from Masahiro Yamada:

 - add a shell script to get Clang version

 - improve portability of build scripts

 - drop always-enabled CONFIG_THIN_ARCHIVE and remove unused code

 - rename built-in.o which is now thin archive to built-in.a

 - process clean/build targets one by one to get along with -j option

 - simplify ld-option

 - improve building with CONFIG_TRIM_UNUSED_KSYMS

 - define KBUILD_MODNAME even for objects shared among multiple modules

 - avoid linking multiple instances of same objects from composite
   objects

 - move <linux/compiler_types.h> to c_flags to include it only for C
   files

 - clean-up various Makefiles

* tag 'kbuild-v4.17' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: (29 commits)
  kbuild: get <linux/compiler_types.h> out of <linux/kconfig.h>
  kbuild: clean up link rule of composite modules
  kbuild: clean up archive rule of built-in.a
  kbuild: remove partial section mismatch detection for built-in.a
  net: liquidio: clean up Makefile for simpler composite object handling
  lib: zstd: clean up Makefile for simpler composite object handling
  kbuild: link $(real-obj-y) instead of $(obj-y) into built-in.a
  kbuild: rename real-objs-y/m to real-obj-y/m
  kbuild: move modname and modname-multi close to modname_flags
  kbuild: simplify modname calculation
  kbuild: fix modname for composite modules
  kbuild: define KBUILD_MODNAME even if multiple modules share objects
  kbuild: remove unnecessary $(subst $(obj)/, , ...) in modname-multi
  kbuild: Use ls(1) instead of stat(1) to obtain file size
  kbuild: link vmlinux only once for CONFIG_TRIM_UNUSED_KSYMS
  kbuild: move include/config/ksym/* to include/ksym/*
  kbuild: move CONFIG_TRIM_UNUSED_KSYMS code unneeded for external module
  kbuild: restore autoksyms.h touch to the top Makefile
  kbuild: move 'scripts' target below
  kbuild: remove wrong 'touch' in adjust_autoksyms.sh
  ...
parents 0734e00e a95b37e2
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -87,6 +87,7 @@ modules.builtin
#
#
include/config
include/config
include/generated
include/generated
include/ksym
arch/*/include/generated
arch/*/include/generated


# stgit generated dirs
# stgit generated dirs
+0 −4
Original line number Original line Diff line number Diff line
@@ -50,10 +50,6 @@ LDFLAGS_MODULE
--------------------------------------------------
--------------------------------------------------
Additional options used for $(LD) when linking modules.
Additional options used for $(LD) when linking modules.


LDFLAGS_vmlinux
--------------------------------------------------
Additional options passed to final link of vmlinux.

KBUILD_VERBOSE
KBUILD_VERBOSE
--------------------------------------------------
--------------------------------------------------
Set the kbuild verbosity. Can be assigned same values as "V=...".
Set the kbuild verbosity. Can be assigned same values as "V=...".
+14 −14
Original line number Original line Diff line number Diff line
@@ -153,12 +153,18 @@ more details, with real examples.
	configuration.
	configuration.


	Kbuild compiles all the $(obj-y) files.  It then calls
	Kbuild compiles all the $(obj-y) files.  It then calls
	"$(LD) -r" to merge these files into one built-in.o file.
	"$(AR) rcSTP" to merge these files into one built-in.a file.
	built-in.o is later linked into vmlinux by the parent Makefile.
	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.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 order of files in $(obj-y) is significant.  Duplicates in
	the lists are allowed: the first instance will be linked into
	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
	Link order is significant, because certain functions
	(module_init() / __initcall) will be called during boot in the
	(module_init() / __initcall) will be called during boot in the
@@ -222,7 +228,7 @@ more details, with real examples.
	Note: Of course, when you are building objects into the kernel,
	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,
	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
	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
--- 3.4 Objects which export symbols


@@ -232,7 +238,7 @@ more details, with real examples.
--- 3.5 Library file goals - lib-y
--- 3.5 Library file goals - lib-y


	Objects listed with obj-* are used for modules, or
	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
	There is also the possibility to list objects that will
	be included in a library, lib.a.
	be included in a library, lib.a.
	All objects listed with lib-y are combined in a single
	All objects listed with lib-y are combined in a single
@@ -244,7 +250,7 @@ more details, with real examples.


	Note that the same kbuild makefile may list files to be built-in
	Note that the same kbuild makefile may list files to be built-in
	and to be part of a library. Therefore the same directory
	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:
	Example:
		#arch/x86/lib/Makefile
		#arch/x86/lib/Makefile
@@ -831,12 +837,6 @@ When kbuild executes, the following steps are followed (roughly):
	Note: ldflags-y can be used to further customise
	Note: ldflags-y can be used to further customise
	the flags used. See chapter 3.7.
	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	Options for $(LD) when linking vmlinux


	LDFLAGS_vmlinux is used to specify additional flags to pass to
	LDFLAGS_vmlinux is used to specify additional flags to pass to
@@ -986,7 +986,7 @@ When kbuild executes, the following steps are followed (roughly):


	$(head-y) lists objects to be linked first in vmlinux.
	$(head-y) lists objects to be linked first in vmlinux.
	$(libs-y) lists directories where a lib.a archive can be located.
	$(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.
	located.


	$(init-y) objects will be located after $(head-y).
	$(init-y) objects will be located after $(head-y).
@@ -1071,7 +1071,7 @@ When kbuild executes, the following steps are followed (roughly):
		extra-y := head.o init_task.o
		extra-y := head.o init_task.o


	In this example, extra-y is used to list object files that
	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
--- 6.7 Commands useful for building a boot image
+1 −1
Original line number Original line Diff line number Diff line
@@ -78,7 +78,7 @@ Binutils
--------
--------


The build system has, as of 4.13, switched to using thin archives (`ar T`)
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.
This requires binutils 2.20 or newer.


Flex
Flex
+49 −40
Original line number Original line Diff line number Diff line
@@ -35,7 +35,7 @@ unexport GREP_OPTIONS
# Most importantly: sub-Makefiles should only ever modify files in
# Most importantly: sub-Makefiles should only ever modify files in
# their own directory. If in some directory we have a dependency on
# 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
# 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
# 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
# after that we are sure that everything which is in that other dir
# is now up to date.
# is now up to date.
@@ -220,7 +220,8 @@ export srctree objtree VPATH
version_h := include/generated/uapi/linux/version.h
version_h := include/generated/uapi/linux/version.h
old_version_h := include/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 \
			 cscope gtags TAGS tags help% %docs check% coccicheck \
			 $(version_h) headers_% archheaders archscripts \
			 $(version_h) headers_% archheaders archscripts \
			 kernelversion %src-pkg
			 kernelversion %src-pkg
@@ -243,6 +244,14 @@ ifeq ($(KBUILD_EXTMOD),)
                endif
                endif
        endif
        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
# install and modules_install need also be processed one by one
ifneq ($(filter install,$(MAKECMDGOALS)),)
ifneq ($(filter install,$(MAKECMDGOALS)),)
        ifneq ($(filter modules_install,$(MAKECMDGOALS)),)
        ifneq ($(filter modules_install,$(MAKECMDGOALS)),)
@@ -418,6 +427,7 @@ KBUILD_CFLAGS_KERNEL :=
KBUILD_AFLAGS_MODULE  := -DMODULE
KBUILD_AFLAGS_MODULE  := -DMODULE
KBUILD_CFLAGS_MODULE  := -DMODULE
KBUILD_CFLAGS_MODULE  := -DMODULE
KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds
KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds
LDFLAGS :=
GCC_PLUGINS_CFLAGS :=
GCC_PLUGINS_CFLAGS :=


export ARCH SRCARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC
export ARCH SRCARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC
@@ -556,14 +566,6 @@ endif
export KBUILD_MODULES KBUILD_BUILTIN
export KBUILD_MODULES KBUILD_BUILTIN


ifeq ($(KBUILD_EXTMOD),)
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
# Objects we will link into vmlinux / subdirs we need to visit
init-y		:= init/
init-y		:= init/
drivers-y	:= drivers/ sound/ firmware/
drivers-y	:= drivers/ sound/ firmware/
@@ -611,13 +613,6 @@ else
include/config/auto.conf: ;
include/config/auto.conf: ;
endif # $(dot-config)
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
# The all: target is the default when no target is given on the
# command line.
# command line.
# This allow a user to issue only 'make' to build a kernel including modules
# This allow a user to issue only 'make' to build a kernel including modules
@@ -984,13 +979,13 @@ vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
vmlinux-alldirs	:= $(sort $(vmlinux-dirs) $(patsubst %/,%,$(filter %/, \
vmlinux-alldirs	:= $(sort $(vmlinux-dirs) $(patsubst %/,%,$(filter %/, \
		     $(init-) $(core-) $(drivers-) $(net-) $(libs-) $(virt-))))
		     $(init-) $(core-) $(drivers-) $(net-) $(libs-) $(virt-))))


init-y		:= $(patsubst %/, %/built-in.o, $(init-y))
init-y		:= $(patsubst %/, %/built-in.a, $(init-y))
core-y		:= $(patsubst %/, %/built-in.o, $(core-y))
core-y		:= $(patsubst %/, %/built-in.a, $(core-y))
drivers-y	:= $(patsubst %/, %/built-in.o, $(drivers-y))
drivers-y	:= $(patsubst %/, %/built-in.a, $(drivers-y))
net-y		:= $(patsubst %/, %/built-in.o, $(net-y))
net-y		:= $(patsubst %/, %/built-in.a, $(net-y))
libs-y1		:= $(patsubst %/, %/lib.a, $(libs-y))
libs-y1		:= $(patsubst %/, %/lib.a, $(libs-y))
libs-y2		:= $(filter-out %.a, $(patsubst %/, %/built-in.o, $(libs-y)))
libs-y2		:= $(patsubst %/, %/built-in.a, $(filter-out %.a, $(libs-y)))
virt-y		:= $(patsubst %/, %/built-in.o, $(virt-y))
virt-y		:= $(patsubst %/, %/built-in.a, $(virt-y))


# Externally visible symbols (used by link-vmlinux.sh)
# Externally visible symbols (used by link-vmlinux.sh)
export KBUILD_VMLINUX_INIT := $(head-y) $(init-y)
export KBUILD_VMLINUX_INIT := $(head-y) $(init-y)
@@ -1003,25 +998,26 @@ export KBUILD_ALLDIRS := $(sort $(filter-out arch/%,$(vmlinux-alldirs)) arch Doc


vmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_INIT) $(KBUILD_VMLINUX_MAIN) $(KBUILD_VMLINUX_LIBS)
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
# Recurse until adjust_autoksyms.sh is satisfied
# kernel build went well. If CONFIG_TRIM_UNUSED_KSYMS is set, this might be
PHONY += autoksyms_recursive
# evaluated more than once.
autoksyms_recursive: $(vmlinux-deps)
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
ifdef CONFIG_TRIM_UNUSED_KSYMS
ifdef CONFIG_TRIM_UNUSED_KSYMS
	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/adjust_autoksyms.sh \
	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/adjust_autoksyms.sh \
	  "$(MAKE) -f $(srctree)/Makefile vmlinux"
	  "$(MAKE) -f $(srctree)/Makefile vmlinux"
endif
endif


# standalone target for easier testing
# For the kernel to actually contain only the needed exported symbols,
include/generated/autoksyms.h: FORCE
# we have to build modules as well to determine what those symbols are.
	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/adjust_autoksyms.sh true
# (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):
	$(Q)mkdir -p $(dir $@)
	$(Q)touch $@


ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)


@@ -1030,7 +1026,13 @@ cmd_link-vmlinux = \
	$(CONFIG_SHELL) $< $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) ;    \
	$(CONFIG_SHELL) $< $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) ;    \
	$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
	$(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)
	+$(call if_changed,link-vmlinux)


# Build samples along the rest of the kernel
# Build samples along the rest of the kernel
@@ -1060,6 +1062,13 @@ endef
include/config/kernel.release: include/config/auto.conf FORCE
include/config/kernel.release: include/config/auto.conf FORCE
	$(call filechk,kernel.release)
	$(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 $(autoksyms_h)
	$(Q)$(MAKE) $(build)=$(@)


# Things we need to do before we recursively start building the kernel
# Things we need to do before we recursively start building the kernel
# or the modules are listed in "prepare".
# or the modules are listed in "prepare".
@@ -1088,7 +1097,7 @@ endif
# that need to depend on updated CONFIG_* values can be checked here.
# that need to depend on updated CONFIG_* values can be checked here.
prepare2: prepare3 prepare-compiler-check outputmakefile asm-generic
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
                   include/config/auto.conf
	$(cmd_crmodverdir)
	$(cmd_crmodverdir)


@@ -1327,7 +1336,7 @@ endif # CONFIG_MODULES
# make distclean Remove editor backup files, patch leftover files and the like
# make distclean Remove editor backup files, patch leftover files and the like


# Directories & files removed with 'make clean'
# Directories & files removed with 'make clean'
CLEAN_DIRS  += $(MODVERDIR)
CLEAN_DIRS  += $(MODVERDIR) include/ksym


# Directories & files removed with 'make mrproper'
# Directories & files removed with 'make mrproper'
MRPROPER_DIRS  += include/config usr/include include/generated          \
MRPROPER_DIRS  += include/config usr/include include/generated          \
Loading