[Nix-dev] Static Executable: Patchelf fails me

Eelco Dolstra eelco.dolstra at logicblox.com
Mon Jan 5 11:40:49 CET 2015


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

> $ 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

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/

More information about the nix-dev mailing list