elf files

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
FlashBurn

elf files

Post 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?
xenos

Re:elf files

Post 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.
FlashBurn

Re:elf files

Post 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!
xenos

Re:elf files

Post 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.
FlashBurn

Re:elf files

Post 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!
Post Reply