zig icon indicating copy to clipboard operation
zig copied to clipboard

incorrect native glibc version detection

Open andrewrk opened this issue 1 year ago • 3 comments

Zig Version

0.12.0-dev.1138+530dc0405

Steps to Reproduce and Observed Behavior

$ zig env | jq .target
"x86_64-linux.6.1.53...6.1.53-gnu.2.19"

Notice that the result is glibc 2.19. This is currently the cross-compiling default (related: #17628):

https://github.com/ziglang/zig/blob/4d106076c3db840f786460e281aded056053ac35/lib/std/target.zig#L348

Expected Behavior

This is incorrect on my system, which is

$ uname -a
Linux ark 6.1.53 #1-NixOS SMP PREEMPT_DYNAMIC Wed Sep 13 07:43:05 UTC 2023 x86_64 GNU/Linux
$ nixos-version 
23.05.3580.5d017a8822e0 (Stoat)

We can easily see the correct value here:

$ ldd /usr/bin/env | grep glibc
	libc.so.6 => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libc.so.6 (0x00007f306c6ad000)
	/nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/ld-linux-x86-64.so.2 => /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib64/ld-linux-x86-64.so.2 (0x00007f306c948000)

It should be 2.37.

Related:

  • #12156

andrewrk avatar Oct 19 '23 21:10 andrewrk

Hmm, after @BratishkaErik's work in #17671, for me, I now see:

$ zig env | jq .target
"x86_64-linux.6.1.53...6.1.53-gnu.2.36"

which is still incorrect. It should be 2.37

andrewrk avatar Oct 24 '23 21:10 andrewrk

Hmm, after @BratishkaErik's work in #17671, for me, I now see:

$ zig env | jq .target
"x86_64-linux.6.1.53...6.1.53-gnu.2.36"

which is still incorrect. It should be 2.37

  1. I think it is correct version since it (likely) reported version from your glibc 64-bit version, not 32-bit, which at least on my PC differs in .dynstr content (/lib/libc.so.6 has size 35_312 and contains GLIBC_2.37 string, /lib64/libc.so.6 has size 32_644 and contains only up to GLIBC_2.36). Since dynamic linker directs to /lib64/libc.so.6 location, IMHO it should be considered as intended version even if it does not contain latest version string (looks like it's intended).

  2. If you disagree, would you like to try patch https://github.com/BratishkaErik/zig/commit/8a8ae1d80120580d357679a643f176e68191a933 ? Basically it collects all versions from available methods and compares to determine maximal available version (among other things like small fixes in ELF parsing and de-duplicating code with std.elf).

BratishkaErik avatar Oct 25 '23 16:10 BratishkaErik

When I run:

/lib/libc.so.6 | grep version
GNU C Library (Gentoo 2.38-r11 (patchset 11)) stable release version 2.38.

is the same as:

zig env | grep target
"target": "x86_64-linux.6.6.21...6.6.21-gnu.2.38",

so it seems to be correct.

chrboesch avatar Apr 21 '24 21:04 chrboesch