Repository navigation
Closed
Description
Thanks a lot for adding zig cc and zig c++ functionality. It is really useful.
I tried to use zig c++ instead of the standard LLVM toolchain for one of my projects. I build it on MacOS. In general, it mostly works, but I've discovered the following issues:
- There is a number of flags passed to the linker using
-Wl,my_linker_option. They are important for proper linking of the project. But some of them are not supported yet.
warning: unsupported linker arg: -search_paths_first
warning: unsupported linker arg: -headerpad_max_install_names
warning: unsupported linker arg: -force_load
warning: unsupported linker arg: -force_load
- If I configure my CMake-based project to use make and then run make, it seems to work fine as long as make is using just a single thread. But if I use e.g.
make -j 2I start seeing some issues:
zig -c test.cpp -std=c++14 -ffast-math -fno-finite-math-only -g -I/path/to/include -emit-llvm -O0 -o test.o
Invalid argument: -c
It seems as if there is a race condition somewhere. As you can seen in zig's command line it misses c++ after zig somehow.
- If I configure my CMake-based project to use
ninjaand then runninja, I see issues with dependency tracking supported by clang. Specifically, there seems to be an issue with handling of-MFflags (see below). Same project can be build just fine if I use the vanilla LLVM toolchain.
zig: error: no such file or directory: 'test.cpp.o.d'
The following command failed when running ninja:
zig clang -c -MD -MV -MF zig-cache/tmp/eamNMvLXEZYC-test.o.d -MD -MT -MF test.cpp.o.d -o zig-cache/tmp/eamNMvLXEZYC-test.o test.cpp
It would be nice if these issues could be resolved.
Please let me know if I can provide any additional information that would allow to fix these issues.
Activity
opti-mix commentedon Mar 28, 2020
Oh, one more thing I forgot to mention:
CXX="zig c++" cmakeit runs into some problems for some targets that play with the compiler name. It seems like cmake does not correctly handle the space betweenzigandc++in some cases. So, I created a small shell-wrapper calledzigc++which looks like this:If I then use it like
CXX="zigc++" cmake, then the issue disappears. So, maybe it is a good idea to provide such wrappers forzig ccandzig c++as part of Zig pre-built binaries?andrewrk commentedon Mar 28, 2020
you're missing
c++here.zig c++ -c ...edit: oops, I see that you noticed this. can you confirm that it's a problem on zig's end though?
opti-mix commentedon Mar 28, 2020
The thing is: if I use a single-threaded make, it does not happen. It seems to happen only with
make -j N, where N > 1. Which indicates that command-line options are passed correctly to zig in a single-threaded make.andrewrk commentedon Mar 28, 2020
You could verify this with
strace -f -e trace=execve make ...and then see what argv is being passed to zigopti-mix commentedon Mar 28, 2020
Seems like it is a make issue, because make dumps a wrong command line in verbose mode. I tried to use the
zigc++wrapper instead ofzig c++and the issue disappears. Seems like the whitespace betweenzigandc++is an issue for CMake or make or both of them.andrewrk commentedon Apr 2, 2020
(2) is a make issue as noted above
(3) is solved in e4edc6d
(4) there is no plan to do this; I consider that to be out of scope of the project
As for (1) I am repurposing this issue to address it. If you run into any more independent problems, let's handle those in new issues.
[-]Some issues with zig c++[/-][+]zig cc: unsupported darwin linker args[/+]andrewrk commentedon Apr 2, 2020
Alright so the remaining issue has to do with the fact that Zig uses LLD as the linker, and until very recently the mach-o LLD code was unmaintained. It does not support these flags.
However now I expect this new team to quickly bring LLD up to speed for mach-o, and so I expect this issue to be resolved with the release of LLVM 11 (in 6 months).
opti-mix commentedon Apr 2, 2020
@andrewrk BTW, I was about to download the latest builds from https://ziglang.org/download/#release-master, but it seems to be not updated since yesterday for some reason. Don't know if it is expected or not.
opti-mix commentedon Apr 2, 2020
I don't quite understand this comment. Couldn't Zig just pass the provided
-Wl,my_linker_optionto a linker "as is", without doing anything about these flags?Or do you say that the error messages I see are from the LLD linker and not from Zig?
12 remaining items
opti-mix commentedon Apr 3, 2020
Great! I can confirm that
-MTissues are solved now. My project can be build almost correctly, except for the-Wl,-force-loadissue mentioned before, which results in the wrongly linked executables missing some parts.andrewrk commentedon Apr 3, 2020
Good to know. Let's revisit the linker issues once LLVM 11 is a bit further along in the release cycle.
Mouvedia commentedon Nov 15, 2020
LLVM 11 seems to have be have been released in October. Is this fixed?
kubkon commentedon Dec 22, 2020
I can shed some more light on (1):
All of the flags with the exception of
force_loadare not currently supported by LLD, however, there is an ongoing effort in LLVM to replace now dated Mach-O backend with a new one that supports these options. Having said that, LLVM11 still uses the old backend by default, and while it is technically possible to switch to the new one already, it currently fails to even build Zig onx86_64(aarch64support is not even started). FYI currently supported flags by the (old) backend are listed here.While not a permanent fix, it is now possible to fall back to the system linker on macOS by setting
export ZIG_SYSTEM_LINKER_HACK=1env var before linking.mikdusan commentedon Jan 1, 2023
These linker args are now supported by zld.