crosstool-NG icon indicating copy to clipboard operation
crosstool-NG copied to clipboard

gold / lld support for parallel linking (GCC-368)

Open rojer opened this issue 1 year ago • 9 comments

Linking phase is taking substantial amount of time on larger projects, it would be great to get support for -fuse-ld=gold and/or -fuse-ld=lld, both of which support parallel linking and are much faster than the default BFD linker.

rojer avatar May 29 '24 22:05 rojer

@igrr how feasible is this?

i took a quick stab at gold support and found:

  • --dynconfig is not supported - not sure how big of a deal this is at linking stage
  • --no-warn-rwx-segments is not supported - probably minor
  • REGION_ALIAS linker script function is not supported. a bit annoying, but can be worked around with some linker script changes.

after that i ran into "unsupported ELF machine" error (i was using an amd64 build of gold, so not surpirsing)

rojer avatar May 29 '24 22:05 rojer

@rojer , gold has no xtensa support yet. It could not process required xtensa-specific relocations until not implemented. It will likely not get it due to very low priority.

Lapshin avatar Jun 10 '24 07:06 Lapshin

ok, what about lld? for our app, it's not uncommon for linking to take 5-15 seconds (depending on hardware). fast incremental builds (1 source file change) are important for developer productivity and currently linking is the biggest factor here.

rojer avatar Jun 10 '24 10:06 rojer

@rojer , you can refer to LLVM project (but it is not stable yet). Seems LLD is supported for versions greater than esp-15.0.0-20221201. (See https://github.com/espressif/llvm-project/pull/53)

Lapshin avatar Jun 10 '24 12:06 Lapshin

ok, does this mean that it can be integrated into IDF as an option, or even the default? i'm looking at the toolchain distribution archive and not sure if the xtensa or risc-v variant is included, i only see amd64 and wasm variants (ld64.lld and wasm-ld):

[rojer@nbf ~/allterco/esp-idf 5.2.1-s2]$ tar tvf llvm-esp-16.0.0-20230516-linux-amd64.tar.xz | grep 'lld'
lrwxrwxrwx root/root         0 2023-05-17 10:58 esp-clang/bin/ld.lld -> lld
-rwxr-xr-x root/root   5296448 2023-05-17 10:58 esp-clang/bin/lld
lrwxrwxrwx root/root         0 2023-05-17 10:58 esp-clang/bin/lld-link -> lld
lrwxrwxrwx root/root         0 2023-05-17 10:58 esp-clang/bin/wasm-ld -> lld
lrwxrwxrwx root/root         0 2023-05-17 10:58 esp-clang/bin/ld64.lld -> lld
[rojer@nbf ~/allterco/esp-idf 5.2.1-s2]$ tar tvf clang-esp-17.0.1_20240419-x86_64-linux-gnu.tar.xz | grep 'lld'
lrwxrwxrwx root/root         0 2024-04-19 23:27 esp-clang/bin/lld-link -> lld
lrwxrwxrwx root/root         0 2024-04-19 23:27 esp-clang/bin/ld.lld -> lld
-rwxr-xr-x root/root  67654984 2024-04-19 22:54 esp-clang/bin/lld
lrwxrwxrwx root/root         0 2024-04-19 23:27 esp-clang/bin/ld64.lld -> lld
lrwxrwxrwx root/root         0 2024-04-19 23:27 esp-clang/bin/wasm-ld -> lld

rojer avatar Jun 10 '24 19:06 rojer

@gerekon PTAL

Lapshin avatar Jun 11 '24 01:06 Lapshin

@rojer LLD supplied with Espressif Clang toolchain supports Xtensa and RISCV archs, but it has some issues.

  1. For Xtensa it includes preliminary support and still has some issues with building IDF apps.
  2. RISCV support comes from the upstream, but again there are some issues with building IDF apps.

Currently we are working on fixing IDF builds with LLD for RISCV chips. Hopefully it will get into the next release. After that we will start working on issues related to IDF builds with LLD for Xtensa chips.

gerekon avatar Jun 12 '24 08:06 gerekon

@rojer But note, that Xtensa support in Clang itself is not optimal as of now (code size and perf), e.g. direct calls are not implemented yet. https://github.com/espressif/llvm-project/issues/90. So it seems to be early to switch to Clang toolchain completely. May be we can find a way to use LLD with GCC as an option.

gerekon avatar Jun 12 '24 08:06 gerekon

oh yes, clang is hopeless in -Os mode, 30% bigger code or so last i checked. what i was hoping for was to compile gcc and link with lld.

ok, thank you for the update, please know that this is eagerly awaited :)

rojer avatar Jun 12 '24 08:06 rojer