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

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

Open
songdongsheng opened this issue Jul 18, 2022 · 12 comments
Open
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness. os-linux
Milestone

Comments

@songdongsheng
Copy link

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 songdongsheng added the bug Observed behavior contradicts documented or intended behavior label Jul 18, 2022
@songdongsheng songdongsheng changed the title Detecting native triple on RHEL9 gives wrong result Detecting native triple on RHEL 9.0 gives wrong result Jul 18, 2022
@songdongsheng
Copy link
Author

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 !

@songdongsheng songdongsheng changed the title Detecting native triple on RHEL 9.0 gives wrong result Detecting native triple on RHEL 9.0 and Fedora 36 gives wrong result Jul 18, 2022
@BratishkaErik
Copy link
Contributor

BratishkaErik commented Jul 18, 2022

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 #6469

@BratishkaErik
Copy link
Contributor

BratishkaErik commented Jul 18, 2022

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
Copy link
Contributor

BratishkaErik commented Jul 18, 2022

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 #12151 will fix this

@Vexu Vexu added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Jul 29, 2022
@Vexu Vexu added this to the 0.10.0 milestone Jul 29, 2022
@BratishkaErik
Copy link
Contributor

And now this is a duplicate of #6469

@andrewrk andrewrk modified the milestones: 0.10.0, 0.10.1 Oct 12, 2022
@songdongsheng
Copy link
Author

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
Copy link
Contributor

BratishkaErik commented Oct 17, 2022

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
Copy link

frett27 commented Dec 13, 2022

the waning message is linked to :

std.log.warn("Encountered error: {s}, falling back to default ABI and dynamic linker.\n", .{@errorName(e)});
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
Copy link

frett27 commented Dec 14, 2022

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

@BratishkaErik
Copy link
Contributor

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

Yes

@andrewrk andrewrk modified the milestones: 0.10.1, 0.11.0 Jan 10, 2023
@eatonphil
Copy link
Contributor

eatonphil commented Jan 31, 2023

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

bors bot added a commit to tigerbeetle/tigerbeetle that referenced this issue Jan 31, 2023
432: No target on linux, except RHEL r=sentientwaffle a=eatonphil

`zig targets` doesn't seem to produce a target that can be safely fed back into `zig build -target X`. Or at least not in a way I can find.

So rather than even trying, we'll just completely omit `-target X` like we used to do. And we'll only override the target in the macOS case. And also RHEL given ziglang/zig#12156.

Closes #433

Co-authored-by: Phil Eaton <[email protected]>
@andrewrk andrewrk modified the milestones: 0.11.0, 0.11.1 Jul 20, 2023
@andrewrk andrewrk modified the milestones: 0.11.1, 0.12.0 Jan 29, 2024
@andrewrk
Copy link
Member

Possibly addressed by 0595feb

@andrewrk andrewrk modified the milestones: 0.14.0, 0.15.0 Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness. os-linux
Projects
None yet
Development

No branches or pull requests

6 participants