-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
std.zig.system.NativeTargetInfo: use getconf for detecting glibc version on glibc systems #12567
std.zig.system.NativeTargetInfo: use getconf for detecting glibc version on glibc systems #12567
Conversation
error.InvalidGnuLibCVersion, | ||
=> break :glibc_ver, | ||
}; | ||
const getconf = std.ChildProcess.exec(.{ .allocator = allocator, .argv = &.{ "getconf", "GNU_LIBC_VERSION" } }) catch unreachable; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC all glibc systems (even more, all POSIX systems https://pubs.opengroup.org/onlinepubs/000095399/utilities/getconf.html) has this program, and if not, it is a bug in systems itself.
} | ||
const glibc_ver_from_stdout = getconf.stdout["glibc ".len..]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to man:
_CS_GNU_LIBC_VERSION (GNU C library only; since glibc 2.3.2)
A string which identifies the GNU C library version on
this system (e.g., "glibc 2.3.4").
@@ -641,167 +598,15 @@ pub fn abiAndDynamicLinkerFromFile( | |||
if (builtin.target.os.tag == .linux and result.target.isGnuLibC() and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But anyway this will be not executed on a non-glibc systems
@topolarity does this fixes #11137 (comment) |
Oops, I forgot that zig doesn't provide glibc 2.35 yet :( |
error: zig does not yet provide glibc version 2.35, the max provided version is 2.34
error: unable to build glibc shared objects: InvalidTargetGLibCVersion
error: zig...
error: The following command exited with error code 1:
/home/bratishkaerik/zig/build/zig build-exe --stack 33554432 /home/bratishkaerik/zig/src/main.zig -lc /home/bratishkaerik/zig/build/zigcpp/libzigcpp.a /usr/lib/llvm/14/lib64/libclang-cpp.so.14 /usr/lib64/liblldMinGW.so /usr/lib64/liblldELF.so /usr/lib64/liblldCOFF.so /usr/lib64/liblldWasm.so /usr/lib64/liblldMachO.so /usr/lib64/liblldCommon.so /usr/lib/llvm/14/lib64/libLLVM-14.so /usr/lib/gcc/x86_64-pc-linux-gnu/11.3.0/libstdc++.so -lunwind --cache-dir /home/bratishkaerik/zig/zig-cache --global-cache-dir /home/bratishkaerik/.cache/zig --name zig --pkg-begin build_options /home/bratishkaerik/zig/zig-cache/options/7X62S_IHrJHJyONEQXfH1Bt-Y-ZrGbNtZVv-QoWvD9uq09Hl8g4BY__8D6284ocN --pkg-end -I /usr/include -fno-build-id --enable-cache
error: the following build command failed with exit code 1:
/home/bratishkaerik/zig/zig-cache/o/87897b425d0e88a403c948b1ad22e5dc/build /home/bratishkaerik/zig/build/zig /home/bratishkaerik/zig /home/bratishkaerik/zig/zig-cache /home/bratishkaerik/.cache/zig -p stage2 -Dstatic-llvm=false -Denable-llvm=true |
My suggestion: diff --git a/src/glibc.zig b/src/glibc.zig
index ceb60ff09..d714d4aa1 100644
--- a/src/glibc.zig
+++ b/src/glibc.zig
@@ -745,14 +745,7 @@ pub fn buildSharedObjects(comp: *Compilation) !void {
return error.InvalidTargetGLibCVersion;
},
}
- } else {
- const latest_index = metadata.all_versions.len - 1;
- // TODO Expose via compile error mechanism instead of log.
- log.err("zig does not yet provide glibc version {}, the max provided version is {}", .{
- target_version, metadata.all_versions[latest_index],
- });
- return error.InvalidTargetGLibCVersion;
- };
+ } else metadata.all_versions.len - 1;
{
var map_contents = std.ArrayList(u8).init(arena); |
|
IIUC we should still be able to use the system glibc in this case, right? |
I force–pushed after this, can you try this version too? (and I'm using dynamic linking, too) ea7c4bc |
I'm hitting this #12567 (comment) |
Yep, I was out of date! This appears to be resolved for me 👍 Re: the glibc version. Zig will currently fallback to using system-provided libc if you ask for system libraries (e.g. if you add |
Something like?: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested on Debian (bookworm), NixOS (unstable), and Arch - all of which are affected by #6469 and #11137 and are fixed by this PR.
This change does mean linking libc will be broken on OS's with too-new libc (e.g. NixOS and Arch) until we have a fallback to link against system libc or update Zig-provided glibc, but this still seems like a step in the right direction even without that
P.S. Not sure what the CI failures are, but they seem unrelated?
Sounds OK to me - most of the logic should already be present in Compilation.zig. Might be as simple as updating If you're up to tackling that, feel free to update this PR or start a new one - whichever you prefer 🙂 |
[if system doesn't provide headers] —> (use latest supplied libc available) ❌
[if glibc newer than supplied] —> (use system libc) ❌ |
Ah, I misunderstood and thought you had meant use the Zig headers to link against the system-provided glibc. Good catch, let's stay faithful to the requested glibc version |
Previously, this code would fail to detect glibc version because it relied on libc.so.6 being a symlink which revealed the answer. On modern distros, this is no longer the case. This new strategy finds the path to libc.so.6 from /usr/bin/env, then inspects the .dynstr section of libc.so.6, looking for symbols that start with "GLIBC_2.". It then parses those as semantic versions and takes the maximum value as the system-native glibc version. closes #6469 see #11137 closes #12567
I created #12788 which supersedes this PR and does not depend on |
…ion on glibc systems Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
Previously, this code would fail to detect glibc version because it relied on libc.so.6 being a symlink which revealed the answer. On modern distros, this is no longer the case. This new strategy finds the path to libc.so.6 from /usr/bin/env, then inspects the .dynstr section of libc.so.6, looking for symbols that start with "GLIBC_2.". It then parses those as semantic versions and takes the maximum value as the system-native glibc version. closes #6469 see #11137 closes #12567
Previously, this code would fail to detect glibc version because it relied on libc.so.6 being a symlink which revealed the answer. On modern distros, this is no longer the case. This new strategy finds the path to libc.so.6 from /usr/bin/env, then inspects the .dynstr section of libc.so.6, looking for symbols that start with "GLIBC_2.". It then parses those as semantic versions and takes the maximum value as the system-native glibc version. closes #6469 see #11137 closes #12567
Closes #6469 and closes #11137
Signed-off-by: Eric Joldasov bratishkaerik@getgoogleoff.me