nixpkgs-mozilla icon indicating copy to clipboard operation
nixpkgs-mozilla copied to clipboard

Exec format error on Rust nightly in WSL

Open mkovaxx opened this issue 7 years ago • 5 comments

Trying to run rustc in an environment created by nix-shell fails with the following error:

bash: /nix/store/74ll1hp30sl0z3md48vxxkri93zk9b3r-rust-1.32.0-nightly-2018-11-29-3e90a12a8/bin/rustc: cannot execute binary file: Exec format error

The same issue is also present with cargo.

This happens in Windows Subsystem for Linux on Windows 10 (version 1809). The output of uname -a:

Linux matrix 4.4.0-17763-Microsoft #253-Microsoft Mon Dec 31 17:49:00 PST 2018 x86_64 GNU/Linux

Here's the default.nix file used:

let
  moz_overlay = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz);
  nixpkgs = import <nixpkgs> { overlays = [ moz_overlay ]; };
in
  with nixpkgs;
  stdenv.mkDerivation rec {
    name = "env";
    env = buildEnv { name = name; paths = buildInputs; };
    buildInputs = [
      (nixpkgs.rustChannelOf { date = "2018-11-30"; channel = "nightly"; }).rust
    ];
  }

Also tried with different nightly builds, and the problem persists.

This is the output of readelf -a on rustc:

ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              DYN (Shared object file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x7e0
  Start of program headers:          2105344 (bytes into file)
  Start of section headers:          7488 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         10
  Size of section headers:           64 (bytes)
  Number of section headers:         28
  Section header string table index: 24

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .note.ABI-tag     NOTE             0000000000000254  00000254
       0000000000000020  0000000000000000   A       0     0     4
  [ 2] .gnu.hash         GNU_HASH         0000000000000278  00000278
       000000000000002c  0000000000000000   A       3     0     8
  [ 3] .dynsym           DYNSYM           00000000000002a8  000002a8
       0000000000000180  0000000000000018   A       4     2     8
  [ 4] .dynstr           STRTAB           0000000000000428  00000428
       000000000000019d  0000000000000000   A       0     0     1
  [ 5] .gnu.version      VERSYM           00000000000005c6  000005c6
       0000000000000020  0000000000000002   A       3     0     2
  [ 6] .gnu.version_r    VERNEED          00000000000005e8  000005e8
       0000000000000020  0000000000000000   A       4     1     8
  [ 7] .rela.dyn         RELA             0000000000000608  00000608
       0000000000000168  0000000000000018   A       3     0     8
  [ 8] .rela.plt         RELA             0000000000000770  00000770
       0000000000000030  0000000000000018  AI       3    10     8
  [ 9] .init             PROGBITS         00000000000007a0  000007a0
       000000000000000e  0000000000000000  AX       0     0     4
  [10] .plt              PROGBITS         00000000000007b0  000007b0
       0000000000000030  0000000000000010  AX       0     0     16
  [11] .text             PROGBITS         00000000000007e0  000007e0
       000000000000024b  0000000000000000  AX       0     0     16
  [12] .fini             PROGBITS         0000000000000a2c  00000a2c
       0000000000000009  0000000000000000  AX       0     0     4
  [13] .eh_frame_hdr     PROGBITS         0000000000000a38  00000a38
       000000000000004c  0000000000000000   A       0     0     4
  [14] .eh_frame         PROGBITS         0000000000000a88  00000a88
       00000000000000fc  0000000000000000   A       0     0     8
  [15] .init_array       INIT_ARRAY       0000000000200d30  00000d30
       0000000000000008  0000000000000000  WA       0     0     8
  [16] .fini_array       FINI_ARRAY       0000000000200d38  00000d38
       0000000000000008  0000000000000000  WA       0     0     8
  [17] .jcr              PROGBITS         0000000000200d40  00000d40
       0000000000000008  0000000000000000  WA       0     0     8
  [18] .data.rel.ro      PROGBITS         0000000000200d48  00000d48
       0000000000000030  0000000000000000  WA       0     0     8
  [19] .dynamic          DYNAMIC          0000000000200d78  00000d78
       0000000000000220  0000000000000010  WA       4     0     8
  [20] .got              PROGBITS         0000000000200f98  00000f98
       0000000000000068  0000000000000008  WA       0     0     8
  [21] .data             PROGBITS         0000000000201000  00001000
       0000000000000008  0000000000000000  WA       0     0     8
  [22] .bss              NOBITS           0000000000201008  00001008
       0000000000000008  0000000000000000  WA       0     0     1
  [23] .comment          PROGBITS         0000000000000000  00001008
       000000000000009b  0000000000000000           0     0     1
  [24] .shstrtab         STRTAB           0000000000000000  000010a3
       00000000000000f1  0000000000000000           0     0     1
  [25] .symtab           SYMTAB           0000000000000000  00001198
       0000000000000708  0000000000000018          26    57     8
  [26] .strtab           STRTAB           0000000000000000  000018a0
       000000000000049e  0000000000000000           0     0     1
  [27] .interp           PROGBITS         0000000000202230  00202230
       0000000000000050  0000000000000000   A       0     0     8
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  l (large), p (processor specific)

There are no section groups in this file.

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  PHDR           0x0000000000202000 0x0000000000202000 0x0000000000202000
                 0x0000000000000230 0x0000000000000230  R E    0x8
  LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000b84 0x0000000000000b84  R E    0x200000
  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000  RW     0x10
  NOTE           0x0000000000000254 0x0000000000000254 0x0000000000000254
                 0x0000000000000020 0x0000000000000020  R      0x4
  GNU_EH_FRAME   0x0000000000000a38 0x0000000000000a38 0x0000000000000a38
                 0x000000000000004c 0x000000000000004c  R      0x4
  LOAD           0x0000000000000d30 0x0000000000200d30 0x0000000000200d30
                 0x00000000000002d8 0x00000000000002e0  RW     0x200000
  GNU_RELRO      0x0000000000000d30 0x0000000000200d30 0x0000000000200d30
                 0x00000000000002d0 0x00000000000002d0  R      0x1
  DYNAMIC        0x0000000000000d78 0x0000000000200d78 0x0000000000200d78
                 0x0000000000000220 0x0000000000000220  RW     0x8
  LOAD           0x0000000000202000 0x0000000000202000 0x0000000000202000
                 0x0000000000000280 0x0000000000000280  RW     0x1000
  INTERP         0x0000000000202230 0x0000000000202230 0x0000000000202230
                 0x0000000000000050 0x0000000000000050  R      0x1
      [Requesting program interpreter: /nix/store/fivq0nbggp4y8mhy3ixprqd7qyn1hy2j-glibc-2.27/lib/ld-linux-x86-64.so.2]

 Section to Segment mapping:
  Segment Sections...
   00
   01     .note.ABI-tag .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .init .plt .text .fini .eh_frame_hdr .eh_frame
   02
   03     .note.ABI-tag
   04     .eh_frame_hdr
   05     .init_array .fini_array .jcr .data.rel.ro .dynamic .got .data .bss
   06     .init_array .fini_array .jcr .data.rel.ro .dynamic .got
   07     .dynamic
   08     .interp
   09     .interp

Dynamic section at offset 0xd78 contains 30 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [librustc_driver-c5e4963f1fae1b6c.so]
 0x0000000000000001 (NEEDED)             Shared library: [libstd-cd5039531bcb67fb.so]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000000f (RPATH)              Library rpath: [$ORIGIN/../lib]
 0x000000000000000c (INIT)               0x7a0
 0x000000000000000d (FINI)               0xa2c
 0x0000000000000019 (INIT_ARRAY)         0x200d30
 0x000000000000001b (INIT_ARRAYSZ)       8 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x200d38
 0x000000000000001c (FINI_ARRAYSZ)       8 (bytes)
 0x000000006ffffef5 (GNU_HASH)           0x278
 0x0000000000000005 (STRTAB)             0x428
 0x0000000000000006 (SYMTAB)             0x2a8
 0x000000000000000a (STRSZ)              413 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000015 (DEBUG)              0x0
 0x0000000000000003 (PLTGOT)             0x200f98
 0x0000000000000002 (PLTRELSZ)           48 (bytes)
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000017 (JMPREL)             0x770
 0x0000000000000007 (RELA)               0x608
 0x0000000000000008 (RELASZ)             360 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x0000000000000018 (BIND_NOW)
 0x000000006ffffffb (FLAGS_1)            Flags: NOW
 0x000000006ffffffe (VERNEED)            0x5e8
 0x000000006fffffff (VERNEEDNUM)         1
 0x000000006ffffff0 (VERSYM)             0x5c6
 0x000000006ffffff9 (RELACOUNT)          7
 0x0000000000000000 (NULL)               0x0

Relocation section '.rela.dyn' at offset 0x608 contains 15 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000200d30  000000000008 R_X86_64_RELATIVE                    8e0
000000200d38  000000000008 R_X86_64_RELATIVE                    8a0
000000200d48  000000000008 R_X86_64_RELATIVE                    940
000000200d60  000000000008 R_X86_64_RELATIVE                    920
000000200d68  000000000008 R_X86_64_RELATIVE                    920
000000200d70  000000000008 R_X86_64_RELATIVE                    930
000000201000  000000000008 R_X86_64_RELATIVE                    201000
000000200fc0  000500000006 R_X86_64_GLOB_DAT 0000000000000000 __gmon_start__ + 0
000000200fc8  000600000006 R_X86_64_GLOB_DAT 0000000000000000 _Jv_RegisterClasses + 0
000000200fd0  000800000006 R_X86_64_GLOB_DAT 0000000000000000 _ZN12rustc_driver4main + 0
000000200fd8  000900000006 R_X86_64_GLOB_DAT 0000000000000000 _ITM_deregisterTMClone + 0
000000200fe0  000a00000006 R_X86_64_GLOB_DAT 0000000000000000 _ITM_registerTMCloneTa + 0
000000200fe8  000b00000006 R_X86_64_GLOB_DAT 0000000000000000 __cxa_finalize@GLIBC_2.2.5 + 0
000000200ff0  000c00000006 R_X86_64_GLOB_DAT 0000000000000000 _ZN12rustc_driver19set + 0
000000200ff8  000d00000006 R_X86_64_GLOB_DAT 0000000000000000 _ZN3std2rt19lang_start + 0

Relocation section '.rela.plt' at offset 0x770 contains 2 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000200fb0  000700000007 R_X86_64_JUMP_SLO 0000000000000000 __libc_start_main@GLIBC_2.2.5 + 0
000000200fb8  000b00000007 R_X86_64_JUMP_SLO 0000000000000000 __cxa_finalize@GLIBC_2.2.5 + 0

The decoding of unwind sections for machine type Advanced Micro Devices X86-64 is not currently supported.

Symbol table '.dynsym' contains 16 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00000000000007a0     0 SECTION LOCAL  DEFAULT    9
     2: 0000000000201008     0 NOTYPE  LOCAL  DEFAULT   22 __bss_start
readelf: Warning: local symbol 2 found at index >= .dynsym's sh_info value of 2
     3: 0000000000201010     0 NOTYPE  LOCAL  DEFAULT   22 _end
readelf: Warning: local symbol 3 found at index >= .dynsym's sh_info value of 2
     4: 0000000000201008     0 NOTYPE  LOCAL  DEFAULT   21 _edata
readelf: Warning: local symbol 4 found at index >= .dynsym's sh_info value of 2
     5: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__
     6: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _Jv_RegisterClasses
     7: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __libc_start_main@GLIBC_2.2.5 (2)
     8: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND _ZN12rustc_driver4main17h
     9: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_deregisterTMCloneTab
    10: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_registerTMCloneTable
    11: 0000000000000000     0 FUNC    WEAK   DEFAULT  UND __cxa_finalize@GLIBC_2.2.5 (2)
    12: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND _ZN12rustc_driver19set_si
    13: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND _ZN3std2rt19lang_start_in
    14: 00000000000007a0     0 FUNC    GLOBAL DEFAULT    9 _init
    15: 0000000000000a2c     0 FUNC    GLOBAL DEFAULT   12 _fini

Symbol table '.symtab' contains 75 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 0000000000202230     0 SECTION LOCAL  DEFAULT   27
     2: 0000000000000254     0 SECTION LOCAL  DEFAULT    1
     3: 0000000000000278     0 SECTION LOCAL  DEFAULT    2
     4: 00000000000002a8     0 SECTION LOCAL  DEFAULT    3
     5: 0000000000000428     0 SECTION LOCAL  DEFAULT    4
     6: 00000000000005c6     0 SECTION LOCAL  DEFAULT    5
     7: 00000000000005e8     0 SECTION LOCAL  DEFAULT    6
     8: 0000000000000608     0 SECTION LOCAL  DEFAULT    7
     9: 0000000000000770     0 SECTION LOCAL  DEFAULT    8
    10: 00000000000007a0     0 SECTION LOCAL  DEFAULT    9
    11: 00000000000007b0     0 SECTION LOCAL  DEFAULT   10
    12: 00000000000007e0     0 SECTION LOCAL  DEFAULT   11
    13: 0000000000000a2c     0 SECTION LOCAL  DEFAULT   12
    14: 0000000000000a38     0 SECTION LOCAL  DEFAULT   13
    15: 0000000000000a88     0 SECTION LOCAL  DEFAULT   14
    16: 0000000000200d30     0 SECTION LOCAL  DEFAULT   15
    17: 0000000000200d38     0 SECTION LOCAL  DEFAULT   16
    18: 0000000000200d40     0 SECTION LOCAL  DEFAULT   17
    19: 0000000000200d48     0 SECTION LOCAL  DEFAULT   18
    20: 0000000000200d78     0 SECTION LOCAL  DEFAULT   19
    21: 0000000000200f98     0 SECTION LOCAL  DEFAULT   20
    22: 0000000000201000     0 SECTION LOCAL  DEFAULT   21
    23: 0000000000201008     0 SECTION LOCAL  DEFAULT   22
    24: 0000000000000000     0 SECTION LOCAL  DEFAULT   23
    25: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS /usr/lib/../lib64/crti.o
    26: 000000000000080c     0 FUNC    LOCAL  DEFAULT   11 call_gmon_start
    27: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS crtstuff.c
    28: 0000000000200d40     0 OBJECT  LOCAL  DEFAULT   17 __JCR_LIST__
    29: 0000000000000830     0 FUNC    LOCAL  DEFAULT   11 deregister_tm_clones
    30: 0000000000000860     0 FUNC    LOCAL  DEFAULT   11 register_tm_clones
    31: 00000000000008a0     0 FUNC    LOCAL  DEFAULT   11 __do_global_dtors_aux
    32: 0000000000201008     1 OBJECT  LOCAL  DEFAULT   22 completed.6330
    33: 0000000000200d38     0 OBJECT  LOCAL  DEFAULT   16 __do_global_dtors_aux_fin
    34: 00000000000008e0     0 FUNC    LOCAL  DEFAULT   11 frame_dummy
    35: 0000000000200d30     0 OBJECT  LOCAL  DEFAULT   15 __frame_dummy_init_array_
    36: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS rustc_binary.6mykey61-cgu
    37: 0000000000000920     7 FUNC    LOCAL  DEFAULT   11 _ZN3std2rt10lang_start28_
    38: 0000000000000930     7 FUNC    LOCAL  DEFAULT   11 _ZN4core3ops8function6FnO
    39: 0000000000000940     1 FUNC    LOCAL  DEFAULT   11 _ZN4core3ptr13drop_in_pla
    40: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS rustc_binary.6mykey61-cgu
    41: 0000000000000950    14 FUNC    LOCAL  DEFAULT   11 _ZN12rustc_binary4main17h
    42: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS crtstuff.c
    43: 0000000000000b80     0 OBJECT  LOCAL  DEFAULT   14 __FRAME_END__
    44: 0000000000200d40     0 OBJECT  LOCAL  DEFAULT   17 __JCR_END__
    45: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS
    46: 0000000000200d30     0 NOTYPE  LOCAL  DEFAULT   15 __preinit_array_start
    47: 0000000000200d40     0 NOTYPE  LOCAL  DEFAULT   16 __fini_array_end
    48: 0000000000200f98     0 OBJECT  LOCAL  DEFAULT   20 _GLOBAL_OFFSET_TABLE_
    49: 0000000000200d30     0 NOTYPE  LOCAL  DEFAULT   15 __preinit_array_end
    50: 0000000000201008     0 NOTYPE  LOCAL  DEFAULT   22 __bss_start
    51: 0000000000200d38     0 NOTYPE  LOCAL  DEFAULT   16 __fini_array_start
    52: 0000000000200d38     0 NOTYPE  LOCAL  DEFAULT   15 __init_array_end
    53: 0000000000201010     0 NOTYPE  LOCAL  DEFAULT   22 _end
    54: 0000000000200d30     0 NOTYPE  LOCAL  DEFAULT   15 __init_array_start
    55: 0000000000201008     0 NOTYPE  LOCAL  DEFAULT   21 _edata
    56: 0000000000200d78     0 OBJECT  LOCAL  DEFAULT   19 _DYNAMIC
    57: 0000000000000990     2 FUNC    GLOBAL DEFAULT   11 __libc_csu_fini
    58: 0000000000200d48    48 OBJECT  GLOBAL HIDDEN    18 anon.d64b5436690cab26f06c
    59: 00000000000007e0     0 FUNC    GLOBAL DEFAULT   11 _start
    60: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__
    61: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _Jv_RegisterClasses
    62: 0000000000000a2c     0 FUNC    GLOBAL DEFAULT   12 _fini
    63: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __libc_start_main@@GLIBC_
    64: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND _ZN12rustc_driver4main17h
    65: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_deregisterTMCloneTab
    66: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_registerTMCloneTable
    67: 0000000000000000     0 FUNC    WEAK   DEFAULT  UND __cxa_finalize@@GLIBC_2.2
    68: 0000000000201008     0 OBJECT  GLOBAL HIDDEN    21 __TMC_END__
    69: 0000000000201000     0 OBJECT  GLOBAL HIDDEN    21 __dso_handle
    70: 00000000000009a0   139 FUNC    GLOBAL DEFAULT   11 __libc_csu_init
    71: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND _ZN12rustc_driver19set_si
    72: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND _ZN3std2rt19lang_start_in
    73: 0000000000000960    36 FUNC    GLOBAL DEFAULT   11 main
    74: 00000000000007a0     0 FUNC    GLOBAL DEFAULT    9 _init

Histogram for `.gnu.hash' bucket list length (total of 3 buckets):
 Length  Number     % of total  Coverage
      0  1          ( 33.3%)
      1  2          ( 66.7%)    100.0%

Version symbols section '.gnu.version' contains 16 entries:
 Addr: 00000000000005c6  Offset: 0x0005c6  Link: 3 (.dynsym)
  000:   0 (*local*)       0 (*local*)       1 (*global*)      1 (*global*)
  004:   1 (*global*)      0 (*local*)       0 (*local*)       2 (GLIBC_2.2.5)
  008:   0 (*local*)       0 (*local*)       0 (*local*)       2 (GLIBC_2.2.5)
  00c:   0 (*local*)       0 (*local*)       1 (*global*)      1 (*global*)

Version needs section '.gnu.version_r' contains 1 entry:
 Addr: 0x00000000000005e8  Offset: 0x0005e8  Link: 4 (.dynstr)
  000000: Version: 1  File: libc.so.6  Cnt: 1
  0x0010:   Name: GLIBC_2.2.5  Flags: none  Version: 2

Displaying notes found in: .note.ABI-tag
  Owner                 Data size       Description
  GNU                  0x00000010       NT_GNU_ABI_TAG (ABI version tag)
    OS: Linux, ABI: 2.6.9

mkovaxx avatar Jan 28 '19 13:01 mkovaxx

i am getting this same issue as well. seems to happen on all channels: stable, beta and nightly

ylixir avatar Feb 12 '19 12:02 ylixir

Just found this as well. I'm guessing the key here is that it's tagged as a shared object file?

Type: DYN (Shared object file)

file reports the same:

$ file $(realpath /nix/store/ps53s9wf1d2r8qgbc4hfypvgfn20ap4g-rust-1.45.0-nightly-2020-04-25-0862458da/bin/cargo)
/nix/store/ds8dmvd8i64is9wq8lkz0kjgmgx77dz6-rust/bin/cargo: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /nix/store/bwzra330vib0ik4d3l8rq6gp6y2ah1fr-glibc-2.30/lib/ld-linux-x86-64.so.2, for GNU/Linux 2.6.9, with debug_info, not stripped

Edit: no, that's not it.

$ cp $(which cargo) ./
$ chmod a+w cargo
$ elfedit --output-type exec cargo
$ ./cargo
bash: ./cargo: cannot execute binary file: Exec format error

Edit 2: It's a linking problem.

$ mkdir -p extract
$ cd extract
$ wget https://static.rust-lang.org/dist/rust-nightly-x86_64-unknown-linux-gnu.tar.gz -qO- | tar vxz --strip-components=1 --exclude='*/rust-docs/*'
$ cd cargo/bin
$ ./cargo
Rust's package manager

USAGE:
    cargo [OPTIONS] [SUBCOMMAND]
...
$ patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" cargo
$ ./cargo
bash: ./cargo: cannot execute binary file: Exec format error
$ /lib64/ld-linux-x86-64.so.2 ./cargo
Rust's package manager

USAGE:
    cargo [OPTIONS] [SUBCOMMAND]
...

And yet, if we invoke the binary with the interpreter directly, it works fine:

$ file cargo
cargo: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /nix/store/bwzra330vib0ik4d3l8rq6gp6y2ah1fr-glibc-2.30/lib/ld-linux-x86-64.so.2, for GNU/Linux 2.6.9, with debug_info, not stripped
$ /nix/store/bwzra330vib0ik4d3l8rq6gp6y2ah1fr-glibc-2.30/lib/ld-linux-x86-64.so.2 ./cargo
Rust's package manager

USAGE:
    cargo [OPTIONS] [SUBCOMMAND]
...

I'm at a loss here. This sounds like something that someone has probably solved before, but if that's the case, I haven't found the answer yet. I'll probably just fork this repo and add wrapper scripts that invoke the correct linker directly rather than doing a patchelf --set-interpreter

npry avatar Apr 29 '20 00:04 npry

My "fix"—not gonna bother upstreaming because there's clearly something deeper wrong here, but I'll leave the link here in case anyone else needs to just get it working.

npry avatar Apr 29 '20 02:04 npry

I'm also getting the same error when trying to install cargo2nix in WSL. Is there any way around this?

antonsmetanin avatar Jul 19 '20 13:07 antonsmetanin

Just FYI, on WSL2 this doesn't occur at all.

573 avatar Feb 24 '21 11:02 573