Skip to content

Commit 746b25b

Browse files
committed
Merge tag 'kbuild-v5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild
Pull Kbuild updates from Masahiro Yamada: - Support 'make compile_commands.json' to generate the compilation database more easily, avoiding stale entries - Support 'make clang-analyzer' and 'make clang-tidy' for static checks using clang-tidy - Preprocess scripts/modules.lds.S to allow CONFIG options in the module linker script - Drop cc-option tests from compiler flags supported by our minimal GCC/Clang versions - Use always 12-digits commit hash for CONFIG_LOCALVERSION_AUTO=y - Use sha1 build id for both BFD linker and LLD - Improve deb-pkg for reproducible builds and rootless builds - Remove stale, useless scripts/namespace.pl - Turn -Wreturn-type warning into error - Fix build error of deb-pkg when CONFIG_MODULES=n - Replace 'hostname' command with more portable 'uname -n' - Various Makefile cleanups * tag 'kbuild-v5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: (34 commits) kbuild: Use uname for LINUX_COMPILE_HOST detection kbuild: Only add -fno-var-tracking-assignments for old GCC versions kbuild: remove leftover comment for filechk utility treewide: remove DISABLE_LTO kbuild: deb-pkg: clean up package name variables kbuild: deb-pkg: do not build linux-headers package if CONFIG_MODULES=n kbuild: enforce -Werror=return-type scripts: remove namespace.pl builddeb: Add support for all required debian/rules targets builddeb: Enable rootless builds builddeb: Pass -n to gzip for reproducible packages kbuild: split the build log of kallsyms kbuild: explicitly specify the build id style scripts/setlocalversion: make git describe output more reliable kbuild: remove cc-option test of -Werror=date-time kbuild: remove cc-option test of -fno-stack-check kbuild: remove cc-option test of -fno-strict-overflow kbuild: move CFLAGS_{KASAN,UBSAN,KCSAN} exports to relevant Makefiles kbuild: remove redundant CONFIG_KASAN check from scripts/Makefile.kasan kbuild: do not create built-in objects for external module builds ...
2 parents 2b71482 + 1e66d50 commit 746b25b

51 files changed

Lines changed: 512 additions & 752 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Documentation/process/submit-checklist.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ and elsewhere regarding submitting Linux kernel patches.
5353

5454
9) Check cleanly with sparse.
5555

56-
10) Use ``make checkstack`` and ``make namespacecheck`` and fix any problems
57-
that they find.
56+
10) Use ``make checkstack`` and fix any problems that it finds.
5857

5958
.. note::
6059

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4273,6 +4273,7 @@ W: https://clangbuiltlinux.github.io/
42734273
B: https://github.com/ClangBuiltLinux/linux/issues
42744274
C: irc://chat.freenode.net/clangbuiltlinux
42754275
F: Documentation/kbuild/llvm.rst
4276+
F: scripts/clang-tools/
42764277
K: \b(?i:clang|llvm)\b
42774278

42784279
CLEANCACHE API

Makefile

Lines changed: 70 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -497,15 +497,14 @@ KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE
497497
KBUILD_CFLAGS := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
498498
-fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \
499499
-Werror=implicit-function-declaration -Werror=implicit-int \
500-
-Wno-format-security \
500+
-Werror=return-type -Wno-format-security \
501501
-std=gnu89
502502
KBUILD_CPPFLAGS := -D__KERNEL__
503503
KBUILD_AFLAGS_KERNEL :=
504504
KBUILD_CFLAGS_KERNEL :=
505505
KBUILD_AFLAGS_MODULE := -DMODULE
506506
KBUILD_CFLAGS_MODULE := -DMODULE
507507
KBUILD_LDFLAGS_MODULE :=
508-
export KBUILD_LDS_MODULE := $(srctree)/scripts/module-common.lds
509508
KBUILD_LDFLAGS :=
510509
CLANG_FLAGS :=
511510

@@ -517,7 +516,6 @@ export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE
517516

518517
export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS
519518
export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
520-
export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE CFLAGS_UBSAN CFLAGS_KCSAN
521519
export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
522520
export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
523521
export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
@@ -634,7 +632,7 @@ endif
634632
# in addition to whatever we do anyway.
635633
# Just "make" or "make all" shall build modules as well
636634

637-
ifneq ($(filter all modules nsdeps,$(MAKECMDGOALS)),)
635+
ifneq ($(filter all modules nsdeps %compile_commands.json clang-%,$(MAKECMDGOALS)),)
638636
KBUILD_MODULES := 1
639637
endif
640638

@@ -707,8 +705,11 @@ $(KCONFIG_CONFIG):
707705
# This exploits the 'multi-target pattern rule' trick.
708706
# The syncconfig should be executed only once to make all the targets.
709707
# (Note: use the grouped target '&:' when we bump to GNU Make 4.3)
708+
quiet_cmd_syncconfig = SYNC $@
709+
cmd_syncconfig = $(MAKE) -f $(srctree)/Makefile syncconfig
710+
710711
%/config/auto.conf %/config/auto.conf.cmd %/generated/autoconf.h: $(KCONFIG_CONFIG)
711-
$(Q)$(MAKE) -f $(srctree)/Makefile syncconfig
712+
+$(call cmd,syncconfig)
712713
else # !may-sync-config
713714
# External modules and some install targets need include/generated/autoconf.h
714715
# and include/config/auto.conf but do not care if they are up-to-date.
@@ -813,16 +814,22 @@ KBUILD_CFLAGS += -ftrivial-auto-var-init=zero
813814
KBUILD_CFLAGS += -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang
814815
endif
815816

816-
DEBUG_CFLAGS := $(call cc-option, -fno-var-tracking-assignments)
817+
# Workaround for GCC versions < 5.0
818+
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801
819+
ifdef CONFIG_CC_IS_GCC
820+
DEBUG_CFLAGS := $(call cc-ifversion, -lt, 0500, $(call cc-option, -fno-var-tracking-assignments))
821+
endif
817822

818823
ifdef CONFIG_DEBUG_INFO
824+
819825
ifdef CONFIG_DEBUG_INFO_SPLIT
820826
DEBUG_CFLAGS += -gsplit-dwarf
821827
else
822828
DEBUG_CFLAGS += -g
823829
endif
830+
824831
KBUILD_AFLAGS += -Wa,-gdwarf-2
825-
endif
832+
826833
ifdef CONFIG_DEBUG_INFO_DWARF4
827834
DEBUG_CFLAGS += -gdwarf-4
828835
endif
@@ -838,6 +845,8 @@ KBUILD_AFLAGS += -gz=zlib
838845
KBUILD_LDFLAGS += --compress-debug-sections=zlib
839846
endif
840847

848+
endif # CONFIG_DEBUG_INFO
849+
841850
KBUILD_CFLAGS += $(DEBUG_CFLAGS)
842851
export DEBUG_CFLAGS
843852

@@ -919,16 +928,16 @@ KBUILD_CFLAGS += $(call cc-disable-warning, restrict)
919928
KBUILD_CFLAGS += $(call cc-disable-warning, maybe-uninitialized)
920929

921930
# disable invalid "can't wrap" optimizations for signed / pointers
922-
KBUILD_CFLAGS += $(call cc-option,-fno-strict-overflow)
931+
KBUILD_CFLAGS += -fno-strict-overflow
923932

924933
# Make sure -fstack-check isn't enabled (like gentoo apparently did)
925-
KBUILD_CFLAGS += $(call cc-option,-fno-stack-check,)
934+
KBUILD_CFLAGS += -fno-stack-check
926935

927936
# conserve stack if available
928937
KBUILD_CFLAGS += $(call cc-option,-fconserve-stack)
929938

930939
# Prohibit date/time macros, which would make the build non-deterministic
931-
KBUILD_CFLAGS += $(call cc-option,-Werror=date-time)
940+
KBUILD_CFLAGS += -Werror=date-time
932941

933942
# enforce correct pointer usage
934943
KBUILD_CFLAGS += $(call cc-option,-Werror=incompatible-pointer-types)
@@ -964,8 +973,8 @@ KBUILD_CPPFLAGS += $(KCPPFLAGS)
964973
KBUILD_AFLAGS += $(KAFLAGS)
965974
KBUILD_CFLAGS += $(KCFLAGS)
966975

967-
KBUILD_LDFLAGS_MODULE += --build-id
968-
LDFLAGS_vmlinux += --build-id
976+
KBUILD_LDFLAGS_MODULE += --build-id=sha1
977+
LDFLAGS_vmlinux += --build-id=sha1
969978

970979
ifeq ($(CONFIG_STRIP_ASM_SYMS),y)
971980
LDFLAGS_vmlinux += $(call ld-option, -X,)
@@ -1377,7 +1386,7 @@ endif
13771386
# using awk while concatenating to the final file.
13781387

13791388
PHONY += modules
1380-
modules: $(if $(KBUILD_BUILTIN),vmlinux) modules_check
1389+
modules: $(if $(KBUILD_BUILTIN),vmlinux) modules_check modules_prepare
13811390
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
13821391

13831392
PHONY += modules_check
@@ -1394,6 +1403,7 @@ targets += modules.order
13941403
# Target to prepare building external modules
13951404
PHONY += modules_prepare
13961405
modules_prepare: prepare
1406+
$(Q)$(MAKE) $(build)=scripts scripts/module.lds
13971407

13981408
# Target to install modules
13991409
PHONY += modules_install
@@ -1452,7 +1462,8 @@ endif # CONFIG_MODULES
14521462

14531463
# Directories & files removed with 'make clean'
14541464
CLEAN_FILES += include/ksym vmlinux.symvers \
1455-
modules.builtin modules.builtin.modinfo modules.nsdeps
1465+
modules.builtin modules.builtin.modinfo modules.nsdeps \
1466+
compile_commands.json
14561467

14571468
# Directories & files removed with 'make mrproper'
14581469
MRPROPER_FILES += include/config include/generated \
@@ -1558,12 +1569,13 @@ help:
15581569
echo ''
15591570
@echo 'Static analysers:'
15601571
@echo ' checkstack - Generate a list of stack hogs'
1561-
@echo ' namespacecheck - Name space analysis on compiled kernel'
15621572
@echo ' versioncheck - Sanity check on version.h usage'
15631573
@echo ' includecheck - Check for duplicate included header files'
15641574
@echo ' export_report - List the usages of all exported symbols'
15651575
@echo ' headerdep - Detect inclusion cycles in headers'
15661576
@echo ' coccicheck - Check with Coccinelle'
1577+
@echo ' clang-analyzer - Check with clang static analyzer'
1578+
@echo ' clang-tidy - Check with clang-tidy'
15671579
@echo ''
15681580
@echo 'Tools:'
15691581
@echo ' nsdeps - Generate missing symbol namespace dependencies'
@@ -1681,14 +1693,18 @@ else # KBUILD_EXTMOD
16811693
# Install the modules built in the module directory
16821694
# Assumes install directory is already created
16831695

1684-
# We are always building modules
1696+
# We are always building only modules.
1697+
KBUILD_BUILTIN :=
16851698
KBUILD_MODULES := 1
16861699

16871700
build-dirs := $(KBUILD_EXTMOD)
16881701
PHONY += modules
1689-
modules: descend
1702+
modules: $(MODORDER)
16901703
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
16911704

1705+
$(MODORDER): descend
1706+
@:
1707+
16921708
PHONY += modules_install
16931709
modules_install: _emodinst_ _emodinst_post
16941710

@@ -1702,8 +1718,12 @@ PHONY += _emodinst_post
17021718
_emodinst_post: _emodinst_
17031719
$(call cmd,depmod)
17041720

1721+
compile_commands.json: $(extmod-prefix)compile_commands.json
1722+
PHONY += compile_commands.json
1723+
17051724
clean-dirs := $(KBUILD_EXTMOD)
1706-
clean: rm-files := $(KBUILD_EXTMOD)/Module.symvers $(KBUILD_EXTMOD)/modules.nsdeps
1725+
clean: rm-files := $(KBUILD_EXTMOD)/Module.symvers $(KBUILD_EXTMOD)/modules.nsdeps \
1726+
$(KBUILD_EXTMOD)/compile_commands.json
17071727

17081728
PHONY += help
17091729
help:
@@ -1715,7 +1735,9 @@ help:
17151735
@echo ' clean - remove generated files in module directory only'
17161736
@echo ''
17171737

1718-
PHONY += prepare
1738+
# no-op for external module builds
1739+
PHONY += prepare modules_prepare
1740+
17191741
endif # KBUILD_EXTMOD
17201742

17211743
# Single targets
@@ -1748,7 +1770,7 @@ MODORDER := .modules.tmp
17481770
endif
17491771

17501772
PHONY += single_modpost
1751-
single_modpost: $(single-no-ko)
1773+
single_modpost: $(single-no-ko) modules_prepare
17521774
$(Q){ $(foreach m, $(single-ko), echo $(extmod-prefix)$m;) } > $(MODORDER)
17531775
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
17541776

@@ -1816,10 +1838,37 @@ nsdeps: export KBUILD_NSDEPS=1
18161838
nsdeps: modules
18171839
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/nsdeps
18181840

1841+
# Clang Tooling
1842+
# ---------------------------------------------------------------------------
1843+
1844+
quiet_cmd_gen_compile_commands = GEN $@
1845+
cmd_gen_compile_commands = $(PYTHON3) $< -a $(AR) -o $@ $(filter-out $<, $(real-prereqs))
1846+
1847+
$(extmod-prefix)compile_commands.json: scripts/clang-tools/gen_compile_commands.py \
1848+
$(if $(KBUILD_EXTMOD),,$(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS)) \
1849+
$(if $(CONFIG_MODULES), $(MODORDER)) FORCE
1850+
$(call if_changed,gen_compile_commands)
1851+
1852+
targets += $(extmod-prefix)compile_commands.json
1853+
1854+
PHONY += clang-tidy clang-analyzer
1855+
1856+
ifdef CONFIG_CC_IS_CLANG
1857+
quiet_cmd_clang_tools = CHECK $<
1858+
cmd_clang_tools = $(PYTHON3) $(srctree)/scripts/clang-tools/run-clang-tools.py $@ $<
1859+
1860+
clang-tidy clang-analyzer: $(extmod-prefix)compile_commands.json
1861+
$(call cmd,clang_tools)
1862+
else
1863+
clang-tidy clang-analyzer:
1864+
@echo "$@ requires CC=clang" >&2
1865+
@false
1866+
endif
1867+
18191868
# Scripts to check various things for consistency
18201869
# ---------------------------------------------------------------------------
18211870

1822-
PHONY += includecheck versioncheck coccicheck namespacecheck export_report
1871+
PHONY += includecheck versioncheck coccicheck export_report
18231872

18241873
includecheck:
18251874
find $(srctree)/* $(RCS_FIND_IGNORE) \
@@ -1834,9 +1883,6 @@ versioncheck:
18341883
coccicheck:
18351884
$(Q)$(BASH) $(srctree)/scripts/$@
18361885

1837-
namespacecheck:
1838-
$(PERL) $(srctree)/scripts/namespace.pl
1839-
18401886
export_report:
18411887
$(PERL) $(srctree)/scripts/export_report.pl
18421888

arch/arm/Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ endif
2020
# linker. All sections should be explicitly named in the linker script.
2121
LDFLAGS_vmlinux += $(call ld-option, --orphan-handling=warn)
2222

23-
ifeq ($(CONFIG_ARM_MODULE_PLTS),y)
24-
KBUILD_LDS_MODULE += $(srctree)/arch/arm/kernel/module.lds
25-
endif
26-
2723
GZFLAGS :=-9
2824
#KBUILD_CFLAGS +=-pipe
2925

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifdef CONFIG_ARM_MODULE_PLTS
23
SECTIONS {
34
.plt : { BYTE(0) }
45
.init.plt : { BYTE(0) }
56
}
7+
#endif

arch/arm/vdso/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ccflags-y += -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO32
1919
ldflags-$(CONFIG_CPU_ENDIAN_BE8) := --be8
2020
ldflags-y := -Bsymbolic --no-undefined -soname=linux-vdso.so.1 \
2121
-z max-page-size=4096 -nostdlib -shared $(ldflags-y) \
22-
--hash-style=sysv --build-id \
22+
--hash-style=sysv --build-id=sha1 \
2323
-T
2424

2525
obj-$(CONFIG_VDSO) += vdso.o

arch/arm64/Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,6 @@ endif
126126

127127
CHECKFLAGS += -D__aarch64__
128128

129-
ifeq ($(CONFIG_ARM64_MODULE_PLTS),y)
130-
KBUILD_LDS_MODULE += $(srctree)/arch/arm64/kernel/module.lds
131-
endif
132-
133129
ifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_REGS),y)
134130
KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
135131
CC_FLAGS_FTRACE := -fpatchable-function-entry=2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
#ifdef CONFIG_ARM64_MODULE_PLTS
12
SECTIONS {
23
.plt (NOLOAD) : { BYTE(0) }
34
.init.plt (NOLOAD) : { BYTE(0) }
45
.text.ftrace_trampoline (NOLOAD) : { BYTE(0) }
56
}
7+
#endif

arch/arm64/kernel/vdso/Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@ btildflags-$(CONFIG_ARM64_BTI_KERNEL) += -z force-bti
2424
# routines, as x86 does (see 6f121e548f83 ("x86, vdso: Reimplement vdso.so
2525
# preparation in build-time C")).
2626
ldflags-y := -shared -nostdlib -soname=linux-vdso.so.1 --hash-style=sysv \
27-
-Bsymbolic $(call ld-option, --no-eh-frame-hdr) --build-id -n \
27+
-Bsymbolic $(call ld-option, --no-eh-frame-hdr) --build-id=sha1 -n \
2828
$(btildflags-y) -T
2929

3030
ccflags-y := -fno-common -fno-builtin -fno-stack-protector -ffixed-x18
3131
ccflags-y += -DDISABLE_BRANCH_PROFILING
3232

3333
CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) $(GCC_PLUGINS_CFLAGS)
34-
KBUILD_CFLAGS += $(DISABLE_LTO)
3534
KASAN_SANITIZE := n
3635
UBSAN_SANITIZE := n
3736
OBJECT_FILES_NON_STANDARD := y
@@ -47,7 +46,7 @@ endif
4746
GCOV_PROFILE := n
4847

4948
obj-y += vdso.o
50-
extra-y += vdso.lds
49+
targets += vdso.lds
5150
CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
5251

5352
# Force dependency (incbin is bad)

arch/arm64/kernel/vdso32/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ VDSO_CFLAGS += -O2
9090
# Some useful compiler-dependent flags from top-level Makefile
9191
VDSO_CFLAGS += $(call cc32-option,-Wdeclaration-after-statement,)
9292
VDSO_CFLAGS += $(call cc32-option,-Wno-pointer-sign)
93-
VDSO_CFLAGS += $(call cc32-option,-fno-strict-overflow)
93+
VDSO_CFLAGS += -fno-strict-overflow
9494
VDSO_CFLAGS += $(call cc32-option,-Werror=strict-prototypes)
95-
VDSO_CFLAGS += $(call cc32-option,-Werror=date-time)
95+
VDSO_CFLAGS += -Werror=date-time
9696
VDSO_CFLAGS += $(call cc32-option,-Werror=incompatible-pointer-types)
9797

9898
# The 32-bit compiler does not provide 128-bit integers, which are used in
@@ -128,7 +128,7 @@ VDSO_LDFLAGS += -Wl,-Bsymbolic -Wl,--no-undefined -Wl,-soname=linux-vdso.so.1
128128
VDSO_LDFLAGS += -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
129129
VDSO_LDFLAGS += -nostdlib -shared -mfloat-abi=soft
130130
VDSO_LDFLAGS += -Wl,--hash-style=sysv
131-
VDSO_LDFLAGS += -Wl,--build-id
131+
VDSO_LDFLAGS += -Wl,--build-id=sha1
132132
VDSO_LDFLAGS += $(call cc32-ldoption,-fuse-ld=bfd)
133133

134134

@@ -155,7 +155,7 @@ asm-obj-vdso := $(addprefix $(obj)/, $(asm-obj-vdso))
155155
obj-vdso := $(c-obj-vdso) $(c-obj-vdso-gettimeofday) $(asm-obj-vdso)
156156

157157
obj-y += vdso.o
158-
extra-y += vdso.lds
158+
targets += vdso.lds
159159
CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
160160

161161
# Force dependency (vdso.s includes vdso.so through incbin)

0 commit comments

Comments
 (0)