Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use clang to do linking. #1538

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open

Conversation

QuLogic
Copy link
Contributor

@QuLogic QuLogic commented Dec 21, 2020

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.

@aykevl
Copy link
Member

aykevl commented Dec 21, 2020

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.

@QuLogic
Copy link
Contributor Author

QuLogic commented Jan 18, 2021

I don't recall closing this...

@QuLogic QuLogic reopened this Jan 18, 2021
@QuLogic
Copy link
Contributor Author

QuLogic commented Jan 18, 2021

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.

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.
@QuLogic
Copy link
Contributor Author

QuLogic commented Jan 18, 2021

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.

@aykevl
Copy link
Member

aykevl commented Jan 18, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants