Re: [PATCH v2 02/41] Makefile: Allow LTO to be disabled for a build

2021-11-04 Thread Tom Rini
On Thu, Nov 04, 2021 at 09:12:02AM -0600, Simon Glass wrote:
> Hi Tom,
> 
> On Thu, 4 Nov 2021 at 08:55, Tom Rini  wrote:
> >
> > On Wed, Nov 03, 2021 at 08:49:01PM -0600, Simon Glass wrote:
> > > Hi Tom,
> > >
> > > On Mon, 1 Nov 2021 at 15:58, Tom Rini  wrote:
> > > >
> > > > On Sun, Oct 31, 2021 at 05:46:43PM -0600, Simon Glass wrote:
> > > > > Hi Tom,
> > > > >
> > > > > On Wed, 27 Oct 2021 at 07:13, Tom Rini  wrote:
> > > > > >
> > > > > > On Wed, Oct 27, 2021 at 02:21:17PM +0200, Heinrich Schuchardt wrote:
> > > > > > >
> > > > > > >
> > > > > > > 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.
> > > > > >
> > > > > > I don't understand why we need this patch at all.  If you want to
> > > > > > disable LTO, disable LTO.  Yes, LTO makes linking take longer which 
> > > > > > can
> > > > > > be annoying on iterative development.  I have a few different 
> > > > > > "HACK: DO
> > > > > > NOT PUSH:  ..." things I git am at the start of a branch, depending 
> > > > > > on
> > > > > > needs.  You can just do that to drop "imply LTO" from the SANDBOX 
> > > > > > stanza
> > > > > > in arch/Kconfig.  We do not need a whole thing around a CONFIG 
> > > > > > option
> > > > > > that can be disabled in the defconfig, or local .config file even.
> > > > > >
> > > > >
> > > > > Cranky time.
> > > > >
> > > > > Of course we don't *need* it. I could just buy a slower build machine
> > > > > and type with two fingers. There are lots of ways to slow things down
> > > > > and LTO is one of them. I change branches at least a dozen times a day
> > > > > and am always trying things out from patchwork. I am sure others do
> > > > > too. LTO dramatically slows down builds. Having a way to easily do
> > > > > this from the build system saves time.
> > > >
> > > > Maybe the answer is that LTO just isn't appropriate for sandbox.  We're
> > > > not doing any specific tests for LTO anywhere (nor does that seem
> > > > appropriate), and we do have platforms in CI that run tests other than
> > > > building, with LTO.
> > >
> > > It has value as a test, I presume, and a demo of how it works. Also it
> > > runs most of the tests.
> > >
> > > But I'm happy to disable it if that helps.
> > >
> > > Still, it doesn't really solve the issue. The same thing happens when
> > > building real boards.
> >
> > Well, a big part of the problem here is I strongly disagree with a
> > make-line flag to override a CONFIG option.  I also hear your use case
> > of "I build this platform so frequently per development session it's a
> > noticeable slowdown and a 'LOCAL:' commit will also screw up my
> > workflow".  So where do we go?  LTO is a 

Re: [PATCH v2 02/41] Makefile: Allow LTO to be disabled for a build

2021-11-04 Thread Simon Glass
Hi Tom,

On Thu, 4 Nov 2021 at 08:55, Tom Rini  wrote:
>
> On Wed, Nov 03, 2021 at 08:49:01PM -0600, Simon Glass wrote:
> > Hi Tom,
> >
> > On Mon, 1 Nov 2021 at 15:58, Tom Rini  wrote:
> > >
> > > On Sun, Oct 31, 2021 at 05:46:43PM -0600, Simon Glass wrote:
> > > > Hi Tom,
> > > >
> > > > On Wed, 27 Oct 2021 at 07:13, Tom Rini  wrote:
> > > > >
> > > > > On Wed, Oct 27, 2021 at 02:21:17PM +0200, Heinrich Schuchardt wrote:
> > > > > >
> > > > > >
> > > > > > 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.
> > > > >
> > > > > I don't understand why we need this patch at all.  If you want to
> > > > > disable LTO, disable LTO.  Yes, LTO makes linking take longer which 
> > > > > can
> > > > > be annoying on iterative development.  I have a few different "HACK: 
> > > > > DO
> > > > > NOT PUSH:  ..." things I git am at the start of a branch, depending on
> > > > > needs.  You can just do that to drop "imply LTO" from the SANDBOX 
> > > > > stanza
> > > > > in arch/Kconfig.  We do not need a whole thing around a CONFIG option
> > > > > that can be disabled in the defconfig, or local .config file even.
> > > > >
> > > >
> > > > Cranky time.
> > > >
> > > > Of course we don't *need* it. I could just buy a slower build machine
> > > > and type with two fingers. There are lots of ways to slow things down
> > > > and LTO is one of them. I change branches at least a dozen times a day
> > > > and am always trying things out from patchwork. I am sure others do
> > > > too. LTO dramatically slows down builds. Having a way to easily do
> > > > this from the build system saves time.
> > >
> > > Maybe the answer is that LTO just isn't appropriate for sandbox.  We're
> > > not doing any specific tests for LTO anywhere (nor does that seem
> > > appropriate), and we do have platforms in CI that run tests other than
> > > building, with LTO.
> >
> > It has value as a test, I presume, and a demo of how it works. Also it
> > runs most of the tests.
> >
> > But I'm happy to disable it if that helps.
> >
> > Still, it doesn't really solve the issue. The same thing happens when
> > building real boards.
>
> Well, a big part of the problem here is I strongly disagree with a
> make-line flag to override a CONFIG option.  I also hear your use case
> of "I build this platform so frequently per development session it's a
> noticeable slowdown and a 'LOCAL:' commit will also screw up my
> workflow".  So where do we go?  LTO is a size versus speed trade-off
> (and -ffunction-sections/-fdata-sections/--gc-unused is a much smaller
> speed trade-off) that's more important on real hardware (and also not
> used as often as it might be, at least so far).  On real boards, there's
> less of a "just turn it off" option because it's required to be small
> enough to use on the 

Re: [PATCH v2 02/41] Makefile: Allow LTO to be disabled for a build

2021-11-04 Thread Tom Rini
On Wed, Nov 03, 2021 at 08:49:01PM -0600, Simon Glass wrote:
> Hi Tom,
> 
> On Mon, 1 Nov 2021 at 15:58, Tom Rini  wrote:
> >
> > On Sun, Oct 31, 2021 at 05:46:43PM -0600, Simon Glass wrote:
> > > Hi Tom,
> > >
> > > On Wed, 27 Oct 2021 at 07:13, Tom Rini  wrote:
> > > >
> > > > On Wed, Oct 27, 2021 at 02:21:17PM +0200, Heinrich Schuchardt wrote:
> > > > >
> > > > >
> > > > > 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.
> > > >
> > > > I don't understand why we need this patch at all.  If you want to
> > > > disable LTO, disable LTO.  Yes, LTO makes linking take longer which can
> > > > be annoying on iterative development.  I have a few different "HACK: DO
> > > > NOT PUSH:  ..." things I git am at the start of a branch, depending on
> > > > needs.  You can just do that to drop "imply LTO" from the SANDBOX stanza
> > > > in arch/Kconfig.  We do not need a whole thing around a CONFIG option
> > > > that can be disabled in the defconfig, or local .config file even.
> > > >
> > >
> > > Cranky time.
> > >
> > > Of course we don't *need* it. I could just buy a slower build machine
> > > and type with two fingers. There are lots of ways to slow things down
> > > and LTO is one of them. I change branches at least a dozen times a day
> > > and am always trying things out from patchwork. I am sure others do
> > > too. LTO dramatically slows down builds. Having a way to easily do
> > > this from the build system saves time.
> >
> > Maybe the answer is that LTO just isn't appropriate for sandbox.  We're
> > not doing any specific tests for LTO anywhere (nor does that seem
> > appropriate), and we do have platforms in CI that run tests other than
> > building, with LTO.
> 
> It has value as a test, I presume, and a demo of how it works. Also it
> runs most of the tests.
> 
> But I'm happy to disable it if that helps.
> 
> Still, it doesn't really solve the issue. The same thing happens when
> building real boards.

Well, a big part of the problem here is I strongly disagree with a
make-line flag to override a CONFIG option.  I also hear your use case
of "I build this platform so frequently per development session it's a
noticeable slowdown and a 'LOCAL:' commit will also screw up my
workflow".  So where do we go?  LTO is a size versus speed trade-off
(and -ffunction-sections/-fdata-sections/--gc-unused is a much smaller
speed trade-off) that's more important on real hardware (and also not
used as often as it might be, at least so far).  On real boards, there's
less of a "just turn it off" option because it's required to be small
enough to use on the hardware.  Since that's not the case on sandbox,
maybe we just need to turn it on in more QEMU platforms (to get broader
test coverage in CI) and off in sandbox.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2 02/41] Makefile: Allow LTO to be disabled for a build

2021-11-03 Thread Simon Glass
Hi Tom,

On Mon, 1 Nov 2021 at 15:58, Tom Rini  wrote:
>
> On Sun, Oct 31, 2021 at 05:46:43PM -0600, Simon Glass wrote:
> > Hi Tom,
> >
> > On Wed, 27 Oct 2021 at 07:13, Tom Rini  wrote:
> > >
> > > On Wed, Oct 27, 2021 at 02:21:17PM +0200, Heinrich Schuchardt wrote:
> > > >
> > > >
> > > > 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.
> > >
> > > I don't understand why we need this patch at all.  If you want to
> > > disable LTO, disable LTO.  Yes, LTO makes linking take longer which can
> > > be annoying on iterative development.  I have a few different "HACK: DO
> > > NOT PUSH:  ..." things I git am at the start of a branch, depending on
> > > needs.  You can just do that to drop "imply LTO" from the SANDBOX stanza
> > > in arch/Kconfig.  We do not need a whole thing around a CONFIG option
> > > that can be disabled in the defconfig, or local .config file even.
> > >
> >
> > Cranky time.
> >
> > Of course we don't *need* it. I could just buy a slower build machine
> > and type with two fingers. There are lots of ways to slow things down
> > and LTO is one of them. I change branches at least a dozen times a day
> > and am always trying things out from patchwork. I am sure others do
> > too. LTO dramatically slows down builds. Having a way to easily do
> > this from the build system saves time.
>
> Maybe the answer is that LTO just isn't appropriate for sandbox.  We're
> not doing any specific tests for LTO anywhere (nor does that seem
> appropriate), and we do have platforms in CI that run tests other than
> building, with LTO.

It has value as a test, I presume, and a demo of how it works. Also it
runs most of the tests.

But I'm happy to disable it if that helps.

Still, it doesn't really solve the issue. The same thing happens when
building real boards.

Regards,
Simon


Re: [PATCH v2 02/41] Makefile: Allow LTO to be disabled for a build

2021-11-01 Thread Tom Rini
On Sun, Oct 31, 2021 at 05:46:43PM -0600, Simon Glass wrote:
> Hi Tom,
> 
> On Wed, 27 Oct 2021 at 07:13, Tom Rini  wrote:
> >
> > On Wed, Oct 27, 2021 at 02:21:17PM +0200, Heinrich Schuchardt wrote:
> > >
> > >
> > > 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.
> >
> > I don't understand why we need this patch at all.  If you want to
> > disable LTO, disable LTO.  Yes, LTO makes linking take longer which can
> > be annoying on iterative development.  I have a few different "HACK: DO
> > NOT PUSH:  ..." things I git am at the start of a branch, depending on
> > needs.  You can just do that to drop "imply LTO" from the SANDBOX stanza
> > in arch/Kconfig.  We do not need a whole thing around a CONFIG option
> > that can be disabled in the defconfig, or local .config file even.
> >
> 
> Cranky time.
> 
> Of course we don't *need* it. I could just buy a slower build machine
> and type with two fingers. There are lots of ways to slow things down
> and LTO is one of them. I change branches at least a dozen times a day
> and am always trying things out from patchwork. I am sure others do
> too. LTO dramatically slows down builds. Having a way to easily do
> this from the build system saves time.

Maybe the answer is that LTO just isn't appropriate for sandbox.  We're
not doing any specific tests for LTO anywhere (nor does that seem
appropriate), and we do have platforms in CI that run tests other than
building, with LTO.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2 02/41] Makefile: Allow LTO to be disabled for a build

2021-10-31 Thread Simon Glass
Hi Tom,

On Wed, 27 Oct 2021 at 07:13, Tom Rini  wrote:
>
> On Wed, Oct 27, 2021 at 02:21:17PM +0200, Heinrich Schuchardt wrote:
> >
> >
> > 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.
>
> I don't understand why we need this patch at all.  If you want to
> disable LTO, disable LTO.  Yes, LTO makes linking take longer which can
> be annoying on iterative development.  I have a few different "HACK: DO
> NOT PUSH:  ..." things I git am at the start of a branch, depending on
> needs.  You can just do that to drop "imply LTO" from the SANDBOX stanza
> in arch/Kconfig.  We do not need a whole thing around a CONFIG option
> that can be disabled in the defconfig, or local .config file even.
>

Cranky time.

Of course we don't *need* it. I could just buy a slower build machine
and type with two fingers. There are lots of ways to slow things down
and LTO is one of them. I change branches at least a dozen times a day
and am always trying things out from patchwork. I am sure others do
too. LTO dramatically slows down builds. Having a way to easily do
this from the build system saves time.

Regards,
Simon


Re: [PATCH v2 02/41] Makefile: Allow LTO to be disabled for a build

2021-10-31 Thread Simon Glass
Hi Heinrich,

On Wed, 27 Oct 2021 at 06:21, Heinrich Schuchardt
 wrote:
>
>
>
> 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?

Probably, but I lose track of all the branches in progress,
particularly when things sit for a while.

> >
> > 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

The CONFIG indicates that LTO is supported, so if we want to do that,
we could fix the problems with LTO for a board/arch and send a patch
to enable it. I think we want it enabled by default.

[..]

Regards

Simon


Re: [PATCH v2 02/41] Makefile: Allow LTO to be disabled for a build

2021-10-27 Thread Tom Rini
On Wed, Oct 27, 2021 at 02:21:17PM +0200, Heinrich Schuchardt wrote:
> 
> 
> 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.

I don't understand why we need this patch at all.  If you want to
disable LTO, disable LTO.  Yes, LTO makes linking take longer which can
be annoying on iterative development.  I have a few different "HACK: DO
NOT PUSH:  ..." things I git am at the start of a branch, depending on
needs.  You can just do that to drop "imply LTO" from the SANDBOX stanza
in arch/Kconfig.  We do not need a whole thing around a CONFIG option
that can be disabled in the defconfig, or local .config file even.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2 02/41] Makefile: Allow LTO to be disabled for a build

2021-10-27 Thread Heinrich Schuchardt




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
  

Re: [PATCH v2 02/41] Makefile: Allow LTO to be disabled for a build

2021-10-27 Thread Ilias Apalodimas
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
> +
>  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 

[PATCH v2 02/41] Makefile: Allow LTO to be disabled for a build

2021-10-23 Thread Simon Glass
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
+
 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