Request for ELF structure information
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    ausPPC
    Posts: 543 from 2007/8/6
    From: Pending...
    Can anyone recommend some reference material on how to interpret the structure of an ELF? I'd like to be able to produce a disassembly that includes any program labels that may be present.

    In my own searches for this information the documents I've found don't deal specifically enough with how ELF symbol tables relate to the various program sections.
    PPC assembly ain't so bad... ;)
  • »06.04.11 - 09:10
    Profile Visit Website
  • MorphOS Developer
    Piru
    Posts: 576 from 2003/2/24
    From: finland, the l...
    I've found readelf.c to be the best reference.
  • »06.04.11 - 11:19
    Profile
  • Just looking around
    yakumo9275
    Posts: 16 from 2008/7/3
    From: Lexington VA /...
    objdump kicks butt! :) there is libreadelf and lots of info on the elf headers around the place. www.wotsit.org etc.
    -- Stu -- [[ G4 Mini / 1.5ghz ]]
  • »06.04.11 - 13:02
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    polluks
    Posts: 783 from 2007/10/23
    From: Gelsenkirchen,...
    You can find the source of diself.e

    Code:
    DisELF 1.8 by LS 2003-07 -> "ecx.mos"
    EHDR
    BITS=32, ENDIAN=BIG, IDENT[11-15]=$00000000
    TYPE=1, MACHINE=20, VERSION=1, FLAGS=$0
    ENTRY=0, PHOFF=$0, SHOFF=$B3390
    EHSIZE=52, PHENTSIZE=0, PHNUM=0
    SHENTSIZE=40, SHNUM=6, SHSTRNDX=3
    SHDR 000 0 0 (000) 0, $0, 0, 0
    SHDR 001 .text PROGBITS ALLOC EXECINSTR 16 0 (000) 729260, $34, 0, 0
    SHDR 002 .rela.text RELA 4 12 (004) 4584, $B20E0, 1, 0
    SHDR 003 .shstrtab STRTAB 1 0 (000) 56, $B3358, 0, 0
    SHDR 004 .symtab SYMTAB 4 16 (005) 64, $B32C8, 1, 0
    SYM 000000 (000) L00000000 LOCAL NOTYPE '' 0, 0
    SYM 000001 (001) L00000000 LOCAL SECTION '' 0, 0
    SYM 000002 (001) L000B20A8 GLOBAL OBJECT '__abox__' 4, 0
    SYM 000003 (000) L00000001 GLOBAL OBJECT 'Compiled with ECX 2.2.2
    (AmigaOS,68K) Registered to Leif Salomonsson.' 0, 0
    SHDR 005 .strtab STRTAB 1 0 (000) 80, $B3308, 0, 0
    <END>


    [ Editiert durch polluks 06.04.2011 - 17:54 ]
    Pegasos II G4: MorphOS 3.9, Zalman M220W · iMac G5 12,1 17", MorphOS 3.18
    Power Mac G3: OSX 10.3 · PowerBook 5,8: OSX 10.5, MorphOS 3.18
  • »06.04.11 - 16:52
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    ausPPC
    Posts: 543 from 2007/8/6
    From: Pending...
    Thank you for your responses and suggestions. But I don't think I was clear enough about what I meant by 'produce a disassembly'... I am developing a ppc assembly debugger for which I have my own crude disassembler. I would like to make this disassembly output a bit less crude by including program labels that may still be present in the ELF. To do this, I will need to understand the ELF data structure rather than relying on someone else's program or library.

    At some point I will very likely also want to create my own ELF loader for this debugger so a language neutral explanation of ELF data structures would be very helpful as I don't like my chances of figuring this out via binary editor...

    Code:
    0000 7f454c46 01020100 00000000 00000000 .ELF............ 
    0010 00010014 00000001 00000000 00000000 ................
    0020 00000070 00000000 00340000 00000028 ...p.....4.....(
    0030 00060003 48000008 60000000 4e800020 ....H...`...N..
    0040 deadbeef 002e7379 6d746162 002e7374 Þ.¾ï..symtab..st
    0050 72746162 002e7368 73747274 6162002e rtab..shstrtab..
    0060 74657874 002e726f 64617461 00000000 text..rodata....
    0070 00000000 00000000 00000000 00000000 ................
    0080 00000000 00000000 00000000 00000000 ................
    0090 00000000 00000000 0000001b 00000001 ................
    00a0 00000006 00000000 00000034 0000000c ...........4....
    00b0 00000000 00000000 00000004 00000000 ................
    00c0 00000021 00000001 00000002 00000000 ...!............
    00d0 00000040 00000004 00000000 00000000 ...@............
    00e0 00000004 00000000 00000011 00000003 ................
    00f0 00000000 00000000 00000044 00000029 ...........D...)
    0100 00000000 00000000 00000001 00000000 ................
    0110 00000001 00000002 00000000 00000000 ................
    0120 00000160 00000050 00000005 00000004 ...`...P........
    0130 00000004 00000010 00000009 00000003 ................
    0140 00000000 00000000 000001b0 0000000e ...........°....
    0150 00000000 00000000 00000001 00000000 ................
    0160 00000000 00000000 00000000 00000000 ................
    0170 00000000 00000000 00000000 03000001 ................
    0180 00000000 00000000 00000000 03000002 ................
    0190 00000001 00000008 00000000 00000001 ................
    01a0 00000005 00000000 00000004 11000002 ................
    01b0 00666f6f 005f5f61 626f785f 5f000000 .foo.__abox__...

    Which started life rather innocently as -

    .text

    b foo

    nop

    foo: blr

    .rodata

    .global __abox__
    __abox__:
    .word 0xdeadbeef
    .type __abox__,@object
    .size __abox__,4


    See? Not much fun...
    PPC assembly ain't so bad... ;)
  • »18.05.11 - 00:05
    Profile Visit Website
  • MorphOS Developer
    Piru
    Posts: 576 from 2003/2/24
    From: finland, the l...
    Quote:

    Thank you for your responses and suggestions. But I don't think I was clear enough about what I meant by 'produce a disassembly'... I am developing a ppc assembly debugger for which I have my own crude disassembler. I would like to make this disassembly output a bit less crude by including program labels that may still be present in the ELF. To do this, I will need to understand the ELF data structure rather than relying on someone else's program or library.

    At some point I will very likely also want to create my own ELF loader for this debugger so a language neutral explanation of ELF data structures would be very helpful as I don't like my chances of figuring this out via binary editor...

    I think I understood you correctly. Since you still need to write your own code, taking inspiration from the existing source code is only sensible.

    You could of course try to read the available documentation such as
    http://www.kernel.org/doc/man-pages/online/pages/man5/elf.5.html or http://www.sco.com/developers/devspecs/gabi41.pdf (page 44 onwards) but frankly nothing quite beats the existing, proven and working example source code as a reference.

    [ Edited by Piru 18.05.2011 - 12:09 ]
  • »18.05.11 - 09:58
    Profile
  • MorphOS Developer
    itix
    Posts: 1516 from 2003/2/24
    From: Finland
    Documentations is apparently very scarce. I managed to build my own loader with a trial and error... I will be in front of my MorphOS machine in Sunday again so I can probably find some header files and such for you...
    1 + 1 = 3 with very large values of 1
  • »19.05.11 - 22:27
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    MarK
    Posts: 641 from 2004/1/25
    From: Prague, The Cz...
    Hi all,

    here comes the pdf:

    http://refspecs.freestandards.org/elf/elfspec_ppc.pdf

    it should be quite clear then...

    bye, MarK.
  • »20.05.11 - 12:22
    Profile