This is an archive of the discontinued LLVM Phabricator instance.

Use more efficient linker for flang debug builder.
ClosedPublic

Authored by stevanradakovic on Mar 18 2021, 2:41 AM.

Details

Summary

Use lld linker for flang debug configuration.

Diff Detail

Event Timeline

stevanradakovic requested review of this revision.Mar 18 2021, 2:41 AM

Which linker does this worker/builder use? It might be worth making sure it's not bfd.

@awarzynski I really can't tell from the logs. here's the local build that passed: http://ex40-01.tcwglab.linaro.org:8019/#/builders/18/builds/81

@awarzynski I really can't tell from the logs. here's the local build that passed: http://ex40-01.tcwglab.linaro.org:8019/#/builders/18/builds/81

Np, from here:

-- Linker detection: GNU ld

That's the bfd linker (yup, the log _does not_ make it easy to find!). For GNU gold you would get:

-- Linker detection: GNU Gold

LLD is even better :)

There are at least two ways to change the linker used by a worker/builder:

  • change the system linker (check which ld and update the corresponding symbolic link)
  • use LLVM_USE_LINKER when configuring CMake (more info: Building LLVM with CMake

More on linker-related issues when building LLVM: https://llvm.org/docs/GettingStarted.html#common-problems. More specifically, Flang has quite demanding memory requirements. It is really worth making sure that one uses the most efficient linker.

I hope that this helps :)

Thanks Andrzej!

I've installed lld on teh worker and used "-DLLVM_ENABLE_LLD=ON" flag here.
So what about parallel_link_jobs? Should we keep this setting or not?

awarzynski added a comment.EditedMar 19 2021, 4:12 AM

Thanks Andrzej!

I've installed lld on teh worker and used "-DLLVM_ENABLE_LLD=ON" flag here.
So what about parallel_link_jobs? Should we keep this setting or not?

This will depend on the number of cores and amount of RAM available. In general, I've never had to use LLVM_PARALLEL_LINK_JOBS. Switching to a more efficient linker has always been sufficient. But this depends on the spec of the machine.

Note that your current config is not working:

CMake Error at cmake/modules/HandleLLVMOptions.cmake:286 (message):
  Host compiler does not support '-fuse-ld=lld'
Call Stack (most recent call first):
  CMakeLists.txt:697 (include)

I couldn't check which version of GCC introduced support for -fuse-ld=lld, but GCC 9.3.0 should be fine. Could you check gcc -fuse-ld=lld file.c for e.g.:

int main() { return 0;}

This worked for me on X86 and AArch64 (tested with GCC 10.2.0 and GCC 9.3.0).

Alternatively, you could use:

  • GCC + ld.gold
  • Clang + LLD

When I install lld package on the worker the current config works. Do you think that will be ok?

Right, and I have also linked /usr/bin/ld to /usr/bin/lld. Is it too much of a hack?

Right, and I have also linked /usr/bin/ld to /usr/bin/lld . Is it too much of a hack?

Personally I don't think that this a hack, but it's worth documenting somewhere what the default linker on that machine is. In particular, there is not much here ATM: http://ex40-01.tcwglab.linaro.org:8019/#/workers/100 (see Admin and Host - please, could you update?).

I'm not a Ubuntu user (or expert) myself, but AFAIK, /usr/bin/ld is just a symlink that points to another symlink (e.g. /usr/bin/ld.bfd). And GCC will probably use e.g. /usr/bin/ld.lld when going through -fuse-ld=lld. I think that the bottom line is that if you rely on /usr/bin/ld, then any system update/upgrade may restore the original config. So you may want to rely on /usr/bin/ld.lld instead.

Use lld linker instead of the bfd. Remove parallel link jobs setting.

Ok this seems more sensible then. I'll make sure that the lld is installed on the worker side in our setup. Let me know if there's anything else. Thanks!

awarzynski accepted this revision.Mar 22 2021, 9:44 AM

This makes sense. Please update the commit message before merging (this has changed a bit since uploading) ;-)

This revision is now accepted and ready to land.Mar 22 2021, 9:44 AM
stevanradakovic retitled this revision from Decrease parallel link jobs for flang debug builder. to Use more efficient linker for flang debug builder..Mar 23 2021, 5:08 AM
stevanradakovic edited the summary of this revision. (Show Details)

Update commit msg.