Skip to content

patchelf fails to --set-interpreter for executable with section headers near start #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ttuegel opened this issue Sep 3, 2014 · 0 comments · Fixed by #39
Closed

Comments

@ttuegel
Copy link
Member

ttuegel commented Sep 3, 2014

The following command fails on an executable I am trying to patch to run on NixOS:

$ patchelf --set-interpreter /nix/store/ywxpkmy9kagcsvbjjhi46pr4xwpd6sfm-glibc-2.19/lib/ld-linux-x86-64.so.2 --debug server 
patching ELF file `server'
replacing section `.interp' with size 80
this is an executable
using replaced section `.interp'
last replaced is 1
looking at section `.interp'
first reserved offset/addr is 0xc00/0x400c00
first page is 0x400000
patchelf: patchelf.cc:693: void ElfFile<Elf_Ehdr, Elf_Phdr, Elf_Shdr, Elf_Addr, Elf_Off, Elf_Dyn, Elf_Sym>::rewriteSectionsExecutable() [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 `(off_t) rdi(hdr->e_shoff) >= startOffset' failed.

I think the assertion is here.

Here are the headers:

$ readelf -e server                                                               
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x41c9f6
  Start of program headers:          64 (bytes into file)
  Start of section headers:          456 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         7
  Size of section headers:           64 (bytes)
  Number of section headers:         22
  Section header string table index: 13

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .interp           PROGBITS         0000000000400be4  00000be4
       000000000000001c  0000000000000000   A       0     0     1
  [ 2] .got              PROGBITS         0000000000707000  00307000
       0000000000000008  0000000000000008  WA       0     0     8
  [ 3] .got.plt          PROGBITS         0000000000707008  00307008
       0000000000000098  0000000000000008  WA       0     0     8
  [ 4] .dynsym           DYNSYM           0000000000705f50  00305f50
       00000000000001f8  0000000000000018   A       5     0     8
  [ 5] .dynstr           STRTAB           0000000000705c90  00305c90
       0000000000000140  0000000000000000   A       0     0     1
  [ 6] .gnu.version      VERSYM           00000000007059d8  003059d8
       000000000000002a  0000000000000002   A       4     0     2
  [ 7] .gnu.version_r    VERNEED          0000000000705a08  00305a08
       0000000000000040  0000000000000000   A       5     2     8
  [ 8] .rela.plt         RELA             0000000000705dd0  00305dd0
       0000000000000180  0000000000000018   A       4     9     8
  [ 9] .plt              PROGBITS         0000000000705b80  00305b80
       0000000000000110  0000000000000010  AX       0     0     4
  [10] .hash             HASH             0000000000705a48  00305a48
       0000000000000074  0000000000000004   A       4     0     8
  [11] .rela             RELA             00000000007059c0  003059c0
       0000000000000018  0000000000000018   A       4     0     8
  [12] .dynamic          DYNAMIC          00000000007070a0  003070a0
       0000000000000130  0000000000000010  WA       5     0     8
  [13] .shstrtab         STRTAB           0000000000000000  00305ac0
       00000000000000bd  0000000000000000           0     0     1
  [14] .text             PROGBITS         0000000000400c00  00000c00
       0000000000189780  0000000000000000  AX       0     0     8
  [15] .rodata           PROGBITS         000000000058a380  0018a380
       000000000017b640  0000000000000000   A       0     0     8
  [16] .gosymtab         PROGBITS         00000000007059c0  003059c0
       0000000000000000  0000000000000000   A       0     0     8
  [17] .gopclntab        PROGBITS         00000000007059c0  003059c0
       0000000000000000  0000000000000000   A       0     0     8
  [18] .noptrdata        PROGBITS         00000000007071d0  003071d0
       000000000000fd38  0000000000000000  WA       0     0     8
  [19] .data             PROGBITS         0000000000716f08  00316f08
       0000000000007888  0000000000000000  WA       0     0     8
  [20] .bss              NOBITS           000000000071e790  0031e790
       0000000000012bb0  0000000000000000  WA       0     0     8
  [21] .noptrbss         NOBITS           0000000000731340  00331340
       0000000002009e00  0000000000000000  WA       0     0     8
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), l (large)
  I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  PHDR           0x0000000000000040 0x0000000000400040 0x0000000000400040
                 0x0000000000000188 0x0000000000000188  R E    1000
  INTERP         0x0000000000000be4 0x0000000000400be4 0x0000000000400be4
                 0x000000000000001c 0x000000000000001c  R      1
      [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
  LOAD           0x0000000000000040 0x0000000000400040 0x0000000000400040
                 0x0000000000306108 0x0000000000306108  R E    1000
  LOAD           0x0000000000307000 0x0000000000707000 0x0000000000707000
                 0x0000000000017790 0x0000000002034140  RW     1000
  DYNAMIC        0x00000000003070a0 0x00000000007070a0 0x00000000007070a0
                 0x0000000000000130 0x0000000000000130  RW     8
  TLS            0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000010  R      8
  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000  RW     8

 Section to Segment mapping:
  Segment Sections...
   00     
   01     .interp 
   02     .interp .dynsym .dynstr .gnu.version .gnu.version_r .rela.plt .plt .hash .rela .shstrtab .text .rodata .gosymtab .gopclntab 
   03     .got .got.plt .dynamic .noptrdata .data .bss .noptrbss 
   04     .dynamic 
   05     
   06

Has anyone encountered this before? Is there a workaround? Please let me know if there's anything else I need to do to debug the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant