Page 1 of 1

Include ELF symtab section in PT_LOAD segment?

Posted: Sun Feb 08, 2009 1:58 pm
by xlq
Is it possible to include an ELF symtab section in a PT_LOAD segment? Would be convenient for module loading.

Re: Include ELF symtab section in PT_LOAD segment?

Posted: Sun Feb 08, 2009 2:34 pm
by JohnnyTheDon
Take a look at the PHDR command (for linker scripts) so you can write your own program headers.

Re: Include ELF symtab section in PT_LOAD segment?

Posted: Mon Feb 09, 2009 4:24 am
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. :|

Re: Include ELF symtab section in PT_LOAD segment?

Posted: Thu Feb 12, 2009 4:53 am
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

Re: Include ELF symtab section in PT_LOAD segment?

Posted: Fri Feb 13, 2009 6:46 am
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

Re: Include ELF symtab section in PT_LOAD segment?

Posted: Fri Feb 13, 2009 10:16 am
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).