Irritating symbol table problem

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
ucosty
Member
Member
Posts: 271
Joined: Tue Aug 08, 2006 7:43 am
Location: Sydney, Australia

Irritating symbol table problem

Post 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?
The cake is a lie | rackbits.com
blound
Member
Member
Posts: 70
Joined: Sat Dec 01, 2007 1:36 pm

Post 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.
Craze Frog
Member
Member
Posts: 368
Joined: Sun Sep 23, 2007 4:52 am

Post 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.)
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

You can declare a label as a function using:
.type FuncName, @function

That should fix the problem.. :)
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
Post Reply