Page 1 of 1

Irritating symbol table problem

Posted: Thu Dec 27, 2007 10:49 pm
by ucosty
I have a working backtrace function which relies on a kernel symbol table I load using grub modules. All of this works properly. My problem lies with generating accurate symbol tables.

Code: Select all

i586-elf-objdump.exe -tC install/kernel.elf | grep .text | sort | cut -c 1-9,25- > symbols
I currently use that command to generate a list of symbols which includes the start and size of each function in the kernel. The problem is that my assembly functions have no reported size.

These functions, for background, are written in GNU AS assembly.

Code: Select all

00101ffa 000005e memory::PageController::VirtToPhys(memory::PageDirectory*, unsigned long)
00102058 000000b memory::PageController::Invalidate(unsigned long*)
00102064 000008c tasks::ProcessController::createProcess(void*, unsigned long)
001020f0 0000000 loader
0010212c 0000000 exception0
00102133 0000000 exception1
A quick look at the kernel .symtab section shows that my assembly functions are listed as NOTYPE, rather than FUNC.

Code: Select all

138: 001020f0     0 NOTYPE  GLOBAL DEFAULT    1 loader
Currently I have a workaround. I currently manually patch the symbols table with a script that replaces the 0 size value with a precalculated value

Code: Select all

sed 's/0000000 loader/0000036 loader/' <symbols > symbols.tmp
Has anybody worked out how to do this properly? More specifically has anybody figured out how to generate proper symbols for assembly functions?

Posted: Thu Dec 27, 2007 10:59 pm
by blound
i had a similar problem along time ago with nasm trying to write a single step debugger with ptrace.. nasm ( and I guess as too ) does not fill in the size.. everything I found online used scripts to do it.

I ended up (i think) reading the symbols tables ( which for this to work has to be in order? ) and subtracting the start of the next symbol with the position of the current one and using that as the size so on steps it would say like "<symbol+#>".. I do not remember if thats exactly how I did it, but if the symbols are in order of how they are in .text then it should work.

Posted: Fri Dec 28, 2007 5:45 am
by Craze Frog
These functions, for background, are written in GNU AS assembly.
You don't write "functions" in assembly, only labels. That's why it says no type. But AS has some assembler directives to fix this, I think. Just compile a C function to assembly and see how GCC did it. (gcc -S file.c.)

Posted: Fri Dec 28, 2007 7:48 am
by Brynet-Inc
You can declare a label as a function using:
.type FuncName, @function

That should fix the problem.. :)