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

Improve alternative libc support #19340

Closed
RossComputerGuy opened this issue Mar 18, 2024 · 8 comments
Closed

Improve alternative libc support #19340

RossComputerGuy opened this issue Mar 18, 2024 · 8 comments

Comments

@RossComputerGuy
Copy link
Contributor

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
@ikskuh
Copy link
Contributor

ikskuh commented Mar 22, 2024

What about --libc <file> and zig libc?

@RossComputerGuy
Copy link
Contributor Author

The problem I have is:

  1. Scanning which functions are available
  2. std.Target detection

@nektro
Copy link
Contributor

nektro commented Mar 22, 2024

  1. weak export all of them
  2. 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

@kassane
Copy link
Contributor

kassane commented Mar 23, 2024

What about --libc <file> and zig libc?

This reminds me a reference from Andrew.

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.

@RossComputerGuy
Copy link
Contributor Author

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

@kassane
Copy link
Contributor

kassane commented Mar 24, 2024

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.

@RossComputerGuy
Copy link
Contributor Author

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.

@andrewrk
Copy link
Member

This is not actionable enough to remain on the issue tracker, please take it to a discussion forum.

@andrewrk andrewrk closed this as not planned Won't fix, can't repro, duplicate, stale Aug 16, 2024
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

No branches or pull requests

5 participants