It seems that grub-mkimage generates awkward ELF files, in which
the Program
header table is at the end of the file instead of right after the
ELF header.
I know very little about ELF, but:
- This figure in ELF standard seems to indicate which is the
"normal" (not
sure if mandatory) location:
http://www.cs.ucdavis.edu/~haungs/paper/node11.html
- Our own ELF loader doesn't like phdroff > 0x2000 either, from
loader/i386/pc/multiboot.c:
/* FIXME: Should we support program headers at strange
locations? */
if (ehdr->e_phoff + ehdr->e_phnum * ehdr->e_phentsize >
MULTIBOOT_SEARCH)
return grub_error (GRUB_ERR_BAD_OS, "program header at a too
high offset");
This breaks self-boot in the LinuxBIOS target. Moving the Program
header
(see attached patch) fixed it, with no apparent drawbacks or
regressions in
any of the ELF loaders around (tested on LinuxBIOS ELF loader and
Efika OF).
I'm not completely sure of its correctness though, and would
appreciate if
someone with a better understanding of ELF can comment on it. In
particular,
I don't know if my proposed solution could overwrite valid data.
Are the
segments garanteed to always leave room for the program header, do we
have to explicitly check for that, or perhaps we need to relocate
the segments
when needed?