From nobody Tue Feb 10 00:39:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1571849429; cv=none; d=zoho.com; s=zohoarc; b=KF1uNiFLffUlAYTg/GFO29fhHJ/dHhgVkv4AHANzjKLjN6zCkI3N2aprOhB8F50MzrjCTup1hTqi+llva9AB4SovkQ7SmzVjk3/26RCE2KavEK83EVtzUlhYfI7pMhvlCMrFI5kBxqlfeUV7070ob2oSvZnvbA/5a8HxOEphw78= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571849429; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2ezTerU+fahrODnGeS2Q4yl8I0itD/MW6YwTHe74QhM=; b=DG3QSP6nWMQpvuZctB4+ywFR5zKUz1OkvdBzz6DOFf9jERnyT+9+g9pylwY1bGdOcc4EbNBj91Z4bTFfQhbX/X4Hs0mKfxjM+rSKtubLdQG0XpS4Qf2CAIU4Tiyv2DguFd9x08H3Sc+eOwUzeZONtzxF9EGljcqn7qJgYmDhSpM= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1571849429856226.53828438065148; Wed, 23 Oct 2019 09:50:29 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iNJoq-0007c0-CE; Wed, 23 Oct 2019 16:49:08 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iNJop-0007bN-F8 for xen-devel@lists.xenproject.org; Wed, 23 Oct 2019 16:49:07 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id f90ae36e-f5b4-11e9-beca-bc764e2007e4; Wed, 23 Oct 2019 16:48:43 +0000 (UTC) X-Inumbo-ID: f90ae36e-f5b4-11e9-beca-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1571849323; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uURSjeXsAm7GqDZ5RKilUL6S2+jUyWd8LpuXoGXkveY=; b=UVGp+izZPlEkb/4jqzNLiAbyCKfcDaomPN+lI7LgYgeixC2XsfKs7RRM os0DpiJDS25Dhp8NTsyFQ/f8Vlp0AHeHuN/t0IM1T2sMl/IDleRQZLOhC pGh2q42dk4TCPB5ZKxEPTx5GqqyMZbZxcK1nsMnTYNOGiH7vFvduqg1FA g=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: K4p6Nebna2gbimho1Jhmy4lRmUpR7GI5DVpsR+rkjwqoNsDFZwOJn0FuShC8yLy46DSS7m9IGM VCNGMSbyXnVTj+vzFFK+xrW526nCqwKl1qLKah2e4Dm1GaP7VDwuzzLHK8YMSz6Xr+wjVFDDQq kSkiwr5qFMALHFGhXmdGqVBUr+2I9fOfIzSMmZMjo/Q/hqzu0HXazWokqxAhHZwo4n5ArAiNvt zQqFBPSBfBy/IId306rYcXYD1JVZg/sjiKRWqs6GfjhmX0jAfch/ij5AS71sAHrA+Qk7vXUQ5D tKQ= X-SBRS: 2.7 X-MesageID: 7778034 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.68,221,1569297600"; d="scan'208";a="7778034" From: Anthony PERARD To: Date: Wed, 23 Oct 2019 17:48:18 +0100 Message-ID: <20191023164837.2700240-5-anthony.perard@citrix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191023164837.2700240-1-anthony.perard@citrix.com> References: <20191023164837.2700240-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [RFC XEN PATCH 04/23] build: Import Kbuild from Linux v5.3 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Anthony PERARD Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This patch import part of Kbuild, the build system from Linux v5.3, 4d856f72c10ecb060868ed10ff1b1453943fc6c8. File imported: scripts/{Makefile.*,Kbuild.include} -> xen/scripts/ scripts/basic -> xen/scripts/basic scripts/mkmakefile -> xen/scripts/Makefile but without: - Extra warning (ccflags) Makefile.extrawarn - Support to build modules Makefile.modbuiltin Makefile.modinst Makefile.modpost Makefile.modsign - Support to install dtb files Makefile.dtbinst `scripts/basic' is for fixdep, a helper to fix dependencies generated by gcc, and add Kbuild generated dependencies. `scripts/mkmakefile' is used for out-of-tree builds. Also update xen/.gitignore to exclude files generated by Kbuild. Signed-off-by: Anthony PERARD --- xen/.gitignore | 4 + xen/scripts/Kbuild.include | 333 +++++++++++++++++++ xen/scripts/Makefile.asm-generic | 58 ++++ xen/scripts/Makefile.build | 528 +++++++++++++++++++++++++++++++ xen/scripts/Makefile.clean | 90 ++++++ xen/scripts/Makefile.gcc-plugins | 59 ++++ xen/scripts/Makefile.headersinst | 102 ++++++ xen/scripts/Makefile.host | 164 ++++++++++ xen/scripts/Makefile.kasan | 51 +++ xen/scripts/Makefile.kcov | 10 + xen/scripts/Makefile.lib | 435 +++++++++++++++++++++++++ xen/scripts/Makefile.ubsan | 19 ++ xen/scripts/basic/.gitignore | 1 + xen/scripts/basic/Makefile | 16 + xen/scripts/basic/fixdep.c | 410 ++++++++++++++++++++++++ xen/scripts/mkmakefile | 17 + 16 files changed, 2297 insertions(+) create mode 100644 xen/scripts/Kbuild.include create mode 100644 xen/scripts/Makefile.asm-generic create mode 100644 xen/scripts/Makefile.build create mode 100644 xen/scripts/Makefile.clean create mode 100644 xen/scripts/Makefile.gcc-plugins create mode 100644 xen/scripts/Makefile.headersinst create mode 100644 xen/scripts/Makefile.host create mode 100644 xen/scripts/Makefile.kasan create mode 100644 xen/scripts/Makefile.kcov create mode 100644 xen/scripts/Makefile.lib create mode 100644 xen/scripts/Makefile.ubsan create mode 100644 xen/scripts/basic/.gitignore create mode 100644 xen/scripts/basic/Makefile create mode 100644 xen/scripts/basic/fixdep.c create mode 100755 xen/scripts/mkmakefile diff --git a/xen/.gitignore b/xen/.gitignore index 9fef41a09b47..516bbd459342 100644 --- a/xen/.gitignore +++ b/xen/.gitignore @@ -1,2 +1,6 @@ +.* *.lex.c *.tab.[ch] + +# We don't want to ignore the following even if they are dot-files +!.gitignore diff --git a/xen/scripts/Kbuild.include b/xen/scripts/Kbuild.include new file mode 100644 index 000000000000..4b0432e095ae --- /dev/null +++ b/xen/scripts/Kbuild.include @@ -0,0 +1,333 @@ +# SPDX-License-Identifier: GPL-2.0 +#### +# kbuild: Generic definitions + +# Convenient variables +comma :=3D , +quote :=3D " +squote :=3D ' +empty :=3D +space :=3D $(empty) $(empty) +space_escape :=3D _-_SPACE_-_ +pound :=3D \# + +### +# Name of target with a '.' as filename prefix. foo/bar.o =3D> foo/.bar.o +dot-target =3D $(dir $@).$(notdir $@) + +### +# The temporary file to save gcc -MD generated dependencies must not +# contain a comma +depfile =3D $(subst $(comma),_,$(dot-target).d) + +### +# filename of target with directory and extension stripped +basetarget =3D $(basename $(notdir $@)) + +### +# real prerequisites without phony targets +real-prereqs =3D $(filter-out $(PHONY), $^) + +### +# Escape single quote for use in echo statements +escsq =3D $(subst $(squote),'\$(squote)',$1) + +### +# Easy method for doing a status message + kecho :=3D : + quiet_kecho :=3D echo +silent_kecho :=3D : +kecho :=3D $($(quiet)kecho) + +### +# filechk is used to check if the content of a generated file is updated. +# Sample usage: +# +# filechk_sample =3D echo $(KERNELRELEASE) +# version.h: FORCE +# $(call filechk,sample) +# +# The rule defined shall write to stdout the content of the new file. +# The existing file will be compared with the new one. +# - If no file exist it is created +# - If the content differ the new file is used +# - If they are equal no change, and no timestamp update +# - stdin is piped in from the first prerequisite ($<) so one has +# to specify a valid file as first prerequisite (often the kbuild file) +define filechk + $(Q)set -e; \ + mkdir -p $(dir $@); \ + { $(filechk_$(1)); } > $@.tmp; \ + if [ -r $@ ] && cmp -s $@ $@.tmp; then \ + rm -f $@.tmp; \ + else \ + $(kecho) ' UPD $@'; \ + mv -f $@.tmp $@; \ + fi +endef + +###### +# gcc support functions +# See documentation in Documentation/kbuild/makefiles.rst + +# cc-cross-prefix +# Usage: CROSS_COMPILE :=3D $(call cc-cross-prefix, m68k-linux-gnu- m68k-l= inux-) +# Return first where a gcc is found in PATH. +# If no gcc found in PATH with listed prefixes return nothing +# +# Note: '2>/dev/null' is here to force Make to invoke a shell. Otherwise, = it +# would try to directly execute the shell builtin 'command'. This workarou= nd +# should be kept for a long time since this issue was fixed only after the +# GNU Make 4.2.1 release. +cc-cross-prefix =3D $(firstword $(foreach c, $(1), \ + $(if $(shell command -v -- $(c)gcc 2>/dev/null), $(c)))) + +# output directory for tests below +TMPOUT :=3D $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/) + +# try-run +# Usage: option =3D $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise) +# Exit code chooses option. "$$TMP" serves as a temporary file and is +# automatically cleaned up. +try-run =3D $(shell set -e; \ + TMP=3D"$(TMPOUT).$$$$.tmp"; \ + TMPO=3D"$(TMPOUT).$$$$.o"; \ + if ($(1)) >/dev/null 2>&1; \ + then echo "$(2)"; \ + else echo "$(3)"; \ + fi; \ + rm -f "$$TMP" "$$TMPO") + +# as-option +# Usage: cflags-y +=3D $(call as-option,-Wa$(comma)-isa=3Dfoo,) + +as-option =3D $(call try-run,\ + $(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2= )) + +# as-instr +# Usage: cflags-y +=3D $(call as-instr,instr,option1,option2) + +as-instr =3D $(call try-run,\ + printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" = -,$(2),$(3)) + +# __cc-option +# Usage: MY_CFLAGS +=3D $(call __cc-option,$(CC),$(MY_CFLAGS),-march=3Dwin= chip-c6,-march=3Di586) +__cc-option =3D $(call try-run,\ + $(1) -Werror $(2) $(3) -c -x c /dev/null -o "$$TMP",$(3),$(4)) + +# Do not attempt to build with gcc plugins during cc-option tests. +# (And this uses delayed resolution so the flags will be up to date.) +CC_OPTION_CFLAGS =3D $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS)) + +# cc-option +# Usage: cflags-y +=3D $(call cc-option,-march=3Dwinchip-c6,-march=3Di586) + +cc-option =3D $(call __cc-option, $(CC),\ + $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS),$(1),$(2)) + +# cc-option-yn +# Usage: flag :=3D $(call cc-option-yn,-march=3Dwinchip-c6) +cc-option-yn =3D $(call try-run,\ + $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) $(1) -c -x c /dev/nu= ll -o "$$TMP",y,n) + +# cc-disable-warning +# Usage: cflags-y +=3D $(call cc-disable-warning,unused-but-set-variable) +cc-disable-warning =3D $(call try-run,\ + $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -W$(strip $(1)) -c -= x c /dev/null -o "$$TMP",-Wno-$(strip $(1))) + +# cc-ifversion +# Usage: EXTRA_CFLAGS +=3D $(call cc-ifversion, -lt, 0402, -O1) +cc-ifversion =3D $(shell [ $(CONFIG_GCC_VERSION)0 $(1) $(2)000 ] && echo $= (3) || echo $(4)) + +# ld-option +# Usage: KBUILD_LDFLAGS +=3D $(call ld-option, -X, -Y) +ld-option =3D $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(= 3)) + +# ar-option +# Usage: KBUILD_ARFLAGS :=3D $(call ar-option,D) +# Important: no spaces around options +ar-option =3D $(call try-run, $(AR) rc$(1) "$$TMP",$(1),$(2)) + +# ld-version +# Note this is mainly for HJ Lu's 3 number binutil versions +ld-version =3D $(shell $(LD) --version | $(srctree)/scripts/ld-version.sh) + +# ld-ifversion +# Usage: $(call ld-ifversion, -ge, 22252, y) +ld-ifversion =3D $(shell [ $(ld-version) $(1) $(2) ] && echo $(3) || echo = $(4)) + +###### + +### +# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=3D +# Usage: +# $(Q)$(MAKE) $(build)=3Ddir +build :=3D -f $(srctree)/scripts/Makefile.build obj + +### +# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.modbuiltin obj=3D +# Usage: +# $(Q)$(MAKE) $(modbuiltin)=3Ddir +modbuiltin :=3D -f $(srctree)/scripts/Makefile.modbuiltin obj + +### +# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.dtbinst obj=3D +# Usage: +# $(Q)$(MAKE) $(dtbinst)=3Ddir +dtbinst :=3D -f $(srctree)/scripts/Makefile.dtbinst obj + +### +# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=3D +# Usage: +# $(Q)$(MAKE) $(clean)=3Ddir +clean :=3D -f $(srctree)/scripts/Makefile.clean obj + +# echo command. +# Short version is used, if $(quiet) equals `quiet_', otherwise full one. +echo-cmd =3D $(if $($(quiet)cmd_$(1)),\ + echo ' $(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';) + +# printing commands +cmd =3D @set -e; $(echo-cmd) $(cmd_$(1)) + +### +# if_changed - execute command if any prerequisite is newer than +# target, or command line has changed +# if_changed_dep - as if_changed, but uses fixdep to reveal dependencies +# including used config symbols +# if_changed_rule - as if_changed but execute rule instead +# See Documentation/kbuild/makefiles.rst for more info + +ifneq ($(KBUILD_NOCMDDEP),1) +# Check if both commands are the same including their order. Result is emp= ty +# string if equal. User may override this check using make KBUILD_NOCMDDEP= =3D1 +cmd-check =3D $(filter-out $(subst $(space),$(space_escape),$(strip $(cmd_= $@))), \ + $(subst $(space),$(space_escape),$(strip $(cmd_$1= )))) +else +cmd-check =3D $(if $(strip $(cmd_$@)),,1) +endif + +# Replace >$< with >$$< to preserve $ when reloading the .cmd file +# (needed for make) +# Replace >#< with >$(pound)< to avoid starting a comment in the .cmd file +# (needed for make) +# Replace >'< with >'\''< to be able to enclose the whole string in '...' +# (needed for the shell) +make-cmd =3D $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd= _$(1))))) + +# Find any prerequisites that is newer than target or that does not exist. +# PHONY targets skipped in both cases. +any-prereq =3D $(filter-out $(PHONY),$?)$(filter-out $(PHONY) $(wildcard $= ^),$^) + +# Execute command if command has changed or prerequisite(s) are updated. +if_changed =3D $(if $(any-prereq)$(cmd-check), = \ + $(cmd); \ + printf '%s\n' 'cmd_$@ :=3D $(make-cmd)' > $(dot-target).cmd, @:) + +# Execute the command and also postprocess generated .d dependencies file. +if_changed_dep =3D $(if $(any-prereq)$(cmd-check),$(cmd_and_fixdep),@:) + +cmd_and_fixdep =3D = \ + $(cmd); \ + scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).cmd;\ + rm -f $(depfile) + +# Usage: $(call if_changed_rule,foo) +# Will check if $(cmd_foo) or any of the prerequisites changed, +# and if so will execute $(rule_foo). +if_changed_rule =3D $(if $(any-prereq)$(cmd-check),$(rule_$(1)),@:) + +### +# why - tell why a target got built +# enabled by make V=3D2 +# Output (listed in the order they are checked): +# (1) - due to target is PHONY +# (2) - due to target missing +# (3) - due to: file1.h file2.h +# (4) - due to command line change +# (5) - due to missing .cmd file +# (6) - due to target not in $(targets) +# (1) PHONY targets are always build +# (2) No target, so we better build it +# (3) Prerequisite is newer than target +# (4) The command line stored in the file named dir/.target.cmd +# differed from actual command line. This happens when compiler +# options changes +# (5) No dir/.target.cmd file (used to store command line) +# (6) No dir/.target.cmd file and target not listed in $(targets) +# This is a good hint that there is a bug in the kbuild file +ifeq ($(KBUILD_VERBOSE),2) +why =3D = \ + $(if $(filter $@, $(PHONY)),- due to target is PHONY, = \ + $(if $(wildcard $@), = \ + $(if $(any-prereq),- due to: $(any-prereq), = \ + $(if $(cmd-check), = \ + $(if $(cmd_$@),- due to command line change, = \ + $(if $(filter $@, $(targets)), = \ + - due to missing .cmd file, = \ + - due to $(notdir $@) not in $$(targets) = \ + ) = \ + ) = \ + ) = \ + ), = \ + - due to target missing = \ + ) = \ + ) + +echo-why =3D $(call escsq, $(strip $(why))) +endif + +##########################################################################= ##### +# +# When a Kconfig string contains a filename, it is suitable for +# passing to shell commands. It is surrounded by double-quotes, and +# any double-quotes or backslashes within it are escaped by +# backslashes. +# +# This is no use for dependencies or $(wildcard). We need to strip the +# surrounding quotes and the escaping from quotes and backslashes, and +# we *do* need to escape any spaces in the string. So, for example: +# +# Usage: $(eval $(call config_filename,FOO)) +# +# Defines FOO_FILENAME based on the contents of the CONFIG_FOO option, +# transformed as described above to be suitable for use within the +# makefile. +# +# Also, if the filename is a relative filename and exists in the source +# tree but not the build tree, define FOO_SRCPREFIX as $(srctree)/ to +# be prefixed to *both* command invocation and dependencies. +# +# Note: We also print the filenames in the quiet_cmd_foo text, and +# perhaps ought to have a version specially escaped for that purpose. +# But it's only cosmetic, and $(patsubst "%",%,$(CONFIG_FOO)) is good +# enough. It'll strip the quotes in the common case where there's no +# space and it's a simple filename, and it'll retain the quotes when +# there's a space. There are some esoteric cases in which it'll print +# the wrong thing, but we don't really care. The actual dependencies +# and commands *do* get it right, with various combinations of single +# and double quotes, backslashes and spaces in the filenames. +# +##########################################################################= ##### +# +define config_filename +ifneq ($$(CONFIG_$(1)),"") +$(1)_FILENAME :=3D $$(subst \\,\,$$(subst \$$(quote),$$(quote),$$(subst $$= (space_escape),\$$(space),$$(patsubst "%",%,$$(subst $$(space),$$(space_esc= ape),$$(CONFIG_$(1))))))) +ifneq ($$(patsubst /%,%,$$(firstword $$($(1)_FILENAME))),$$(firstword $$($= (1)_FILENAME))) +else +ifeq ($$(wildcard $$($(1)_FILENAME)),) +ifneq ($$(wildcard $$(srctree)/$$($(1)_FILENAME)),) +$(1)_SRCPREFIX :=3D $(srctree)/ +endif +endif +endif +endif +endef +# +##########################################################################= ##### + +# delete partially updated (i.e. corrupted) files on error +.DELETE_ON_ERROR: + +# do not delete intermediate files automatically +.SECONDARY: diff --git a/xen/scripts/Makefile.asm-generic b/xen/scripts/Makefile.asm-ge= neric new file mode 100644 index 000000000000..82ad63dcd62b --- /dev/null +++ b/xen/scripts/Makefile.asm-generic @@ -0,0 +1,58 @@ +# SPDX-License-Identifier: GPL-2.0 +# include/asm-generic contains a lot of files that are used +# verbatim by several architectures. +# +# This Makefile reads the file arch/$(SRCARCH)/include/(uapi/)/asm/Kbuild +# and for each file listed in this file with generic-y creates +# a small wrapper file in arch/$(SRCARCH)/include/generated/(uapi/)/asm. + +PHONY :=3D all +all: + +src :=3D $(subst /generated,,$(obj)) +-include $(src)/Kbuild + +# $(generic)/Kbuild lists mandatory-y. Exclude um since it is a special ca= se. +ifneq ($(SRCARCH),um) +include $(generic)/Kbuild +endif + +include scripts/Kbuild.include + +redundant :=3D $(filter $(mandatory-y) $(generated-y), $(generic-y)) +redundant +=3D $(foreach f, $(generic-y), $(if $(wildcard $(srctree)/$(src= )/$(f)),$(f))) +redundant :=3D $(sort $(redundant)) +$(if $(redundant),\ + $(warning redundant generic-y found in $(src)/Kbuild: $(redundant))) + +# If arch does not implement mandatory headers, fallback to asm-generic on= es. +mandatory-y :=3D $(filter-out $(generated-y), $(mandatory-y)) +generic-y +=3D $(foreach f, $(mandatory-y), $(if $(wildcard $(srctree)/$= (src)/$(f)),,$(f))) + +generic-y :=3D $(addprefix $(obj)/, $(generic-y)) +generated-y :=3D $(addprefix $(obj)/, $(generated-y)) + +# Remove stale wrappers when the corresponding files are removed from gene= ric-y +old-headers :=3D $(wildcard $(obj)/*.h) +unwanted :=3D $(filter-out $(generic-y) $(generated-y),$(old-headers)) + +quiet_cmd_wrap =3D WRAP $@ + cmd_wrap =3D echo "\#include " > $@ + +quiet_cmd_remove =3D REMOVE $(unwanted) + cmd_remove =3D rm -f $(unwanted) + +all: $(generic-y) + $(if $(unwanted),$(call cmd,remove)) + @: + +$(obj)/%.h: + $(call cmd,wrap) + +# Create output directory. Skip it if at least one old header exists +# since we know the output directory already exists. +ifeq ($(old-headers),) +$(shell mkdir -p $(obj)) +endif + +.PHONY: $(PHONY) diff --git a/xen/scripts/Makefile.build b/xen/scripts/Makefile.build new file mode 100644 index 000000000000..2f66ed388d1c --- /dev/null +++ b/xen/scripts/Makefile.build @@ -0,0 +1,528 @@ +# SPDX-License-Identifier: GPL-2.0 +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +# Building +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +src :=3D $(obj) + +PHONY :=3D __build +__build: + +# Init all relevant variables used in kbuild files so +# 1) they have correct type +# 2) they do not inherit any value from the environment +obj-y :=3D +obj-m :=3D +lib-y :=3D +lib-m :=3D +always :=3D +targets :=3D +subdir-y :=3D +subdir-m :=3D +EXTRA_AFLAGS :=3D +EXTRA_CFLAGS :=3D +EXTRA_CPPFLAGS :=3D +EXTRA_LDFLAGS :=3D +asflags-y :=3D +ccflags-y :=3D +cppflags-y :=3D +ldflags-y :=3D + +subdir-asflags-y :=3D +subdir-ccflags-y :=3D + +# Read auto.conf if it exists, otherwise ignore +-include include/config/auto.conf + +include scripts/Kbuild.include + +# The filename Kbuild has precedence over Makefile +kbuild-dir :=3D $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) +kbuild-file :=3D $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuil= d,$(kbuild-dir)/Makefile) +include $(kbuild-file) + +include scripts/Makefile.lib + +# Do not include host rules unless needed +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs= -y)$(hostcxxlibs-m),) +include scripts/Makefile.host +endif + +ifndef obj +$(warning kbuild: Makefile.build is included improperly) +endif + +ifeq ($(MAKECMDGOALS)$(need-modorder),) +ifneq ($(obj-m),) +$(warning $(patsubst %.o,'%.ko',$(obj-m)) will not be built even though ob= j-m is specified.) +$(warning You cannot use subdir-y/m to visit a module Makefile. Use obj-y/= m instead.) +endif +endif + +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + +ifneq ($(strip $(lib-y) $(lib-m) $(lib-)),) +lib-target :=3D $(obj)/lib.a +real-obj-y +=3D $(obj)/lib-ksyms.o +endif + +ifneq ($(strip $(real-obj-y) $(need-builtin)),) +builtin-target :=3D $(obj)/built-in.a +endif + +ifeq ($(CONFIG_MODULES)$(need-modorder),y1) +modorder-target :=3D $(obj)/modules.order +endif + +mod-targets :=3D $(patsubst %.o, %.mod, $(obj-m)) + +__build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)= ) \ + $(if $(KBUILD_MODULES),$(obj-m) $(mod-targets) $(modorder-target)) \ + $(subdir-ym) $(always) + @: + +# Linus' kernel sanity checking tool +ifeq ($(KBUILD_CHECKSRC),1) + quiet_cmd_checksrc =3D CHECK $< + cmd_checksrc =3D $(CHECK) $(CHECKFLAGS) $(c_flags) $< +else ifeq ($(KBUILD_CHECKSRC),2) + quiet_cmd_force_checksrc =3D CHECK $< + cmd_force_checksrc =3D $(CHECK) $(CHECKFLAGS) $(c_flags) $< +endif + +ifneq ($(KBUILD_ENABLE_EXTRA_GCC_CHECKS),) + cmd_checkdoc =3D $(srctree)/scripts/kernel-doc -none $< +endif + +# Compile C sources (.c) +# ------------------------------------------------------------------------= --- + +# Default is built-in, unless we know otherwise +$(foreach x, i ll lst o s symtypes, $(patsubst %.o,%.$(x),$(real-obj-m))):= \ + part-of-module :=3D y + +modkern_cflags =3D \ + $(if $(part-of-module), \ + $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \ + $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL)) +quiet_modtag =3D $(if $(part-of-module),[M], ) + +quiet_cmd_cc_s_c =3D CC $(quiet_modtag) $@ + cmd_cc_s_c =3D $(CC) $(filter-out $(DEBUG_CFLAGS), $(c_flags)) $(DIS= ABLE_LTO) -fverbose-asm -S -o $@ $< + +$(obj)/%.s: $(src)/%.c FORCE + $(call if_changed_dep,cc_s_c) + +quiet_cmd_cpp_i_c =3D CPP $(quiet_modtag) $@ +cmd_cpp_i_c =3D $(CPP) $(c_flags) -o $@ $< + +$(obj)/%.i: $(src)/%.c FORCE + $(call if_changed_dep,cpp_i_c) + +# These mirror gensymtypes_S and co below, keep them in synch. +cmd_gensymtypes_c =3D = \ + $(CPP) -D__GENKSYMS__ $(c_flags) $< | = \ + scripts/genksyms/genksyms $(if $(1), -T $(2)) = \ + $(patsubst y,-R,$(CONFIG_MODULE_REL_CRCS)) = \ + $(if $(KBUILD_PRESERVE),-p) = \ + -r $(firstword $(wildcard $(2:.symtypes=3D.symref) /dev/null)) + +quiet_cmd_cc_symtypes_c =3D SYM $(quiet_modtag) $@ +cmd_cc_symtypes_c =3D = \ + $(call cmd_gensymtypes_c,true,$@) >/dev/null; = \ + test -s $@ || rm -f $@ + +$(obj)/%.symtypes : $(src)/%.c FORCE + $(call cmd,cc_symtypes_c) + +# LLVM assembly +# Generate .ll files from .c +quiet_cmd_cc_ll_c =3D CC $(quiet_modtag) $@ + cmd_cc_ll_c =3D $(CC) $(c_flags) -emit-llvm -S -o $@ $< + +$(obj)/%.ll: $(src)/%.c FORCE + $(call if_changed_dep,cc_ll_c) + +# C (.c) files +# The C file is compiled and updated dependency information is generated. +# (See cmd_cc_o_c + relevant part of rule_cc_o_c) + +quiet_cmd_cc_o_c =3D CC $(quiet_modtag) $@ + cmd_cc_o_c =3D $(CC) $(c_flags) -c -o $@ $< + +ifdef CONFIG_MODVERSIONS +# When module versioning is enabled the following steps are executed: +# o compile a .o from .c +# o if .o doesn't contain a __ksymtab version, i.e. does +# not export symbols, it's done. +# o otherwise, we calculate symbol versions using the good old +# genksyms on the preprocessed source and postprocess them in a way +# that they are usable as a linker script +# o generate .tmp_.o from .o using the linker to +# replace the unresolved symbols __crc_exported_symbol with +# the actual value of the checksum generated by genksyms +# o remove .tmp_.o to .o + +cmd_modversions_c =3D \ + if $(OBJDUMP) -h $@ | grep -q __ksymtab; then \ + $(call cmd_gensymtypes_c,$(KBUILD_SYMTYPES),$(@:.o=3D.symtypes)) \ + > $(@D)/.tmp_$(@F:.o=3D.ver); \ + \ + $(LD) $(KBUILD_LDFLAGS) -r -o $(@D)/.tmp_$(@F) $@ \ + -T $(@D)/.tmp_$(@F:.o=3D.ver); \ + mv -f $(@D)/.tmp_$(@F) $@; \ + rm -f $(@D)/.tmp_$(@F:.o=3D.ver); \ + fi +endif + +ifdef CONFIG_FTRACE_MCOUNT_RECORD +ifndef CC_USING_RECORD_MCOUNT +# compiler will not generate __mcount_loc use recordmcount or recordmcount= .pl +ifdef BUILD_C_RECORDMCOUNT +ifeq ("$(origin RECORDMCOUNT_WARN)", "command line") + RECORDMCOUNT_FLAGS =3D -w +endif +# Due to recursion, we must skip empty.o. +# The empty.o file is created in the make process in order to determine +# the target endianness and word size. It is made before all other C +# files, including recordmcount. +sub_cmd_record_mcount =3D \ + if [ $(@) !=3D "scripts/mod/empty.o" ]; then \ + $(objtree)/scripts/recordmcount $(RECORDMCOUNT_FLAGS) "$(@)"; \ + fi; +recordmcount_source :=3D $(srctree)/scripts/recordmcount.c \ + $(srctree)/scripts/recordmcount.h +else +sub_cmd_record_mcount =3D perl $(srctree)/scripts/recordmcount.pl "$(ARCH)= " \ + "$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \ + "$(if $(CONFIG_64BIT),64,32)" \ + "$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS)" \ + "$(LD) $(KBUILD_LDFLAGS)" "$(NM)" "$(RM)" "$(MV)" \ + "$(if $(part-of-module),1,0)" "$(@)"; +recordmcount_source :=3D $(srctree)/scripts/recordmcount.pl +endif # BUILD_C_RECORDMCOUNT +cmd_record_mcount =3D $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_f= lags)), \ + $(sub_cmd_record_mcount)) +endif # CC_USING_RECORD_MCOUNT +endif # CONFIG_FTRACE_MCOUNT_RECORD + +ifdef CONFIG_STACK_VALIDATION +ifneq ($(SKIP_STACK_VALIDATION),1) + +__objtool_obj :=3D $(objtree)/tools/objtool/objtool + +objtool_args =3D $(if $(CONFIG_UNWINDER_ORC),orc generate,check) + +objtool_args +=3D $(if $(part-of-module), --module,) + +ifndef CONFIG_FRAME_POINTER +objtool_args +=3D --no-fp +endif +ifdef CONFIG_GCOV_KERNEL +objtool_args +=3D --no-unreachable +endif +ifdef CONFIG_RETPOLINE + objtool_args +=3D --retpoline +endif +ifdef CONFIG_X86_SMAP + objtool_args +=3D --uaccess +endif + +# 'OBJECT_FILES_NON_STANDARD :=3D y': skip objtool checking for a directory +# 'OBJECT_FILES_NON_STANDARD_foo.o :=3D 'y': skip objtool checking for a f= ile +# 'OBJECT_FILES_NON_STANDARD_foo.o :=3D 'n': override directory skip for a= file +cmd_objtool =3D $(if $(patsubst y%,, \ + $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n= ), \ + $(__objtool_obj) $(objtool_args) $@) +objtool_obj =3D $(if $(patsubst y%,, \ + $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n= ), \ + $(__objtool_obj)) + +endif # SKIP_STACK_VALIDATION +endif # CONFIG_STACK_VALIDATION + +# Rebuild all objects when objtool changes, or is enabled/disabled. +objtool_dep =3D $(objtool_obj) \ + $(wildcard include/config/orc/unwinder.h \ + include/config/stack/validation.h) + +ifdef CONFIG_TRIM_UNUSED_KSYMS +cmd_gen_ksymdeps =3D \ + $(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ >> $(dot-target).cmd +endif + +define rule_cc_o_c + $(call cmd,checksrc) + $(call cmd_and_fixdep,cc_o_c) + $(call cmd,gen_ksymdeps) + $(call cmd,checkdoc) + $(call cmd,objtool) + $(call cmd,modversions_c) + $(call cmd,record_mcount) +endef + +define rule_as_o_S + $(call cmd_and_fixdep,as_o_S) + $(call cmd,gen_ksymdeps) + $(call cmd,objtool) + $(call cmd,modversions_S) +endef + +# List module undefined symbols (or empty line if not enabled) +ifdef CONFIG_TRIM_UNUSED_KSYMS +cmd_undef_syms =3D $(NM) $< | sed -n 's/^ *U //p' | xargs echo +else +cmd_undef_syms =3D echo +endif + +# Built-in and composite module parts +$(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_dep) FORCE + $(call cmd,force_checksrc) + $(call if_changed_rule,cc_o_c) + +cmd_mod =3D { \ + echo $(if $($*-objs)$($*-y)$($*-m), $(addprefix $(obj)/, $($*-objs) $($*-= y) $($*-m)), $(@:.mod=3D.o)); \ + $(cmd_undef_syms); \ + } > $@ + +$(obj)/%.mod: $(obj)/%.o FORCE + $(call if_changed,mod) + +targets +=3D $(mod-targets) + +quiet_cmd_cc_lst_c =3D MKLST $@ + cmd_cc_lst_c =3D $(CC) $(c_flags) -g -c -o $*.o $< && \ + $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \ + System.map $(OBJDUMP) > $@ + +$(obj)/%.lst: $(src)/%.c FORCE + $(call if_changed_dep,cc_lst_c) + +# header test (header-test-y, header-test-m target) +# ------------------------------------------------------------------------= --- + +quiet_cmd_cc_s_h =3D CC $@ + cmd_cc_s_h =3D $(CC) $(c_flags) -S -o $@ -x c /dev/null -include $< + +$(obj)/%.h.s: $(src)/%.h FORCE + $(call if_changed_dep,cc_s_h) + +# Compile assembler sources (.S) +# ------------------------------------------------------------------------= --- + +modkern_aflags :=3D $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL) + +$(real-obj-m) : modkern_aflags :=3D $(KBUILD_AFLAGS_MODULE) $(AFLAGS_= MODULE) +$(real-obj-m:.o=3D.s): modkern_aflags :=3D $(KBUILD_AFLAGS_MODULE) $(AFLAG= S_MODULE) + +# .S file exports must have their C prototypes defined in asm/asm-prototyp= es.h +# or a file that it includes, in order to get versioned symbols. We build a +# dummy C file that includes asm-prototypes and the EXPORT_SYMBOL lines fr= om +# the .S file (with trailing ';'), and run genksyms on that, to extract ve= rs. +# +# This is convoluted. The .S file must first be preprocessed to run guards= and +# expand names, then the resulting exports must be constructed into plain +# EXPORT_SYMBOL(symbol); to build our dummy C file, and that gets preproce= ssed +# to make the genksyms input. +# +# These mirror gensymtypes_c and co above, keep them in synch. +cmd_gensymtypes_S =3D = \ + { echo "\#include " ; = \ + echo "\#include " ; = \ + $(CPP) $(a_flags) $< | = \ + grep "\<___EXPORT_SYMBOL\>" | = \ + sed 's/.*___EXPORT_SYMBOL[[:space:]]*\([a-zA-Z0-9_]*\)[[:space:]]*,.*= /EXPORT_SYMBOL(\1);/' ; } | \ + $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | = \ + scripts/genksyms/genksyms $(if $(1), -T $(2)) = \ + $(patsubst y,-R,$(CONFIG_MODULE_REL_CRCS)) = \ + $(if $(KBUILD_PRESERVE),-p) = \ + -r $(firstword $(wildcard $(2:.symtypes=3D.symref) /dev/null)) + +quiet_cmd_cc_symtypes_S =3D SYM $(quiet_modtag) $@ +cmd_cc_symtypes_S =3D = \ + $(call cmd_gensymtypes_S,true,$@) >/dev/null; = \ + test -s $@ || rm -f $@ + +$(obj)/%.symtypes : $(src)/%.S FORCE + $(call cmd,cc_symtypes_S) + + +quiet_cmd_cpp_s_S =3D CPP $(quiet_modtag) $@ +cmd_cpp_s_S =3D $(CPP) $(a_flags) -o $@ $< + +$(obj)/%.s: $(src)/%.S FORCE + $(call if_changed_dep,cpp_s_S) + +quiet_cmd_as_o_S =3D AS $(quiet_modtag) $@ + cmd_as_o_S =3D $(CC) $(a_flags) -c -o $@ $< + +ifdef CONFIG_MODVERSIONS + +ASM_PROTOTYPES :=3D $(wildcard $(srctree)/arch/$(SRCARCH)/include/asm/asm-= prototypes.h) + +ifneq ($(ASM_PROTOTYPES),) + +# versioning matches the C process described above, with difference that +# we parse asm-prototypes.h C header to get function definitions. + +cmd_modversions_S =3D \ + if $(OBJDUMP) -h $@ | grep -q __ksymtab; then \ + $(call cmd_gensymtypes_S,$(KBUILD_SYMTYPES),$(@:.o=3D.symtypes)) \ + > $(@D)/.tmp_$(@F:.o=3D.ver); \ + \ + $(LD) $(KBUILD_LDFLAGS) -r -o $(@D)/.tmp_$(@F) $@ \ + -T $(@D)/.tmp_$(@F:.o=3D.ver); \ + mv -f $(@D)/.tmp_$(@F) $@; \ + rm -f $(@D)/.tmp_$(@F:.o=3D.ver); \ + fi +endif +endif + +$(obj)/%.o: $(src)/%.S $(objtool_dep) FORCE + $(call if_changed_rule,as_o_S) + +targets +=3D $(filter-out $(subdir-obj-y), $(real-obj-y)) $(real-obj-m) $(= lib-y) +targets +=3D $(extra-y) $(MAKECMDGOALS) $(always) + +# Linker scripts preprocessor (.lds.S -> .lds) +# ------------------------------------------------------------------------= --- +quiet_cmd_cpp_lds_S =3D LDS $@ + cmd_cpp_lds_S =3D $(CPP) $(cpp_flags) -P -U$(ARCH) \ + -D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $< + +$(obj)/%.lds: $(src)/%.lds.S FORCE + $(call if_changed_dep,cpp_lds_S) + +# ASN.1 grammar +# ------------------------------------------------------------------------= --- +quiet_cmd_asn1_compiler =3D ASN.1 $@ + cmd_asn1_compiler =3D $(objtree)/scripts/asn1_compiler $< \ + $(subst .h,.c,$@) $(subst .c,.h,$@) + +$(obj)/%.asn1.c $(obj)/%.asn1.h: $(src)/%.asn1 $(objtree)/scripts/asn1_com= piler + $(call cmd,asn1_compiler) + +# Build the compiled-in targets +# ------------------------------------------------------------------------= --- + +# To build objects in subdirs, we need to descend into the directories +$(sort $(subdir-obj-y)): $(subdir-ym) ; + +# +# Rule to compile a set of .o files into one .a file (without symbol table) +# +ifdef builtin-target + +quiet_cmd_ar_builtin =3D AR $@ + cmd_ar_builtin =3D rm -f $@; $(AR) rcSTP$(KBUILD_ARFLAGS) $@ $(real-= prereqs) + +$(builtin-target): $(real-obj-y) FORCE + $(call if_changed,ar_builtin) + +targets +=3D $(builtin-target) +endif # builtin-target + +# +# Rule to create modules.order file +# +# Create commands to either record .ko file or cat modules.order from +# a subdirectory +$(modorder-target): $(subdir-ym) FORCE + $(Q){ $(foreach m, $(modorder), \ + $(if $(filter %/modules.order, $m), cat $m, echo $m);) :; } \ + | $(AWK) '!x[$$0]++' - > $@ + +# +# Rule to compile a set of .o files into one .a file (with symbol table) +# +ifdef lib-target + +$(lib-target): $(lib-y) FORCE + $(call if_changed,ar) + +targets +=3D $(lib-target) + +dummy-object =3D $(obj)/.lib_exports.o +ksyms-lds =3D $(dot-target).lds + +quiet_cmd_export_list =3D EXPORTS $@ +cmd_export_list =3D $(OBJDUMP) -h $< | \ + sed -ne '/___ksymtab/s/.*+\([^ ]*\).*/EXTERN(\1)/p' >$(ksyms-lds);\ + rm -f $(dummy-object);\ + echo | $(CC) $(a_flags) -c -o $(dummy-object) -x assembler -;\ + $(LD) $(ld_flags) -r -o $@ -T $(ksyms-lds) $(dummy-object);\ + rm $(dummy-object) $(ksyms-lds) + +$(obj)/lib-ksyms.o: $(lib-target) FORCE + $(call if_changed,export_list) + +targets +=3D $(obj)/lib-ksyms.o + +endif + +# NOTE: +# Do not replace $(filter %.o,^) with $(real-prereqs). When a single object +# module is turned into a multi object module, $^ will contain header file +# dependencies recorded in the .*.cmd file. +quiet_cmd_link_multi-m =3D LD [M] $@ + cmd_link_multi-m =3D $(LD) $(ld_flags) -r -o $@ $(filter %.o,$^) + +$(multi-used-m): FORCE + $(call if_changed,link_multi-m) +$(call multi_depend, $(multi-used-m), .o, -objs -y -m) + +targets +=3D $(multi-used-m) +targets :=3D $(filter-out $(PHONY), $(targets)) + +# Add intermediate targets: +# When building objects with specific suffix patterns, add intermediate +# targets that the final targets are derived from. +intermediate_targets =3D $(foreach sfx, $(2), \ + $(patsubst %$(strip $(1)),%$(sfx), \ + $(filter %$(strip $(1)), $(targets)))) +# %.asn1.o <- %.asn1.[ch] <- %.asn1 +# %.dtb.o <- %.dtb.S <- %.dtb <- %.dts +# %.lex.o <- %.lex.c <- %.l +# %.tab.o <- %.tab.[ch] <- %.y +targets +=3D $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h) \ + $(call intermediate_targets, .dtb.o, .dtb.S .dtb) \ + $(call intermediate_targets, .lex.o, .lex.c) \ + $(call intermediate_targets, .tab.o, .tab.c .tab.h) + +# Descending +# ------------------------------------------------------------------------= --- + +PHONY +=3D $(subdir-ym) +$(subdir-ym): + $(Q)$(MAKE) $(build)=3D$@ \ + need-builtin=3D$(if $(filter $@/built-in.a, $(subdir-obj-y)),1) \ + need-modorder=3D$(if $(need-modorder),$(if $(filter $@/modules.order, $(m= odorder)),1)) + +# Add FORCE to the prequisites of a target to force it to be always rebuil= t. +# ------------------------------------------------------------------------= --- + +PHONY +=3D FORCE + +FORCE: + +# Read all saved command lines and dependencies for the $(targets) we +# may be building above, using $(if_changed{,_dep}). As an +# optimization, we don't need to read them if the target does not +# exist, we will rebuild anyway in that case. + +existing-targets :=3D $(wildcard $(sort $(targets))) + +-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) + +ifdef building_out_of_srctree +# Create directories for object files if they do not exist +obj-dirs :=3D $(sort $(obj) $(patsubst %/,%, $(dir $(targets)))) +# If targets exist, their directories apparently exist. Skip mkdir. +existing-dirs :=3D $(sort $(patsubst %/,%, $(dir $(existing-targets)))) +obj-dirs :=3D $(strip $(filter-out $(existing-dirs), $(obj-dirs))) +ifneq ($(obj-dirs),) +$(shell mkdir -p $(obj-dirs)) +endif +endif + +.PHONY: $(PHONY) diff --git a/xen/scripts/Makefile.clean b/xen/scripts/Makefile.clean new file mode 100644 index 000000000000..0b80e3207b20 --- /dev/null +++ b/xen/scripts/Makefile.clean @@ -0,0 +1,90 @@ +# SPDX-License-Identifier: GPL-2.0 +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +# Cleaning up +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +src :=3D $(obj) + +PHONY :=3D __clean +__clean: + +include scripts/Kbuild.include + +# The filename Kbuild has precedence over Makefile +kbuild-dir :=3D $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) +include $(if $(wildcard $(kbuild-dir)/Kbuild), $(kbuild-dir)/Kbuild, $(kbu= ild-dir)/Makefile) + +# Figure out what we need to build from the various variables +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +__subdir-y :=3D $(patsubst %/,%,$(filter %/, $(obj-y))) +subdir-y +=3D $(__subdir-y) +__subdir-m :=3D $(patsubst %/,%,$(filter %/, $(obj-m))) +subdir-m +=3D $(__subdir-m) +__subdir- :=3D $(patsubst %/,%,$(filter %/, $(obj-))) +subdir- +=3D $(__subdir-) + +# Subdirectories we need to descend into + +subdir-ym :=3D $(sort $(subdir-y) $(subdir-m)) +subdir-ymn :=3D $(sort $(subdir-ym) $(subdir-)) + +# Add subdir path + +subdir-ymn :=3D $(addprefix $(obj)/,$(subdir-ymn)) + +# build a list of files to remove, usually relative to the current +# directory + +__clean-files :=3D $(extra-y) $(extra-m) $(extra-) \ + $(always) $(targets) $(clean-files) \ + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \ + $(hostlibs-y) $(hostlibs-m) $(hostlibs-) \ + $(hostcxxlibs-y) $(hostcxxlibs-m) + +__clean-files :=3D $(filter-out $(no-clean-files), $(__clean-files)) + +# clean-files is given relative to the current directory, unless it +# starts with $(objtree)/ (which means "./", so do not add "./" unless +# you want to delete a file from the toplevel object directory). + +__clean-files :=3D $(wildcard = \ + $(addprefix $(obj)/, $(filter-out $(objtree)/%, $(__clean-files))) \ + $(filter $(objtree)/%, $(__clean-files))) + +# same as clean-files + +__clean-dirs :=3D $(wildcard = \ + $(addprefix $(obj)/, $(filter-out $(objtree)/%, $(clean-dirs))) \ + $(filter $(objtree)/%, $(clean-dirs))) + +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +quiet_cmd_clean =3D CLEAN $(obj) + cmd_clean =3D rm -f $(__clean-files) +quiet_cmd_cleandir =3D CLEAN $(__clean-dirs) + cmd_cleandir =3D rm -rf $(__clean-dirs) + + +__clean: $(subdir-ymn) +ifneq ($(strip $(__clean-files)),) + +$(call cmd,clean) +endif +ifneq ($(strip $(__clean-dirs)),) + +$(call cmd,cleandir) +endif + @: + + +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D +# Generic stuff +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + +# Descending +# ------------------------------------------------------------------------= --- + +PHONY +=3D $(subdir-ymn) +$(subdir-ymn): + $(Q)$(MAKE) $(clean)=3D$@ + +.PHONY: $(PHONY) diff --git a/xen/scripts/Makefile.gcc-plugins b/xen/scripts/Makefile.gcc-pl= ugins new file mode 100644 index 000000000000..5f7df50cfe7a --- /dev/null +++ b/xen/scripts/Makefile.gcc-plugins @@ -0,0 +1,59 @@ +# SPDX-License-Identifier: GPL-2.0 + +gcc-plugin-$(CONFIG_GCC_PLUGIN_CYC_COMPLEXITY) +=3D cyc_complexity_plugin.= so + +gcc-plugin-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) +=3D latent_entropy_plugin.= so +gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) \ + +=3D -DLATENT_ENTROPY_PLUGIN +ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY + DISABLE_LATENT_ENTROPY_PLUGIN +=3D -fplugin-arg-latent_entropy_plugin-= disable +endif +export DISABLE_LATENT_ENTROPY_PLUGIN + +gcc-plugin-$(CONFIG_GCC_PLUGIN_SANCOV) +=3D sancov_plugin.so + +gcc-plugin-$(CONFIG_GCC_PLUGIN_STRUCTLEAK) +=3D structleak_plugin.so +gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_VERBOSE) \ + +=3D -fplugin-arg-structleak_plugin-verbose +gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF) \ + +=3D -fplugin-arg-structleak_plugin-byref +gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL) \ + +=3D -fplugin-arg-structleak_plugin-byref-all +gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK) \ + +=3D -DSTRUCTLEAK_PLUGIN + +gcc-plugin-$(CONFIG_GCC_PLUGIN_RANDSTRUCT) +=3D randomize_layout_plugin.so +gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_RANDSTRUCT) \ + +=3D -DRANDSTRUCT_PLUGIN +gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_RANDSTRUCT_PERFORMANCE) \ + +=3D -fplugin-arg-randomize_layout_plugin-performance-mode + +gcc-plugin-$(CONFIG_GCC_PLUGIN_STACKLEAK) +=3D stackleak_plugin.so +gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK) \ + +=3D -DSTACKLEAK_PLUGIN +gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK) \ + +=3D -fplugin-arg-stackleak_plugin-track-min-size=3D$(CONFIG_STACKLEAK_T= RACK_MIN_SIZE) +ifdef CONFIG_GCC_PLUGIN_STACKLEAK + DISABLE_STACKLEAK_PLUGIN +=3D -fplugin-arg-stackleak_plugin-disable +endif +export DISABLE_STACKLEAK_PLUGIN + +gcc-plugin-$(CONFIG_GCC_PLUGIN_ARM_SSP_PER_TASK) +=3D arm_ssp_per_task_plu= gin.so +ifdef CONFIG_GCC_PLUGIN_ARM_SSP_PER_TASK + DISABLE_ARM_SSP_PER_TASK_PLUGIN +=3D -fplugin-arg-arm_ssp_per_task_plu= gin-disable +endif +export DISABLE_ARM_SSP_PER_TASK_PLUGIN + +# All the plugin CFLAGS are collected here in case a build target needs to +# filter them out of the KBUILD_CFLAGS. +GCC_PLUGINS_CFLAGS :=3D $(strip $(addprefix -fplugin=3D$(objtree)/scripts/= gcc-plugins/, $(gcc-plugin-y)) $(gcc-plugin-cflags-y)) +# The sancov_plugin.so is included via CFLAGS_KCOV, so it is removed here. +GCC_PLUGINS_CFLAGS :=3D $(filter-out %/sancov_plugin.so, $(GCC_PLUGINS_CFL= AGS)) +export GCC_PLUGINS_CFLAGS + +# Add the flags to the build! +KBUILD_CFLAGS +=3D $(GCC_PLUGINS_CFLAGS) + +# All enabled GCC plugins are collected here for building below. +GCC_PLUGIN :=3D $(gcc-plugin-y) +export GCC_PLUGIN diff --git a/xen/scripts/Makefile.headersinst b/xen/scripts/Makefile.header= sinst new file mode 100644 index 000000000000..1b405a7ed14f --- /dev/null +++ b/xen/scripts/Makefile.headersinst @@ -0,0 +1,102 @@ +# SPDX-License-Identifier: GPL-2.0 +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +# Installing headers +# +# All headers under include/uapi, include/generated/uapi, +# arch//include/uapi and arch//include/generated/uapi are +# exported. +# They are preprocessed to remove __KERNEL__ section of the file. +# +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +PHONY :=3D __headers +__headers: + +include scripts/Kbuild.include + +src :=3D $(srctree)/$(obj) +gen :=3D $(objtree)/$(subst include/,include/generated/,$(obj)) +dst :=3D usr/include + +-include $(src)/Kbuild + +# $(filter %/, ...) is a workaround for GNU Make <=3D 4.2.1, where +# $(wildcard $(src)/*/) contains not only directories but also regular fil= es. +src-subdirs :=3D $(patsubst $(src)/%/,%,$(filter %/, $(wildcard $(src)/*/)= )) +gen-subdirs :=3D $(patsubst $(gen)/%/,%,$(filter %/, $(wildcard $(gen)/*/)= )) +all-subdirs :=3D $(sort $(src-subdirs) $(gen-subdirs)) + +src-headers :=3D $(if $(src-subdirs), $(shell cd $(src) && find $(src-subd= irs) -name '*.h')) +src-headers :=3D $(filter-out $(no-export-headers), $(src-headers)) +gen-headers :=3D $(if $(gen-subdirs), $(shell cd $(gen) && find $(gen-subd= irs) -name '*.h')) +gen-headers :=3D $(filter-out $(no-export-headers), $(gen-headers)) + +# If the same header is exported from source and generated directories, +# the former takes precedence, but this should be warned. +duplicated :=3D $(filter $(gen-headers), $(src-headers)) +$(if $(duplicated), $(warning duplicated header export: $(duplicated))) + +gen-headers :=3D $(filter-out $(duplicated), $(gen-headers)) + +# Add dst path prefix +all-subdirs :=3D $(addprefix $(dst)/, $(all-subdirs)) +src-headers :=3D $(addprefix $(dst)/, $(src-headers)) +gen-headers :=3D $(addprefix $(dst)/, $(gen-headers)) +all-headers :=3D $(src-headers) $(gen-headers) + +# Work out what needs to be removed +old-subdirs :=3D $(wildcard $(all-subdirs)) +old-headers :=3D $(if $(old-subdirs),$(shell find $(old-subdirs) -name '*.= h')) +unwanted :=3D $(filter-out $(all-headers), $(old-headers)) + +# Create directories +existing-dirs :=3D $(sort $(dir $(old-headers))) +wanted-dirs :=3D $(sort $(dir $(all-headers))) +new-dirs :=3D $(filter-out $(existing-dirs), $(wanted-dirs)) +$(if $(new-dirs), $(shell mkdir -p $(new-dirs))) + +# Rules + +ifndef HDRCHECK + +quiet_cmd_install =3D HDRINST $@ + cmd_install =3D $(CONFIG_SHELL) $(srctree)/scripts/headers_install.s= h $< $@ + +$(src-headers): $(dst)/%.h: $(src)/%.h $(srctree)/scripts/headers_install.= sh FORCE + $(call if_changed,install) + +$(gen-headers): $(dst)/%.h: $(gen)/%.h $(srctree)/scripts/headers_install.= sh FORCE + $(call if_changed,install) + +quiet_cmd_remove =3D REMOVE $(unwanted) + cmd_remove =3D rm -f $(unwanted) + +__headers: $(all-headers) +ifneq ($(unwanted),) + $(call cmd,remove) +endif + @: + +existing-headers :=3D $(filter $(old-headers), $(all-headers)) + +-include $(foreach f,$(existing-headers),$(dir $(f)).$(notdir $(f)).cmd) + +else + +quiet_cmd_check =3D HDRCHK $< + cmd_check =3D $(PERL) $(srctree)/scripts/headers_check.pl $(dst) $(S= RCARCH) $<; touch $@ + +check-files :=3D $(addsuffix .chk, $(all-headers)) + +$(check-files): $(dst)/%.chk : $(dst)/% $(srctree)/scripts/headers_check.pl + $(call cmd,check) + +__headers: $(check-files) + @: + +endif + +PHONY +=3D FORCE +FORCE: + +.PHONY: $(PHONY) diff --git a/xen/scripts/Makefile.host b/xen/scripts/Makefile.host new file mode 100644 index 000000000000..2208ebbd8c4c --- /dev/null +++ b/xen/scripts/Makefile.host @@ -0,0 +1,164 @@ +# SPDX-License-Identifier: GPL-2.0 +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +# Building binaries on the host system +# Binaries are used during the compilation of the kernel, for example +# to preprocess a data file. +# +# Both C and C++ are supported, but preferred language is C for such utili= ties. +# +# Sample syntax (see Documentation/kbuild/makefiles.rst for reference) +# hostprogs-y :=3D bin2hex +# Will compile bin2hex.c and create an executable named bin2hex +# +# hostprogs-y :=3D lxdialog +# lxdialog-objs :=3D checklist.o lxdialog.o +# Will compile lxdialog.c and checklist.c, and then link the executable +# lxdialog, based on checklist.o and lxdialog.o +# +# hostprogs-y :=3D qconf +# qconf-cxxobjs :=3D qconf.o +# qconf-objs :=3D menu.o +# Will compile qconf as a C++ program, and menu as a C program. +# They are linked as C++ code to the executable qconf + +__hostprogs :=3D $(sort $(hostprogs-y) $(hostprogs-m)) +host-cshlib :=3D $(sort $(hostlibs-y) $(hostlibs-m)) +host-cxxshlib :=3D $(sort $(hostcxxlibs-y) $(hostcxxlibs-m)) + +# C code +# Executables compiled from a single .c file +host-csingle :=3D $(foreach m,$(__hostprogs), \ + $(if $($(m)-objs)$($(m)-cxxobjs),,$(m))) + +# C executables linked based on several .o files +host-cmulti :=3D $(foreach m,$(__hostprogs),\ + $(if $($(m)-cxxobjs),,$(if $($(m)-objs),$(m)))) + +# Object (.o) files compiled from .c files +host-cobjs :=3D $(sort $(foreach m,$(__hostprogs),$($(m)-objs))) + +# C++ code +# C++ executables compiled from at least one .cc file +# and zero or more .c files +host-cxxmulti :=3D $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m))) + +# C++ Object (.o) files compiled from .cc files +host-cxxobjs :=3D $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs))) + +# Object (.o) files used by the shared libaries +host-cshobjs :=3D $(sort $(foreach m,$(host-cshlib),$($(m:.so=3D-objs)))) +host-cxxshobjs :=3D $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=3D-objs)= ))) + +host-csingle :=3D $(addprefix $(obj)/,$(host-csingle)) +host-cmulti :=3D $(addprefix $(obj)/,$(host-cmulti)) +host-cobjs :=3D $(addprefix $(obj)/,$(host-cobjs)) +host-cxxmulti :=3D $(addprefix $(obj)/,$(host-cxxmulti)) +host-cxxobjs :=3D $(addprefix $(obj)/,$(host-cxxobjs)) +host-cshlib :=3D $(addprefix $(obj)/,$(host-cshlib)) +host-cxxshlib :=3D $(addprefix $(obj)/,$(host-cxxshlib)) +host-cshobjs :=3D $(addprefix $(obj)/,$(host-cshobjs)) +host-cxxshobjs :=3D $(addprefix $(obj)/,$(host-cxxshobjs)) + +##### +# Handle options to gcc. Support building with separate output directory + +_hostc_flags =3D $(KBUILD_HOSTCFLAGS) $(HOST_EXTRACFLAGS) \ + $(HOSTCFLAGS_$(basetarget).o) +_hostcxx_flags =3D $(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \ + $(HOSTCXXFLAGS_$(basetarget).o) + +# $(objtree)/$(obj) for including generated headers from checkin source fi= les +ifeq ($(KBUILD_EXTMOD),) +ifdef building_out_of_srctree +_hostc_flags +=3D -I $(objtree)/$(obj) +_hostcxx_flags +=3D -I $(objtree)/$(obj) +endif +endif + +hostc_flags =3D -Wp,-MD,$(depfile) $(_hostc_flags) +hostcxx_flags =3D -Wp,-MD,$(depfile) $(_hostcxx_flags) + +##### +# Compile programs on the host + +# Create executable from a single .c file +# host-csingle -> Executable +quiet_cmd_host-csingle =3D HOSTCC $@ + cmd_host-csingle =3D $(HOSTCC) $(hostc_flags) $(KBUILD_HOSTLDFLAGS) = -o $@ $< \ + $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F)) +$(host-csingle): $(obj)/%: $(src)/%.c FORCE + $(call if_changed_dep,host-csingle) + +# Link an executable based on list of .o files, all plain c +# host-cmulti -> executable +quiet_cmd_host-cmulti =3D HOSTLD $@ + cmd_host-cmulti =3D $(HOSTCC) $(KBUILD_HOSTLDFLAGS) -o $@ \ + $(addprefix $(obj)/,$($(@F)-objs)) \ + $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F)) +$(host-cmulti): FORCE + $(call if_changed,host-cmulti) +$(call multi_depend, $(host-cmulti), , -objs) + +# Create .o file from a single .c file +# host-cobjs -> .o +quiet_cmd_host-cobjs =3D HOSTCC $@ + cmd_host-cobjs =3D $(HOSTCC) $(hostc_flags) -c -o $@ $< +$(host-cobjs): $(obj)/%.o: $(src)/%.c FORCE + $(call if_changed_dep,host-cobjs) + +# Link an executable based on list of .o files, a mixture of .c and .cc +# host-cxxmulti -> executable +quiet_cmd_host-cxxmulti =3D HOSTLD $@ + cmd_host-cxxmulti =3D $(HOSTCXX) $(KBUILD_HOSTLDFLAGS) -o $@ \ + $(foreach o,objs cxxobjs,\ + $(addprefix $(obj)/,$($(@F)-$(o)))) \ + $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F)) +$(host-cxxmulti): FORCE + $(call if_changed,host-cxxmulti) +$(call multi_depend, $(host-cxxmulti), , -objs -cxxobjs) + +# Create .o file from a single .cc (C++) file +quiet_cmd_host-cxxobjs =3D HOSTCXX $@ + cmd_host-cxxobjs =3D $(HOSTCXX) $(hostcxx_flags) -c -o $@ $< +$(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE + $(call if_changed_dep,host-cxxobjs) + +# Compile .c file, create position independent .o file +# host-cshobjs -> .o +quiet_cmd_host-cshobjs =3D HOSTCC -fPIC $@ + cmd_host-cshobjs =3D $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $< +$(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE + $(call if_changed_dep,host-cshobjs) + +# Compile .c file, create position independent .o file +# Note that plugin capable gcc versions can be either C or C++ based +# therefore plugin source files have to be compilable in both C and C++ mo= de. +# This is why a C++ compiler is invoked on a .c file. +# host-cxxshobjs -> .o +quiet_cmd_host-cxxshobjs =3D HOSTCXX -fPIC $@ + cmd_host-cxxshobjs =3D $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $< +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE + $(call if_changed_dep,host-cxxshobjs) + +# Link a shared library, based on position independent .o files +# *.o -> .so shared library (host-cshlib) +quiet_cmd_host-cshlib =3D HOSTLLD -shared $@ + cmd_host-cshlib =3D $(HOSTCC) $(KBUILD_HOSTLDFLAGS) -shared -o $@ \ + $(addprefix $(obj)/,$($(@F:.so=3D-objs))) \ + $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F)) +$(host-cshlib): FORCE + $(call if_changed,host-cshlib) +$(call multi_depend, $(host-cshlib), .so, -objs) + +# Link a shared library, based on position independent .o files +# *.o -> .so shared library (host-cxxshlib) +quiet_cmd_host-cxxshlib =3D HOSTLLD -shared $@ + cmd_host-cxxshlib =3D $(HOSTCXX) $(KBUILD_HOSTLDFLAGS) -shared -o $@= \ + $(addprefix $(obj)/,$($(@F:.so=3D-objs))) \ + $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F)) +$(host-cxxshlib): FORCE + $(call if_changed,host-cxxshlib) +$(call multi_depend, $(host-cxxshlib), .so, -objs) + +targets +=3D $(host-csingle) $(host-cmulti) $(host-cobjs)\ + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host= -cxxshlib) $(host-cxxshobjs) diff --git a/xen/scripts/Makefile.kasan b/xen/scripts/Makefile.kasan new file mode 100644 index 000000000000..6410bd22fe38 --- /dev/null +++ b/xen/scripts/Makefile.kasan @@ -0,0 +1,51 @@ +# SPDX-License-Identifier: GPL-2.0 +ifdef CONFIG_KASAN_GENERIC + +ifdef CONFIG_KASAN_INLINE + call_threshold :=3D 10000 +else + call_threshold :=3D 0 +endif + +KASAN_SHADOW_OFFSET ?=3D $(CONFIG_KASAN_SHADOW_OFFSET) + +CFLAGS_KASAN_MINIMAL :=3D -fsanitize=3Dkernel-address + +cc-param =3D $(call cc-option, -mllvm -$(1), $(call cc-option, --param $(1= ))) + +# -fasan-shadow-offset fails without -fsanitize +CFLAGS_KASAN_SHADOW :=3D $(call cc-option, -fsanitize=3Dkernel-address \ + -fasan-shadow-offset=3D$(KASAN_SHADOW_OFFSET), \ + $(call cc-option, -fsanitize=3Dkernel-address \ + -mllvm -asan-mapping-offset=3D$(KASAN_SHADOW_OFFSET))) + +ifeq ($(strip $(CFLAGS_KASAN_SHADOW)),) + CFLAGS_KASAN :=3D $(CFLAGS_KASAN_MINIMAL) +else + # Now add all the compiler specific options that are valid standalone + CFLAGS_KASAN :=3D $(CFLAGS_KASAN_SHADOW) \ + $(call cc-param,asan-globals=3D1) \ + $(call cc-param,asan-instrumentation-with-call-threshold=3D$(call_thresh= old)) \ + $(call cc-param,asan-stack=3D$(CONFIG_KASAN_STACK)) \ + $(call cc-param,asan-instrument-allocas=3D1) +endif + +endif # CONFIG_KASAN_GENERIC + +ifdef CONFIG_KASAN_SW_TAGS + +ifdef CONFIG_KASAN_INLINE + instrumentation_flags :=3D -mllvm -hwasan-mapping-offset=3D$(KASAN_SHA= DOW_OFFSET) +else + instrumentation_flags :=3D -mllvm -hwasan-instrument-with-calls=3D1 +endif + +CFLAGS_KASAN :=3D -fsanitize=3Dkernel-hwaddress \ + -mllvm -hwasan-instrument-stack=3D0 \ + $(instrumentation_flags) + +endif # CONFIG_KASAN_SW_TAGS + +ifdef CONFIG_KASAN +CFLAGS_KASAN_NOSANITIZE :=3D -fno-builtin +endif diff --git a/xen/scripts/Makefile.kcov b/xen/scripts/Makefile.kcov new file mode 100644 index 000000000000..52b113302443 --- /dev/null +++ b/xen/scripts/Makefile.kcov @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0-only +ifdef CONFIG_KCOV + +kcov-flags-$(CONFIG_CC_HAS_SANCOV_TRACE_PC) +=3D -fsanitize-coverage=3Dtra= ce-pc +kcov-flags-$(CONFIG_KCOV_ENABLE_COMPARISONS) +=3D -fsanitize-coverage=3Dtr= ace-cmp +kcov-flags-$(CONFIG_GCC_PLUGIN_SANCOV) +=3D -fplugin=3D$(objtree)/scripts= /gcc-plugins/sancov_plugin.so + +export CFLAGS_KCOV :=3D $(kcov-flags-y) + +endif diff --git a/xen/scripts/Makefile.lib b/xen/scripts/Makefile.lib new file mode 100644 index 000000000000..41c50f9461e5 --- /dev/null +++ b/xen/scripts/Makefile.lib @@ -0,0 +1,435 @@ +# SPDX-License-Identifier: GPL-2.0 +# Backward compatibility +asflags-y +=3D $(EXTRA_AFLAGS) +ccflags-y +=3D $(EXTRA_CFLAGS) +cppflags-y +=3D $(EXTRA_CPPFLAGS) +ldflags-y +=3D $(EXTRA_LDFLAGS) + +# flags that take effect in current and sub directories +KBUILD_AFLAGS +=3D $(subdir-asflags-y) +KBUILD_CFLAGS +=3D $(subdir-ccflags-y) + +# Figure out what we need to build from the various variables +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + +# When an object is listed to be built compiled-in and modular, +# only build the compiled-in version +obj-m :=3D $(filter-out $(obj-y),$(obj-m)) + +# Libraries are always collected in one lib file. +# Filter out objects already built-in +lib-y :=3D $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m))) + +# Determine modorder. +# Unfortunately, we don't have information about ordering between -y +# and -m subdirs. Just put -y's first. +modorder :=3D $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-= m:.o=3D.ko)) + +# Handle objects in subdirs +# ------------------------------------------------------------------------= --- +# 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) +__subdir-y :=3D $(patsubst %/,%,$(filter %/, $(obj-y))) +subdir-y +=3D $(__subdir-y) +__subdir-m :=3D $(patsubst %/,%,$(filter %/, $(obj-m))) +subdir-m +=3D $(__subdir-m) +obj-y :=3D $(patsubst %/, %/built-in.a, $(obj-y)) +obj-m :=3D $(filter-out %/, $(obj-m)) + +# Subdirectories we need to descend into +subdir-ym :=3D $(sort $(subdir-y) $(subdir-m)) + +# if $(foo-objs), $(foo-y), or $(foo-m) exists, foo.o is a composite object +multi-used-y :=3D $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=3D-ob= js)) $($(m:.o=3D-y))), $(m)))) +multi-used-m :=3D $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=3D-ob= js)) $($(m:.o=3D-y)) $($(m:.o=3D-m))), $(m)))) +multi-used :=3D $(multi-used-y) $(multi-used-m) + +# $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to +# tell kbuild to descend +subdir-obj-y :=3D $(filter %/built-in.a, $(obj-y)) + +# Replace multi-part objects by their individual parts, +# including built-in.a from subdirectories +real-obj-y :=3D $(foreach m, $(obj-y), $(if $(strip $($(m:.o=3D-objs)) $($= (m:.o=3D-y))),$($(m:.o=3D-objs)) $($(m:.o=3D-y)),$(m))) +real-obj-m :=3D $(foreach m, $(obj-m), $(if $(strip $($(m:.o=3D-objs)) $($= (m:.o=3D-y)) $($(m:.o=3D-m))),$($(m:.o=3D-objs)) $($(m:.o=3D-y)) $($(m:.o= =3D-m)),$(m))) + +# DTB +# If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built +extra-y +=3D $(dtb-y) +extra-$(CONFIG_OF_ALL_DTBS) +=3D $(dtb-) + +ifneq ($(CHECK_DTBS),) +extra-y +=3D $(patsubst %.dtb,%.dt.yaml, $(dtb-y)) +extra-$(CONFIG_OF_ALL_DTBS) +=3D $(patsubst %.dtb,%.dt.yaml, $(dtb-)) +endif + +# Test self-contained headers + +# Wildcard searches in $(srctree)/$(src)/, but not in $(objtree)/$(obj)/. +# Stale generated headers are often left over, so pattern matching should +# be avoided. Please notice $(srctree)/$(src)/ and $(objtree)/$(obj) point +# to the same location for in-tree building. So, header-test-pattern-y sho= uld +# be used with care. +header-test-y +=3D $(filter-out $(header-test-), \ + $(patsubst $(srctree)/$(src)/%, %, \ + $(wildcard $(addprefix $(srctree)/$(src)/, \ + $(header-test-pattern-y))))) + +extra-$(CONFIG_HEADER_TEST) +=3D $(addsuffix .s, $(header-test-y) $(header= -test-m)) + +# Add subdir path + +extra-y :=3D $(addprefix $(obj)/,$(extra-y)) +always :=3D $(addprefix $(obj)/,$(always)) +targets :=3D $(addprefix $(obj)/,$(targets)) +modorder :=3D $(addprefix $(obj)/,$(modorder)) +obj-m :=3D $(addprefix $(obj)/,$(obj-m)) +lib-y :=3D $(addprefix $(obj)/,$(lib-y)) +subdir-obj-y :=3D $(addprefix $(obj)/,$(subdir-obj-y)) +real-obj-y :=3D $(addprefix $(obj)/,$(real-obj-y)) +real-obj-m :=3D $(addprefix $(obj)/,$(real-obj-m)) +multi-used-m :=3D $(addprefix $(obj)/,$(multi-used-m)) +subdir-ym :=3D $(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 =3D $(subst $(space),:,$(sort $(foreach m,$(multi-used),\ + $(if $(filter $*.o, $($(m:.o=3D-objs)) $($(m:.o=3D-y)) $($(m:.o=3D-m))),= $(m:.o=3D))))) + +modname =3D $(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) +name-fix =3D $(squote)$(quote)$(subst $(comma),_,$(subst -,_,$1))$(quote)$= (squote) +basename_flags =3D -DKBUILD_BASENAME=3D$(call name-fix,$(basetarget)) +modname_flags =3D -DKBUILD_MODNAME=3D$(call name-fix,$(modname)) + +orig_c_flags =3D $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \ + $(ccflags-y) $(CFLAGS_$(basetarget).o) +_c_flags =3D $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c= _flags)) +orig_a_flags =3D $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) \ + $(asflags-y) $(AFLAGS_$(basetarget).o) +_a_flags =3D $(filter-out $(AFLAGS_REMOVE_$(basetarget).o), $(orig_a= _flags)) +_cpp_flags =3D $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F)) + +# +# Enable gcov profiling flags for a file, directory or for all files depen= ding +# on variables GCOV_PROFILE_obj.o, GCOV_PROFILE and CONFIG_GCOV_PROFILE_ALL +# (in this order) +# +ifeq ($(CONFIG_GCOV_KERNEL),y) +_c_flags +=3D $(if $(patsubst n%,, \ + $(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)= ), \ + $(CFLAGS_GCOV)) +endif + +# +# Enable address sanitizer flags for kernel except some files or directori= es +# we don't want to check (depends on variables KASAN_SANITIZE_obj.o, KASAN= _SANITIZE) +# +ifeq ($(CONFIG_KASAN),y) +_c_flags +=3D $(if $(patsubst n%,, \ + $(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \ + $(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE)) +endif + +ifeq ($(CONFIG_UBSAN),y) +_c_flags +=3D $(if $(patsubst n%,, \ + $(UBSAN_SANITIZE_$(basetarget).o)$(UBSAN_SANITIZE)$(CONFIG_UBSAN_SANITIZ= E_ALL)), \ + $(CFLAGS_UBSAN)) +endif + +ifeq ($(CONFIG_KCOV),y) +_c_flags +=3D $(if $(patsubst n%,, \ + $(KCOV_INSTRUMENT_$(basetarget).o)$(KCOV_INSTRUMENT)$(CONFIG_KCOV_INSTRUM= ENT_ALL)), \ + $(CFLAGS_KCOV)) +endif + +# $(srctree)/$(src) for including checkin headers from generated source fi= les +# $(objtree)/$(obj) for including generated headers from checkin source fi= les +ifeq ($(KBUILD_EXTMOD),) +ifdef building_out_of_srctree +_c_flags +=3D -I $(srctree)/$(src) -I $(objtree)/$(obj) +_a_flags +=3D -I $(srctree)/$(src) -I $(objtree)/$(obj) +_cpp_flags +=3D -I $(srctree)/$(src) -I $(objtree)/$(obj) +endif +endif + +c_flags =3D -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) = \ + -include $(srctree)/include/linux/compiler_types.h \ + $(_c_flags) $(modkern_cflags) \ + $(basename_flags) $(modname_flags) + +a_flags =3D -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) = \ + $(_a_flags) $(modkern_aflags) + +cpp_flags =3D -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) = \ + $(_cpp_flags) + +ld_flags =3D $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F)) + +DTC_INCLUDE :=3D $(srctree)/scripts/dtc/include-prefixes + +dtc_cpp_flags =3D -Wp,-MD,$(depfile).pre.tmp -nostdinc = \ + $(addprefix -I,$(DTC_INCLUDE)) \ + -undef -D__DTS__ + +# Useful for describing the dependency of composite objects +# Usage: +# $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_a= dd) +define multi_depend +$(foreach m, $(notdir $1), \ + $(eval $(obj)/$m: \ + $(addprefix $(obj)/, $(foreach s, $3, $($(m:%$(strip $2)=3D%$(s))))))) +endef + +# LEX +# ------------------------------------------------------------------------= --- +quiet_cmd_flex =3D LEX $@ + cmd_flex =3D $(LEX) -o$@ -L $< + +$(obj)/%.lex.c: $(src)/%.l FORCE + $(call if_changed,flex) + +# YACC +# ------------------------------------------------------------------------= --- +quiet_cmd_bison =3D YACC $@ + cmd_bison =3D $(YACC) -o$@ -t -l $< + +$(obj)/%.tab.c: $(src)/%.y FORCE + $(call if_changed,bison) + +quiet_cmd_bison_h =3D YACC $@ + cmd_bison_h =3D $(YACC) -o/dev/null --defines=3D$@ -t -l $< + +$(obj)/%.tab.h: $(src)/%.y FORCE + $(call if_changed,bison_h) + +# Shipped files +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + +quiet_cmd_shipped =3D SHIPPED $@ +cmd_shipped =3D cat $< > $@ + +$(obj)/%: $(src)/%_shipped + $(call cmd,shipped) + +# Commands useful for building a boot image +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D +# +# Use as following: +# +# target: source(s) FORCE +# $(if_changed,ld/objcopy/gzip) +# +# and add target to extra-y so that we know we have to +# read in the saved command line + +# Linking +# ------------------------------------------------------------------------= --- + +quiet_cmd_ld =3D LD $@ + cmd_ld =3D $(LD) $(ld_flags) $(real-prereqs) -o $@ + +# Archive +# ------------------------------------------------------------------------= --- + +quiet_cmd_ar =3D AR $@ + cmd_ar =3D rm -f $@; $(AR) rcsTP$(KBUILD_ARFLAGS) $@ $(real-prereqs) + +# Objcopy +# ------------------------------------------------------------------------= --- + +quiet_cmd_objcopy =3D OBJCOPY $@ +cmd_objcopy =3D $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@ + +# Gzip +# ------------------------------------------------------------------------= --- + +quiet_cmd_gzip =3D GZIP $@ + cmd_gzip =3D cat $(real-prereqs) | gzip -n -f -9 > $@ + +# DTC +# ------------------------------------------------------------------------= --- +DTC ?=3D $(objtree)/scripts/dtc/dtc + +# Disable noisy checks by default +ifeq ($(findstring 1,$(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),) +DTC_FLAGS +=3D -Wno-unit_address_vs_reg \ + -Wno-unit_address_format \ + -Wno-avoid_unnecessary_addr_size \ + -Wno-alias_paths \ + -Wno-graph_child_address \ + -Wno-simple_bus_reg \ + -Wno-unique_unit_address \ + -Wno-pci_device_reg +endif + +ifneq ($(findstring 2,$(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),) +DTC_FLAGS +=3D -Wnode_name_chars_strict \ + -Wproperty_name_chars_strict +endif + +DTC_FLAGS +=3D $(DTC_FLAGS_$(basetarget)) + +# Generate an assembly file to wrap the output of the device tree compiler +quiet_cmd_dt_S_dtb=3D DTB $@ +cmd_dt_S_dtb=3D \ +{ \ + echo '\#include '; \ + echo '.section .dtb.init.rodata,"a"'; \ + echo '.balign STRUCT_ALIGNMENT'; \ + echo '.global __dtb_$(subst -,_,$(*F))_begin'; \ + echo '__dtb_$(subst -,_,$(*F))_begin:'; \ + echo '.incbin "$<" '; \ + echo '__dtb_$(subst -,_,$(*F))_end:'; \ + echo '.global __dtb_$(subst -,_,$(*F))_end'; \ + echo '.balign STRUCT_ALIGNMENT'; \ +} > $@ + +$(obj)/%.dtb.S: $(obj)/%.dtb FORCE + $(call if_changed,dt_S_dtb) + +quiet_cmd_dtc =3D DTC $@ +cmd_dtc =3D mkdir -p $(dir ${dtc-tmp}) ; \ + $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \ + $(DTC) -O $(2) -o $@ -b 0 \ + $(addprefix -i,$(dir $<) $(DTC_INCLUDE)) $(DTC_FLAGS) \ + -d $(depfile).dtc.tmp $(dtc-tmp) ; \ + cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile) + +$(obj)/%.dtb: $(src)/%.dts $(DTC) FORCE + $(call if_changed_dep,dtc,dtb) + +DT_CHECKER ?=3D dt-validate +DT_BINDING_DIR :=3D Documentation/devicetree/bindings +DT_TMP_SCHEMA :=3D $(objtree)/$(DT_BINDING_DIR)/processed-schema.yaml + +quiet_cmd_dtb_check =3D CHECK $@ + cmd_dtb_check =3D $(DT_CHECKER) -u $(srctree)/$(DT_BINDING_DIR) -p $= (DT_TMP_SCHEMA) $@ ; + +define rule_dtc_dt_yaml + $(call cmd_and_fixdep,dtc,yaml) + $(call cmd,dtb_check) +endef + +$(obj)/%.dt.yaml: $(src)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE + $(call if_changed_rule,dtc_dt_yaml) + +dtc-tmp =3D $(subst $(comma),_,$(dot-target).dts.tmp) + +# Bzip2 +# ------------------------------------------------------------------------= --- + +# Bzip2 and LZMA do not include size in file... so we have to fake that; +# append the size as a 32-bit littleendian number as gzip does. +size_append =3D printf $(shell \ +dec_size=3D0; \ +for F in $(real-prereqs); do \ + fsize=3D$$($(CONFIG_SHELL) $(srctree)/scripts/file-size.sh $$F); \ + dec_size=3D$$(expr $$dec_size + $$fsize); \ +done; \ +printf "%08x\n" $$dec_size | \ + sed 's/\(..\)/\1 /g' | { \ + read ch0 ch1 ch2 ch3; \ + for ch in $$ch3 $$ch2 $$ch1 $$ch0; do \ + printf '%s%03o' '\\' $$((0x$$ch)); \ + done; \ + } \ +) + +quiet_cmd_bzip2 =3D BZIP2 $@ + cmd_bzip2 =3D { cat $(real-prereqs) | bzip2 -9; $(size_append); } > = $@ + +# Lzma +# ------------------------------------------------------------------------= --- + +quiet_cmd_lzma =3D LZMA $@ + cmd_lzma =3D { cat $(real-prereqs) | lzma -9; $(size_append); } > $@ + +quiet_cmd_lzo =3D LZO $@ + cmd_lzo =3D { cat $(real-prereqs) | lzop -9; $(size_append); } > $@ + +quiet_cmd_lz4 =3D LZ4 $@ + cmd_lz4 =3D { cat $(real-prereqs) | lz4c -l -c1 stdin stdout; \ + $(size_append); } > $@ + +# U-Boot mkimage +# ------------------------------------------------------------------------= --- + +MKIMAGE :=3D $(srctree)/scripts/mkuboot.sh + +# SRCARCH just happens to match slightly more than ARCH (on sparc), so red= uces +# the number of overrides in arch makefiles +UIMAGE_ARCH ?=3D $(SRCARCH) +UIMAGE_COMPRESSION ?=3D $(if $(2),$(2),none) +UIMAGE_OPTS-y ?=3D +UIMAGE_TYPE ?=3D kernel +UIMAGE_LOADADDR ?=3D arch_must_set_this +UIMAGE_ENTRYADDR ?=3D $(UIMAGE_LOADADDR) +UIMAGE_NAME ?=3D 'Linux-$(KERNELRELEASE)' + +quiet_cmd_uimage =3D UIMAGE $@ + cmd_uimage =3D $(CONFIG_SHELL) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux= \ + -C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \ + -T $(UIMAGE_TYPE) \ + -a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \ + -n $(UIMAGE_NAME) -d $< $@ + +# XZ +# ------------------------------------------------------------------------= --- +# Use xzkern to compress the kernel image and xzmisc to compress other thi= ngs. +# +# xzkern uses a big LZMA2 dictionary since it doesn't increase memory usage +# of the kernel decompressor. A BCJ filter is used if it is available for +# the target architecture. xzkern also appends uncompressed size of the da= ta +# using size_append. The .xz format has the size information available at +# the end of the file too, but it's in more complex format and it's good to +# avoid changing the part of the boot code that reads the uncompressed siz= e. +# Note that the bytes added by size_append will make the xz tool think that +# the file is corrupt. This is expected. +# +# xzmisc doesn't use size_append, so it can be used to create normal .xz +# files. xzmisc uses smaller LZMA2 dictionary than xzkern, because a very +# big dictionary would increase the memory usage too much in the multi-call +# decompression mode. A BCJ filter isn't used either. +quiet_cmd_xzkern =3D XZKERN $@ + cmd_xzkern =3D { cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap= .sh; \ + $(size_append); } > $@ + +quiet_cmd_xzmisc =3D XZMISC $@ + cmd_xzmisc =3D cat $(real-prereqs) | xz --check=3Dcrc32 --lzma2=3Ddi= ct=3D1MiB > $@ + +# ASM offsets +# ------------------------------------------------------------------------= --- + +# Default sed regexp - multiline due to syntax constraints +# +# Use [:space:] because LLVM's integrated assembler inserts around +# the .ascii directive whereas GCC keeps the as-is. +define sed-offsets + 's:^[[:space:]]*\.ascii[[:space:]]*"\(.*\)".*:\1:; \ + /^->/{s:->#\(.*\):/* \1 */:; \ + s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \ + s:->::; p;}' +endef + +# Use filechk to avoid rebuilds when a header changes, but the resulting f= ile +# does not +define filechk_offsets + echo "#ifndef $2"; \ + echo "#define $2"; \ + echo "/*"; \ + echo " * DO NOT MODIFY."; \ + echo " *"; \ + echo " * This file was generated by Kbuild"; \ + echo " */"; \ + echo ""; \ + sed -ne $(sed-offsets) < $<; \ + echo ""; \ + echo "#endif" +endef diff --git a/xen/scripts/Makefile.ubsan b/xen/scripts/Makefile.ubsan new file mode 100644 index 000000000000..019771b845c5 --- /dev/null +++ b/xen/scripts/Makefile.ubsan @@ -0,0 +1,19 @@ +# SPDX-License-Identifier: GPL-2.0 +ifdef CONFIG_UBSAN + CFLAGS_UBSAN +=3D $(call cc-option, -fsanitize=3Dshift) + CFLAGS_UBSAN +=3D $(call cc-option, -fsanitize=3Dinteger-divide-by-z= ero) + CFLAGS_UBSAN +=3D $(call cc-option, -fsanitize=3Dunreachable) + CFLAGS_UBSAN +=3D $(call cc-option, -fsanitize=3Dsigned-integer-over= flow) + CFLAGS_UBSAN +=3D $(call cc-option, -fsanitize=3Dbounds) + CFLAGS_UBSAN +=3D $(call cc-option, -fsanitize=3Dobject-size) + CFLAGS_UBSAN +=3D $(call cc-option, -fsanitize=3Dbool) + CFLAGS_UBSAN +=3D $(call cc-option, -fsanitize=3Denum) + +ifdef CONFIG_UBSAN_ALIGNMENT + CFLAGS_UBSAN +=3D $(call cc-option, -fsanitize=3Dalignment) +endif + + # -fsanitize=3D* options makes GCC less smart than usual and + # increase number of 'maybe-uninitialized false-positives + CFLAGS_UBSAN +=3D $(call cc-option, -Wno-maybe-uninitialized) +endif diff --git a/xen/scripts/basic/.gitignore b/xen/scripts/basic/.gitignore new file mode 100644 index 000000000000..a776371a3502 --- /dev/null +++ b/xen/scripts/basic/.gitignore @@ -0,0 +1 @@ +fixdep diff --git a/xen/scripts/basic/Makefile b/xen/scripts/basic/Makefile new file mode 100644 index 000000000000..548aeb592806 --- /dev/null +++ b/xen/scripts/basic/Makefile @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0-only +### +# This Makefile lists the most basic programs used during the build proces= s. +# The programs listed herein are what are needed to do the basic stuff, +# such as fix file dependencies. +# This initial step is needed to avoid files to be recompiled +# when kernel configuration changes (which is what happens when +# .config is included by main Makefile. +# ------------------------------------------------------------------------= --- +# fixdep: Used to generate dependency information during build process + +hostprogs-y :=3D fixdep +always :=3D $(hostprogs-y) + +# fixdep is needed to compile other host programs +$(addprefix $(obj)/,$(filter-out fixdep,$(always))): $(obj)/fixdep diff --git a/xen/scripts/basic/fixdep.c b/xen/scripts/basic/fixdep.c new file mode 100644 index 000000000000..9ba47b0a47b9 --- /dev/null +++ b/xen/scripts/basic/fixdep.c @@ -0,0 +1,410 @@ +/* + * "Optimize" a list of dependencies as spit out by gcc -MD + * for the kernel build + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D + * + * Author Kai Germaschewski + * Copyright 2002 by Kai Germaschewski + * + * This software may be used and distributed according to the terms + * of the GNU General Public License, incorporated herein by reference. + * + * + * Introduction: + * + * gcc produces a very nice and correct list of dependencies which + * tells make when to remake a file. + * + * To use this list as-is however has the drawback that virtually + * every file in the kernel includes autoconf.h. + * + * If the user re-runs make *config, autoconf.h will be + * regenerated. make notices that and will rebuild every file which + * includes autoconf.h, i.e. basically all files. This is extremely + * annoying if the user just changed CONFIG_HIS_DRIVER from n to m. + * + * So we play the same trick that "mkdep" played before. We replace + * the dependency on autoconf.h by a dependency on every config + * option which is mentioned in any of the listed prerequisites. + * + * kconfig populates a tree in include/config/ with an empty file + * for each config symbol and when the configuration is updated + * the files representing changed config options are touched + * which then let make pick up the changes and the files that use + * the config symbols are rebuilt. + * + * So if the user changes his CONFIG_HIS_DRIVER option, only the objects + * which depend on "include/config/his/driver.h" will be rebuilt, + * so most likely only his driver ;-) + * + * The idea above dates, by the way, back to Michael E Chastain, AFAIK. + * + * So to get dependencies right, there are two issues: + * o if any of the files the compiler read changed, we need to rebuild + * o if the command line given to the compile the file changed, we + * better rebuild as well. + * + * The former is handled by using the -MD output, the later by saving + * the command line used to compile the old object and comparing it + * to the one we would now use. + * + * Again, also this idea is pretty old and has been discussed on + * kbuild-devel a long time ago. I don't have a sensibly working + * internet connection right now, so I rather don't mention names + * without double checking. + * + * This code here has been based partially based on mkdep.c, which + * says the following about its history: + * + * Copyright abandoned, Michael Chastain, . + * This is a C version of syncdep.pl by Werner Almesberger. + * + * + * It is invoked as + * + * fixdep + * + * and will read the dependency file + * + * The transformed dependency snipped is written to stdout. + * + * It first generates a line + * + * cmd_ =3D + * + * and then basically copies the ..d file to stdout, in the + * process filtering out the dependency on autoconf.h and adding + * dependencies on include/config/my/option.h for every + * CONFIG_MY_OPTION encountered in any of the prerequisites. + * + * It will also filter out all the dependencies on *.ver. We need + * to make sure that the generated version checksum are globally up + * to date before even starting the recursive build, so it's too late + * at this point anyway. + * + * We don't even try to really parse the header files, but + * merely grep, i.e. if CONFIG_FOO is mentioned in a comment, it will + * be picked up as well. It's not a problem with respect to + * correctness, since that can only give too many dependencies, thus + * we cannot miss a rebuild. Since people tend to not mention totally + * unrelated CONFIG_ options all over the place, it's not an + * efficiency problem either. + * + * (Note: it'd be easy to port over the complete mkdep state machine, + * but I don't think the added complexity is worth it) + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static void usage(void) +{ + fprintf(stderr, "Usage: fixdep \n"); + exit(1); +} + +/* + * In the intended usage of this program, the stdout is redirected to .*.c= md + * files. The return value of printf() and putchar() must be checked to ca= tch + * any error, e.g. "No space left on device". + */ +static void xprintf(const char *format, ...) +{ + va_list ap; + int ret; + + va_start(ap, format); + ret =3D vprintf(format, ap); + if (ret < 0) { + perror("fixdep"); + exit(1); + } + va_end(ap); +} + +static void xputchar(int c) +{ + int ret; + + ret =3D putchar(c); + if (ret =3D=3D EOF) { + perror("fixdep"); + exit(1); + } +} + +/* + * Print out a dependency path from a symbol name + */ +static void print_dep(const char *m, int slen, const char *dir) +{ + int c, prev_c =3D '/', i; + + xprintf(" $(wildcard %s/", dir); + for (i =3D 0; i < slen; i++) { + c =3D m[i]; + if (c =3D=3D '_') + c =3D '/'; + else + c =3D tolower(c); + if (c !=3D '/' || prev_c !=3D '/') + xputchar(c); + prev_c =3D c; + } + xprintf(".h) \\\n"); +} + +struct item { + struct item *next; + unsigned int len; + unsigned int hash; + char name[0]; +}; + +#define HASHSZ 256 +static struct item *hashtab[HASHSZ]; + +static unsigned int strhash(const char *str, unsigned int sz) +{ + /* fnv32 hash */ + unsigned int i, hash =3D 2166136261U; + + for (i =3D 0; i < sz; i++) + hash =3D (hash ^ str[i]) * 0x01000193; + return hash; +} + +/* + * Lookup a value in the configuration string. + */ +static int is_defined_config(const char *name, int len, unsigned int hash) +{ + struct item *aux; + + for (aux =3D hashtab[hash % HASHSZ]; aux; aux =3D aux->next) { + if (aux->hash =3D=3D hash && aux->len =3D=3D len && + memcmp(aux->name, name, len) =3D=3D 0) + return 1; + } + return 0; +} + +/* + * Add a new value to the configuration string. + */ +static void define_config(const char *name, int len, unsigned int hash) +{ + struct item *aux =3D malloc(sizeof(*aux) + len); + + if (!aux) { + perror("fixdep:malloc"); + exit(1); + } + memcpy(aux->name, name, len); + aux->len =3D len; + aux->hash =3D hash; + aux->next =3D hashtab[hash % HASHSZ]; + hashtab[hash % HASHSZ] =3D aux; +} + +/* + * Record the use of a CONFIG_* word. + */ +static void use_config(const char *m, int slen) +{ + unsigned int hash =3D strhash(m, slen); + + if (is_defined_config(m, slen, hash)) + return; + + define_config(m, slen, hash); + print_dep(m, slen, "include/config"); +} + +/* test if s ends in sub */ +static int str_ends_with(const char *s, int slen, const char *sub) +{ + int sublen =3D strlen(sub); + + if (sublen > slen) + return 0; + + return !memcmp(s + slen - sublen, sub, sublen); +} + +static void parse_config_file(const char *p) +{ + const char *q, *r; + const char *start =3D p; + + while ((p =3D strstr(p, "CONFIG_"))) { + if (p > start && (isalnum(p[-1]) || p[-1] =3D=3D '_')) { + p +=3D 7; + continue; + } + p +=3D 7; + q =3D p; + while (*q && (isalnum(*q) || *q =3D=3D '_')) + q++; + if (str_ends_with(p, q - p, "_MODULE")) + r =3D q - 7; + else + r =3D q; + if (r > p) + use_config(p, r - p); + p =3D q; + } +} + +static void *read_file(const char *filename) +{ + struct stat st; + int fd; + char *buf; + + fd =3D open(filename, O_RDONLY); + if (fd < 0) { + fprintf(stderr, "fixdep: error opening file: "); + perror(filename); + exit(2); + } + if (fstat(fd, &st) < 0) { + fprintf(stderr, "fixdep: error fstat'ing file: "); + perror(filename); + exit(2); + } + buf =3D malloc(st.st_size + 1); + if (!buf) { + perror("fixdep: malloc"); + exit(2); + } + if (read(fd, buf, st.st_size) !=3D st.st_size) { + perror("fixdep: read"); + exit(2); + } + buf[st.st_size] =3D '\0'; + close(fd); + + return buf; +} + +/* Ignore certain dependencies */ +static int is_ignored_file(const char *s, int len) +{ + return str_ends_with(s, len, "include/generated/autoconf.h") || + str_ends_with(s, len, "include/generated/autoksyms.h") || + str_ends_with(s, len, ".ver"); +} + +/* + * Important: The below generated source_foo.o and deps_foo.o variable + * assignments are parsed not only by make, but also by the rather simple + * parser in scripts/mod/sumversion.c. + */ +static void parse_dep_file(char *m, const char *target) +{ + char *p; + int is_last, is_target; + int saw_any_target =3D 0; + int is_first_dep =3D 0; + void *buf; + + while (1) { + /* Skip any "white space" */ + while (*m =3D=3D ' ' || *m =3D=3D '\\' || *m =3D=3D '\n') + m++; + + if (!*m) + break; + + /* Find next "white space" */ + p =3D m; + while (*p && *p !=3D ' ' && *p !=3D '\\' && *p !=3D '\n') + p++; + is_last =3D (*p =3D=3D '\0'); + /* Is the token we found a target name? */ + is_target =3D (*(p-1) =3D=3D ':'); + /* Don't write any target names into the dependency file */ + if (is_target) { + /* The /next/ file is the first dependency */ + is_first_dep =3D 1; + } else if (!is_ignored_file(m, p - m)) { + *p =3D '\0'; + + /* + * Do not list the source file as dependency, so that + * kbuild is not confused if a .c file is rewritten + * into .S or vice versa. Storing it in source_* is + * needed for modpost to compute srcversions. + */ + if (is_first_dep) { + /* + * If processing the concatenation of multiple + * dependency files, only process the first + * target name, which will be the original + * source name, and ignore any other target + * names, which will be intermediate temporary + * files. + */ + if (!saw_any_target) { + saw_any_target =3D 1; + xprintf("source_%s :=3D %s\n\n", + target, m); + xprintf("deps_%s :=3D \\\n", target); + } + is_first_dep =3D 0; + } else { + xprintf(" %s \\\n", m); + } + + buf =3D read_file(m); + parse_config_file(buf); + free(buf); + } + + if (is_last) + break; + + /* + * Start searching for next token immediately after the first + * "whitespace" character that follows this token. + */ + m =3D p + 1; + } + + if (!saw_any_target) { + fprintf(stderr, "fixdep: parse error; no targets found\n"); + exit(1); + } + + xprintf("\n%s: $(deps_%s)\n\n", target, target); + xprintf("$(deps_%s):\n", target); +} + +int main(int argc, char *argv[]) +{ + const char *depfile, *target, *cmdline; + void *buf; + + if (argc !=3D 4) + usage(); + + depfile =3D argv[1]; + target =3D argv[2]; + cmdline =3D argv[3]; + + xprintf("cmd_%s :=3D %s\n\n", target, cmdline); + + buf =3D read_file(depfile); + parse_dep_file(buf, target); + free(buf); + + return 0; +} diff --git a/xen/scripts/mkmakefile b/xen/scripts/mkmakefile new file mode 100755 index 000000000000..4d0faebb1719 --- /dev/null +++ b/xen/scripts/mkmakefile @@ -0,0 +1,17 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# Generates a small Makefile used in the root of the output +# directory, to allow make to be started from there. +# The Makefile also allow for more convinient build of external modules + +# Usage +# $1 - Kernel src directory + +if [ "${quiet}" !=3D "silent_" ]; then + echo " GEN Makefile" +fi + +cat << EOF > Makefile +# Automatically generated by $(realpath $0): don't edit +include $(realpath $1/Makefile) +EOF --=20 Anthony PERARD _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel