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

add support for targeting glibc 2.39 #20207

Merged
merged 23 commits into from
Jun 6, 2024
Merged

add support for targeting glibc 2.39 #20207

merged 23 commits into from
Jun 6, 2024

Conversation

andrewrk
Copy link
Member

@andrewrk andrewrk commented Jun 6, 2024

closes #20106

cc @rootbeer and @motiejus for review (if you're interested)

@rootbeer
Copy link
Contributor

rootbeer commented Jun 6, 2024

Wow, so glad they updated the copyright year on all 1500 files to 2024... Github is having problems with inline code reviews on this enormous change, so I'll make my comments here.

In lib/std/zig/target.zig the two new architectures could use some lower-bound checks on supported glibc version. I think loongarch64 was added in glibc v2.36 (according to https://lists.gnu.org/archive/html/info-gnu/2022-08/msg00000.html), so it should have a .glibc_min = .{ .major = 2, .minor = 36, .patch = 0 }. And riscv32 was added in v2.27 (see https://risc-v-getting-started-guide.readthedocs.io/en/latest/linux-introduction.html), so those two lines should have .glibc_min = .{ .major = 2, .minor = 27, .patch = 0 }. Of course, these are just guardrails for eventual end users, so they're not required for this patch.

I randomly sampled the rest of the diff, and the only thing I noticed was that libcrypt has been fully deprecated, so there are several changes in here that remove the LIBCRYPT_SO #define (e.g., in lib/libc/include/x86-linux-gnu/gnu/lib-names-32.h). Technically this could be protected with a Zig glibc version check, but I'd be surprised if there many uses of it in the wild. (If there are, hopefully folks that run into the missing symbol will at least this comment here ...)

So, LGTM!

@andrewrk
Copy link
Member Author

andrewrk commented Jun 6, 2024

Wow, so glad they updated the copyright year on all 1500 files to 2024...

no kidding 🙄

Thanks for the review!

andrewrk and others added 23 commits June 5, 2024 22:43
Instead Zig passes it based on the target.
This is a patch to glibc features.h which makes
_DYNAMIC_STACK_SIZE_SOURCE undefined unless the version is >= 2.34.

This feature was introduced with glibc 2.34 and without this patch, code
built against these headers but then run on an older glibc will end up
making a call to sysconf() that returns -1 for the value of SIGSTKSZ
and MINSIGSTKSZ.
- `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.
This is necessary to build glib.
following suit from b40943e,
add a version guard in addition to the ISOC2X check.
Here's the glibc commit that adds reallocarray to glibc:
https://sourceware.org/git/?p=glibc.git;a=commit;h=2e0bbbfbf95fc9e22692e93658a6fbdd2d4554da

The reallocarray symbol is declared in both stdlib.h and malloc.h.

Fix #17607
So only expose these in generic-glibc/string.h if Zig is building
a v2.38 (or later) glibc stub.

Announcement of 2.38 that notes strlcpy and strlcat:
https://lists.gnu.org/archive/html/info-gnu/2023-07/msg00010.html
generated from ziglang/glibc-abi-tool commit
fc5d0a7046b76795e4219f8f168e118ec29fbc53 which now contains glibc 2.39
README file stays intact.
- `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.
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.
instead of importing every header file under the sun, I copied a couple
inline functions into these files to make them work.
I don't know where glibc thinks uintptr_t is coming from, but here it
is.
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.
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.
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.
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.
@motiejus
Copy link
Contributor

motiejus commented Jun 6, 2024

closes #20106

cc @rootbeer and @motiejus for review (if you're interested)

Cc @linzhp @sywhang

@andrewrk andrewrk disabled auto-merge June 6, 2024 05:51
@andrewrk andrewrk merged commit 4d49935 into master Jun 6, 2024
10 checks passed
@andrewrk andrewrk deleted the glibc-2.39 branch June 6, 2024 16:24
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

Successfully merging this pull request may close these issues.

add support for targeting glibc 2.39
6 participants