aboutsummaryrefslogtreecommitdiff
path: root/src/link/Coff.zig
diff options
context:
space:
mode:
authorAlex Rønne Petersen <alex@alexrp.com>2025-04-10 19:17:29 +0200
committerAlex Rønne Petersen <alex@alexrp.com>2025-04-11 17:12:31 +0200
commit1f896c1bf89aa0e3d2a0dce1f4cf6ba6ce5ae9ed (patch)
tree66d5586f636c37b65a1b99de3c0665bab97ec3f0 /src/link/Coff.zig
parentee0ff134e9f82bf87751a5174c27b191c04e16c0 (diff)
downloadzig-1f896c1bf89aa0e3d2a0dce1f4cf6ba6ce5ae9ed.tar.gz
zig-1f896c1bf89aa0e3d2a0dce1f4cf6ba6ce5ae9ed.zip
Introduce libzigc for libc function implementations in Zig.
This lays the groundwork for #2879. This library will be built and linked when a static libc is going to be linked into the compilation. Currently, that means musl, wasi-libc, and MinGW-w64. As a demonstration, this commit removes the musl C code for a few string functions and implements them in libzigc. This means that those libzigc functions are now load-bearing for musl and wasi-libc. Note that if a function has an implementation in compiler-rt already, libzigc should not implement it. Instead, as we recently did for memcpy/memmove, we should delete the libc copy and rely on the compiler-rt implementation. I repurposed the existing "universal libc" code to do this. That code hadn't seen development beyond basic string functions in years, and was only usable-ish on freestanding. I think that if we want to seriously pursue the idea of Zig providing a freestanding libc, we should do so only after defining clear goals (and non-goals) for it. See also #22240 for a similar case.
Diffstat (limited to 'src/link/Coff.zig')
-rw-r--r--src/link/Coff.zig11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/link/Coff.zig b/src/link/Coff.zig
index da27c5c076..4b20ba99dd 100644
--- a/src/link/Coff.zig
+++ b/src/link/Coff.zig
@@ -2147,6 +2147,12 @@ fn linkWithLLD(coff: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
},
}
+ if (comp.config.link_libc and link_in_crt) {
+ if (comp.zigc_static_lib) |zigc| {
+ try argv.append(try zigc.full_object_path.toString(arena));
+ }
+ }
+
// libc++ dep
if (comp.config.link_libcpp) {
try argv.append(try comp.libcxxabi_static_lib.?.full_object_path.toString(arena));
@@ -2172,11 +2178,6 @@ fn linkWithLLD(coff: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
}
if (is_exe_or_dyn_lib and !comp.skip_linker_dependencies) {
- if (!comp.config.link_libc) {
- if (comp.libc_static_lib) |lib| {
- try argv.append(try lib.full_object_path.toString(arena));
- }
- }
// MSVC compiler_rt is missing some stuff, so we build it unconditionally but
// and rely on weak linkage to allow MSVC compiler_rt functions to override ours.
if (comp.compiler_rt_obj) |obj| try argv.append(try obj.full_object_path.toString(arena));