287 Commits

Author SHA1 Message Date
Frank Denis
e60072635e
Add libdl shims from wasi-libc 2025-01-29 12:48:56 +01:00
Frank Denis
8a8da49b52
Re-add lazy preopen changes 2025-01-29 11:54:08 +01:00
Frank Denis
3f4c43b0aa
Update wasi-libc to d03829489904d38c624f6de9983190f1e5e7c9c5 2025-01-29 11:54:02 +01:00
Alex Rønne Petersen
b3d9b0e3f6 musl: Manually inline __tls_get_addr into s390x __tls_get_offset.
See these mailing list threads:

* https://www.openwall.com/lists/musl/2024/11/23/3
* https://www.openwall.com/lists/musl/2025/01/24/1

This supplants cc73d7ad749df8d53da442faa2e7af5d69357b33.
2025-01-24 20:02:30 +01:00
Andrew Kelley
b31a2c9555
Merge pull request #22541 from ziglang/pipeline
Compilation pipeline: spawn Jobs earlier that produce linker inputs
2025-01-21 14:27:05 -05:00
Alex Rønne Petersen
f1f269c6ee libc: Remove a bunch of code for architectures we don't actually support.
Namely:

* alpha
* hppa
* ia64
* microblaze
* nios2
* or1k
* s390
* sh
2025-01-21 09:30:16 +01:00
Andrew Kelley
f5485a52bc reject crti.o/crtn.o, embrace the future
crti.o/crtn.o is a legacy strategy for calling constructor functions
upon object loading that has been superseded by the
init_array/fini_array mechanism.

Zig code depends on neither, since the language intentionally has no way
to initialize data at runtime, but alas the Zig linker still must
support this feature since popular languages depend on it.

Anyway, the way it works is that crti.o has the machine code prelude of
two functions called _init and _fini, each in their own section with the
respective name. crtn.o has the machine code instructions comprising the
exitlude for each function. In between, objects use the .init and .fini
link section to populate the function body.

This function is then expected to be called upon object initialization
and deinitialization.

This mechanism is depended on by libc, for example musl and glibc, but
only for older ISAs. By the time the libcs gained support for newer
ISAs, they had moved on to the init_array/fini_array mechanism instead.

For the Zig linker, we are trying to move the linker towards
order-independent objects which is incompatible with the legacy
crti/crtn mechanism.

Therefore, this commit drops support entirely for crti/crtn mechanism,
which is necessary since the other commits in this branch make it
nondeterministic in which order the libc objects and the other link
inputs are sent to the linker.

The linker is still expected to produce a deterministic output, however,
by ignoring object input order for the purposes of symbol resolution.
2025-01-20 20:59:52 -08:00
Andrew Kelley
b07958e6b7 delete asm files from wasi libc
why the hell are there asm files in wasi libc to begin with?
2025-01-17 12:34:15 -08:00
Andrew Kelley
e6dc85f1b4 remove memcpy and memmove from bundled libcs
These are provided instead by compiler_rt.

Part of #2879
2025-01-17 12:34:15 -08:00
Alex Rønne Petersen
8019694e17 mingw: Add upstream RtlSecureZeroMemory implementation.
Closes #22475.
2025-01-14 05:31:14 +01:00
Alex Rønne Petersen
6066e7bfd1
std.zig.target: Remove wasm32-freestanding-musl.
This is, at least today, a very broken target: It doesn't actually build either
musl or wasi-libc even if you use -lc. It does give you musl headers, but that's
it. Those headers are not terribly useful, however, without any implementation
code. You can sort of call some math functions because they just so happen to
have implementations in compiler-rt. But that's only true for a small subset,
and I don't think users should be relying on the ABI surface of a library that
is an implementation detail of the compiler.

Clearly, a freestanding-capable libc of sorts is a useful thing as evidenced by
newlib, picolibc, etc existing. However, calling it "musl" is misleading when it
isn't actually musl-compatible, nor can it ever be because the musl API surface
is inextricably tied to the Linux kernel. In the discussion on #20690, there was
agreement that once we split up the API and ABI components in the target string,
the API component should be about compatibility, not whether you literally get a
particular implementation of it. Also, we decided that Linux musl and wasi-libc
musl shouldn't use the same API tag precisely because they're not actually
compatible.

(And besides, how would any syscall even be implemented in freestanding? Who or
what would we be calling?)

So I think we should remove this triple for now. If we decide to reintroduce
something like this, especially once #2879 gets going, we should come up with a
bespoke name for it rather than using "musl".
2024-12-15 12:25:12 +01:00
Alex Rønne Petersen
45fff0a511
mingw: Update sources to dcd7fefc703fb4b12187235386900d34cc13fdc5. 2024-12-14 07:02:14 +01:00
Alex Rønne Petersen
87083e8e7e
mingw: Update headers to dcd7fefc703fb4b12187235386900d34cc13fdc5. 2024-12-14 07:02:12 +01:00
Michael Dusan
a68119f8f1 macos: vendored libc: bump to SDK 15.1 2024-12-13 03:55:54 +01:00
Alex Rønne Petersen
c666ebb1f8
musl: Add unwinding protection in clone() implementations.
Whatever was in the frame pointer register prior to clone() will no longer be
valid in the child process, so zero it to protect FP-based unwinders. This is
just an extension of what was already done for i386 and x86_64. Only applied
to architectures where the _start() code also zeroes the frame pointer.
2024-12-11 00:10:17 +01:00
Alex Rønne Petersen
67e524da54
musl: Update libc.S against musl 1.2.5.
All supported architectures included except for x32 (currently broken).
2024-11-23 03:10:58 +01:00
Alex Rønne Petersen
cc73d7ad74
musl: Mark __tls_get_addr as hidden before invoking it on s390x.
https://www.openwall.com/lists/musl/2024/11/23/3
2024-11-23 03:10:54 +01:00
Alex Rønne Petersen
4972a871c5
musl: Mark __restore(_rt) functions hidden on riscv.
https://www.openwall.com/lists/musl/2024/11/23/2
2024-11-23 01:24:35 +01:00
Alex Rønne Petersen
ea26af0b9d
musl: Set symbol type for the START function on i386 and x86_64.
https://www.openwall.com/lists/musl/2024/11/23/1
2024-11-23 01:23:02 +01:00
Alex Rønne Petersen
50cae505f7
glibc: Fix an LP_SIZE redefinition warning for gnux32. 2024-11-02 10:42:53 +01:00
Alex Rønne Petersen
ec0e6440b1
musl: Update sources from musl 1.2.5.
Adds mipsn32 and x32 sources.

Also remove some useless .in files.
2024-11-02 10:42:53 +01:00
Alex Rønne Petersen
3ec27ae648
musl: Update headers from musl 1.2.5.
Adds mips64-linux-muslabin32 and x86_64-linux-muslx32 headers.
2024-11-02 10:42:53 +01:00
Alex Rønne Petersen
92ae5818d2 musl: Align _init/_fini symbols correctly on arm.
See upstream patch: https://www.openwall.com/lists/musl/2024/10/10/4
2024-10-11 03:20:39 +02:00
Alex Rønne Petersen
4cc1b060eb
glibc: Update abilists file for loongarch64-linux-gnusf support.
Also a 269 KB -> 240 KB size reduction due to the new format version.
2024-10-03 04:39:39 +02:00
Alex Rønne Petersen
6635d02143
glibc: Add loongarch64-linux-gnusf headers. 2024-10-03 04:39:39 +02:00
Alex Rønne Petersen
c1cc63e5ff libc: Work around LLVM's misassembly of j <reg> on mips r6.
See: https://github.com/ziglang/zig/issues/21315
2024-09-23 17:26:30 -07:00
Andrew Kelley
96fcc8d63b
Merge pull request #21195 from alexrp/glibc-fixes
`glibc`: Some bug fixes, plus arc and csky start files
2024-09-06 10:50:56 -07:00
Alex Rønne Petersen
b230e4f598 glibc: Patch to work around missing features in LLVM's s390x assembler.
Revert this with LLVM 20.
2024-09-06 10:39:30 -07:00
Alex Rønne Petersen
747460025e
glibc: Add csky start files. 2024-09-05 06:16:26 +02:00
Alex Rønne Petersen
06945d5eb7
glibc: Add arc start files. 2024-09-05 06:16:26 +02:00
Federico Di Pierro
b7a98d0d59 lib: guard definition of strl{cat,cpy} against glibc version when _FORTIFY_SOURCE is enabled.
Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
2024-09-01 00:34:15 -07:00
Alex Rønne Petersen
5dd2bb525d glibc: Define _IO_stdin_used in start code and reference it in stub asm.
This is necessary to inform the real, non-stub glibc that a program built with
Zig is using a modern `FILE` structure, i.e. glibc 2.1+. This is particularly
important on lesser-used architectures where the legacy code is poorly tested;
for example, glibc 2.40 introduced a regression for the legacy case in the
libio cleanup code, causing all Zig-compiled MIPS binaries to crash on exit.
2024-08-23 11:09:20 -07:00
Alex Rønne Petersen
945fc7064b glibc: Add missing xstatver.h for some linux architectures.
Specifically for alpha, arm, hppa, microblaze, and sh.

Closes #20054.
2024-08-23 00:58:16 -07:00
YANG Xudong
0f0f543a9a
loongarch: add glibc start.S to make zig-bootstrap work for loongarch64-linux-gnu (#21015) 2024-08-14 21:32:03 +00:00
Andrew Kelley
71a27ebd84
Merge pull request #21004 from alexrp/linux-6.10
Linux 6.10 headers/syscalls
2024-08-09 13:08:39 -07:00
Alex Rønne Petersen
c62a2ad2ec
Update Linux kernel headers to 6.10. 2024-08-08 23:39:00 +02:00
Alex Rønne Petersen
21ff35590c
Update glibc start files to 2.40. 2024-08-08 04:41:04 +02:00
Alex Rønne Petersen
0b76be3a01
Update glibc headers to 2.40. 2024-08-08 04:41:04 +02:00
Andrew Kelley
cd5f673cae
Merge pull request #20909 from alexrp/glibc-riscv
Support building glibc for riscv32/riscv64
2024-08-07 01:14:54 -07:00
Andrew Kelley
1b88c6a8a2 glibc: update abilists file
updated for glibc 2.40, and adds arc, csky, and m68k
2024-08-05 09:53:37 -07:00
Tristan Ross
3ebb880663
glibc: Replace ilp32/lp64 headers with ilp32d/lp64d.
The former are soft float; the latter are hard float. We primarily care about
hard float here.

Signed-off-by: Alex Rønne Petersen <alex@alexrp.com>
2024-08-02 09:54:08 +02:00
Alex Rønne Petersen
635a3d87de
glibc: Change riscv32-linux-gnuilp32 target triple to riscv32-linux-gnu.
This target triple was weird on multiple levels:

* The `ilp32` ABI is the soft float ABI. This is not the main ABI we want to
  support on RISC-V; rather, we want `ilp32d`.
* `gnuilp32` is a bespoke tag that was introduced in Zig. The rest of the world
  just uses `gnu` for RISC-V target triples.
* `gnu_ilp32` is already the name of an ILP32 ABI used on AArch64. `gnuilp32` is
  too easy to confuse with this.
* We don't use this convention for `riscv64-linux-gnu`.
* Supporting all RISC-V ABIs with this convention will result in combinatorial
  explosion; see #20690.
2024-08-02 09:54:08 +02:00
Pat Tullmann
a31fe8aa3e glibc headers: arc4random* functions added in glibc 2.36
Here's the glibc v2.36 announcment noting the addition of arc4random,
arc4random_buf and arc4random_uniform:

  https://sourceware.org/git/?p=glibc.git;a=blob;f=NEWS;h=8420a65cd06874ee09518366b8fba746a557212a;hb=6f4e0fcfa2d2b0915816a3a3a1d48b4763a7dee2

Tested with the testcase from the bug.  I get a compile-time error when
building against older glibc (instead of a linker error), and no errors
(as before) when compiling against v2.36 or later.  And the glibc_compat
regression tests pass.

Fix #20426
2024-07-03 02:57:24 -04:00
Pat Tullmann
8bee879fc2 test/link/glibc_compat: Add C test case for glibc versions
glibc_runtime_check.c is a simple test case that exercises glibc functions
that might smoke out linking problems with Zig's C compiler.  The
build.zig compiles it against a variety of glibc versions.

Also document and test glibc v2.2.5 (from 2002) as the oldest working
glibc target for C binaries.
2024-06-06 09:36:16 -07:00
Pat Tullmann
d8fffee3fb glibc: restore "weak_hidden_alias" macro for older glibc versions
The fstat,lstat,stat,mknod stubs used to build older (before v2.33)
glibc versions depend on the weak_hidden_alias macro.  It was removed
from the glibc libc-symbols header, so patch it back in for the older
builds.
2024-06-05 22:43:54 -07:00
Kang Seonghoon
5293bdfe63 glibc patch: get correct files compiled into libc_nonshared.a
The scope of libc_nonshared.a was greatly changed in glibc 2.33 and
2.34, but only the change from 2.34 was reflected so far. Glibc 2.33
finally switched to versioned symbols for stat functions, meaning that
libc_nonshared.a no longer contains them since 2.33. Relevant files were
therefore reverted to 2.32 versions and renamed accordingly.

This commit also removes errno.c, which was probably added to
libc_nonshared.a based on a wrong assumption that glibc/include/errno.h
requires glibc/csu/errno.c. In reality errno.h should refer to
__libc_errno (not to be confused with the public __errno_location),
which should be imported from libc.so. The inclusion of errno.c resulted
in wrong compile options as well; this commit fixes them as well.
2024-06-05 22:43:54 -07:00
Andrew Kelley
fd8b50ca5c glibc patch: remove some static asserts from fstatat
These are tripping on 32-bit x86 but are intended to prevent glibc
itself from being built with a bad configuration. Zig is only using this
file to create libc_nonshared.a, so it's not relevant.
2024-06-05 22:43:53 -07:00
Andrew Kelley
82ec333f27 glibc patch: don't check __LIBC macro
This is the only place in all of glibc that this macro is referenced.
What is it doing? Only preventing fstatat.c from knowing the type
definition of `__time64_t`, apparently.

Fixes compilation of fstatat.c on 32-bit x86.
2024-06-05 22:43:53 -07:00
Andrew Kelley
090025c457 glibc patch: add missing includes for inttypes.h
I don't know where glibc thinks uintptr_t is coming from, but here it
is.
2024-06-05 22:43:53 -07:00
Andrew Kelley
eead70f2d6 glibc patch: make fstatat.c and fstatat64.c compile
instead of importing every header file under the sun, I copied a couple
inline functions into these files to make them work.
2024-06-05 22:43:53 -07:00