[Nix-dev] Building portable linux binaries on NixOS

Kamil Chmielewski kamil.chm at gmail.com
Fri Oct 9 14:23:30 CEST 2015


Unfortunately, I can't make patchelf works:
$ patchelf --set-interpreter /lib/ld-linux-x86-64.so.2 go-app
patchelf: patchelf.cc:693: void ElfFile<Elf_Ehdr, Elf_Phdr, Elf_Shdr,
Elf_Addr, Elf_Off, Elf_Dyn, Elf_Sym>::rewriteSectionsExecutable() [with
Elf_Ehdr = Elf64_Ehdr; Elf_Phdr = Elf64_Phdr; Elf_Shdr = Elf64_Shdr;
Elf_Addr = long unsigned int; Elf_Off = long unsigned int; Elf_Dyn =
Elf64_Dyn; Elf_Sym = Elf64_Sym]: Assertion `(off_t) rdi(hdr->e_shoff) >=
startOffset' failed.
Aborted

I try to buiild it in docker for now.
Thx for sugestions.

Cheers,
Kamil

2015-10-09 7:50 GMT+02:00 Bryan Gardiner <bog at khumba.net>:

> On Thu, 8 Oct 2015 00:03:23 +0200
> Kamil Chmielewski <kamil.chm at gmail.com> wrote:
>
> > 2015-10-07 20:44 GMT+02:00 Bryan Gardiner <bog at khumba.net>:
> >
> > > > your shell does not find "./go-app".
> > > > What does ls -l say?
> > >
> >
> > The file path is right and exists for sure.
> >
> >
> > > Most likely Kamil is in the right directory, and this is just a known
> > > quirk: bash tries to exec the program, the exec fails because the
> > > binary's interpreter is set incorrectly, and bash incorrectly
> > > interprets the failure as the program not existing.  See
> > > https://nixos.org/patchelf.html (although, there is an open bug about
> > > patchelf not working on Go binaries, see
> > > https://github.com/NixOS/patchelf/issues/66).
> >
> > Looks like the issue. Any ideas what to do?
>
> I'm not sure if you've tried patchelf and hit that bug, or if you
> haven't...  If you haven't, then try something like the following:
>
> $ patchelf --set-interpreter /lib/ld-linux.so.2 go-app
> $ patchelf --set-rpath /lib:/usr/lib:/usr/local/lib go-app
> $ ./go-app  # (on Ubuntu)
>
> You should consult /etc/ld.so.conf on Ubuntu for the correct library
> directories (not on Ubuntu here, so I can't see what how it does
> things).
>
> I think though, wouldn't the correct thing to do (after setting the
> interpreter) actually be to *remove* the RPATH from the binary to have
> it work on non-NixOS, using the normal system library lookup?  I don't
> see a --remove-rpath option on patchelf though.  I can't recall
> whether RPATH inhibits normal lookup directories, if not then you
> wouldn't need to change it, or you could just set it to be empty...
> See ld.so(8).
>
> Cheers,
> Bryan
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.science.uu.nl/pipermail/nix-dev/attachments/20151009/9030248d/attachment.html 


More information about the nix-dev mailing list