[Nix-dev] patchelf on statically linked executables

Mathijs Kwik mathijs at bluescreen303.nl
Tue Dec 11 15:24:58 CET 2012


readelf output here: https://gist.github.com/4258922
binaries themselves (32/64) are available at: http://phantomjs.org/download.html

On Tue, Dec 11, 2012 at 3:16 PM, Eelco Dolstra
<eelco.dolstra at logicblox.com> wrote:
> Hi,
>
> On 11/12/12 15:06, Mathijs Kwik wrote:
>
>> 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)
>
> Eh.  It's using ld-linux-x86-64.so.2, which is rather strange for a supposedly
> statically linked program.  Maybe you can put the output of "readelf -a" somewhere?
>
>> 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.
>
> This does suggest a broken binary since the e_shstrndx header field refers to a
> non-existent section (that's "Section header string table index" in the readelf
> output BTW).
>
> --
> --
> Eelco Dolstra | LogicBlox, Inc. | http://nixos.org/~eelco/
> _______________________________________________
> nix-dev mailing list
> nix-dev at lists.science.uu.nl
> http://lists.science.uu.nl/mailman/listinfo/nix-dev


More information about the nix-dev mailing list