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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49895C433EF for ; Wed, 27 Oct 2021 12:21:29 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7F2ED6109E for ; Wed, 27 Oct 2021 12:21:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7F2ED6109E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D5D9B83409; Wed, 27 Oct 2021 14:21:25 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.b="BbbKfevH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 74BF68346A; Wed, 27 Oct 2021 14:21:23 +0200 (CEST) Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id DAAF783230 for ; Wed, 27 Oct 2021 14:21:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=heinrich.schuchardt@canonical.com Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 636DC3F17F for ; Wed, 27 Oct 2021 12:21:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1635337279; bh=5UIEd4MLLq4T2I81q6lA6P5XqRkr8R/vHVPAhXuIvTM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=BbbKfevHIU2uCRxnXcfPtN815MteTSUV1ANmjBnm/lYP3lIORxyrdi/ofswwCWIPA 1QClup3tTpiGKiqRjNv2NWZjQ/Ze3a0X25xF7cGK67DsWVqEV8+v7sb+jz6UJFye65 ifUDesy03RUPlO1KEr/rnIMFvtJe5V2jMniYRKeSUy5LQp9LIIXN6vZRbwo4PsH1NV J8LpDXGcj8plJD7w8kBZoKDgFgwvIn0pCYU6bb9qk4OS0W+oMuvnkSoWvPEtNlE//a /Evp4436pRgDLLf/SIsRAKhf4KZuawOXpmvPQvhrSs8/yYi/0fUy9zm5tU/YyFzYyT /fhKfvqT4+nQw== Received: by mail-wr1-f70.google.com with SMTP id g15-20020a5d64ef000000b0016a1331535eso597734wri.10 for ; Wed, 27 Oct 2021 05:21:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=5UIEd4MLLq4T2I81q6lA6P5XqRkr8R/vHVPAhXuIvTM=; b=LREgWbm/NjX94b3ONHhNPQuj5gePF8SBMjHEL0jsRGqhHDIBfpPd9DK54f6adFDN4J 5gD0BVUB22w9lW2FZIl5h1etAzem8cE8vcKb3LwQYgAeQoc23+pBioG7vbrKD2grLg20 bznyl4WtpjAMMxvpJIzSRGgW2MsE7Mo6HOA2dw+BvMjudrk/fdL9uL8Sq3R4K4kVUyH6 pKGWwqZ507keGyC7Wv32otgDCr7SMN5porUbrE1By0GArC9wyxngCBmrFAxVbhSTk+hy mQvrnqqq/94LxVWqUJ2fhXHfqaK1OqjNTp2UlC2OxzxzVAj3v5DpL2CysQPXNOngkGmI etCA== X-Gm-Message-State: AOAM532A/svMP8xL5qgMTQVY85txle4fkJBzoKtPmlsG7jxaLx1n51Re DlYOEDKY9PHueaaXUTqYeunrjUEs9zu4nFPTGZA5nXVEpjNdYh+sYYzUns8sOF7NHudM9lv5gDo eq2+ueWtVu8qAI+yjD7/2nCpIEnnQakw= X-Received: by 2002:adf:df8e:: with SMTP id z14mr5548169wrl.114.1635337279070; Wed, 27 Oct 2021 05:21:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxH3e2vt0FDAv8pNNoUCAOsoa0ZkYjDoDHBeXpzcTeIHEsQyreUiixTbkAsOeXRbOAJU9SaeQ== X-Received: by 2002:adf:df8e:: with SMTP id z14mr5548132wrl.114.1635337278784; Wed, 27 Oct 2021 05:21:18 -0700 (PDT) Received: from [192.168.123.35] (ip-88-152-144-157.hsi03.unitymediagroup.de. [88.152.144.157]) by smtp.gmail.com with ESMTPSA id p12sm23657235wrr.67.2021.10.27.05.21.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Oct 2021 05:21:18 -0700 (PDT) Message-ID: Date: Wed, 27 Oct 2021 14:21:17 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.2 Subject: Re: [PATCH v2 02/41] Makefile: Allow LTO to be disabled for a build Content-Language: en-US To: Simon Glass Cc: U-Boot Mailing List , Michal Simek , Tom Rini , Daniel Schwierzeck , Steffen Jaeckel , =?UTF-8?Q?Marek_Beh=c3=ban?= , Lukas Auer , Dennis Gilmore , Masahiro Yamada , Ilias Apalodimas , Heinrich Schuchardt References: <20211023232635.9195-1-sjg@chromium.org> <20211023232635.9195-3-sjg@chromium.org> From: Heinrich Schuchardt In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean On 10/27/21 10:50, Ilias Apalodimas wrote: > Hi Simon > > How does this patch related to the standard boot series? Shouldn't > this be a completely separate patch? > > Thanks > /Ilias > > On Sun, 24 Oct 2021 at 02:26, Simon Glass wrote: >> >> LTO (Link-Time Optimisation) is an very useful feature which can >> significantly reduce the size of U-Boot binaries. So far it has been >> made available for selected ARM boards and sandbox. >> >> However, incremental builds are much slower when LTO is used. For example, >> an incremental build of sandbox takes 2.1 seconds on my machine, but 6.7 >> seconds with LTO enabled. >> >> Add a LTO_BUILD=n parameter to the build, so it can be disabled during >> development if needed, for faster builds. >> >> Add some documentation about LTO while we are here. >> >> Signed-off-by: Simon Glass >> --- >> >> (no changes since v1) >> >> Makefile | 18 +++++++++++++----- >> arch/arm/config.mk | 4 ++-- >> arch/arm/include/asm/global_data.h | 2 +- >> doc/build/gcc.rst | 17 +++++++++++++++++ >> 4 files changed, 33 insertions(+), 8 deletions(-) >> >> diff --git a/Makefile b/Makefile >> index b79b2319ff6..7057723e046 100644 >> --- a/Makefile >> +++ b/Makefile >> @@ -434,6 +434,9 @@ KBUILD_CFLAGS += -fshort-wchar -fno-strict-aliasing >> KBUILD_AFLAGS := -D__ASSEMBLY__ >> KBUILD_LDFLAGS := >> >> +# Set this to "n" use of LTO for this build, e.g. LTO_BUILD=n >> +LTO_BUILD ?= y This does not allow LTO_BUILD=y to enable LTO for CONFIG_LTO=n. We should have something like LTO_CONFIG ?= $CONFIG_LTO Best regards Heinrich >> + >> ifeq ($(cc-name),clang) >> ifneq ($(CROSS_COMPILE),) >> CLANG_TARGET := --target=$(notdir $(CROSS_COMPILE:%-=%)) >> @@ -641,6 +644,11 @@ export CFLAGS_EFI # Compiler flags to add when building EFI app >> export CFLAGS_NON_EFI # Compiler flags to remove when building EFI app >> export EFI_TARGET # binutils target if EFI is natively supported >> >> +export LTO_ENABLE >> + >> +# This is y if LTO is enabled for this build >> +LTO_ENABLE=$(if $(CONFIG_LTO),$(LTO_BUILD),) >> + >> # If board code explicitly specified LDSCRIPT or CONFIG_SYS_LDSCRIPT, use >> # that (or fail if absent). Otherwise, search for a linker script in a >> # standard location. >> @@ -688,16 +696,16 @@ endif >> LTO_CFLAGS := >> LTO_FINAL_LDFLAGS := >> export LTO_CFLAGS LTO_FINAL_LDFLAGS >> -ifdef CONFIG_LTO >> +ifeq ($(LTO_ENABLE),y) >> ifeq ($(cc-name),clang) >> - LTO_CFLAGS += -flto >> + LTO_CFLAGS += -DLTO_ENABLE -flto >> LTO_FINAL_LDFLAGS += -flto >> >> AR = $(shell $(CC) -print-prog-name=llvm-ar) >> NM = $(shell $(CC) -print-prog-name=llvm-nm) >> else >> NPROC := $(shell nproc 2>/dev/null || echo 1) >> - LTO_CFLAGS += -flto=$(NPROC) >> + LTO_CFLAGS += -DLTO_ENABLE -flto=$(NPROC) >> LTO_FINAL_LDFLAGS += -fuse-linker-plugin -flto=$(NPROC) >> >> # use plugin aware tools >> @@ -1717,7 +1725,7 @@ ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(ARCH)/Makefile.postlink) >> >> # Generate linker list symbols references to force compiler to not optimize >> # them away when compiling with LTO >> -ifdef CONFIG_LTO >> +ifeq ($(LTO_ENABLE),y) >> u-boot-keep-syms-lto := keep-syms-lto.o >> u-boot-keep-syms-lto_c := $(patsubst %.o,%.c,$(u-boot-keep-syms-lto)) >> >> @@ -1739,7 +1747,7 @@ endif >> >> # Rule to link u-boot >> # May be overridden by arch/$(ARCH)/config.mk >> -ifdef CONFIG_LTO >> +ifeq ($(LTO_ENABLE),y) >> quiet_cmd_u-boot__ ?= LTO $@ >> cmd_u-boot__ ?= \ >> $(CC) -nostdlib -nostartfiles \ >> diff --git a/arch/arm/config.mk b/arch/arm/config.mk >> index b107b1af27a..065dbec4064 100644 >> --- a/arch/arm/config.mk >> +++ b/arch/arm/config.mk >> @@ -15,11 +15,11 @@ CFLAGS_NON_EFI := -fno-pic -ffixed-r9 -ffunction-sections -fdata-sections \ >> -fstack-protector-strong >> CFLAGS_EFI := -fpic -fshort-wchar >> >> -ifneq ($(CONFIG_LTO)$(CONFIG_USE_PRIVATE_LIBGCC),yy) >> +ifneq ($(LTO_ENABLE)$(CONFIG_USE_PRIVATE_LIBGCC),yy) >> LDFLAGS_FINAL += --gc-sections >> endif >> >> -ifndef CONFIG_LTO >> +ifneq ($(LTO_ENABLE),y) >> PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections >> endif >> >> diff --git a/arch/arm/include/asm/global_data.h b/arch/arm/include/asm/global_data.h >> index 085e12b5d4d..b255b195aa0 100644 >> --- a/arch/arm/include/asm/global_data.h >> +++ b/arch/arm/include/asm/global_data.h >> @@ -98,7 +98,7 @@ struct arch_global_data { >> >> #include >> >> -#if defined(__clang__) || defined(CONFIG_LTO) >> +#if defined(__clang__) || defined(LTO_ENABLE) >> >> #define DECLARE_GLOBAL_DATA_PTR >> #define gd get_gd() >> diff --git a/doc/build/gcc.rst b/doc/build/gcc.rst >> index cdd79700326..136c318727d 100644 >> --- a/doc/build/gcc.rst >> +++ b/doc/build/gcc.rst >> @@ -141,6 +141,23 @@ of dtc is new enough. It also makes sure that pylibfdt is present, if needed >> Note that the :doc:`tools` are always built with the included version of libfdt >> so it is not possible to build U-Boot tools with a system libfdt, at present. >> >> +Link-time optimisation (LTO) >> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> + >> +U-Boot supports link-time optimisation which can reduce the size of the final >> +U-Boot binaries, particularly with SPL. >> + >> +At present this can be enabled by ARM boards by adding `CONFIG_LTO=y` into the >> +defconfig file. Other architectures are not supported. LTO is enabled by default >> +for sandbox. >> + >> +This does incur a link-time penalty of several seconds. For faster incremental >> +builds during development, you can disable it by setting `LTO_BUILD` to `n`. >> + >> +.. code-block:: bash >> + >> + LTO_BUILD=n make >> + >> Other build targets >> ~~~~~~~~~~~~~~~~~~~ >> >> -- >> 2.33.0.1079.g6e70778dc9-goog >>