@@ -497,15 +497,14 @@ KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE
497497KBUILD_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
502502KBUILD_CPPFLAGS := -D__KERNEL__
503503KBUILD_AFLAGS_KERNEL :=
504504KBUILD_CFLAGS_KERNEL :=
505505KBUILD_AFLAGS_MODULE := -DMODULE
506506KBUILD_CFLAGS_MODULE := -DMODULE
507507KBUILD_LDFLAGS_MODULE :=
508- export KBUILD_LDS_MODULE := $(srctree ) /scripts/module-common.lds
509508KBUILD_LDFLAGS :=
510509CLANG_FLAGS :=
511510
@@ -517,7 +516,6 @@ export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE
517516
518517export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS
519518export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
520- export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE CFLAGS_UBSAN CFLAGS_KCSAN
521519export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
522520export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
523521export 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
639637endif
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)
712713else # !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
813814KBUILD_CFLAGS += -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang
814815endif
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
818823ifdef CONFIG_DEBUG_INFO
824+
819825ifdef CONFIG_DEBUG_INFO_SPLIT
820826DEBUG_CFLAGS += -gsplit-dwarf
821827else
822828DEBUG_CFLAGS += -g
823829endif
830+
824831KBUILD_AFLAGS += -Wa,-gdwarf-2
825- endif
832+
826833ifdef CONFIG_DEBUG_INFO_DWARF4
827834DEBUG_CFLAGS += -gdwarf-4
828835endif
@@ -838,6 +845,8 @@ KBUILD_AFLAGS += -gz=zlib
838845KBUILD_LDFLAGS += --compress-debug-sections=zlib
839846endif
840847
848+ endif # CONFIG_DEBUG_INFO
849+
841850KBUILD_CFLAGS += $(DEBUG_CFLAGS )
842851export DEBUG_CFLAGS
843852
@@ -919,16 +928,16 @@ KBUILD_CFLAGS += $(call cc-disable-warning, restrict)
919928KBUILD_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
928937KBUILD_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
934943KBUILD_CFLAGS += $(call cc-option,-Werror=incompatible-pointer-types)
@@ -964,8 +973,8 @@ KBUILD_CPPFLAGS += $(KCPPFLAGS)
964973KBUILD_AFLAGS += $(KAFLAGS )
965974KBUILD_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
970979ifeq ($(CONFIG_STRIP_ASM_SYMS ) ,y)
971980LDFLAGS_vmlinux += $(call ld-option, -X,)
@@ -1377,7 +1386,7 @@ endif
13771386# using awk while concatenating to the final file.
13781387
13791388PHONY += 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
13831392PHONY += modules_check
@@ -1394,6 +1403,7 @@ targets += modules.order
13941403# Target to prepare building external modules
13951404PHONY += modules_prepare
13961405modules_prepare : prepare
1406+ $(Q )$(MAKE ) $(build ) =scripts scripts/module.lds
13971407
13981408# Target to install modules
13991409PHONY += modules_install
@@ -1452,7 +1462,8 @@ endif # CONFIG_MODULES
14521462
14531463# Directories & files removed with 'make clean'
14541464CLEAN_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'
14581469MRPROPER_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 :=
16851698KBUILD_MODULES := 1
16861699
16871700build-dirs := $(KBUILD_EXTMOD )
16881701PHONY += modules
1689- modules : descend
1702+ modules : $( MODORDER )
16901703 $(Q )$(MAKE ) -f $(srctree ) /scripts/Makefile.modpost
16911704
1705+ $(MODORDER ) : descend
1706+ @:
1707+
16921708PHONY += modules_install
16931709modules_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+
17051724clean-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
17081728PHONY += help
17091729help :
@@ -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+
17191741endif # KBUILD_EXTMOD
17201742
17211743# Single targets
@@ -1748,7 +1770,7 @@ MODORDER := .modules.tmp
17481770endif
17491771
17501772PHONY += 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
18161838nsdeps : 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
18241873includecheck :
18251874 find $(srctree ) /* $(RCS_FIND_IGNORE ) \
@@ -1834,9 +1883,6 @@ versioncheck:
18341883coccicheck :
18351884 $(Q )$(BASH ) $(srctree ) /scripts/$@
18361885
1837- namespacecheck :
1838- $(PERL ) $(srctree ) /scripts/namespace.pl
1839-
18401886export_report :
18411887 $(PERL ) $(srctree ) /scripts/export_report.pl
18421888
0 commit comments