83 Commits

Author SHA1 Message Date
Alex Rønne Petersen
031b0d6063 glibc: change library link order to prefer libc.so symbols
Also avoid resolving symbols in libraries that were later removed if possible.

closes #24347
2025-10-19 11:50:32 +02:00
Alex Rønne Petersen
675b1a15a1
glibc: update crt0 code to 2.42 2025-08-01 09:00:27 +02:00
Alex Rønne Petersen
cdd6e9ee3a
glibc: update abilists file to 2.42 2025-07-31 21:47:02 +02:00
Alex Rønne Petersen
6667e0fbb4
Revert "glibc: Patch to work around missing features in LLVM's s390x assembler."
This reverts commit b230e4f598bd18b47f3f1c981869c597a06c7452.

Closes #21329.
2025-04-04 06:08:10 +02:00
TCROC
d590b87b6f
glibc: fix uninitialized memory in __pthread_cond_s for <=2.40
* https://sourceware.org/bugzilla/show_bug.cgi?id=32786
* https://inbox.sourceware.org/libc-alpha/87zfhpfqsm.fsf@oldenburg.str.redhat.com
2025-03-13 20:23:27 +00:00
Alex Rønne Petersen
a5b8a2938d
glibc: Update abilists file to 2.41. 2025-01-31 14:38:23 +01:00
Alex Rønne Petersen
5702d67af6
glibc: Update source files to 2.41. 2025-01-31 14:38:21 +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
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
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
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
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
Alex Rønne Petersen
21ff35590c
Update glibc start files to 2.40. 2024-08-08 04:41:04 +02: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
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
Andrew Kelley
4c068c3be1 glibc patch: inline x86-lp_size.h
I could have just included the file from upstream glibc, but it was too
silly so I just inlined it. This patch could be dropped in a future
glibc update if desired. If omitted it will cause easily solvable
C compilation failures building glibc nonshared.
2024-06-05 22:43:53 -07:00
Motiejus Jakštys
9e76385afc glibc patch: add backwards compatibility for some symbols
- `fcntl` was renamed to `fcntl64` in glibc 2.28 (see #9485)
- `res_{,n}{search,query,querydomain}` became "their own" symbols since
  glibc 2.34: they were prefixed with `__` before.

This PR makes it possible to use `fcntl` with glibc 2.27 or older and
the `res_*` functions with glibc 2.33 or older.

These patches will become redundant with universal-headers and can be
dropped. But we have to do with what we have now.
2024-06-05 22:43:53 -07:00
Andrew Kelley
ad34de32a8 update glibc start files to 2.39
README file stays intact.
2024-06-05 22:43:53 -07:00
Andrew Kelley
53137050f8 glibc: update abilists file
generated from ziglang/glibc-abi-tool commit
fc5d0a7046b76795e4219f8f168e118ec29fbc53 which now contains glibc 2.39
2024-06-05 22:43:53 -07:00
Andrew Kelley
362460ec24 minor cosmetic fixups
* fix typos and redundancies in docs
* use Target.isGnuLibc
2024-01-04 17:26:06 -07:00
Pat Tullmann
71e809852c lib/libc/glibc/: Add README.md
Add a README with an overview of how Zig's glibc support is implemented.
2024-01-04 17:12:07 -07:00
Pat Tullmann
2c6372a117 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-01-04 17:12:07 -07:00
Kang Seonghoon
f1bd218a88 glibc: remove unused stat-related files for 2.33+
Effectively reverts 3dcd3612dca6f649a1e05f558c5d6ed462d2e4a4.
2024-01-04 17:12:07 -07:00
Kang Seonghoon
7dcf7412c4 glibc: 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.

Fixes #16152
2024-01-04 17:12:07 -07:00
Andrew Kelley
701ef1f8c2 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.
2023-10-13 19:32:54 -07:00
Andrew Kelley
0b16500604 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.
2023-10-13 19:31:57 -07:00
Andrew Kelley
6d8b7e95b5 glibc patch: add missing includes for inttypes.h
I don't know where glibc thinks uintptr_t is coming from, but here it
is.
2023-10-13 18:12:00 -07:00
Andrew Kelley
50e18343a9 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.
2023-10-13 18:06:12 -07:00
Andrew Kelley
89aa63bec7 glibc patch: inline x86-lp_size.h
I could have just included the file from upstream glibc, but it was too
silly so I just inlined it. This patch could be dropped in a future
glibc update if desired. If omitted it will cause easily solvable
C compilation failures building glibc nonshared.
2023-10-13 18:03:00 -07:00
Motiejus Jakštys
b40943e253 glibc patch: add backwards compatibility for some symbols
- `fcntl` was renamed to `fcntl64` in glibc 2.28 (see #9485)
- `res_{,n}{search,query,querydomain}` became "their own" symbols since
  glibc 2.34: they were prefixed with `__` before.

This PR makes it possible to use `fcntl` with glibc 2.27 or older and
the `res_*` functions with glibc 2.33 or older.

These patches will become redundant with universal-headers and can be
dropped. But we have to do with what we have now.
2023-10-13 17:44:27 -07:00
Andrew Kelley
4a3002848c glibc: update libc-modules.h to 2.38 2023-10-13 17:44:27 -07:00
Andrew Kelley
2314051aca update glibc start files to 2.38
I went ahead and left the README.md file deleted because it had broken
git hashes. Better to use `git log -- lib/libc/glibc/` to find out the
patches.
2023-10-13 17:44:27 -07:00
Andrew Kelley
f458c13494 glibc: update abilists file
generated from the latest commits of ziglang/glibc-abi-tool which
contains glibc 2.35, 2.36, 2.37, and 2.38.
2023-10-13 17:44:27 -07:00
Motiejus Jakštys
892d4e1302 glibc hacks: add another commit to our patches 2023-05-04 10:36:37 +03:00
Motiejus Jakštys
652e8cf864 glibc compat: add a test and README 2023-03-28 22:29:20 +03:00
Motiejus Jakštys
7e6aeead85 glibc: add backwards compatibility for some symbols
- `fcntl` was renamed to `fcntl64` in glibc 2.28 (see #9485)
- `res_{,n}{search,query,querydomain}` became "their own" symbols since
  glibc 2.34: they were prefixed with `__` before.

This PR makes it possible to use `fcntl` with glibc 2.27 or older and
the `res_*` functions with glibc 2.33 or older.

These patches will become redundant with universal-headers and can be
dropped. But we have to do with what we have now.

Closes #9485
2023-03-28 20:35:08 +03:00