zig
zig copied to clipboard
Improve alternative libc support
Right now, I'm looking to develop my own Linux distro using Zig and I have to supply a libc. A libc implementation which I am interested in using is LLVM's libc, I am also interested in using a pure Zig libc but it is harder to detect and supply what the libc. Currently, these are the things I am looking for Zig being able to do:
- Builder API to supply libc library + headers
- Programmatic function / definition detection
What about --libc <file>
and zig libc
?
The problem I have is:
- Scanning which functions are available
-
std.Target
detection
- weak export all of them
-
builtin.target
re 1 if its just a matter of wanting to know which ones to implement first, remove -lc
and see which symbols the linker starts complaining about being missing
What about
--libc <file>
andzig libc
?
This reminds me a reference from Andrew.
- https://github.com/ziglang/zig/issues/514#issuecomment-467172534
When it comes to C code, it's common to use -nostdlib
and -nostdinc
, but in the zig build interface it gets complicated, leaving only the absence of .linkLibC
as an alternative solution.
I recently tried to port picolibc to zig build. However, so far I have only encountered a link problem.
As is currently the case with emscripten, it would be interesting to add initial support for the rtos and microlibc interfaces, since cross-compilation is also mentioned in microcontrollers.
@kassane Was your linker issue related to libc, libm, libutil, etc not being found? I ran into a similar issue when I tried adding my own libc to Zig. The only thing I did was add it into the abi enum and any switches which didn't have an else.
Hi @RossComputerGuy ,
Sorry for the delay in responding.
Yes, I've been having problems with linking, specifically link scripting with lld
instead of gnu-ld
. Picolibc has a modification to generate a link script for lld (meson), but I need to do more testing on it.
The most critical part of these tests is the toolchain, as compatibility is never 100% (maybe 99.9%) and this where more attention to detail is required, especially for a solo developer.
Yes, I've been having problems with linking, specifically link scripting with lld instead of gnu-ld. Picolibc has a modification to generate a link script for lld (meson), but I need to do more testing on it.
Oh, gotcha. Yeah when I tried adding my own libc into my Zig fork, I ran into this linker issue:
error: ld.lld: unable to find library -lm
error: ld.lld: unable to find library -lpthread
error: ld.lld: unable to find library -lc
error: ld.lld: unable to find library -ldl
error: ld.lld: unable to find library -lrt
error: ld.lld: unable to find library -lutil
I got these errors despite targeting glibc, seems like it isn't straight forward to add new libc support into Zig. I'm hoping with this issue that we can get a simpler way to specify custom or unsupported libc without patching Zig.