espressif / crosstool-NG

crosstool-NG with support for Xtensa
Other
121 stars 63 forks source link

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

Open rojer opened 5 months ago

rojer commented 5 months ago

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 commented 5 months ago

@igrr how feasible is this?

i took a quick stab at gold support and found:

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

Lapshin commented 5 months ago

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

rojer commented 5 months ago

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.

Lapshin commented 5 months ago

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

rojer commented 5 months ago

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
Lapshin commented 5 months ago

@gerekon PTAL

gerekon commented 5 months ago

@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 commented 5 months ago

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

rojer commented 5 months ago

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