Page 1 of 1
Accessing Symbol Table from within program
Posted: Fri Sep 12, 2008 1:06 am
by thepowersgang
I'm working on doing stack back tracing in my OS and want to be able to read the symbol table from the error handler. Is there a way of getting the address of the symbol table at compile time via a linker variable or the such?
Re: Accessing Symbol Table from within program
Posted: Fri Sep 12, 2008 1:51 am
by AJ
Hi,
What format are you using? If you are using ELF, this is quite easy and symbols will be added with LD unless you use the -s switch. Reading the headers, you need to read the string table. The symbol table then uses pointers in to the string table to provide symbol names.
With PE/COFF, I guess there must be a similar way.
Cheers,
Adam
Re: Accessing Symbol Table from within program
Posted: Fri Sep 12, 2008 3:30 am
by thepowersgang
The problem is this is my kernel so afik the ELF header is not loaded by grub. Could it be possible to use a linker script to copy the symbol table to the data section?
Re: Accessing Symbol Table from within program
Posted: Fri Sep 12, 2008 6:07 am
by Stevo14
If you are able to read files off of the disk (or floppy, wherever your kernel's ELF file is located), then you could just load the ELF file off of the disk, extract the string and symbol tables, and put them at some known address for your error handlers to find (discarding the rest of the file to save space). Alternatively, you could have grub load your kernel's ELF file as a module and do the same thing to it.