Page 1 of 1

Including .symtab in kernels binary image

Posted: Fri Aug 12, 2016 8:02 am
by Firzen
I am trying to include the symbol table of my kernel (or at least my statically linked kernel stdlib) in its binary image, so that I can use parts of the kernel like a shared library when loading processes.

The problem is that there does not seem to be a good way to dump the symbols of an elf image to binary.
I could of course just append the original elf file to the binary kernel image, but that feels pretty wasteful.

objcopy --extract-symbol yields a file that is the same size as the original image, so that doesn't seem to help at all and read-elf doesn't seem to let me dump the binary, the best it can do is dumping a representation of the hex values in plaintext.

Will I have to write my own way of getting that information or am I missing something trivial?

Just statically linking to kernel adresses in kernel modules is not an option sadly, since I want to be able to migrate processes to user space and patch the symbols into the user space stdlib then.

Re: Including .symtab in kernels binary image

Posted: Fri Aug 12, 2016 1:03 pm
by heat
If you use a multiboot compliant bootloader, it usually loads your elf symbols as multiboot information. If you don't, one easy solution is to include your kernel image into your initrd (if you use one).

EDIT: Also you can use nm to make a System.map, like Linux does.

Re: Including .symtab in kernels binary image

Posted: Fri Aug 12, 2016 2:23 pm
by Firzen
Thank you for the advice. I will probably end up writing a small program that gives me a nicer binary representation of the nm output, but it's a great starting point.