Page 1 of 1
Reading kernel symbols from the grub header
Posted: Sun Mar 14, 2010 9:06 am
by AlfaOmega08
I need to read my kernel .symtab. Looking at the multiboot spec seems that when the bit 5 of flags, the informations below are valid for an ELF file. My flags are 0x7EF so bit 5 is enabled. I neither have a MBOOT_AOUT_KLUDGE in the multiboot header. However my info are:
Num: 0x2CA
Size: 0x28
Addr: 0x140000
Shndx: 0x2C7
I am in higher half so i translate 0x140000 to 0xC0140000. Everything I find there is a long list of 0s, while I expected to see a list of Elf section headers. Any ideas?
Re: Reading kernel symbols from the grub header
Posted: Fri Mar 19, 2010 11:00 am
by florianh80
Hi,
I've got exactly the same problem here.
Anyone here has an idea whats going wrong?
Flo
Re: Reading kernel symbols from the grub header
Posted: Fri Mar 19, 2010 1:23 pm
by torshie
You can try to edit the linker script and put the symbol table into .text section.
Change your linker script something like this:
Code: Select all
.text {
*(.text)
*(.text.*)
__symbol_start__ = .;
*(.dynsm) /* I don't know whether the symbol table is actually here. */
}
I haven't tried this, but it should work.
BTW, I'm using a second stage loader to load my kernel, so I can load whatever I want into anywhere
. The loader itself is loaded by grub. I wrote the loader because I found it was difficult to load a 64-bit higher-half kernel with grub.
Re: Reading kernel symbols from the grub header
Posted: Fri Mar 19, 2010 1:45 pm
by florianh80
First, thanks for the reply!
But i tried something like this before.
And this will double the symbol informations in the elf file, which I don't like very much.
The second problem is, it won't work like expected...
I have this section in my linker script:
Code: Select all
.text : AT(ADDR(.text) - 0xC0000000) {
*(.text)
*(.rodata)
start_ksyms = .;
*(.symtab)
end_ksyms = .;
}
But that won't do the trick.
Code: Select all
readelf -s kernel.bin | grep ksyms
372: c0106005 0 NOTYPE GLOBAL DEFAULT 1 start_ksyms
544: c0106005 0 NOTYPE GLOBAL DEFAULT 1 end_ksyms
The difference between start_ksyms and end_ksyms is zero...
Any more ideas?
P.S.: My first example Kernel used some EXPORT Macro like Linux does. That works fine, but my current project is written in C++ and I've found no suitable way to do something similar to C++ classes...
Re: Reading kernel symbols from the grub header
Posted: Fri Mar 19, 2010 2:29 pm
by florianh80
Hmm, i figured out that my grub (0.96) gives some misleading output about the symbol table location.
Look at this code snippet from the Grub Stage2 file boot.c:
Code: Select all
...
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);
...
Grub prints the address AFTER incrementing it with the size of the whole table.
And I was wondering why the address for the symtab in the multiboot structure was different from that was grub said.
I don't know if it is an error in grub, but it is not really easy to unterstand.
Flo
Re: Reading kernel symbols from the grub header
Posted: Sat Mar 20, 2010 9:14 am
by AlfaOmega08
You're right. shtab=something shows the end of the section header table. But the address found in the grub header is without the size summed.
I get shtab=0x146F90 and but the address given is 0x140000
Re: Reading kernel symbols from the grub header
Posted: Sat Mar 20, 2010 9:21 am
by florianh80
Hi,
yes, and I also figured out why there was strange data at the address where my section headers should be.
It was my mistake loading the kernel image. I load it from a floppy image like this:
But my Kernel was getting larger the last days...
With debugging stuff and things like that, it was bigger than 400*512bytes. The symbol table seems to be at the end of my ELF file and thus was not loaded.
Now everything works as expected.
Re: Reading kernel symbols from the grub header
Posted: Sat Mar 20, 2010 9:29 am
by AlfaOmega08
I'm loading the elf from a CD. The image should be loaded by GRUB without specifing any size.
Re: Reading kernel symbols from the grub header
Posted: Sat Mar 20, 2010 9:33 am
by florianh80
hmm, does
show any symbol table section? (.symtab)
Maybe you stripped it off the final kernel image.
Flo