ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.83k stars 2.55k forks source link

Detecting native triple on RHEL 9.0 and Fedora 36 gives wrong result #12156

Open songdongsheng opened 2 years ago

songdongsheng commented 2 years ago

Zig Version

0.10.0-dev.3027+0e26c6149

Steps to Reproduce

podman run --rm -it registry.access.redhat.com/ubi9

dnf install -y bsdtar gcc-c++ jq && rpm -qa | grep -E "binutils|kernel-headers|glibc-devel|gcc-c++" export PATH=/opt/zig:/usr/sbin:/usr/bin:/sbin:/bin

$ zig version 0.10.0-dev.3027+0e26c6149

zig targets | jq -r '.native.triple'

x86_64-linux.5.10.16...5.10.16-musl

Expected Behavior

zig targets | jq -r '.native.triple'

x86_64-linux.5.10.16...5.10.16-gnu.2.34

Actual Behavior

zig targets | jq -r '.native.triple'

x86_64-linux.5.10.16...5.10.16-musl

RHEL 9 is glibc distributions, not musl !

songdongsheng commented 2 years ago

Fedora 36 give wrong glibc version 2.19 instead of the correct version 2.35 !

$ podman run --rm -it quay.io/fedora/fedora:36

$ dnf install -y bsdtar gcc-c++ jq

$ rpm -qa | grep -E "binutils|kernel-headers|glibc-devel|gcc-c++"
kernel-headers-5.18.4-200.fc36.x86_64
glibc-devel-2.35-4.fc36.x86_64
binutils-gold-2.37-27.fc36.x86_64
binutils-2.37-27.fc36.x86_64
gcc-c++-12.1.1-1.fc36.x86_64

$ zig version
0.10.0-dev.3027+0e26c6149

$ zig targets | jq -r '.native.triple'
x86_64-linux.5.18...5.18-gnu.2.19

It should be x86_64-linux.5.18...5.18-gnu.2.35, not x86_64-linux.5.18...5.18-gnu.2.19 !

BratishkaErik commented 2 years ago

Fedora 36 give wrong glibc version 2.19 instead of the correct version 2.35 !

$ podman run --rm -it quay.io/fedora/fedora:36

$ dnf install -y bsdtar gcc-c++ jq

$ rpm -qa | grep -E "binutils|kernel-headers|glibc-devel|gcc-c++"
kernel-headers-5.18.4-200.fc36.x86_64
glibc-devel-2.35-4.fc36.x86_64
binutils-gold-2.37-27.fc36.x86_64
binutils-2.37-27.fc36.x86_64
gcc-c++-12.1.1-1.fc36.x86_64

$ zig version
0.10.0-dev.3027+0e26c6149

$ zig targets | jq -r '.native.triple'
x86_64-linux.5.18...5.18-gnu.2.19

It should be x86_64-linux.5.18...5.18-gnu.2.35, not x86_64-linux.5.18...5.18-gnu.2.19 !

Duplicate of https://github.com/ziglang/zig/issues/6469

BratishkaErik commented 2 years ago

Zig Version

0.10.0-dev.3027+0e26c6149

Steps to Reproduce

podman run --rm -it registry.access.redhat.com/ubi9

dnf install -y bsdtar gcc-c++ jq && rpm -qa | grep -E "binutils|kernel-headers|glibc-devel|gcc-c++" export PATH=/opt/zig:/usr/sbin:/usr/bin:/sbin:/bin

$ zig version 0.10.0-dev.3027+0e26c6149

zig targets | jq -r '.native.triple'

x86_64-linux.5.10.16...5.10.16-musl

Expected Behavior

zig targets | jq -r '.native.triple'

x86_64-linux.5.10.16...5.10.16-gnu.2.34

Actual Behavior

zig targets | jq -r '.native.triple'

x86_64-linux.5.10.16...5.10.16-musl

RHEL 9 is glibc distributions, not musl !

Are you using static build from https://ziglang.org/download ? If so, can you please share output of file /usr/bin/env and file /bin/bash

BratishkaErik commented 2 years ago

Well, according to https://catalog.redhat.com/software/containers/ubi9/ubi/615bcf606feffc5384e8452e?container-tabs=packages your Red Hat Universal Base Image 9 installs coreutils-single package, not coreutils, so https://github.com/ziglang/zig/pull/12151 will fix this

BratishkaErik commented 2 years ago

And now this is a duplicate of https://github.com/ziglang/zig/issues/6469

songdongsheng commented 2 years ago

No.

fedora 36 reports x86_64-linux.5.19...5.19-gnu.2.35, this is correct.

But UBI9 (RHEL 9) still report x86_64-linux.5.19...5.19-musl:

# sudo podman run --rm -it registry.access.redhat.com/ubi9

# dnf update -y && dnf install -y jq xz

# rpm -qa | grep -E "coreutils-|libgcc-|glibc-2" | sort
coreutils-single-8.32-31.el9.x86_64
glibc-2.34-28.el9_0.2.x86_64
libgcc-11.2.1-9.4.el9.x86_64

# rm -fr /opt/zig/ && mkdir -p $_ && cd $_ \
    && curl -sSL https://ziglang.org/builds/zig-linux-x86_64-0.10.0-dev.4418+99c3578f6.tar.xz \
    | tar --strip-components=1 -xvJf -

# export PATH=/opt/zig:/usr/sbin:/usr/bin:/sbin:/bin

# zig version
0.10.0-dev.4418+99c3578f6

# zig targets | jq -r '.native.triple'
warning: Encountered error: UnexpectedEndOfFile, falling back to default ABI and dynamic linker.

x86_64-linux.5.19...5.19-musl
BratishkaErik commented 2 years ago

My suggestion — something to do with this?

readelf -d /usr/bin/coreutils 

Dynamic section at offset 0x144200 contains 31 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libselinux.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libacl.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libattr.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libcap.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000000c (INIT)               0xf000
 0x000000000000000d (FINI)               0xee564
 0x0000000000000019 (INIT_ARRAY)         0x13b7f0
 0x000000000000001b (INIT_ARRAYSZ)       8 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x13b7f8
 0x000000000000001c (FINI_ARRAYSZ)       8 (bytes)
 0x000000006ffffef5 (GNU_HASH)           0x3b0
 0x0000000000000005 (STRTAB)             0x27e0
 0x0000000000000006 (SYMTAB)             0x3f8
 0x000000000000000a (STRSZ)              4156 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000015 (DEBUG)              0x0
 0x0000000000000003 (PLTGOT)             0x145430
 0x0000000000000002 (PLTRELSZ)           8592 (bytes)
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000017 (JMPREL)             0xcbf0
 0x0000000000000007 (RELA)               0x3cb0
 0x0000000000000008 (RELASZ)             36672 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x0000000000000018 (BIND_NOW)           
 0x000000006ffffffb (FLAGS_1)            Flags: NOW PIE
 0x000000006ffffffe (VERNEED)            0x3b20
 0x000000006fffffff (VERNEEDNUM)         4
 0x000000006ffffff0 (VERSYM)             0x381c
 0x000000006ffffff9 (RELACOUNT)          1510
 0x0000000000000000 (NULL)               0x0
readelf -d /bin/sh

Dynamic section at offset 0x144698 contains 28 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libtinfo.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000000c (INIT)               0x2e000
 0x000000000000000d (FINI)               0x108608
 0x0000000000000019 (INIT_ARRAY)         0x142c10
 0x000000000000001b (INIT_ARRAYSZ)       8 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x142c18
 0x000000000000001c (FINI_ARRAYSZ)       8 (bytes)
 0x000000006ffffef5 (GNU_HASH)           0x3b0
 0x0000000000000005 (STRTAB)             0x13b50
 0x0000000000000006 (SYMTAB)             0x4f88
 0x000000000000000a (STRSZ)              40131 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000015 (DEBUG)              0x0
 0x0000000000000003 (PLTGOT)             0x145898
 0x0000000000000002 (PLTRELSZ)           5400 (bytes)
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000017 (JMPREL)             0x2c840
 0x0000000000000007 (RELA)               0x1ec80
 0x0000000000000008 (RELASZ)             56256 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x0000000000000018 (BIND_NOW)           
 0x000000006ffffffb (FLAGS_1)            Flags: NOW PIE
 0x000000006ffffffe (VERNEED)            0x1ebc0
 0x000000006fffffff (VERNEEDNUM)         1
 0x000000006ffffff0 (VERSYM)             0x1d814
 0x000000006ffffff9 (RELACOUNT)          2330
 0x0000000000000000 (NULL)               0x0

UPD: my approach with getconf works fine with this, but... :)

frett27 commented 1 year ago

the waning message is linked to : https://github.com/ziglang/zig/blob/d3b1cdf508242cbef9b107aaf5ede627e63c9e7b/lib/std/zig/system/NativeTargetInfo.zig#L339 searching for "/usr/bin/env" this is why my project compilation goes to fallback in the nix environment, but works on my pc (the env file exists)

frett27 commented 1 year ago

@BratishkaErik do you have the /usr/bin/env on your system ?

BratishkaErik commented 1 year ago

@BratishkaErik do you have the /usr/bin/env on your system ?

Yes

eatonphil commented 1 year ago

If it helps anyone: King and I were able to work around this by checking if I'm building on RHEL and if so, link against glibc rather than musl. (Zig 0.9.1).

# Zig picks musl libc instead of glibc, incorrectly                                                                                                                                          
# https://github.com/ziglang/zig/issues/12156                                                                                                                                                
if [ -f "/etc/redhat-release" ]; then
    target="-target native-native-gnu"
fi