zig icon indicating copy to clipboard operation
zig copied to clipboard

bash: /usr/bin/zig: cannot execute: required file not found

Open f0rcemaster opened this issue 1 year ago • 4 comments

Zig Version

master

Steps to Reproduce and Observed Behavior

compile and install as described in README.md

uname -a
 6.8.7-gentoo #1 SMP PREEMPT_DYNAMIC Fri Apr 19 23:09:45 CEST 2024 x86_64 Intel(R) Core(TM) i7-3720QM CPU @ 2.60GHz GenuineIntel GNU/Linux

cmake .. --install-prefix=/usr
-- The C compiler identification is GNU 13.2.1
-- The CXX compiler identification is GNU 13.2.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring zig version 0.13.0-dev.4+c7ffdbcd4
-- Found llvm: -lLLVM-17 (Required is at least version "17")
-- Found clang: /usr/lib/llvm/17/lib64/libclang-cpp.so.17 (Required is at least version "17")
-- Found lld: /usr/lib/llvm/17/lib64/liblldMinGW.so;/usr/lib/llvm/17/lib64/liblldELF.so;/usr/lib/llvm/17/lib64/liblldCOFF.so;/usr/lib/llvm/17/lib64/liblldWasm.so;/usr/lib/llvm/17/lib64/liblldMachO.so;/usr/lib/llvm/17/lib64/liblldCommon.so (Required is at least version "17")
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
ma-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Configuring done (1.4s)
-- Generating done (0.0s)
-- Build files have been written to: /usr/src/lang/zig/ziglang/zig/build

make install
[ 36%] Built target zigcpp
[ 47%] Built target zig-wasm2c
[ 68%] Built target zig1
[ 94%] Built target zig2
[100%] Built target stage3
Install the project...
-- Install configuration: "Debug"
warning: Encountered error: UnexpectedEndOfFile, falling back to default ABI and dynamic linker.
warning: Encountered error: UnexpectedEndOfFile, falling back to default ABI and dynamic linker.
warning: Encountered error: UnexpectedEndOfFile, falling back to default ABI and dynamic linker.
warning: Encountered error: UnexpectedEndOfFile, falling back to default ABI and dynamic linker.
warning: Encountered error: UnexpectedEndOfFile, falling back to default ABI and dynamic linker.
warning: Encountered error: UnexpectedEndOfFile, falling back to default ABI and dynamic linker.
warning: Encountered error: UnexpectedEndOfFile, falling back to default ABI and dynamic linker.
warning: Encountered error: UnexpectedEndOfFile, falling back to default ABI and dynamic linker.
warning: Encountered error: UnexpectedEndOfFile, falling back to default ABI and dynamic linker.
warning: Encountered error: UnexpectedEndOfFile, falling back to default ABI and dynamic linker.

zig
bash: /usr/bin/zig: cannot execute: required file not found
objdump -p /usr/bin/zig

/usr/bin/zig:     file format elf64-x86-64

Program Header:
    PHDR off    0x0000000000000040 vaddr 0x0000000001000040 paddr 0x0000000001000040 align 2**3
         filesz 0x00000000000002a0 memsz 0x00000000000002a0 flags r--
  INTERP off    0x00000000000002e0 vaddr 0x00000000010002e0 paddr 0x00000000010002e0 align 2**0
         filesz 0x0000000000000019 memsz 0x0000000000000019 flags r--
    LOAD off    0x0000000000000000 vaddr 0x0000000001000000 paddr 0x0000000001000000 align 2**12
         filesz 0x00000000007584b8 memsz 0x00000000007584b8 flags r--
    LOAD off    0x00000000007584c0 vaddr 0x00000000017594c0 paddr 0x00000000017594c0 align 2**12
         filesz 0x00000000028e12a0 memsz 0x00000000028e12a0 flags r-x
    LOAD off    0x0000000003039760 vaddr 0x000000000403b760 paddr 0x000000000403b760 align 2**12
         filesz 0x00000000001183c8 memsz 0x0000000000118bd0 flags rw-
    LOAD off    0x0000000003152330 vaddr 0x0000000004155330 paddr 0x0000000004155330 align 2**12
         filesz 0x00000000000c14a8 memsz 0x00000000000d55d9 flags rw-
     TLS off    0x0000000003039760 vaddr 0x000000000403b760 paddr 0x000000000403b760 align 2**3
         filesz 0x0000000000000010 memsz 0x0000000000000048 flags r--
 DYNAMIC off    0x0000000003150148 vaddr 0x0000000004152148 paddr 0x0000000004152148 align 2**3
         filesz 0x0000000000000240 memsz 0x0000000000000240 flags rw-
   RELRO off    0x0000000003039760 vaddr 0x000000000403b760 paddr 0x000000000403b760 align 2**0
         filesz 0x00000000001183c8 memsz 0x00000000001198a0 flags r--
EH_FRAME off    0x00000000003c18e8 vaddr 0x00000000013c18e8 paddr 0x00000000013c18e8 align 2**2
         filesz 0x00000000000791ac memsz 0x00000000000791ac flags r--
   STACK off    0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**0
         filesz 0x0000000000000000 memsz 0x0000000002000000 flags rw-
    NOTE off    0x00000000000002fc vaddr 0x00000000010002fc paddr 0x00000000010002fc align 2**2
         filesz 0x0000000000000020 memsz 0x0000000000000020 flags r--

Dynamic Section:
  RUNPATH              /usr/lib/llvm/17/lib64
  NEEDED               libclang-cpp.so.17
  NEEDED               liblldMinGW.so.17
  NEEDED               liblldELF.so.17
  NEEDED               liblldCOFF.so.17
  NEEDED               liblldWasm.so.17
  NEEDED               liblldMachO.so.17
  NEEDED               liblldCommon.so.17
  NEEDED               libstdc++.so.6
  NEEDED               libLLVM-17.so
  NEEDED               libc.so.6
  NEEDED               ld-linux-x86-64.so.2
  FLAGS                0x0000000000000008
  FLAGS_1              0x0000000000000001
  DEBUG                0x0000000000000000
  RELA                 0x0000000001012198
  RELASZ               0x00000000000007b0
  RELAENT              0x0000000000000018
  JMPREL               0x0000000001012948
  PLTRELSZ             0x0000000000004608
  PLTGOT               0x00000000041523b8
  PLTREL               0x0000000000000007
  SYMTAB               0x0000000001000320
  SYMENT               0x0000000000000018
  STRTAB               0x0000000001008168
  STRSZ                0x000000000000a02b
  GNU_HASH             0x0000000001006118
  HASH                 0x0000000001006500
  INIT_ARRAY           0x0000000004152130
  INIT_ARRAYSZ         0x0000000000000018
  INIT                 0x000000000403786c
  FINI                 0x0000000004037888
  VERSYM               0x0000000001005840
  VERNEED              0x0000000001005f58
  VERNEEDNUM           0x0000000000000004

Version References:
  required from libstdc++.so.6:
    0x08922974 0x00 04 GLIBCXX_3.4
    0x0297f871 0x00 03 GLIBCXX_3.4.21
    0x0297f876 0x00 06 GLIBCXX_3.4.26
    0x0297f879 0x00 08 GLIBCXX_3.4.29
    0x056bafd3 0x00 07 CXXABI_1.3
    0x0bafd179 0x00 05 CXXABI_1.3.9
  required from libLLVM-17.so:
    0x011b3217 0x00 12 LLVM_17
  required from libc.so.6:
    0x09691a75 0x00 11 GLIBC_2.2.5
    0x0d696913 0x00 13 GLIBC_2.3
    0x09691972 0x00 25 GLIBC_2.3.2
    0x09691974 0x00 15 GLIBC_2.3.4
    0x0d696914 0x00 14 GLIBC_2.4
    0x0d696917 0x00 20 GLIBC_2.7
    0x0d696919 0x00 19 GLIBC_2.9
    0x06969190 0x00 17 GLIBC_2.10
    0x06969196 0x00 09 GLIBC_2.16
    0x06969197 0x00 22 GLIBC_2.17
    0x06969185 0x00 18 GLIBC_2.25
    0x06969187 0x00 21 GLIBC_2.27
    0x069691b2 0x00 23 GLIBC_2.32
    0x069691b3 0x00 16 GLIBC_2.33
    0x069691b4 0x00 02 GLIBC_2.34
    0x069691b8 0x00 24 GLIBC_2.38
  required from ld-linux-x86-64.so.2:
    0x0d696913 0x00 10 GLIBC_2.3


Expected Behavior

execute zig

f0rcemaster avatar Apr 20 '24 20:04 f0rcemaster

First thing you can probably try is instead of setting --install-prefix=/usr, you can do -DCMAKE_INSTALL_PREFIX=/usr. If that doesn't work then you might want to look at your dynamic linker and see if that's working right. These warnings look suspicious:

warning: Encountered error: UnexpectedEndOfFile, falling back to default ABI and dynamic linker.
warning: Encountered error: UnexpectedEndOfFile, falling back to default ABI and dynamic linker.
warning: Encountered error: UnexpectedEndOfFile, falling back to default ABI and dynamic linker.
warning: Encountered error: UnexpectedEndOfFile, falling back to default ABI and dynamic linker.
warning: Encountered error: UnexpectedEndOfFile, falling back to default ABI and dynamic linker.
warning: Encountered error: UnexpectedEndOfFile, falling back to default ABI and dynamic linker.
warning: Encountered error: UnexpectedEndOfFile, falling back to default ABI and dynamic linker.
warning: Encountered error: UnexpectedEndOfFile, falling back to default ABI and dynamic linker.
warning: Encountered error: UnexpectedEndOfFile, falling back to default ABI and dynamic linker.
warning: Encountered error: UnexpectedEndOfFile, falling back to default ABI and dynamic linker.

RossComputerGuy avatar Apr 20 '24 22:04 RossComputerGuy

You nees to set correct dynamic linker using -DZIG_TARGET_DYNAMIC_LINKER=<path> option.

Do you have multicall USE flag set on sys-apps/coreutils? If so, your /usr/bin/env is a script and Zig incorrectly recognizes it as full executable, which leads to your error:

https://github.com/ziglang/zig/blob/3c5e840732053318f5e722d6cc16f65d51cdc297/lib/std/zig/system.zig#L999

buffer.len is 255

https://github.com/ziglang/zig/blob/3c5e840732053318f5e722d6cc16f65d51cdc297/lib/std/zig/system.zig#L1032-L1035

Tries to read at least this amount of bytes from file, fails and breaks file as ELF file/(finishes too early).

https://github.com/ziglang/zig/blob/3c5e840732053318f5e722d6cc16f65d51cdc297/lib/std/zig/system.zig#L1068-L1073

Tries to parse this as ELF file, but it's too short, here error logs.

BratishkaErik avatar Apr 21 '24 09:04 BratishkaErik

Yes the USE flag multicall is set on sys-apps/coreutils triggering the bug. Thank you for solving the problem.

ghost avatar Apr 21 '24 12:04 ghost

USE flag multicall is set on sys-apps/coreutils triggering the bug.

Doesn't multicall just make it /usr/bin/env into a symlink to the real ELF? And we should support that out of the box.

daurnimator avatar Apr 23 '24 05:04 daurnimator