Use clang to do linking.
This avoids having to guess what the linker name-with-build-triplet is, as we can just pass the target to it in the same way as the compilation stage.
Close #1536.
I agree this is is an important cleanup. Unfortunately it fails to link, it appears to use the system linker even when cross compiling (which won't work with ld.bfd):
/usr/bin/ld: unrecognised emulation mode: armelf_linux_eabi
Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu elf_l1om elf_k1om i386pep i386pe
I think this can be fixed with an extra linker parameter -fuse-ld=lld
I also see this error:
main.go:803: error: failed to link /tmp/tinygo728791357/main: none of these commands were found in your $PATH: clang-11
And this one, on MacOS:
main.go:803: error: failed to link /var/folders/yy/d215g62s727f4w2137t9jl2m0000gn/T/tinygo016104012/main: fork/exec /usr/local/opt/llvm@11/bin/clang-11: no such file or directory
I have a suspicion what is causing it, but maybe it's best to first try out the first fix to see how well it works. In short, the name clang (which should be treated specially) is not recognized as a linker in builder/tools.go. For that, the functions runCCompiler and link should probably be merged to a single function.
I don't recall closing this...
Thanks for the pointers. As a first step, I just copied the clang special case from runCCompiler to link, and those can be merged together later if it works. Right now, I'm not really sure where these arguments on which CI is failing come from. There doesn't appear to be -EL, --hash-style=both, or -demangle in the tinygo source code.
Oh, I missed that it was complaining about -fuse-ld=lld first, and those arguments are probably coming from clang attempting to pass lld arguments to something that isn't that. I guess later those CI configurations will need to be modified to install lld instead of the cross-gcc files.
The configurations that actually run appear to still be using ld.bfd, perhaps. Maybe this update will work better.
For MacOS, it looks like you're also switching the compiler (from cc to clang), where you will probably want to use the system linker. As far as I know, ld64.lld is not yet very usable (in fact, they're rewriting the linker right now).
And this:
error: invalid linker name in argument '-fuse-ld=lld'
Is only present when building LLVM statically, so I think something else needs to be done. Apparently Clang has a check to see whether lld is installed, but in this case it should ignore that and try to use it anyway (as lld is built into TinyGo when linking LLVM statically).