Re: [Nix-dev] Static Executable: Patchelf fails me

2015-01-05 Thread Vladimír Čunát
On 01/05/2015 12:24 AM, Moritz Ulrich wrote:
> 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 guess that's the only thing you can do with a static executable (using 
static libc is bad enough by itself). Of course, you can feign the paths 
by some chroots, proot or VM.

Vladimir

___
nix-dev mailing list
nix-dev@lists.science.uu.nl
http://lists.science.uu.nl/mailman/listinfo/nix-dev


Re: [Nix-dev] Static Executable: Patchelf fails me

2015-01-05 Thread Eelco Dolstra
Hi,

On 05/01/15 00:24, Moritz Ulrich wrote:

> $ patchelf ./s3d.run 
> patchelf: patchelf.cc:292: void ElfFile 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

The error message could be more elegant, but the main issue is that patchelf
cannot work on static binaries because there is nothing to patch: no ELF
interpreter section, no DT_NEEDED entries, etc.

> Setting LD_PRELOAD with pkgs.libredirect doesn't have any effect. (Is
> this expected?)

Same thing, LD_PRELOAD doesn't work with static binaries because it affects the
dynamic linker, which doesn't get used for static executables.

If there is a dynamic executable hidden inside the static executable via UPX
compression or something similar, I guess you need to decompress it first and
then apply patchelf.

-- 
Eelco Dolstra | LogicBlox, Inc. | http://nixos.org/~eelco/
___
nix-dev mailing list
nix-dev@lists.science.uu.nl
http://lists.science.uu.nl/mailman/listinfo/nix-dev


Re: [Nix-dev] Static Executable: Patchelf fails me

2015-01-04 Thread Luca Bruno
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  wrote:

>
> Sorry for mangling the lines. I blame Emacs.
>
> Moritz Ulrich  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(0x70, 2415740, PROT_READ|PROT_WRITE|PROT_EXEC,
> MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, 0, 0) = 0x70
> > readlink("/proc/self/exe", "/home/moritz/downloads/s3d/s3d.r"..., 4096)
> = 34
> > mmap(0x40, 2420736, PROT_NONE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS,
> -1, 0) = 0x40
> > mmap(0x40, 1235252, PROT_READ|PROT_WRITE|PROT_EXEC,
> MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x40
> > mprotect(0x40, 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_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)  = 0x55777000
> > 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(0x30, 1511424, PROT_READ|PROT_EXEC,
> MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0) = 0x30
> > mmap(0x64e000, 4096, PROT_READ|PROT_WRITE,
> MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x14e000) = 0x64e000
> > mprotect(0x7fffc000, 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)
> = 0x77ff9000
> >
> 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\\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) = 0x77df7000
> > mprotect(0x77df9000, 2093056, PROT_NONE) = 0
> > mmap(0x77ff8000, 4096, PROT_READ|PROT_WRITE,
> MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1000) = 0x77ff8000
> > 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", 0x7fffb940) = -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", 0x7fffb940) = -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", 0x7fffb940) = -1 ENOENT (No
> such file or dir

Re: [Nix-dev] Static Executable: Patchelf fails me

2015-01-04 Thread Moritz Ulrich

Sorry for mangling the lines. I blame Emacs.

Moritz Ulrich  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(0x70, 2415740, PROT_READ|PROT_WRITE|PROT_EXEC, 
> MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, 0, 0) = 0x70
> readlink("/proc/self/exe", "/home/moritz/downloads/s3d/s3d.r"..., 4096) = 34
> mmap(0x40, 2420736, PROT_NONE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 
> 0) = 0x40
> mmap(0x40, 1235252, PROT_READ|PROT_WRITE|PROT_EXEC, 
> MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x40
> mprotect(0x40, 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_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)  = 0x55777000
> 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(0x30, 1511424, PROT_READ|PROT_EXEC, 
> MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0) = 0x30
> mmap(0x64e000, 4096, PROT_READ|PROT_WRITE, 
> MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x14e000) = 0x64e000
> mprotect(0x7fffc000, 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) = 
> 0x77ff9000
> 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\\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) = 
> 0x77df7000
> mprotect(0x77df9000, 2093056, PROT_NONE) = 0
> mmap(0x77ff8000, 4096, PROT_READ|PROT_WRITE, 
> MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1000) = 0x77ff8000
> 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", 0x7fffb940) = -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", 0x7fffb940) = -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", 0x7fffb940) = -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", 0x7fffb940) = -1 ENOENT (No 
> such file or directory)
> open("/