ELF feelings and dynamic linking in ARM linux

There are things in the ARM elf binaries that I would like to better understand.

I need to figure this out to get my assembler assembler on the ELF home server for gp2x f200. So I started by compiling this program with the crosschompiling toolchain open2x:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(){
    chdir("/usr/gp2x");
    execl("/usr/gp2x/gp2xmenu", "/usr/gp2x/gp2xmenu", NULL);
    return 0;
}

Otherwise, it looks just fine, nothing special compared to x86. In ELF headers, the Flags field is used! I found some specs of ARM elves, but no mention is made of why they are needed.

ELF Header:
  Magic:   7f 45 4c 46 01 01 01 61 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2 complement, little endian
  Version:                           1 (current)
  OS/ABI:                            ARM
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           ARM
  Version:                           0x1
  Entry point address:               0x82f8
  Start of program headers:          52 (bytes into file)
  Start of section headers:          3032 (bytes into file)
  Flags:                             0x202, has entry point, GNU EABI, software FP
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         6
  Size of section headers:           40 (bytes)
  Number of section headers:         31
  Section header string table index: 28

Now other structures are not much different from what they are on x86. It actually looks very familiar! Even the type of relocation is familiar (R_386_JUMP_SLOT vs R_ARM_JUMP_SLOT). Although here it starts strange.

Relocation section '.rel.plt' at offset 0x280 contains 4 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00010638  00000116 R_ARM_JUMP_SLOT   000082c8   abort
0001063c  00000416 R_ARM_JUMP_SLOT   000082d4   __libc_start_main
00010640  00000516 R_ARM_JUMP_SLOT   000082e0   execl
00010644  00000716 R_ARM_JUMP_SLOT   000082ec   chdir

Disassembly of section .plt:

000082b4 <.plt>:
    82b4:   e52de004    str lr, [sp, #-4]!
    82b8:   e59fe004    ldr lr, [pc, #4]    ; 82c4 <.plt+0x10>
    82bc:   e08fe00e    add lr, pc, lr
    82c0:   e5bef008    ldr pc, [lr, #8]!
    82c4:   00008368    andeq   r8, r0, r8, ror #6
    82c8:   e28fc600    add ip, pc, #0  ; 0x0
    82cc:   e28cca08    add ip, ip, #32768  ; 0x8000
    82d0:   e5bcf368    ldr pc, [ip, #872]!
    82d4:   e28fc600    add ip, pc, #0  ; 0x0
    82d8:   e28cca08    add ip, ip, #32768  ; 0x8000
    82dc:   e5bcf360    ldr pc, [ip, #864]!
    82e0:   e28fc600    add ip, pc, #0  ; 0x0
    82e4:   e28cca08    add ip, ip, #32768  ; 0x8000
    82e8:   e5bcf358    ldr pc, [ip, #856]!
    82ec:   e28fc600    add ip, pc, #0  ; 0x0
    82f0:   e28cca08    add ip, ip, #32768  ; 0x8000
    82f4:   e5bcf350    ldr pc, [ip, #848]!

Sym.Value, PLT. , , . R_ARM_JUMP_SLOT? PLT ?

    82ec:   e28fc600    add ip, pc, #0  ; 0x0
    82f0:   e28cca08    add ip, ip, #32768  ; 0x8000
    82f4:   e5bcf350    ldr pc, [ip, #848]!

0x8000, . , , , -fPIC -shared.

.. ARM?

+3
1

. ARM linux . : R_ARM_ABS32. , , .

X86 ELF , , , gcc- . .

PLT . , . , ELF.

gp2x f200 ! "system" -libc .\/

+1

Source: https://habr.com/ru/post/1734546/


All Articles