Include ELF symtab section in PT_LOAD segment?

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
xlq
Member
Member
Posts: 36
Joined: Mon Dec 11, 2006 7:51 am

Include ELF symtab section in PT_LOAD segment?

Post by xlq »

Is it possible to include an ELF symtab section in a PT_LOAD segment? Would be convenient for module loading.
Marionette the flexible kernel
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: Include ELF symtab section in PT_LOAD segment?

Post by JohnnyTheDon »

Take a look at the PHDR command (for linker scripts) so you can write your own program headers.
xlq
Member
Member
Posts: 36
Joined: Mon Dec 11, 2006 7:51 am

Re: Include ELF symtab section in PT_LOAD segment?

Post by xlq »

linker.ld

Code: Select all

ENTRY(_start)
OUTPUT_FORMAT(elf32-i386)
PHDRS {
    loadable PT_LOAD FLAGS(7) ;
}
SECTIONS { 
    .text : {
        *(.text*)
    } :loadable
    .symtab : {
        *(.symtab)
    } :loadable
}
foo.c

Code: Select all

void foo(void){}
void _start(void)
{
    for (;;);
}
gcc -nostdlib -Wl,-T,linker.ld -o foo foo.c

All I get in the (only) segment is .text. :|
Marionette the flexible kernel
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Include ELF symtab section in PT_LOAD segment?

Post by JamesM »

Hi,

If you're loading a kernel module, you're acting as the static linker, not the dynamic linker. (I.e. you're acting as 'ld' on the command line, not ld.so). That means you look at section information, rather than segment information.

Sections are for linking, segments are for loading.

Cheers,

James
xlq
Member
Member
Posts: 36
Joined: Mon Dec 11, 2006 7:51 am

Re: Include ELF symtab section in PT_LOAD segment?

Post by xlq »

Yes, JamesM, I am fully aware of that. I can read the section headers of the ELF module - that's fine, since GRUB loads the entire ELF module file, headers and all.

The problem I'm having is getting the addresses of the *kernel's* symbols, to resolve the ELF module's symbols. Hence, I need the kernel's symbol table.

Therefore, if there's a way of including the *kernel's* symbol table in a PT_LOAD segment of the *kernel*, then it would be really convenient.

Sorry for the misunderstanding
Marionette the flexible kernel
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Include ELF symtab section in PT_LOAD segment?

Post by JamesM »

Grub loads your kernel's symbol table. Look at the multiboot information - you'll get a full list of section headers. (as long as you don't use the AOUT_KLUDGE).
Post Reply