ELF symbol loading support is added.

This commit is contained in:
okuji 2001-07-03 13:52:28 +00:00
parent 49230cb103
commit b7e8ad7e6d
5 changed files with 154 additions and 58 deletions

View file

@ -1,3 +1,9 @@
2001-07-03 OKUJI Yoshinori <okuji@gnu.org>
From Julien Bordet <julien.bordet@int-evry.fr>:
* stage2/i386-elf.h (Elf32_Shdr): New type.
* stage2/boot.c (load_image): Added ELF symbol loading support.
2001-06-22 OKUJI Yoshinori <okuji@gnu.org>
* stage2/char_io.c [STAGE1_5] (grub_strcmp): Defined, even

1
NEWS
View file

@ -36,6 +36,7 @@ New in 1.0 - XXXX-XX-XX:
`--with-configfile', so that you can load a remotely specified
configuration file automatically, like the network boot images.
* VSTa filesystem support is added.
* ELF symbol loading support is added.
New in 0.5.96 - 2000-10-04:
* New commands, "reboot" and "halt".

1
THANKS
View file

@ -41,6 +41,7 @@ Jochen Hoenicke <jochen@gnu.org>
Johannes Kroeger <hanne@squirrel.owl.de>
John Tobey <spam@john-edwin-tobey.org>
Josip Rodin <joy@cibalia.gkvk.hr>
Julien Bordet <julien.bordet@int-evry.fr>
Kalle Olavi Niemitalo <tosi@ees2.oulu.fi>
Khimenko Victor <grub@khim.sch57.msk.ru>
Klaus Reichl <klaus.reichl@alcatel.at>

View file

@ -558,7 +558,80 @@ load_image (char *kernel, char *arg, kernel_t suggested_type,
errnum = ERR_EXEC_FORMAT;
else
{
/* FIXME: load ELF symbols */
/* Load ELF symbols. */
Elf32_Shdr *shdr = NULL;
int tab_size, sec_size;
int symtab_err = 0;
mbi.syms.e.num = pu.elf->e_shnum;
mbi.syms.e.size = pu.elf->e_shentsize;
mbi.syms.e.shndx = pu.elf->e_shstrndx;
/* We should align to a 4K boundary here for good measure. */
if (align_4k)
cur_addr = (cur_addr + 0xFFF) & 0xFFFFF000;
tab_size = pu.elf->e_shentsize * pu.elf->e_shnum;
grub_seek (pu.elf->e_shoff);
if (grub_read ((char *) RAW_ADDR (cur_addr), tab_size)
== tab_size)
{
mbi.syms.e.addr = cur_addr;
shdr = (Elf32_Shdr *) mbi.syms.e.addr;
cur_addr += tab_size;
printf (", shtab=0x%x", cur_addr);
for (i = 0; i < mbi.syms.e.num; i++)
{
/* This section is a loaded section,
so we don't care. */
if (shdr[i].sh_addr != 0)
continue;
/* This section is empty, so we don't care. */
if (shdr[i].sh_size == 0)
continue;
/* Align the section to a sh_addralign bits boundary. */
cur_addr = ((cur_addr + shdr[i].sh_addralign) &
- (int) shdr[i].sh_addralign);
grub_seek (shdr[i].sh_offset);
sec_size = shdr[i].sh_size;
if (! (memcheck (cur_addr, sec_size)
&& (grub_read ((char *) RAW_ADDR (cur_addr),
sec_size)
== sec_size)))
{
symtab_err = 1;
break;
}
shdr[i].sh_addr = cur_addr;
cur_addr += sec_size;
}
}
else
symtab_err = 1;
if (mbi.syms.e.addr < RAW_ADDR(0x10000))
symtab_err = 1;
if (symtab_err)
{
printf ("(bad)");
mbi.syms.e.num = 0;
mbi.syms.e.size = 0;
mbi.syms.e.addr = 0;
mbi.syms.e.shndx = 0;
cur_addr = 0;
}
else
mbi.flags |= MB_INFO_ELF_SHDR;
}
}
}

View file

@ -1,7 +1,7 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1996 Erich Boleyn <erich@uruk.org>
* Copyright (C) 2001 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -95,6 +95,21 @@ Elf32_Ehdr;
& (h.e_ident[EI_VERSION] == EV_CURRENT) & (h.e_type == ET_EXEC) \
& (h.e_machine == EM_386) & (h.e_version == EV_CURRENT))
/* section table - ? */
typedef struct
{
Elf32_Word sh_name; /* Section name (string tbl index) */
Elf32_Word sh_type; /* Section type */
Elf32_Word sh_flags; /* Section flags */
Elf32_Addr sh_addr; /* Section virtual addr at execution */
Elf32_Off sh_offset; /* Section file offset */
Elf32_Word sh_size; /* Section size in bytes */
Elf32_Word sh_link; /* Link to another section */
Elf32_Word sh_info; /* Additional section information */
Elf32_Word sh_addralign; /* Section alignment */
Elf32_Word sh_entsize; /* Entry size if section holds table */
}
Elf32_Shdr;
/* symbol table - page 4-25, figure 4-15 */
typedef struct