Skip to content

Commit

Permalink
Merge tag 'kbuild-v6.2' of git://git.kernel.org/pub/scm/linux/kernel/…
Browse files Browse the repository at this point in the history
…git/masahiroy/linux-kbuild

Pull Kbuild updates from Masahiro Yamada:

 - Support zstd-compressed debug info

 - Allow W=1 builds to detect objects shared among multiple modules

 - Add srcrpm-pkg target to generate a source RPM package

 - Make the -s option detection work for future GNU Make versions

 - Add -Werror to KBUILD_CPPFLAGS when CONFIG_WERROR=y

 - Allow W=1 builds to detect -Wundef warnings in any preprocessed files

 - Raise the minimum supported version of binutils to 2.25

 - Use $(intcmp ...) to compare integers if GNU Make >= 4.4 is used

 - Use $(file ...) to read a file if GNU Make >= 4.2 is used

 - Print error if GNU Make older than 3.82 is used

 - Allow modpost to detect section mismatches with Clang LTO

 - Include vmlinuz.efi into kernel tarballs for arm64 CONFIG_EFI_ZBOOT=y

* tag 'kbuild-v6.2' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: (29 commits)
  buildtar: fix tarballs with EFI_ZBOOT enabled
  modpost: Include '.text.*' in TEXT_SECTIONS
  padata: Mark padata_work_init() as __ref
  kbuild: ensure Make >= 3.82 is used
  kbuild: refactor the prerequisites of the modpost rule
  kbuild: change module.order to list *.o instead of *.ko
  kbuild: use .NOTINTERMEDIATE for future GNU Make versions
  kconfig: refactor Makefile to reduce process forks
  kbuild: add read-file macro
  kbuild: do not sort after reading modules.order
  kbuild: add test-{ge,gt,le,lt} macros
  Documentation: raise minimum supported version of binutils to 2.25
  kbuild: add -Wundef to KBUILD_CPPFLAGS for W=1 builds
  kbuild: move -Werror from KBUILD_CFLAGS to KBUILD_CPPFLAGS
  kbuild: Port silent mode detection to future gnu make.
  init/version.c: remove #include <generated/utsrelease.h>
  firmware_loader: remove #include <generated/utsrelease.h>
  modpost: Mark uuid_le type to be suitable only for MEI
  kbuild: add ability to make source rpm buildable using koji
  kbuild: warn objects shared among multiple modules
  ...
  • Loading branch information
torvalds committed Dec 19, 2022
2 parents 158738e + 731c4ea commit 6feb57c
Show file tree
Hide file tree
Showing 42 changed files with 286 additions and 156 deletions.
4 changes: 2 additions & 2 deletions Documentation/process/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Rust (optional) 1.62.0 rustc --version
bindgen (optional) 0.56.0 bindgen --version
GNU make 3.82 make --version
bash 4.2 bash --version
binutils 2.23 ld -v
binutils 2.25 ld -v
flex 2.5.35 flex --version
bison 2.0 bison --version
pahole 1.16 pahole --version
Expand Down Expand Up @@ -119,7 +119,7 @@ Bash 4.2 or newer is needed.
Binutils
--------

Binutils 2.23 or newer is needed to build the kernel.
Binutils 2.25 or newer is needed to build the kernel.

pkg-config
----------
Expand Down
26 changes: 19 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ NAME = Hurr durr I'ma ninja sloth
# Comments in this file are targeted only to the developer, do not
# expect to learn how to build the kernel reading this file.

ifeq ($(filter undefine,$(.FEATURES)),)
$(error GNU Make >= 3.82 is required. Your Make version is $(MAKE_VERSION))
endif

$(if $(filter __%, $(MAKECMDGOALS)), \
$(error targets prefixed with '__' are only for internal use))

Expand Down Expand Up @@ -93,10 +97,17 @@ endif

# If the user is running make -s (silent mode), suppress echoing of
# commands
# make-4.0 (and later) keep single letter options in the 1st word of MAKEFLAGS.

ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
quiet=silent_
KBUILD_VERBOSE = 0
ifeq ($(filter 3.%,$(MAKE_VERSION)),)
silence:=$(findstring s,$(firstword -$(MAKEFLAGS)))
else
silence:=$(findstring s,$(filter-out --%,$(MAKEFLAGS)))
endif

ifeq ($(silence),s)
quiet=silent_
KBUILD_VERBOSE = 0
endif

export quiet Q KBUILD_VERBOSE
Expand Down Expand Up @@ -369,7 +380,7 @@ else # !mixed-build
include $(srctree)/scripts/Kbuild.include

# Read KERNELRELEASE from include/config/kernel.release (if it exists)
KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
KERNELRELEASE = $(call read-file, include/config/kernel.release)
KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION

Expand Down Expand Up @@ -859,7 +870,8 @@ stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong

KBUILD_CFLAGS += $(stackp-flags-y)

KBUILD_CFLAGS-$(CONFIG_WERROR) += -Werror
KBUILD_CPPFLAGS-$(CONFIG_WERROR) += -Werror
KBUILD_CPPFLAGS += $(KBUILD_CPPFLAGS-y)
KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds

KBUILD_RUSTFLAGS-$(CONFIG_WERROR) += -Dwarnings
Expand Down Expand Up @@ -990,7 +1002,7 @@ KBUILD_LDFLAGS += -mllvm -import-instr-limit=5
# Check for frame size exceeding threshold during prolog/epilog insertion
# when using lld < 13.0.0.
ifneq ($(CONFIG_FRAME_WARN),0)
ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 130000; echo $$?),0)
ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 130000),y)
KBUILD_LDFLAGS += -plugin-opt=-warn-stack-size=$(CONFIG_FRAME_WARN)
endif
endif
Expand Down Expand Up @@ -1560,7 +1572,7 @@ __modinst_pre:
rm -f $(MODLIB)/build ; \
ln -s $(CURDIR) $(MODLIB)/build ; \
fi
@sed 's:^:kernel/:' modules.order > $(MODLIB)/modules.order
@sed 's:^\(.*\)\.o$$:kernel/\1.ko:' modules.order > $(MODLIB)/modules.order
@cp -f modules.builtin $(MODLIB)/
@cp -f $(objtree)/modules.builtin.modinfo $(MODLIB)/

Expand Down
2 changes: 1 addition & 1 deletion arch/riscv/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ else
endif

ifeq ($(CONFIG_LD_IS_LLD),y)
ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 150000; echo $$?),0)
ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 150000),y)
KBUILD_CFLAGS += -mno-relax
KBUILD_AFLAGS += -mno-relax
ifndef CONFIG_AS_IS_LLVM
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ endif
KBUILD_LDFLAGS += -m elf_$(UTS_MACHINE)

ifdef CONFIG_LTO_CLANG
ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 130000; echo $$?),0)
ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 130000),y)
KBUILD_LDFLAGS += -plugin-opt=-stack-alignment=$(if $(CONFIG_X86_32),4,8)
endif
endif
Expand Down
2 changes: 0 additions & 2 deletions drivers/base/firmware_loader/firmware.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include <linux/list.h>
#include <linux/completion.h>

#include <generated/utsrelease.h>

/**
* enum fw_opt - options to control firmware loading behaviour
*
Expand Down
1 change: 0 additions & 1 deletion init/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include <linux/printk.h>
#include <linux/uts.h>
#include <linux/utsname.h>
#include <generated/utsrelease.h>
#include <linux/proc_ns.h>

static int __init early_hostname(char *arg)
Expand Down
12 changes: 10 additions & 2 deletions kernel/padata.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,16 @@ static struct padata_work *padata_work_alloc(void)
return pw;
}

static void padata_work_init(struct padata_work *pw, work_func_t work_fn,
void *data, int flags)
/*
* This function is marked __ref because this function may be optimized in such
* a way that it directly refers to work_fn's address, which causes modpost to
* complain when work_fn is marked __init. This scenario was observed with clang
* LTO, where padata_work_init() was optimized to refer directly to
* padata_mt_helper() because the calls to padata_work_init() with other work_fn
* values were eliminated or inlined.
*/
static void __ref padata_work_init(struct padata_work *pw, work_func_t work_fn,
void *data, int flags)
{
if (flags & PADATA_WORK_ONSTACK)
INIT_WORK_ONSTACK(&pw->pw_work, work_fn);
Expand Down
29 changes: 27 additions & 2 deletions lib/Kconfig.debug
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,21 @@ config DEBUG_INFO_REDUCED
DEBUG_INFO build and compile times are reduced too.
Only works with newer gcc versions.

config DEBUG_INFO_COMPRESSED
bool "Compressed debugging information"
choice
prompt "Compressed Debug information"
help
Compress the resulting debug info. Results in smaller debug info sections,
but requires that consumers are able to decompress the results.

If unsure, choose DEBUG_INFO_COMPRESSED_NONE.

config DEBUG_INFO_COMPRESSED_NONE
bool "Don't compress debug information"
help
Don't compress debug info sections.

config DEBUG_INFO_COMPRESSED_ZLIB
bool "Compress debugging information with zlib"
depends on $(cc-option,-gz=zlib)
depends on $(ld-option,--compress-debug-sections=zlib)
help
Expand All @@ -327,6 +340,18 @@ config DEBUG_INFO_COMPRESSED
preferable to setting $KDEB_COMPRESS to "none" which would be even
larger.

config DEBUG_INFO_COMPRESSED_ZSTD
bool "Compress debugging information with zstd"
depends on $(cc-option,-gz=zstd)
depends on $(ld-option,--compress-debug-sections=zstd)
help
Compress the debug information using zstd. This may provide better
compression than zlib, for about the same time costs, but requires newer
toolchain support. Requires GCC 13.0+ or Clang 16.0+, binutils 2.40+, and
zstd.

endchoice # "Compressed Debug information"

config DEBUG_INFO_SPLIT
bool "Produce split debuginfo in .dwo files"
depends on $(cc-option,-gsplit-dwarf)
Expand Down
48 changes: 45 additions & 3 deletions scripts/Kbuild.include
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@ empty :=
space := $(empty) $(empty)
space_escape := _-_SPACE_-_
pound := \#
define newline


endef

###
# Comparison macros.
# Usage: $(call test-lt, $(CONFIG_LLD_VERSION), 150000)
#
# Use $(intcmp ...) if supported. (Make >= 4.4)
# Otherwise, fall back to the 'test' shell command.
ifeq ($(intcmp 1,0,,,y),y)
test-ge = $(intcmp $(strip $1)0, $(strip $2)0,,y,y)
test-gt = $(intcmp $(strip $1)0, $(strip $2)0,,,y)
else
test-ge = $(shell test $(strip $1)0 -ge $(strip $2)0 && echo y)
test-gt = $(shell test $(strip $1)0 -gt $(strip $2)0 && echo y)
endif
test-le = $(call test-ge, $2, $1)
test-lt = $(call test-gt, $2, $1)

###
# Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o
Expand Down Expand Up @@ -40,6 +60,21 @@ escsq = $(subst $(squote),'\$(squote)',$1)
# Quote a string to pass it to C files. foo => '"foo"'
stringify = $(squote)$(quote)$1$(quote)$(squote)

###
# The path to Kbuild or Makefile. Kbuild has precedence over Makefile.
kbuild-dir = $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
kbuild-file = $(or $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Makefile)

###
# Read a file, replacing newlines with spaces
#
# Make 4.2 or later can read a file by using its builtin function.
ifneq ($(filter-out 3.% 4.0 4.1, $(MAKE_VERSION)),)
read-file = $(subst $(newline),$(space),$(file < $1))
else
read-file = $(shell cat $1 2>/dev/null)
endif

###
# Easy method for doing a status message
kecho := :
Expand Down Expand Up @@ -150,9 +185,6 @@ endif
make-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1)))))

# Find any prerequisites that are newer than target or that do not exist.
# (This is not true for now; $? should contain any non-existent prerequisites,
# but it does not work as expected when .SECONDARY is present. This seems a bug
# of GNU Make.)
# PHONY targets skipped in both cases.
newer-prereqs = $(filter-out $(PHONY),$?)

Expand Down Expand Up @@ -228,4 +260,14 @@ endif
.DELETE_ON_ERROR:

# do not delete intermediate files automatically
#
# .NOTINTERMEDIATE is more correct, but only available on newer Make versions.
# Make 4.4 introduced .NOTINTERMEDIATE, and it appears in .FEATURES, but the
# global .NOTINTERMEDIATE does not work. We can use it on Make > 4.4.
# Use .SECONDARY for older Make versions, but "newer-prereq" cannot detect
# deleted files.
ifneq ($(and $(filter notintermediate, $(.FEATURES)),$(filter-out 4.4,$(MAKE_VERSION))),)
.NOTINTERMEDIATE:
else
.SECONDARY:
endif
6 changes: 3 additions & 3 deletions scripts/Makefile.asm-generic
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ PHONY := all
all:

src := $(subst /generated,,$(obj))
-include $(src)/Kbuild

include $(srctree)/scripts/Kbuild.include
-include $(kbuild-file)

# $(generic)/Kbuild lists mandatory-y. Exclude um since it is a special case.
ifneq ($(SRCARCH),um)
include $(srctree)/$(generic)/Kbuild
endif

include $(srctree)/scripts/Kbuild.include

redundant := $(filter $(mandatory-y) $(generated-y), $(generic-y))
redundant += $(foreach f, $(generic-y), $(if $(wildcard $(srctree)/$(src)/$(f)),$(f)))
redundant := $(sort $(redundant))
Expand Down
14 changes: 8 additions & 6 deletions scripts/Makefile.build
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ subdir-ccflags-y :=

include $(srctree)/scripts/Kbuild.include
include $(srctree)/scripts/Makefile.compiler

# The filename Kbuild has precedence over Makefile
kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
include $(or $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Makefile)

include $(kbuild-file)
include $(srctree)/scripts/Makefile.lib

# Do not include hostprogs rules unless needed.
Expand Down Expand Up @@ -226,6 +222,10 @@ endif

cmd_check_local_export = $(srctree)/scripts/check-local-export $@

ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),)
cmd_warn_shared_object = $(if $(word 2, $(modname-multi)),$(warning $(kbuild-file): $*.o is added to multiple modules: $(modname-multi)))
endif

define rule_cc_o_c
$(call cmd_and_fixdep,cc_o_c)
$(call cmd,gen_ksymdeps)
Expand All @@ -235,6 +235,7 @@ define rule_cc_o_c
$(call cmd,gen_objtooldep)
$(call cmd,gen_symversions_c)
$(call cmd,record_mcount)
$(call cmd,warn_shared_object)
endef

define rule_as_o_S
Expand All @@ -243,6 +244,7 @@ define rule_as_o_S
$(call cmd,check_local_export)
$(call cmd,gen_objtooldep)
$(call cmd,gen_symversions_S)
$(call cmd,warn_shared_object)
endef

# Built-in and composite module parts
Expand Down Expand Up @@ -433,7 +435,7 @@ $(obj)/built-in.a: $(real-obj-y) FORCE
# modules.order unless contained modules are updated.

cmd_modules_order = { $(foreach m, $(real-prereqs), \
$(if $(filter %/modules.order, $m), cat $m, echo $(patsubst %.o,%.ko,$m));) :; } \
$(if $(filter %/modules.order, $m), cat $m, echo $m);) :; } \
> $@

$(obj)/modules.order: $(obj-m) FORCE
Expand Down
5 changes: 1 addition & 4 deletions scripts/Makefile.clean
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ PHONY := __clean
__clean:

include $(srctree)/scripts/Kbuild.include

# The filename Kbuild has precedence over Makefile
kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
include $(or $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Makefile)
include $(kbuild-file)

# Figure out what we need to build from the various variables
# ==========================================================================
Expand Down
4 changes: 2 additions & 2 deletions scripts/Makefile.compiler
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ cc-disable-warning = $(call try-run,\

# gcc-min-version
# Usage: cflags-$(call gcc-min-version, 70100) += -foo
gcc-min-version = $(shell [ $(CONFIG_GCC_VERSION)0 -ge $(1)0 ] && echo y)
gcc-min-version = $(call test-ge, $(CONFIG_GCC_VERSION), $1)

# clang-min-version
# Usage: cflags-$(call clang-min-version, 110000) += -foo
clang-min-version = $(shell [ $(CONFIG_CLANG_VERSION)0 -ge $(1)0 ] && echo y)
clang-min-version = $(call test-ge, $(CONFIG_CLANG_VERSION), $1)

# ld-option
# Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y)
Expand Down
6 changes: 5 additions & 1 deletion scripts/Makefile.debug
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ else
DEBUG_RUSTFLAGS += -Cdebuginfo=2
endif

ifdef CONFIG_DEBUG_INFO_COMPRESSED
ifdef CONFIG_DEBUG_INFO_COMPRESSED_ZLIB
DEBUG_CFLAGS += -gz=zlib
KBUILD_AFLAGS += -gz=zlib
KBUILD_LDFLAGS += --compress-debug-sections=zlib
else ifdef CONFIG_DEBUG_INFO_COMPRESSED_ZSTD
DEBUG_CFLAGS += -gz=zstd
KBUILD_AFLAGS += -gz=zstd
KBUILD_LDFLAGS += --compress-debug-sections=zstd
endif

KBUILD_CFLAGS += $(DEBUG_CFLAGS)
Expand Down
2 changes: 1 addition & 1 deletion scripts/Makefile.dtbinst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ __dtbs_install:

include include/config/auto.conf
include $(srctree)/scripts/Kbuild.include
include $(src)/Makefile
include $(kbuild-file)

dtbs := $(addprefix $(dst)/, $(dtb-y) $(if $(CONFIG_OF_ALL_DTBS),$(dtb-)))
subdirs := $(addprefix $(obj)/, $(subdir-y) $(subdir-m))
Expand Down
1 change: 1 addition & 0 deletions scripts/Makefile.extrawarn
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ KBUILD_CFLAGS += -Wno-sign-compare
KBUILD_CFLAGS += -Wno-type-limits
KBUILD_CFLAGS += -Wno-shift-negative-value

KBUILD_CPPFLAGS += -Wundef
KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1

else
Expand Down
Loading

0 comments on commit 6feb57c

Please sign in to comment.