From mboxrd@z Thu Jan 1 00:00:00 1970 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 0F6F7C433EF for ; Tue, 11 Jan 2022 11:31: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: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vsDjPQenRfs0qLhY3k+orpDQ1N3//qwJeUr4dM+2cJg=; b=W3o+iTFGBua2UI RMI0agdsowljSKox75tqtACguWCoBYysjfR031YdKC4/oAj/rcXNzGmLu+UZdi4ARJ5e/QESD/Adz tBxI2iCLRi8CaugtbJTETNdwIXX5dmR7DFaAbs4XITCSfQ3R0ALsBsB5BCTsAvxKtAnv4uq+nbqPf tiaEsz/OA/rQ86/LQTvaEIpn9QERgr/kdjUanTbTBVxP5KV+UxrscJ+aiGa4p65ra3XpDpulT21Bd 1wtsy8upD9GtmxIoNeZTQYb6kcvl7vFjoi2Uc9X3KRX8NCTqYIl1sK0KFe975dv1WzTpTX+shhUW+ /PZAnKd0lAleYlqoKJlw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n7FME-00G3UZ-L8; Tue, 11 Jan 2022 11:30:30 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n7FM6-00G3TF-Rb for linux-arm-kernel@lists.infradead.org; Tue, 11 Jan 2022 11:30:24 +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 95A281FB; Tue, 11 Jan 2022 03:30:21 -0800 (PST) Received: from FVFF77S0Q05N (unknown [10.57.1.156]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D6B843F766; Tue, 11 Jan 2022 03:30:20 -0800 (PST) Date: Tue, 11 Jan 2022 11:30:18 +0000 From: Mark Rutland To: Andre Przywara Cc: linux-arm-kernel@lists.infradead.org, Jaxson Han Subject: Re: [boot-wrapper PATCH v2 3/9] Makefile: Tell compiler to generate bare-metal code Message-ID: References: <20211222181607.1203191-1-andre.przywara@arm.com> <20211222181607.1203191-4-andre.przywara@arm.com> <20220107143811.3d193704@donnerap.cambridge.arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220107143811.3d193704@donnerap.cambridge.arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220111_033023_027680_8D7E941C X-CRM114-Status: GOOD ( 38.39 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Jan 07, 2022 at 02:38:11PM +0000, Andre Przywara wrote: > On Fri, 7 Jan 2022 13:53:50 +0000 > Mark Rutland wrote: > > Hi Mark, > > > On Wed, Dec 22, 2021 at 06:16:01PM +0000, Andre Przywara wrote: > > > Our GCC invocation does not provide many parameters, which lets the > > > toolchain fill in its own default setup. > > > In case of a native build or when using a full-featured cross-compiler, > > > this probably means Linux userland, which is not what we want for a > > > bare-metal application like boot-wrapper. > > > > > > Tell the compiler to forget about those standard settings, and only use > > > what we explicitly ask for. In particular that means to not use toolchain > > > provided libraries and headers, since they might pull in more code than > > > we want, and might not run well in the boot-wrapper environment. > > > > > > This also enables optimisation, since it produces much better code and > > > tends to avoid problems due to missing inlining, for instance. > > > > I'd appreciate if we could add some explanation for these (just in the commit > > message is fine), as e.g. it's not clear to me why -fno-toplevel-reorder is > > necessary. > > Yeah, I was expecting some discussion about this. I went over most options > from the manpage a while ago (for some unrelated baremetal code project), > and decided for each option whether it would make sense or not. TBH I > don't remember every detail from that, but I can certainly just drop the > less critical options from that list. Yes please. To be clear, I'm only suggesting dropping a few of these, and I think the others just needs some explanation. I'm certain we *should* add: -ffreestanding -nostdlib ... and I'd be happy to take a patch adding just those as an immediate fix. I think the folllowing are reasonable but need some explanation: -Wstrict-prototypes // Just to catch accidents -fno-stack-protector // Because we dont have any init/support code -fno-strict-aliasing // Do we rely on type punning today? -fno-unwind-tables // Because we don't consume the result -fno-asynchronous-unwind-tables // Because we don't consume the result I don't understand why we need: -fno-common -fno-toplevel-reorder -Os ... and I suspect we can drop those unless we have some rationale. I'm torn over: -nostdinc ... as IIUC that's just to catch accidental includes, but necessitates the prior patch adding copies of some headers. We could arguably leave that as-is and just be careful. > And I would be happy to add some rationale for each of them, but wonder > what the best place would be? I'd rather do this in a file than in a > commit message, would you prefer comments in Makefile.am, or in README or > a separate file, with a pointer from Makefile.am. Or in a commit message > anyway? I think within the Makefile would be best if you're happy to organise it, e.g. # The boot-wrapper is a non-hosted environment and isn't linked # with standard libraries. CFLAGS += -ffreestanding -nostdlib # Avoid the pointless creation og a GOT CFLAGS += -fno-pic -fno-pie ... does that work for you? Thanks, Mark. > > Cheers, > Andre > > > > > > > Signed-off-by: Andre Przywara > > > --- > > > Makefile.am | 7 ++++++- > > > 1 file changed, 6 insertions(+), 1 deletion(-) > > > > > > diff --git a/Makefile.am b/Makefile.am > > > index 3e970a3..d9ad6d1 100644 > > > --- a/Makefile.am > > > +++ b/Makefile.am > > > @@ -124,9 +124,14 @@ CHOSEN_NODE := chosen { \ > > > > > > CPPFLAGS += $(INITRD_FLAGS) > > > CFLAGS += -I$(top_srcdir)/include/ -I$(top_srcdir)/$(ARCH_SRC)/include/ > > > -CFLAGS += -Wall -fomit-frame-pointer > > > +CFLAGS += -Wall -Wstrict-prototypes -fomit-frame-pointer > > > +CFLAGS += -ffreestanding -nostdinc -nostdlib > > > +CFLAGS += -fno-common -fno-strict-aliasing -fno-stack-protector > > > +CFLAGS += -fno-toplevel-reorder > > > +CFLAGS += -fno-unwind-tables -fno-asynchronous-unwind-tables > > > CFLAGS += -ffunction-sections -fdata-sections > > > CFLAGS += -fno-pic -fno-pie > > > +CFLAGS += -Os > > > LDFLAGS += --gc-sections > > > > > > OBJ := $(addprefix $(ARCH_SRC),$(ARCH_OBJ)) $(addprefix $(COMMON_SRC),$(COMMON_OBJ)) > > > -- > > > 2.25.1 > > > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel