Page 1 of 1

elf files

Posted: Tue May 23, 2006 5:00 am
by FlashBurn
I moved my kernel from flat binary to the elf format, because I want add modules. Now I have the problem that I cannot take the image of the kernel 1:1 for the tables and sections, because the .bss section is where all the other section and tables are in memory.

Is there a way to link an elf object file so that the .text, .data and .bss section come behind the other sections? - this would only be a solution for the kernel, for programs I have to find another -

How do you work with elf files, especialy shared libs and where do you put the needed sections for linking with shared libs?

Re:elf files

Posted: Tue May 23, 2006 5:28 am
by xenos
I think you can use a linker script similar to this one:

Code: Select all

SECTIONS {
  .bss 0x00100000 :{
    *(.common)
    *(.bss*)
    *(.gnu.linkonce.b.*)
  }

  .text :{
    *(.text)
    *(.text.*)
      *(.stub)
    *(.rodata*)
    *(.gnu.linkonce.t.*)
      *(.gnu.linkonce.r.*)
      *(.gcc_except_table)
      *(.eh_frame)
  }

  .data :{
    *(.data*)
    *(.gnu.linkonce.d.*)
  }
}
This should place the segments in order bss - text - data.

I also use elf for my kernel but it does not have any sections for linking it with other modules. Instead, every boot module has an entry point and is executed in the boot process. It can determine the kernel entry points via some kind of system call (like interrupt or syscall). If it serves as a shared library, it uses another system call to make its entry points available to the kernel.

Re:elf files

Posted: Tue May 23, 2006 7:15 am
by FlashBurn
I?ve also thought about another method for modules, but at some point I have to write a runtime linker and why not using it for the kernel modules!?

With your linker script I would have the problem that I then have to move the sections and for that I have to parse the elf file in my loader, so I only load the file and jumo to the beginning and it?s working! I only need the tables for linking modules into the kernel!

So I need a way to save the tables at a good place. I thought that I could use an elf file like it is and let it so in memory w/o moving data and saving the tables for later use!

Re:elf files

Posted: Tue May 23, 2006 11:58 pm
by xenos
In that case you should redesign your bootloader instead of your kernel elf file. (I didn't see the point because I use grub, which does not load the elf file 1:1.) Your bootloader needs to read the section tables and interpret them, so it can place all sections where they belong, reserve space for them (.bss) etc. If you need the linking information, it should also put it somewhere your kernel can find it.

Another way is to treat the kernel similar to an ordinary executable and use the bootloader to load and link the kernel and all modules.

Re:elf files

Posted: Wed May 24, 2006 1:14 am
by FlashBurn
I will let it so that my bootloader only loads the file and jumps to the begining of the code. Then the kernel will parse the elf structure and will save the table for later use!