Skip to contentSkip to conversation

Add Buildroot toolchain support for LLD

RFC PATCH New Joseph Kogut 4 participants 14 messages Jul 24, 2019 – Oct 20, 2019

lore
Share & tools
lore
#0 lore raw

cover Add Buildroot toolchain support for LLD

Hello,

This series adds support for changing the default linker Buildroot uses, and adds the LLVM project's LLD linker as an alternative to ld.bfd.

LLD offers significantly faster linking compared to GNU Gold and ld.bfd, as well as features like identical code folding (ICF) for generating smaller binaries.

This patchset does not aim to support the more advanced linking features of LLD, but rather allows LLD to be used as a drop-in replacement for the standard GNU linker.

Below are some comparisons with individual package build times with and without LLD. Tests of individual packages are conducted by building a complete image without ccache, then doing:

make [package]-dirclean && time make [package]

BFD: LLD:
FFmpeg:

        real    0m49.493s       real    0m48.912s
        user    10m55.617s      user    10m47.596s
        sys     0m40.307s       sys     0m42.746s

Python3:

        real    0m31.480s       real    0m31.273s
        user    1m35.363s       user    1m34.245s
        sys     0m9.554s        sys     0m10.448s

PostgreSQL:

        real    0m40.440s       real    0m40.015s
        user    3m20.186s       user    3m17.695s
        sys     0m22.199s       sys     0m22.656s

Node.js:

        real    1m47.497s       real    1m45.562s
        user    33m57.731s      user    33m55.133s
        sys     2m2.629s        sys     2m3.313s

As you can see, build times are slightly lower with LLD, but are mostly a wash. Overall build times are not significantly different between the two, however, debug builds may see a greater difference in link times. Performance may vary on other systems.

Some packages such as glibc depend on ld.bfd, and a new environment variable (BR2_NO_LINKER_OVERRIDE) allows disabling the linker override for specific packages when necessary.

Support is currently only provided for Buildroot's toolchain, and only with GCC 9.x, which supports the ld.lld linker driver upstream. Support for older versions of GCC is possible, but it would need to be backported with a trivial patch [1]. I'm open to discussion about if and how linker override support should be handled with external toolchains.

[1] https://patchwork.ozlabs.org/patch/987183/

Joseph Kogut (4):
llvm: disable bindings on host
package/lld: new package
toolchain-wrapper: add linker override option
Add linker override to config options

 Config.in                      | 27 +++++++++++++++++++++++++++
 DEVELOPERS                     |  1 +
 package/Config.in.host         |  1 +
 package/gcc/gcc.mk             |  3 ++-
 package/glibc/glibc.mk         |  3 +++
 package/lld/Config.in.host     | 16 ++++++++++++++++
 package/lld/lld.hash           |  3 +++
 package/lld/lld.mk             | 23 +++++++++++++++++++++++
 package/llvm/llvm.mk           |  3 ++-
 toolchain/toolchain-wrapper.c  | 11 +++++++++++
 toolchain/toolchain-wrapper.mk |  4 ++++
 11 files changed, 93 insertions(+), 2 deletions(-)
 create mode 100644 package/lld/Config.in.host
 create mode 100644 package/lld/lld.hash
 create mode 100644 package/lld/lld.mk

--
2.22.0

#1 lore raw

RFC PATCH 1/4 llvm: disable bindings on host

---
 package/llvm/llvm.mk | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
package/llvm/llvm.mk +2 -1
index 3c62285188..11c8d90af0 100644
@@ -184,7 +184,8 @@ LLVM_CONF_OPTS += -DLLVM_HOST_TRIPLE=$(GNU_TARGET_NAME)
 # check preventively. Building the Go and OCaml bindings is yet unsupported.
 HOST_LLVM_CONF_OPTS += \
 	-DGO_EXECUTABLE=GO_EXECUTABLE-NOTFOUND \
-	-DOCAMLFIND=OCAMLFIND-NOTFOUND
+	-DOCAMLFIND=OCAMLFIND-NOTFOUND \
+	-DLLVM_ENABLE_BINDINGS=OFF
 
 # Builds a release host tablegen that gets used during the LLVM build.
 HOST_LLVM_CONF_OPTS += -DLLVM_OPTIMIZED_TABLEGEN=ON
Signature · 1 line
2.22.0
#2 lore raw

RFC PATCH 1/4 llvm: disable bindings on host

Hi Joseph,

Le 24/07/2019 ? 19:35, Joseph Kogut a ?crit?:

Quoted 10 lines
---
 package/llvm/llvm.mk | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
package/llvm/llvm.mk +0 -0
index 3c62285188..11c8d90af0 100644

package/llvm/llvm.mk LLVM_CONF_OPTS += -DLLVM_HOST_TRIPLE=$(GNU_TARGET_NAME) · line 188

Quoted 6 lines
package/llvm/llvm.mk +2 -1
@@ -184,7 +184,8 @@ LLVM_CONF_OPTS += -DLLVM_HOST_TRIPLE=$(GNU_TARGET_NAME)
 # check preventively. Building the Go and OCaml bindings is yet unsupported.
 HOST_LLVM_CONF_OPTS += \
 	-DGO_EXECUTABLE=GO_EXECUTABLE-NOTFOUND \
-	-DOCAMLFIND=OCAMLFIND-NOTFOUND
+	-DOCAMLFIND=OCAMLFIND-NOTFOUND \
+	-DLLVM_ENABLE_BINDINGS=OFF

With LLVM_ENABLE_BINDINGS=OFF, you should be able to remove GO_EXECUTABLE and DOCAMLFIND

Best regards,
Romain

Quoted 4 lines
package/llvm/llvm.mk +0 -0
 # Builds a release host tablegen that gets used during the LLVM build.
 HOST_LLVM_CONF_OPTS += -DLLVM_OPTIMIZED_TABLEGEN=ON
 
#3 lore raw

RFC PATCH 1/4 llvm: disable bindings on host

In reply to Joseph Kogut
Quoted 1 line · Joseph Kogut

Can you explain why this is needed/wanted?

Regards,
Arnout

Quoted 19 lines
---
 package/llvm/llvm.mk | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
package/llvm/llvm.mk +2 -1
index 3c62285188..11c8d90af0 100644
@@ -184,7 +184,8 @@ LLVM_CONF_OPTS += -DLLVM_HOST_TRIPLE=$(GNU_TARGET_NAME)
 # check preventively. Building the Go and OCaml bindings is yet unsupported.
 HOST_LLVM_CONF_OPTS += \
 	-DGO_EXECUTABLE=GO_EXECUTABLE-NOTFOUND \
-	-DOCAMLFIND=OCAMLFIND-NOTFOUND
+	-DOCAMLFIND=OCAMLFIND-NOTFOUND \
+	-DLLVM_ENABLE_BINDINGS=OFF
 
 # Builds a release host tablegen that gets used during the LLVM build.
 HOST_LLVM_CONF_OPTS += -DLLVM_OPTIMIZED_TABLEGEN=ON
#4 lore raw

RFC PATCH 1/4 llvm: disable bindings on host

Quoted 11 lines · Arnout Vandecappelle
Quoted 1 line · Joseph Kogut

Can you explain why this is needed/wanted?

Regards,
Arnout

Nope. This commit was a while ago, and when I was working on this feature, I found that certain bindings were still enabled which caused a build failure. I researched the configure flags for LLVM, and found this one. Enabling it fixed the build, so I added it.

It's very possible the enabling of this flag obviates the need for the priors. If that's the case, I would of course support removing the unneeded flags.

Best,
Joseph

#5 lore raw

RFC PATCH 2/4 package/lld: new package

In reply to Joseph Kogut
---
 DEVELOPERS                 |  1 +
 package/Config.in.host     |  1 +
 package/lld/Config.in.host | 16 ++++++++++++++++
 package/lld/lld.hash       |  3 +++
 package/lld/lld.mk         | 23 +++++++++++++++++++++++
 5 files changed, 44 insertions(+)
 create mode 100644 package/lld/Config.in.host
 create mode 100644 package/lld/lld.hash
 create mode 100644 package/lld/lld.mk
DEVELOPERS +1 -0
index 4ab4e36593..bdc98edd12 100644
@@ -1221,6 +1221,7 @@ F:	package/at-spi2-core/
 F:	package/clang/
 F:	package/gconf/
 F:	package/libnss/
+F:	package/lld/
 F:	package/llvm/
 F:	package/python-cython/
 F:	package/python-raven/
package/Config.in.host +1 -0
index 1501889b72..abacf3c42a 100644
@@ -34,6 +34,7 @@ menu "Host utilities"
 	source "package/jq/Config.in.host"
 	source "package/jsmin/Config.in.host"
 	source "package/libp11/Config.in.host"
+	source "package/lld/Config.in.host"
 	source "package/lpc3250loader/Config.in.host"
 	source "package/lttng-babeltrace/Config.in.host"
 	source "package/mender-artifact/Config.in.host"
package/lld/Config.in.host new file +16 -0
new file mode 100644
index 0000000000..c04b7924fa
@@ -0,0 +1,16 @@
+config BR2_PACKAGE_HOST_LLD
+	bool "host lld"
+	depends on BR2_PACKAGE_LLVM_ARCH_SUPPORTS # llvm
+	depends on BR2_HOST_GCC_AT_LEAST_4_8 # llvm
+	select BR2_PACKAGE_HOST_LLVM
+	help
+	  LLD is a linker from the LLVM project that is a drop-in
+	  replacement for system linkers, and runs much faster than
+	  them. It also provides features that are useful for
+	  toolchain developers.
+
+	  https://lld.llvm.org/
+
+comment "lld needs a toolchain w/ host gcc >= 4.8"
+	depends on BR2_PACKAGE_LLVM_ARCH_SUPPORTS
+	depends on !BR2_HOST_GCC_AT_LEAST_4_8
package/lld/lld.hash new file +3 -0
new file mode 100644
index 0000000000..dfbb290cf4
@@ -0,0 +1,3 @@
+# locally calculated
+sha256 9caec8ec922e32ffa130f0fb08e4c5a242d7e68ce757631e425e9eba2e1a6e37  lld-8.0.0.src.tar.xz
+sha256 f0502d2d0e19748c534ee95ea486c092273303dbef76404c8b17dc8bf6ca441b  LICENSE.TXT
package/lld/lld.mk new file +23 -0
new file mode 100644
index 0000000000..a6933e2961
@@ -0,0 +1,23 @@
+################################################################################
+#
+# lld
+#
+################################################################################
+
+LLD_VERSION = 8.0.0
+LLD_SITE = https://llvm.org/releases/$(LLD_VERSION)
+LLD_SOURCE = lld-$(LLD_VERSION).src.tar.xz
+LLD_LICENSE = NCSA
+LLD_LICENSE_FILES = LICENSE.TXT
+LLD_SUPPORTS_IN_SOURCE_BUILD = NO
+HOST_LLD_DEPENDENCIES = host-llvm
+
+# GCC looks for tools in a different path from LLD's default installation path
+define HOST_LLD_CREATE_SYMLINKS
+	ln -sf $(HOST_DIR)/bin/lld $(HOST_DIR)/$(GNU_TARGET_NAME)/bin/lld
+	ln -sf $(HOST_DIR)/bin/lld $(HOST_DIR)/$(GNU_TARGET_NAME)/bin/ld.lld
+endef
+
+HOST_LLD_POST_INSTALL_HOOKS += HOST_LLD_CREATE_SYMLINKS
+
+$(eval $(host-cmake-package))
Signature · 1 line
2.22.0
#6 lore raw

RFC PATCH 2/4 package/lld: new package

Quoted 1 line · Joseph Kogut

Applied to master, thanks. Not very useful as is, but it will give some
autobuilder exposure.

[snip]

package/lld/Config.in.host line 5

Quoted 5 lines
package/lld/Config.in.host new file +5 -0
+config BR2_PACKAGE_HOST_LLD
+	bool "host lld"
+	depends on BR2_PACKAGE_LLVM_ARCH_SUPPORTS # llvm
+	depends on BR2_HOST_GCC_AT_LEAST_4_8 # llvm
+	select BR2_PACKAGE_HOST_LLVM

This symbol doesn't exist, so I removed it.

Regards,
Arnout

[snip]

#7 lore raw

RFC PATCH 3/4 toolchain-wrapper: add linker override option

In reply to Joseph Kogut
---
 toolchain/toolchain-wrapper.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
toolchain/toolchain-wrapper.c +11 -0
index c73a0cc079..131a239f7f 100644
@@ -360,6 +360,17 @@ int main(int argc, char **argv)
 	}
 #endif /* ARCH || CPU */
 
+#if defined(BR_LINKER)
+	/* Specify our linker if it's not already set */
+	for (i = 1; i < argc; i++) {
+		if (!strncmp(argv[i], "-fuse-ld=", strlen("-fuse-ld=")))
+			break;
+	}
+	if (i == argc && !getenv("BR2_NO_LINKER_OVERRIDE")) {
+		*cur++ = "-fuse-ld=" BR_LINKER;
+	}
+#endif /* BR_LINKER */
+
 	if (parse_source_date_epoch_from_env()) {
 		*cur++ = _time_;
 		*cur++ = _date_;
Signature · 1 line
2.22.0
#8 lore raw

RFC PATCH 3/4 toolchain-wrapper: add linker override option

Quoted 10 lines · Joseph Kogut
---
 toolchain/toolchain-wrapper.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
toolchain/toolchain-wrapper.c +0 -0
index c73a0cc079..131a239f7f 100644

toolchain/toolchain-wrapper.c int main(int argc, char **argv) · line 369

Quoted 10 lines
toolchain/toolchain-wrapper.c +7 -0
@@ -360,6 +360,17 @@ int main(int argc, char **argv)
 	}
 #endif /* ARCH || CPU */
 
+#if defined(BR_LINKER)
+	/* Specify our linker if it's not already set */
+	for (i = 1; i < argc; i++) {
+		if (!strncmp(argv[i], "-fuse-ld=", strlen("-fuse-ld=")))
+			break;
+	}
+	if (i == argc && !getenv("BR2_NO_LINKER_OVERRIDE")) {

A while ago we decided that "internal" environment variables should use BR_
prefix, while "user" variables should use BR2_. I'm not sure if we consistently do that, but I do think that here we should.

Regards,
Arnout

Quoted 8 lines
toolchain/toolchain-wrapper.c +4 -0
+		*cur++ = "-fuse-ld=" BR_LINKER;
+	}
+#endif /* BR_LINKER */
+
 	if (parse_source_date_epoch_from_env()) {
 		*cur++ = _time_;
 		*cur++ = _date_;
#9 lore raw

RFC PATCH 4/4 Add linker override to config options

In reply to Joseph Kogut
---
 Config.in                      | 27 +++++++++++++++++++++++++++
 package/gcc/gcc.mk             |  3 ++-
 package/glibc/glibc.mk         |  3 +++
 toolchain/toolchain-wrapper.mk |  4 ++++
 4 files changed, 36 insertions(+), 1 deletion(-)
Config.in +27 -0
index 757ad1ca40..576d95305d 100644
@@ -318,6 +318,33 @@ config BR2_JLEVEL
 	  Number of jobs to run simultaneously. If 0, determine
 	  automatically according to number of CPUs on the host system.
 
+choice
+	prompt "Default linker"
+	default BR2_LINKER_BFD
+	help
+	  Choose the default linker
+	  Individual packages may override this choice
+
+config BR2_LINKER_BFD
+	bool "GNU ld"
+	help
+	  GNU GCC linker
+
+config BR2_LINKER_LLD
+	bool "LLVM LLD"
+	select BR2_PACKAGE_HOST_LLD
+	help
+	  Clang/LLVM linker
+
+	  Offers a faster link times compared to GNU linkers such as ld.bfd and
+	  ld.gold.
+
+	  NOTE: This option requires building LLVM, which is time consuming itself.
+
+	  https://lld.llvm.org/
+
+endchoice
+
 config BR2_CCACHE
 	bool "Enable compiler cache"
 	help
package/gcc/gcc.mk +2 -1
index 46ad16df13..aef0038639 100644
@@ -85,7 +85,8 @@ HOST_GCC_COMMON_DEPENDENCIES = \
 	host-gmp \
 	host-mpc \
 	host-mpfr \
-	$(if $(BR2_BINFMT_FLAT),host-elf2flt)
+	$(if $(BR2_BINFMT_FLAT),host-elf2flt) \
+	$(if $(BR2_LINKER_LLD),host-lld)
 
 HOST_GCC_COMMON_CONF_OPTS = \
 	--target=$(GNU_TARGET_NAME) \
package/glibc/glibc.mk +3 -0
index f8d8c1bd87..1c06028241 100644
@@ -32,6 +32,9 @@ GLIBC_LICENSE_FILES = COPYING COPYING.LIB LICENSES
 # glibc is part of the toolchain so disable the toolchain dependency
 GLIBC_ADD_TOOLCHAIN_DEPENDENCY = NO
 
+# Glibc requires ld.bfd
+GLIBC_MAKE_ENV += BR2_NO_LINKER_OVERRIDE=1
+
 # Before glibc is configured, we must have the first stage
 # cross-compiler and the kernel headers
 GLIBC_DEPENDENCIES = host-gcc-initial linux-headers host-bison host-gawk \
toolchain/toolchain-wrapper.mk +4 -0
index ca66fa7ba4..ff7a7ab448 100644
@@ -16,6 +16,10 @@ endif
 TOOLCHAIN_WRAPPER_ARGS = $($(PKG)_TOOLCHAIN_WRAPPER_ARGS)
 TOOLCHAIN_WRAPPER_ARGS += -DBR_SYSROOT='"$(STAGING_SUBDIR)"'
 
+ifeq ($(BR2_LINKER_LLD),y)
+TOOLCHAIN_WRAPPER_ARGS += -DBR_LINKER='"lld"'
+endif
+
 TOOLCHAIN_WRAPPER_OPTS = \
 	$(call qstrip,$(BR2_SSP_OPTION)) \
 	$(call qstrip,$(BR2_TARGET_OPTIMIZATION))
Signature · 1 line
2.22.0
#10 lore raw

RFC PATCH 4/4 Add linker override to config options

Quoted 2 lines · Joseph Kogut

[...]

toolchain/toolchain-wrapper.mk endif · line 20

Quoted 3 lines
toolchain/toolchain-wrapper.mk +2 -0
+ifeq ($(BR2_LINKER_LLD),y)
+TOOLCHAIN_WRAPPER_ARGS += -DBR_LINKER='"lld"'

Sorry for the nitpicking but Buildroot normally uses the "BR2_" prefix fo perhaps this should be "BR2_LINKER"

Signature · 1 line
Carlos Santos <[email protected]>
#11 lore raw

RFC PATCH 4/4 Add linker override to config options

Hi Carlos,

Quoted 12 lines · Carlos Santos
Quoted 2 lines · Joseph Kogut

[...]

toolchain/toolchain-wrapper.mk endif · line 20

Quoted 3 lines
toolchain/toolchain-wrapper.mk +2 -0
+ifeq ($(BR2_LINKER_LLD),y)
+TOOLCHAIN_WRAPPER_ARGS += -DBR_LINKER='"lld"'

Sorry for the nitpicking but Buildroot normally uses the "BR2_" prefix fo perhaps this should be "BR2_LINKER"

Correct, most constants are prefixed with BR2_*, with the exception of definitions in the toolchain wrapper. I chose BR_LINKER to remain consistent with the other code in the wrapper.

Best,
Joseph

#12 lore raw

RFC PATCH 4/4 Add linker override to config options

In reply to Joseph Kogut
Quoted 1 line · Joseph Kogut

Please make the commit message a bit more extensive. Actually, almost all of
the cover text could be put here.

Quoted 12 lines
---
 Config.in                      | 27 +++++++++++++++++++++++++++
 package/gcc/gcc.mk             |  3 ++-
 package/glibc/glibc.mk         |  3 +++
 toolchain/toolchain-wrapper.mk |  4 ++++
 4 files changed, 36 insertions(+), 1 deletion(-)
Config.in +0 -0
index 757ad1ca40..576d95305d 100644

Config.in config BR2_JLEVEL · line 323

Quoted 6 lines
Config.in +3 -0
@@ -318,6 +318,33 @@ config BR2_JLEVEL
 	  Number of jobs to run simultaneously. If 0, determine
 	  automatically according to number of CPUs on the host system.
 
+choice
+	prompt "Default linker"
+	default BR2_LINKER_BFD

I think this option belongs in the toolchain menu, under the toolchain generic
options.

Config.in config BR2_JLEVEL · line 326

Quoted 3 lines
Config.in +3 -0
+	help
+	  Choose the default linker
+	  Individual packages may override this choice

Please end sentences with a period, and if it's intended as two paragraphs, add
an empty line between them.

Config.in config BR2_JLEVEL · line 335

Quoted 9 lines
Config.in +9 -0
+
+config BR2_LINKER_BFD
+	bool "GNU ld"
+	help
+	  GNU GCC linker
+
+config BR2_LINKER_LLD
+	bool "LLVM LLD"
+	select BR2_PACKAGE_HOST_LLD

If this requires gcc 9+, you should add

depends on BR2_TOOLCHAIN_GCC_AT_LEAST_9

Quoted 20 lines
Config.in +12 -0
+	help
+	  Clang/LLVM linker
+
+	  Offers a faster link times compared to GNU linkers such as ld.bfd and
+	  ld.gold.
+
+	  NOTE: This option requires building LLVM, which is time consuming itself.
+
+	  https://lld.llvm.org/
+
+endchoice
+
 config BR2_CCACHE
 	bool "Enable compiler cache"
 	help
package/gcc/gcc.mk +0 -0
index 46ad16df13..aef0038639 100644

package/gcc/gcc.mk HOST_GCC_COMMON_DEPENDENCIES = \ · line 89

Quoted 6 lines
package/gcc/gcc.mk +2 -1
@@ -85,7 +85,8 @@ HOST_GCC_COMMON_DEPENDENCIES = \
 	host-gmp \
 	host-mpc \
 	host-mpfr \
-	$(if $(BR2_BINFMT_FLAT),host-elf2flt)
+	$(if $(BR2_BINFMT_FLAT),host-elf2flt) \
+	$(if $(BR2_LINKER_LLD),host-lld)

I think it's not really needed by gcc itself, but only by the packages that
will add the -fuse-ld flag, right? Then I think it's more appropriate to add the dependency to the toolchain (virtual) package. That way, we also support external toolchains.

Quoted 22 lines
package/gcc/gcc.mk +0 -0
 HOST_GCC_COMMON_CONF_OPTS = \
 	--target=$(GNU_TARGET_NAME) \
package/glibc/glibc.mk +3 -0
index f8d8c1bd87..1c06028241 100644
@@ -32,6 +32,9 @@ GLIBC_LICENSE_FILES = COPYING COPYING.LIB LICENSES
 # glibc is part of the toolchain so disable the toolchain dependency
 GLIBC_ADD_TOOLCHAIN_DEPENDENCY = NO
 
+# Glibc requires ld.bfd
+GLIBC_MAKE_ENV += BR2_NO_LINKER_OVERRIDE=1
+
 # Before glibc is configured, we must have the first stage
 # cross-compiler and the kernel headers
 GLIBC_DEPENDENCIES = host-gcc-initial linux-headers host-bison host-gawk \
toolchain/toolchain-wrapper.mk +0 -0
index ca66fa7ba4..ff7a7ab448 100644

toolchain/toolchain-wrapper.mk endif · line 25

Quoted 10 lines
toolchain/toolchain-wrapper.mk +4 -0
@@ -16,6 +16,10 @@ endif
 TOOLCHAIN_WRAPPER_ARGS = $($(PKG)_TOOLCHAIN_WRAPPER_ARGS)
 TOOLCHAIN_WRAPPER_ARGS += -DBR_SYSROOT='"$(STAGING_SUBDIR)"'
 
+ifeq ($(BR2_LINKER_LLD),y)
+TOOLCHAIN_WRAPPER_ARGS += -DBR_LINKER='"lld"'
+endif
+
 TOOLCHAIN_WRAPPER_OPTS = \
 	$(call qstrip,$(BR2_SSP_OPTION)) \
 	$(call qstrip,$(BR2_TARGET_OPTIMIZATION))

I think two additional patches will be needed:

1. An update to the manual that explains how to disable lld in the adding-packages section.

2. An update to genrandconfig that makes sure the LLD option gets tested in the autobuilders.

Regards,
Arnout

#13 lore raw

cover Add Buildroot toolchain support for LLD

In reply to Joseph Kogut

Hello Joseph,

Le 24/07/2019 ? 19:35, Joseph Kogut a ?crit?:

Quoted 11 lines

Hello,

This series adds support for changing the default linker Buildroot uses, and adds the LLVM project's LLD linker as an alternative to ld.bfd.

LLD offers significantly faster linking compared to GNU Gold and ld.bfd, as well as features like identical code folding (ICF) for generating smaller binaries.

This patchset does not aim to support the more advanced linking features of LLD, but rather allows LLD to be used as a drop-in replacement for the standard GNU linker.

Do you think the test result could be improved by using the more advanced linking features ?

Quoted 37 lines

Below are some comparisons with individual package build times with and without LLD. Tests of individual packages are conducted by building a complete image without ccache, then doing:

make [package]-dirclean && time make [package]

BFD: LLD:
FFmpeg:

        real    0m49.493s       real    0m48.912s
        user    10m55.617s      user    10m47.596s
        sys     0m40.307s       sys     0m42.746s

Python3:

        real    0m31.480s       real    0m31.273s
        user    1m35.363s       user    1m34.245s
        sys     0m9.554s        sys     0m10.448s

PostgreSQL:

        real    0m40.440s       real    0m40.015s
        user    3m20.186s       user    3m17.695s
        sys     0m22.199s       sys     0m22.656s

Node.js:

        real    1m47.497s       real    1m45.562s
        user    33m57.731s      user    33m55.133s
        sys     2m2.629s        sys     2m3.313s

As you can see, build times are slightly lower with LLD, but are mostly a wash. Overall build times are not significantly different between the two, however, debug builds may see a greater difference in link times. Performance may vary on other systems.

Some packages such as glibc depend on ld.bfd, and a new environment variable (BR2_NO_LINKER_OVERRIDE) allows disabling the linker override for specific packages when necessary.

Quoted 5 lines

Support is currently only provided for Buildroot's toolchain, and only with GCC 9.x, which supports the ld.lld linker driver upstream. Support for older versions of GCC is possible, but it would need to be backported with a trivial patch [1]. I'm open to discussion about if and how linker override support should be handled with external toolchains.

What was the architecture you used for this test ?

Since llvm/clang/lld take a lot of time to build, do you think it could be useful to be able to import a clang toolchain as an external toolchain ?

That was the question during the Buildroot FOSDEM meeting 2018:
https://www.elinux.org/Buildroot:DeveloperDaysFOSDEM2018#LLVM.2FClang

Best regards,
Romain

Quoted 33 lines

[1] https://patchwork.ozlabs.org/patch/987183/

Joseph Kogut (4):
llvm: disable bindings on host
package/lld: new package
toolchain-wrapper: add linker override option
Add linker override to config options

 Config.in                      | 27 +++++++++++++++++++++++++++
 DEVELOPERS                     |  1 +
 package/Config.in.host         |  1 +
 package/gcc/gcc.mk             |  3 ++-
 package/glibc/glibc.mk         |  3 +++
 package/lld/Config.in.host     | 16 ++++++++++++++++
 package/lld/lld.hash           |  3 +++
 package/lld/lld.mk             | 23 +++++++++++++++++++++++
 package/llvm/llvm.mk           |  3 ++-
 toolchain/toolchain-wrapper.c  | 11 +++++++++++
 toolchain/toolchain-wrapper.mk |  4 ++++
 11 files changed, 93 insertions(+), 2 deletions(-)
 create mode 100644 package/lld/Config.in.host
 create mode 100644 package/lld/lld.hash
 create mode 100644 package/lld/lld.mk

--
2.22.0

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot