[Nix-dev] patchelf on statically linked executables

Mathijs Kwik mathijs at bluescreen303.nl
Tue Dec 11 15:06:45 CET 2012


Hi all,

I'm trying to patch a statically linked executable, but run into an error.

$ file bin/phantomjs
bin/phantomjs: ELF 64-bit LSB executable, x86-64, version 1
(GNU/Linux), statically linked, stripped

$ strace bin/phantomjs
execve("bin/phantomjs", ["bin/phantomjs"], [/* 75 vars */]) = 0
mmap(0x24f7000, 34440656, PROT_READ|PROT_WRITE|PROT_EXEC,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, 0, 0) = 0x24f7000
readlink("/proc/self/exe", "/home/mathijs/Downloads/phantomj"..., 4096) = 66
mmap(0x400000, 34566144, PROT_NONE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x400000
mmap(0x400000, 32413904, PROT_READ|PROT_WRITE|PROT_EXEC,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x400000
mprotect(0x400000, 32413904, PROT_READ|PROT_EXEC) = 0
mmap(0x22ea000, 1957120, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0x1eea000) = 0x22ea000
mprotect(0x22ea000, 1957120, PROT_READ|PROT_WRITE) = 0
mmap(0x24c8000, 191672, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x24c8000
open("/lib64/ld-linux-x86-64.so.2", O_RDONLY) = -1 ENOENT (No such
file or directory)
_exit(127)                              = ?
+++ exited with 127 +++

So this seems to fail on "open" for the dynamic loader.
I want to patch it, but it fails with some unclear error.
$ patchelf --set-interpreter
/nix/store/cj7a81wsm1ijwwpkks3725661h3263p5-glibc-2.13/lib/ld-linux-x86-64.so.2
./bin/phantomjs
patchelf: patchelf.cc:289: 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.

Does this mean the binary is somehow broken?

Thanks,
Mathijs


More information about the nix-dev mailing list