diff mbox series

[v2,4/4] Makefile: lld: set -O2 linker flag when linking with LLD

Message ID 20190211193008.24101-4-ndesaulniers@google.com
State New
Headers show
Series [v2,1/4] init/Kconfig: add config support for detecting linker | expand

Commit Message

Nick Desaulniers Feb. 11, 2019, 7:30 p.m. UTC
For arm64:
0.34% size improvement with lld -O2 over lld for vmlinux.
3.3% size improvement with lld -O2 over lld for Image.lz4-dtb.

Link: https://github.com/ClangBuiltLinux/linux/issues/343
Suggested-by: Rui Ueyama <ruiu@google.com>
Suggested-by: Nathan Chancellor <natechancellor@gmail.com>
Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>

Tested-by: Nathan Chancellor <natechancellor@gmail.com>

Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>

---
Changes V1->V2:
* add tested and reviewed by tags.

 Makefile | 4 ++++
 1 file changed, 4 insertions(+)

-- 
2.20.1.791.gb4d0f1c61a-goog

Comments

Peter Zijlstra Feb. 12, 2019, 12:22 p.m. UTC | #1
On Mon, Feb 11, 2019 at 11:30:06AM -0800, ndesaulniers@google.com wrote:
> For arm64:

> 0.34% size improvement with lld -O2 over lld for vmlinux.

> 3.3% size improvement with lld -O2 over lld for Image.lz4-dtb.


The Changelog is utterly failing to explain what it does.

> Link: https://github.com/ClangBuiltLinux/linux/issues/343


That is irrelevant crap.

> Suggested-by: Rui Ueyama <ruiu@google.com>

> Suggested-by: Nathan Chancellor <natechancellor@gmail.com>

> Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>

> Tested-by: Nathan Chancellor <natechancellor@gmail.com>

> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>

> ---

> Changes V1->V2:

> * add tested and reviewed by tags.

> 

>  Makefile | 4 ++++

>  1 file changed, 4 insertions(+)

> 

> diff --git a/Makefile b/Makefile

> index 00e8e01d23fc..8011555745aa 100644

> --- a/Makefile

> +++ b/Makefile

> @@ -718,6 +718,10 @@ else

>  KBUILD_CFLAGS += -Wno-unused-but-set-variable

>  endif

>  

> +ifdef CONFIG_LD_IS_LLD

> +KBUILD_LDFLAGS += -O2

> +endif

> +

>  KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)

>  ifdef CONFIG_FRAME_POINTER

>  KBUILD_CFLAGS	+= -fno-omit-frame-pointer -fno-optimize-sibling-calls

> -- 

> 2.20.1.791.gb4d0f1c61a-goog

>
Masahiro Yamada Feb. 16, 2019, 2:55 a.m. UTC | #2
On Tue, Feb 12, 2019 at 5:42 AM <ndesaulniers@google.com> wrote:
>

> For arm64:

> 0.34% size improvement with lld -O2 over lld for vmlinux.

> 3.3% size improvement with lld -O2 over lld for Image.lz4-dtb.

>

> Link: https://github.com/ClangBuiltLinux/linux/issues/343

> Suggested-by: Rui Ueyama <ruiu@google.com>

> Suggested-by: Nathan Chancellor <natechancellor@gmail.com>

> Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>

> Tested-by: Nathan Chancellor <natechancellor@gmail.com>

> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>

> ---

> Changes V1->V2:

> * add tested and reviewed by tags.

>

>  Makefile | 4 ++++

>  1 file changed, 4 insertions(+)

>

> diff --git a/Makefile b/Makefile

> index 00e8e01d23fc..8011555745aa 100644

> --- a/Makefile

> +++ b/Makefile

> @@ -718,6 +718,10 @@ else

>  KBUILD_CFLAGS += -Wno-unused-but-set-variable

>  endif

>

> +ifdef CONFIG_LD_IS_LLD

> +KBUILD_LDFLAGS += -O2

> +endif

> +



I wondered why this option should be added only for lld,
and I found the answer in the "Link:"

"for bfd, didn't seem to change the size at all (I can't recall if
this was arm64 or x86 I had tested with though)."


Hmm, I see.
My 'man ld' says it is currently effective only for shared libraries.


       -O level
           If level is a numeric values greater than zero ld optimizes the
           output.  This might take significantly longer and therefore
           probably should only be enabled for the final binary.  At the
           moment this option only affects ELF shared library generation.
           Future releases of the linker may make more use of this option.
           Also currently there is no difference in the linker's behaviour for
           different non-zero values of this option.  Again this may change
           with future releases.



I am fine with adding it unconditionally
as long as it is harmless for bfd, gold.






>  KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)

>  ifdef CONFIG_FRAME_POINTER

>  KBUILD_CFLAGS  += -fno-omit-frame-pointer -fno-optimize-sibling-calls

> --

> 2.20.1.791.gb4d0f1c61a-goog

>



-- 
Best Regards
Masahiro Yamada
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 00e8e01d23fc..8011555745aa 100644
--- a/Makefile
+++ b/Makefile
@@ -718,6 +718,10 @@  else
 KBUILD_CFLAGS += -Wno-unused-but-set-variable
 endif
 
+ifdef CONFIG_LD_IS_LLD
+KBUILD_LDFLAGS += -O2
+endif
+
 KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
 ifdef CONFIG_FRAME_POINTER
 KBUILD_CFLAGS	+= -fno-omit-frame-pointer -fno-optimize-sibling-calls