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
native: initial linking support for linux #15326
Conversation
|
Seems like the native ci tests fail immediately... Is the linker installed on there? |
|
Ugh. We need our own linker. I'd prefer not to need one at all, but... |
|
Before implementing this I asked @medvednikov about this. He said it was ok to use an external Linker since writing a linker is a huge project on its own, we could reuse existing stuff and he thinks that native should only generate .o (or similar) files. Edit: also, we can implement our own linker at any time in the future |
|
|
||
| os.write_file_array(obj_name, g.buf) or { panic(err) } | ||
|
|
||
| match g.pref.os { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just call the method, if the check is done on it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because linking is only implemented for Linux. I don‘t accidentally want to call link() with another OS or else an error will be thrown. Once All OSes receive their linking functionality, I‘ll remove the first check. That‘s why there are // TEMPORARY comments.
|
As expected, all Linux ci tests fail. Maybe |
... and that's part of why I said we need our own linker. :-) |
|
If you want to do this, go ahead. I think we should at least get the whole native backend working before we implement a custom linker. |
|
I agree, it's just going to be painful making sure everyone (including the CI runners) has the same linker installed. |
|
I definitely see your point. We could also check for different linkers, just like the c compiler with cgen, the default gnu |
|
@medvednikov what do you think about this? |
|
@Spydr06 I still think what I said before. lld can be installed separately for now, on ci boxes as well. Later V will quietly fetch it or distribute like it does for tcc. New modern linkers are fast, no need to re-write them. It's the machine code generation that's slow. |
|
|
Tests still fail even though lld is now installed... |
|
Question is: Why are they failing now? There's no message about ld.lld not being found. |
|
I don't know it. On my local system everything works. Testing in a vanilla Ubuntu VM rn. |
|
Oof. Yeah, works for me too, on Manjaro: |
|
Yes, on the Ubuntu VM everything works as well |
|
V needs a "verbose test failure" switch (if it doesn't already have an undocumented one...) |
|
Question: Will use of the linker be optional? I really, really like the 186 byte hello_world, as opposed to the 10k hello_world. :-\ |
|
I can implement a switch for that, should be easy. I think we should figure out with which libraries to link with in general. Currently, it just links with the stuff which cgen also links against. If there is no library to link with, we can just skip that step |
|
maybe this will work |
Building V works nevertheless, so all those files should be there as they are necessary for V to compile |
|
I really cannot think of any reason why this is happening, since the C compiler seems to work. |
I think we should implement our own linker too since the easy cross-compilation is one of the huge advantages of the native backend. |
|
^ This works on Ubuntu 20.04 (the paths are taken from I am not sure that invoking the linker directly is a good idea at this stage (it will burden V with discovering what are the local conventions/paths, which is not trivial, and we do depend on a C compiler anyways). It would be much simpler to rely on either gcc or clang for now (used just as frontends to the linkers). |
In the long term, that is true, but as @Spydr06 said, it would be a huge project on its own, and it is out of scope for this PR. |
|
Thank you very much, seems like it works now. I can fix the docker tests later myself I think |
|
Great job as always @spytheman ! |
ok, I will make it default to ld then. |
|
native-backend-ci passes now |
|
sorry, I will not change this PR anymore, to avoid merge conflicts |
I have no problem with that, your help is much appreciated |
|
I'd prefer mold, too, except they don't have a Windows version yet. :-\ |
|
As I already said, we can check if mold is installed on the user's system and then use it. If not, we can fall back to |
|
Seems like only alpine is the problem now, nice! |
|
we can skip alpine for now |
|
It should be fine now. |
This reverts commit d2adf9c.
…s a symlink for /lib64/ld-linux-x86-64.so.2 to /lib/ld-musl-x86_64.so.1)
|
Thank you all so much for your help, I really appreciate it. |
This PR contains initial linking support for Linux using
ld.lld. The generated object file now gets linked with some libraries (libc,pthread, etc.) and the C runtime objects. Currently, this isn't that useful since calling external functions is not implemented yet.I don't know how many tests will pass... I only tested it on Linux x86_64, other OSes should be unchanged.