[Nix-dev] Static Executable: Patchelf fails me

Luca Bruno lethalman88 at gmail.com
Mon Jan 5 01:21:03 CET 2015


Not an expert here, but maybe the binary is so much stripped that patchelf
is not able to determine the right offsets for patching the binary.

About the segfault, maybe it spawns some other process and the libs are not
propagated? That may explain why the symlink works.

On Mon, Jan 5, 2015 at 12:33 AM, Moritz Ulrich <moritz at tarn-vedra.de> wrote:

>
> Sorry for mangling the lines. I blame Emacs.
>
> Moritz Ulrich <moritz at tarn-vedra.de> writes:
>
> > Hello,
> >
> > I'm trying to package/run a static executable for Simplify3D, a
> > commercial 3D printer slicing software. My usual approaches (patchelf,
> > LD_PRELOAD) fail me here, so I'm asking for help
> >
> > Some information on the file:
> >
> > $ file ./s3d.run
> > ./s3d.run: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux),
> statically linked, stripped
> >
> > $ strace ./s3d.run
> > execve("./s3d.run", ["./s3d.run"], [/* 110 vars */]) = 0
> > mmap(0x700000, 2415740, PROT_READ|PROT_WRITE|PROT_EXEC,
> MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, 0, 0) = 0x700000
> > readlink("/proc/self/exe", "/home/moritz/downloads/s3d/s3d.r"..., 4096)
> = 34
> > mmap(0x400000, 2420736, PROT_NONE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS,
> -1, 0) = 0x400000
> > mmap(0x400000, 1235252, PROT_READ|PROT_WRITE|PROT_EXEC,
> MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x400000
> > mprotect(0x400000, 1235252, PROT_READ|PROT_EXEC) = 0
> > mmap(0x62e000, 66376, PROT_READ|PROT_WRITE,
> MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0x12e000) = 0x62e000
> > mprotect(0x62e000, 66376, PROT_READ|PROT_WRITE) = 0
> > mmap(0x63f000, 64072, PROT_READ|PROT_WRITE,
> MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x63f000
> > open("/lib64/ld-linux-x86-64.so.2", O_RDONLY) = -1 ENOENT (No such file
> or directory)
> > _exit(127)                              = ?
> > +++ exited with 127 +++
> >
> > $ patchelf ./s3d.run
> > patchelf: patchelf.cc:292: void ElfFile<Elf_Ehdr, Elf_Phdr, Elf_Shdr,
> Elf_Addr, Elf_Off, Elf_Dyn, Elf_Sym>::parse() [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 `shstrtabIndex < shdrs.size()' failed.
> > Aborted
> >
> > Setting LD_PRELOAD with pkgs.libredirect doesn't have any effect. (Is
> > this expected?) I also tried running the executable with
> > ld-linux-x86-64.so.2 directly (with and without LD_PRELOAD).
> >
> > With LD_PRELOAD, it got a bit further:
> >
> > $
> LD_PRELOAD=/nix/store/qc0jqhjassfw1anmy1zbq5v5717yn8xs-libredirect-0/lib/libredirect.so
> NIX_REDIRECTS=/lib64/ld-linux-x86-64.so.2=$(cat
> /nix/store/w1lj2s6v2wjmgd44fdi9i1p53qbxrqdc-gcc-wrapper-4.8.3/nix-support/dynamic-linker)
> strace
> /nix/store/la5imi1602jxhpds9675n2n2d0683lbq-glibc-2.20/lib/ld-linux-x86-64.so.2
> ./s3d.run
> >
> execve("/nix/store/la5imi1602jxhpds9675n2n2d0683lbq-glibc-2.20/lib/ld-linux-x86-64.so.2",
> ["/nix/store/la5imi1602jxhpds9675n"..., "./s3d.run"], [/* 111 vars */]) = 0
> > brk(0)                                  = 0x555555777000
> > open("./s3d.run", O_RDONLY|O_CLOEXEC)   = 3
> > read(3,
> "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\2\0>\0\1\0\0\0H\371F\0\0\0\0\0"..., 832) =
> 832
> > fstat(3, {st_mode=S_IFREG|0755, st_size=30666582, ...}) = 0
> > getcwd("/home/moritz/downloads/s3d", 128) = 27
> > mmap(0x300000, 1511424, PROT_READ|PROT_EXEC,
> MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0) = 0x300000
> > mmap(0x64e000, 4096, PROT_READ|PROT_WRITE,
> MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x14e000) = 0x64e000
> > mprotect(0x7fffffffc000, 4096,
> PROT_READ|PROT_WRITE|PROT_EXEC|PROT_GROWSDOWN) = 0
> > close(3)                                = 0
> > mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
> = 0x7ffff7ff9000
> >
> open("/nix/store/qc0jqhjassfw1anmy1zbq5v5717yn8xs-libredirect-0/lib/libredirect.so",
> O_RDONLY|O_CLOEXEC) = 3
> > read(3,
> "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0000\n\0\0\0\0\0\0"..., 832)
> = 832
> > fstat(3, {st_mode=S_IFREG|0555, st_size=9589, ...}) = 0
> > mmap(NULL, 2104616, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3,
> 0) = 0x7ffff7df7000
> > mprotect(0x7ffff7df9000, 2093056, PROT_NONE) = 0
> > mmap(0x7ffff7ff8000, 4096, PROT_READ|PROT_WRITE,
> MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1000) = 0x7ffff7ff8000
> > close(3)                                = 0
> > access("/etc/ld-nix.so.preload", R_OK)  = -1 ENOENT (No such file or
> directory)
> > open("/run/opengl-driver/lib/tls/x86_64/libdl.so.2", O_RDONLY|O_CLOEXEC)
> = -1 ENOENT (No such file or directory)
> > stat("/run/opengl-driver/lib/tls/x86_64", 0x7fffffffb940) = -1 ENOENT
> (No such file or directory)
> > open("/run/opengl-driver/lib/tls/libdl.so.2", O_RDONLY|O_CLOEXEC) = -1
> ENOENT (No such file or directory)
> > stat("/run/opengl-driver/lib/tls", 0x7fffffffb940) = -1 ENOENT (No such
> file or directory)
> > open("/run/opengl-driver/lib/x86_64/libdl.so.2", O_RDONLY|O_CLOEXEC) =
> -1 ENOENT (No such file or directory)
> > stat("/run/opengl-driver/lib/x86_64", 0x7fffffffb940) = -1 ENOENT (No
> such file or directory)
> > open("/run/opengl-driver/lib/libdl.so.2", O_RDONLY|O_CLOEXEC) = -1
> ENOENT (No such file or directory)
> > stat("/run/opengl-driver/lib", {st_mode=S_IFDIR|0555, st_size=4096,
> ...}) = 0
> > open("/run/opengl-driver-32/lib/tls/x86_64/libdl.so.2",
> O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> > stat("/run/opengl-driver-32/lib/tls/x86_64", 0x7fffffffb940) = -1 ENOENT
> (No such file or directory)
> > open("/run/opengl-driver-32/lib/tls/libdl.so.2", O_RDONLY|O_CLOEXEC) =
> -1 ENOENT (No such file or directory)
> > stat("/run/opengl-driver-32/lib/tls", 0x7fffffffb940) = -1 ENOENT (No
> such file or directory)
> > open("/run/opengl-driver-32/lib/x86_64/libdl.so.2", O_RDONLY|O_CLOEXEC)
> = -1 ENOENT (No such file or directory)
> > stat("/run/opengl-driver-32/lib/x86_64", 0x7fffffffb940) = -1 ENOENT (No
> such file or directory)
> > open("/run/opengl-driver-32/lib/libdl.so.2", O_RDONLY|O_CLOEXEC) = -1
> ENOENT (No such file or directory)
> > stat("/run/opengl-driver-32/lib", {st_mode=S_IFDIR|0555, st_size=4096,
> ...}) = 0
> >
> open("/nix/store/la5imi1602jxhpds9675n2n2d0683lbq-glibc-2.20/lib/tls/x86_64/libdl.so.2",
> O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> >
> stat("/nix/store/la5imi1602jxhpds9675n2n2d0683lbq-glibc-2.20/lib/tls/x86_64",
> 0x7fffffffb940) = -1 ENOENT (No such file or directory)
> >
> open("/nix/store/la5imi1602jxhpds9675n2n2d0683lbq-glibc-2.20/lib/tls/libdl.so.2",
> O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> > stat("/nix/store/la5imi1602jxhpds9675n2n2d0683lbq-glibc-2.20/lib/tls",
> 0x7fffffffb940) = -1 ENOENT (No such file or directory)
> >
> open("/nix/store/la5imi1602jxhpds9675n2n2d0683lbq-glibc-2.20/lib/x86_64/libdl.so.2",
> O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> >
> stat("/nix/store/la5imi1602jxhpds9675n2n2d0683lbq-glibc-2.20/lib/x86_64",
> 0x7fffffffb940) = -1 ENOENT (No such file or directory)
> >
> open("/nix/store/la5imi1602jxhpds9675n2n2d0683lbq-glibc-2.20/lib/libdl.so.2",
> O_RDONLY|O_CLOEXEC) = 3
> > read(3,
> "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\340\16\0\0\0\0\0\0"...,
> 832) = 832
> > fstat(3, {st_mode=S_IFREG|0555, st_size=18784, ...}) = 0
> > mmap(NULL, 2109712, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3,
> 0) = 0x7ffff7bf3000
> > mprotect(0x7ffff7bf6000, 2093056, PROT_NONE) = 0
> > mmap(0x7ffff7df5000, 8192, PROT_READ|PROT_WRITE,
> MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7ffff7df5000
> > close(3)                                = 0
> > open("/run/opengl-driver/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT
> (No such file or directory)
> > open("/run/opengl-driver-32/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = -1
> ENOENT (No such file or directory)
> >
> open("/nix/store/la5imi1602jxhpds9675n2n2d0683lbq-glibc-2.20/lib/libc.so.6",
> O_RDONLY|O_CLOEXEC) = 3
> > read(3,
> "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0000\35\2\0\0\0\0\0"..., 832)
> = 832
> > fstat(3, {st_mode=S_IFREG|0555, st_size=1906959, ...}) = 0
> > mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
> = 0x7ffff7bf2000
> > mmap(NULL, 3787296, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3,
> 0) = 0x7ffff7855000
> > mprotect(0x7ffff79e9000, 2093056, PROT_NONE) = 0
> > mmap(0x7ffff7be8000, 24576, PROT_READ|PROT_WRITE,
> MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x193000) = 0x7ffff7be8000
> > mmap(0x7ffff7bee000, 14880, PROT_READ|PROT_WRITE,
> MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7ffff7bee000
> > close(3)                                = 0
> > mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
> = 0x7ffff7854000
> > mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
> = 0x7ffff7853000
> > arch_prctl(ARCH_SET_FS, 0x7ffff7854700) = 0
> > mprotect(0x7ffff7be8000, 16384, PROT_READ) = 0
> > mprotect(0x7ffff7df5000, 4096, PROT_READ) = 0
> > --- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x8} ---
> > +++ killed by SIGSEGV +++
> > Segmentation fault
> >
> > It's also worth to note that the executable (an installer) works just
> > fine when I symlink any ld-linux-x86-64.so.2 to /lib64.
> >
> > I found a similar issue on the mailing list[1] where the executable was
> > packed with UPX[2] (pkgs.upx), and a string in my file points in that
> > direction too - but upx refuses to unpack it, complaining it wasn't
> > packed with it.
> >
> > Does anyone have an idea how I can get this to work?
> >
> > Please excuse if my approaches seem foolish - I'm not very familar with
> > all ELF et al.
> >
> >
> > Cheers,
> > Moritz
> >
> > [1]:
> http://lists.science.uu.nl/pipermail/nix-dev/2012-December/010233.html
> > [2]: http://upx.sourceforge.net/
>
> --
>
> _______________________________________________
> nix-dev mailing list
> nix-dev at lists.science.uu.nl
> http://lists.science.uu.nl/mailman/listinfo/nix-dev
>
>


-- 
NixOS Linux <http://nixos.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.science.uu.nl/pipermail/nix-dev/attachments/20150105/716dbca8/attachment-0001.html 


More information about the nix-dev mailing list