From patchwork Mon Jul 29 14:31:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 13745143 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D65C4C3DA4A for ; Mon, 29 Jul 2024 14:51:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=GN/GNS3Oe+d0yHzdcX9Z5r8aLiWvqxGNIlJjkNslJac=; b=0lS8mPYjo5fACvTzNkYteYRH8L HVLZioVhyoumsUXjcjmA0kxsYc3bvpyCxu5VHrKUevse588aQoO+LiTExJW46W3FtJIp34EOTs3Sr uJjI1Hlig6kbQk+2hXj3YtCwjDPHoAYEhHmQ6/kEUlB4uDd52+/Eyx1fHldjoEORvOeP/KDaClJbN b/2HhgVhomiOVV697BOtQl2JGB58YGzCItR1iSDQPdx3tlgiOHcQExPOeVWJcWqGsr960FheMp3mP aHVAGtKC4ZLbDKVzO0+ic0ghRUDs9jTZdoqQ3tIL5PoygpFaHEYvJMf+huiJFXPWkDfdaHwUKhbYn qe12byHQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYRiw-0000000Bk1p-126X; Mon, 29 Jul 2024 14:51:42 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYRPI-0000000BcBZ-0yOk for linux-arm-kernel@lists.infradead.org; Mon, 29 Jul 2024 14:31:25 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 74169143D; Mon, 29 Jul 2024 07:31:49 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0C3E43F64C; Mon, 29 Jul 2024 07:31:22 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org Cc: akos.denke@arm.com, andre.przywara@arm.com, luca.fancellu@arm.com, mark.rutland@arm.com, maz@kernel.org Subject: [BOOT-WRAPPER 1/3] Makefile: rework test-dtc-option Date: Mon, 29 Jul 2024 15:31:14 +0100 Message-Id: <20240729143116.1804615-2-mark.rutland@arm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240729143116.1804615-1-mark.rutland@arm.com> References: <20240729143116.1804615-1-mark.rutland@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240729_073124_345436_8B440A27 X-CRM114-Status: GOOD ( 13.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently we have the test-dtc-option helepr to check whether dtc supports an option. In subsequent patches we'll want similar for ld, and it seems likely that we'll want this for other commands in future. This patch adds a new test-cmd helper that can be used to check whether a command succeeds (based on its return value), and can be used to choose between a value if the comand succeeds and a value if the command fails. The existing test-dtc-option helper is reworked to use test-cmd. The helpers are added near the start of the file so that they'll be defined prior to usage whetever they're used within the file. This is purely for human comprehension as Make itself does not care about their location within the Makefile. Signed-off-by: Mark Rutland Cc: Andre Przywara Cc: Akos Denke Cc: Luca Fancellu Cc: Marc Zyngier --- Makefile.am | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Makefile.am b/Makefile.am index 6ebece2..6ab5cfd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,6 +9,16 @@ SCRIPT_DIR := $(top_srcdir)/scripts +# test-cmd cmd,val-if-success,val-if-success,val-if-failure +define test-cmd +$(if $(shell { $(1); } >/dev/null 2>&1 && echo "success"),$(2),$(3)) +endef + +# Run dtc with an given command line option to check support for it. +define test-dtc-option +$(call test-cmd,echo "/dts-v1/;/{};" | $(DTC) $(1) -o /dev/null,$(1),) +endef + # VE PHYS_OFFSET := $(shell perl -I $(SCRIPT_DIR) $(SCRIPT_DIR)/findmem.pl $(KERNEL_DTB)) UART_BASE := $(shell perl -I $(SCRIPT_DIR) $(SCRIPT_DIR)/findbase.pl $(KERNEL_DTB) 0 'arm,pl011') @@ -162,11 +172,6 @@ $(COMMON_SRC): model.lds: $(LD_SCRIPT) Makefile $(CPP) $(CPPFLAGS) -ansi -DPHYS_OFFSET=$(PHYS_OFFSET) -DMBOX_OFFSET=$(MBOX_OFFSET) -DKERNEL_OFFSET=$(KERNEL_OFFSET) -DFDT_OFFSET=$(FDT_OFFSET) -DFS_OFFSET=$(FS_OFFSET) $(XEN) -DXEN_OFFSET=$(XEN_OFFSET) -DKERNEL=$(KERNEL_IMAGE) -DFILESYSTEM=$(FILESYSTEM) -DTEXT_LIMIT=$(TEXT_LIMIT) -P -C -o $@ $< -# Run dtc with an given command line option to check support for it. -define test-dtc-option -$(if $(shell echo "/dts-v1/;/{};" | $(DTC) $(1) -o /dev/null 2>&1),,$(1)) -endef - DTC_NOWARN = $(call test-dtc-option,-Wno-clocks_property) DTC_NOWARN += $(call test-dtc-option,-Wno-gpios_property) From patchwork Mon Jul 29 14:31:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 13745144 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DBA59C3DA61 for ; Mon, 29 Jul 2024 14:52:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=6kGh9GoUxNLayUkPZCHukQrE2hG91i9359sBedpe7Hk=; b=EtARInr4CxGf9ukpAyr+f0gsES 7njl2MV4ehUGiZcekH2d26oXl/syVD9EpxmNWMhfgMLfnpRQ+VBmeAlZvZAGvvENxFw99X93/IXm+ 1gGB+COEx49+gLEsG16Ei1Y1w8HwxNsc/eFk7SNgg5eC8QUn27G0HhZoMBAMsmRC84IDi5hz9ngWV 9j1clR6XDwMaJGC8jtjRL/rFrtXFrsllasHrNKO0TCiovRJGBdwANuzpL61K2y5aomHwZNdnYHeia 4x0NPuj73nEMq2PoT701Zl7lVA14/ckDXp+5q0JjXXlJLw0csNPYaBaSFdqlZ0xJVeUhPhJXs7TKK iHRBn2lw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYRjJ-0000000BkAX-3QNG; Mon, 29 Jul 2024 14:52:05 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYRPK-0000000BcCX-2s99 for linux-arm-kernel@lists.infradead.org; Mon, 29 Jul 2024 14:31:28 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0C1D31007; Mon, 29 Jul 2024 07:31:51 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 989173F64C; Mon, 29 Jul 2024 07:31:24 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org Cc: akos.denke@arm.com, andre.przywara@arm.com, luca.fancellu@arm.com, mark.rutland@arm.com, maz@kernel.org Subject: [BOOT-WRAPPER 2/3] Makefile: suppress RWX segment warnings Date: Mon, 29 Jul 2024 15:31:15 +0100 Message-Id: <20240729143116.1804615-3-mark.rutland@arm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240729143116.1804615-1-mark.rutland@arm.com> References: <20240729143116.1804615-1-mark.rutland@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240729_073126_854732_27A7A847 X-CRM114-Status: UNSURE ( 8.91 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Contemporary versions of GNU LD warn about segments with RWX permissions, which can occur when building the boot-wrapper, e.g. | aarch64-linux-ld: warning: linux-system.axf has a LOAD segment with RWX permissions This is due to sections with RW- and R-X being adjacent, and getting combined into a single segment with RWX permissions: | [mark@lakrids:~/src/boot-wrapper-aarch64]% readelf -l linux-system.axf | | Elf file type is EXEC (Executable file) | Entry point 0x80000000 | There are 4 program headers, starting at offset 64 | | Program Headers: | Type Offset VirtAddr PhysAddr | FileSiz MemSiz Flags Align | LOAD 0x0000000000010000 0x0000000080000000 0x0000000080000000 | 0x0000000000010000 0x0000000000010000 RWE 0x10000 | LOAD 0x0000000000020000 0x0000000080200000 0x0000000080200000 | 0x000000000331b200 0x000000000331b200 RW 0x10000 | LOAD 0x0000000003340000 0x0000000088000000 0x0000000088000000 | 0x0000000000002e05 0x0000000000002e05 RW 0x10000 | GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000 | 0x0000000000000000 0x0000000000000000 RW 0x10 | | Section to Segment mapping: | Segment Sections... | 00 .boot .mbox | 01 .kernel | 02 .dtb | 03 Since the bootwrapper runs with the MMU off, the RWX permissions aren't a problem, and the simplest solution is to suppress the warning with the '--no-warn-rwx-segments' option to LD. Add the necessary logic to suprress the warning when supported by LD. Signed-off-by: Mark Rutland Cc: Andre Przywara Cc: Akos Denke Cc: Luca Fancellu Cc: Marc Zyngier --- Makefile.am | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile.am b/Makefile.am index 6ab5cfd..6ee6afa 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,6 +19,10 @@ define test-dtc-option $(call test-cmd,echo "/dts-v1/;/{};" | $(DTC) $(1) -o /dev/null,$(1),) endef +define test-ld-option +$(call test-cmd,$(LD) $(1) --help,$(1),) +endef + # VE PHYS_OFFSET := $(shell perl -I $(SCRIPT_DIR) $(SCRIPT_DIR)/findmem.pl $(KERNEL_DTB)) UART_BASE := $(shell perl -I $(SCRIPT_DIR) $(SCRIPT_DIR)/findbase.pl $(KERNEL_DTB) 0 'arm,pl011') @@ -141,6 +145,7 @@ CFLAGS += -fno-stack-protector CFLAGS += -ffunction-sections -fdata-sections CFLAGS += -fno-pic -fno-pie LDFLAGS += --gc-sections +LDFLAGS += $(call test-ld-option,--no-warn-rwx-segments) OBJ := $(addprefix $(ARCH_SRC),$(ARCH_OBJ)) $(addprefix $(COMMON_SRC),$(COMMON_OBJ)) From patchwork Mon Jul 29 14:31:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 13745145 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2F909C3DA4A for ; Mon, 29 Jul 2024 14:52:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=OwZ+YBV1g2FbL6rUY0RQPmFN47MEogO4EgPmT2v1gcA=; b=Ooxp8roHhVLiW0YBQrkhRfFewM ZGl7QOeZ+4N3YPD6Jvh7lIHY9LnHA35TMcx1WJR/Jg5ipeNVgeBNtQDy+pIkrLHJukDsi0sTo56Zh JgkHoQQ5IagPKUpTq9ZbKMDRVDVl96EI6KMjZPKNV7ojQYa+5TaqzkGrXVJPISuduC2nXD9V+fYGK IGuHGhRJ4Fgcn7oG0cURLdAzQXktTUG3JKGI5BVNfUFa9kbSFAtXvoIvZ5quILjK1VL9iriW5aPvc HbH3V8t3VRHpKgkYU0PFCEyHs+4ttqnVZRkYe0wT3MdxYaNuw45m73XMV4ontEBdQ8P4HBORDVGtZ il2Prcdg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYRjj-0000000BkLr-2oKZ; Mon, 29 Jul 2024 14:52:31 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYRPM-0000000BcD8-1LHk for linux-arm-kernel@lists.infradead.org; Mon, 29 Jul 2024 14:31:29 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AAD11143D; Mon, 29 Jul 2024 07:31:52 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 341B13F64C; Mon, 29 Jul 2024 07:31:26 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org Cc: akos.denke@arm.com, andre.przywara@arm.com, luca.fancellu@arm.com, mark.rutland@arm.com, maz@kernel.org Subject: [BOOT-WRAPPER 3/3] configure: allow the use of bare-metal toolchains Date: Mon, 29 Jul 2024 15:31:16 +0100 Message-Id: <20240729143116.1804615-4-mark.rutland@arm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240729143116.1804615-1-mark.rutland@arm.com> References: <20240729143116.1804615-1-mark.rutland@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240729_073128_422460_5C81902F X-CRM114-Status: GOOD ( 11.28 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently it is not possible to build the boot-wrapper with a bare-metal toolchain, as the configure script tries to build a hosted object. For example, trying to build with the bare-metal aarch64-linux GCC 13.2.0 toolchain from kernel.org fails with: | [mark@lakrids:~/src/boot-wrapper-aarch64]% usekorg 13.2.0 ./configure --enable-gicv3 --host=aarch64-linux --with-kernel-dir=../linux --with-cmdline="console=ttyAMA0 earlycon=pl011,0x1c090000 root=/dev/vda kvm_arm.mode=vhe" | checking for a BSD-compatible install... /usr/bin/install -c | checking whether build environment is sane... yes | checking for aarch64-linux-strip... aarch64-linux-strip | checking for a thread-safe mkdir -p... /usr/bin/mkdir -p | checking for gawk... gawk | checking whether make sets $(MAKE)... yes | checking whether make supports nested variables... yes | checking whether DTB file exists... yes | checking whether kernel image exists... yes | checking for aarch64-linux-gcc... aarch64-linux-gcc | checking whether the C compiler works... no | configure: error: in `/home/mark/src/boot-wrapper-aarch64': | configure: error: C compiler cannot create executables | See `config.log' for more details This behaviour was an unintentional side-effect of moving to autotools in commit: bae4ae6a834cd15b ("Add autotools configuration.") ... as the default CFLAGS end up trying to build a hosted object. Pass the necessary CFLAGS to build a bare-metal object. matching what we do in Makefile.am, so that the configure script doesn't reject bare-metal toolchains. Signed-off-by: Mark Rutland Cc: Andre Przywara Cc: Akos Denke Cc: Luca Fancellu Cc: Marc Zyngier --- configure.ac | 3 +++ 1 file changed, 3 insertions(+) diff --git a/configure.ac b/configure.ac index ce41dae..1f2f4f6 100644 --- a/configure.ac +++ b/configure.ac @@ -128,6 +128,9 @@ AC_ARG_ENABLE([gicv3], AM_CONDITIONAL([GICV3], [test "x$USE_GICV3" = "xyes"]) AS_IF([test "x$USE_GICV3" = "xyes"], [], [USE_GICV3=no]) +# Ensure AC_PROG_CC tries to build a bare-metal object +CFLAGS="${CFLAGS} -ffreestanding -nostdlib" + # Ensure that we have all the needed programs AC_PROG_CC AC_PROG_CPP