Subject: Re: ELF format questions
To: None <nigel@ind.tansu.com.au, port-mac68k@netbsd.org>
From: Matt Thomas <matt@3am-software.com>
List: port-mac68k
Date: 02/28/2001 21:35:09
At 01:30 PM 3/1/2001 +1100, nigel@ind.tansu.com.au wrote:

>         This is more of a question for the kernel list,
>but I had to unsubscribe to that (too many mailing lists).
>Sorry for the slightly off-topic nature.
>
>
>         I am trying to add ELF support to the Booter.
>Now, I have added most of the guts of load_elf() from
>libsa's loadfile.c, but there are a few aspects of an
>ELF program that I don't understand.
>
>
>         Chuck Silvers kindly provided me with an ELF kernel.
>Here is a dump of its contents:
>
>% elfdump -ecps .Macintosh/netbsd.elf | head -n90
>
>ELF Header
>   ei_magic:   { 0x7f, E, L, F }
>   ei_class:   ELFCLASS32          ei_data:      ELFDATA2MSB
>   e_machine:  EM_68K              e_version:    EV_CURRENT
>   e_type:     ET_EXEC
>   e_flags:                     0
>   e_entry:                0x2e00  e_ehsize:     52  e_shstrndx:    6
>   e_shoff:              0x1d6918  e_shentsize:  40  e_shnum:       9
>   e_phoff:                  0x34  e_phentsize:  32  e_phnum:       2
>
>Program Header[0]:
>     p_vaddr:      0x0             p_flags:    [ PF_X  PF_R ]
>     p_paddr:      0x0             p_type:     [ PT_LOAD ]
>     p_filesz:     0x1c31a7        p_memsz:    0x1c31a7
>     p_offset:     0x78            p_align:    0x8
>
>Program Header[1]:
>     p_vaddr:      0x1c51a8        p_flags:    [ PF_W  PF_R ]
>     p_paddr:      0x1c51a8        p_type:     [ PT_LOAD ]
>     p_filesz:     0x134fc         p_memsz:    0x4f7fc
>     p_offset:     0x1c3220        p_align:    0x10
>         My questions:
>
>
>1) ELF executables have two ways of describing executable stuff:
>    Program Headers and Section Headers. loadfile.c parses all of
>    the Program Headers, and some of the Section Headers (for SYMs).
>
>    Can anyone think of a reason why it would not simply parse all
>    of the Section Headers, and only process the ones that were
>    relevant to loading an executable?

Don't do that.  The PT_LOAD segments are the only things to worry
about (except for find the debug symbol table if you care about symbols).

Load the program segments, and if memsz > filesz, bzero that space.
That's it.  It's really quite simple.

>--
>| Nigel Pearson, nigel@ind.tansu.com.au | "Reality is that which,   |
>|   Telstra NW-D, Sydney, Australia.    |  when you stop believing  |
>| Office: 9206 3468    Fax:  9212 6329  |  in it, doesn't go away." |
>| Mobile: 0408 664435  Home: 9792 6998  | Philip K. Dick - 'Valis.' |

--
Matt Thomas               Internet:   matt@3am-software.com
3am Software Foundry      WWW URL:    http://www.3am-software.com/bio/matt/
Cupertino, CA             Disclaimer: I avow all knowledge of this message