7 Commits

Author SHA1 Message Date
Alex Rønne Petersen
e9ac2ce116
compiler-rt: move strlen from libzigc to here
LLVM 21 has started recognizing strlen-like idioms and optimizing them to strlen
calls, so we need this function provided in compiler-rt for libc-less
compilations.
2025-08-30 06:36:41 +02:00
David Senoner
9399fcddce libc: use zig isnan and derivates for mingw 2025-08-27 03:58:32 +02:00
David
55848363fd
libc: implement common abs for various integer sizes (#23893)
* libc: implement common `abs` for various integer sizes

* libc: move imaxabs to inttypes.zig and don't use cInclude

* libc: delete `fabs` c implementations because already implemented in compiler_rt

* libc: export functions depending on the target libc

Previously all the functions that were exported were handled equally,
though some may exist and some not inside the same file. Moving the
checks inside the file allows handling different functions differently

* remove empty ifs in inttypes

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>

* remove empty ifs in stdlib

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>

* libc: use `@abs` for the absolute value calculation

---------

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
2025-05-21 00:57:38 +02:00
Alex Rønne Petersen
092352ec63
compiler-rt, zigc: Use hidden visibility except when testing.
This prevents symbols from these libraries from polluting the dynamic symbol
tables of binaries built with Zig. The downside is that we no longer deduplicate
the symbols at run time due to weak linkage.

Closes #7935.
Closes #13303.
Closes #19342.
2025-05-19 00:22:03 +02:00
Bryson Miller
08d534e8d8
Introduce common strcasecmp and strncasecmp implementations (#23840) 2025-05-15 10:58:33 +02:00
David
2c241b263c
Introduce common bzero libc implementation. (#23812)
* Introduce common `bzero` libc implementation.

* Update test name according to review

Co-authored-by: Linus Groh <mail@linusgroh.de>

* address code review

- import common implementation when musl or wasi is included
- don't use `c_builtins`, use `@memset`

* bzero calling conv to .c

* Apply review

Co-authored-by: Veikka Tuominen <git@vexu.eu>

---------

Co-authored-by: Linus Groh <mail@linusgroh.de>
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2025-05-10 10:37:21 +02:00
Alex Rønne Petersen
1f896c1bf8
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.
2025-04-11 17:12:31 +02:00