Combining two executables in one ELF file
Posted: Thu Jul 02, 2009 8:26 pm
My OS has a somewhat complex booting process, involving the kernel loading a small usermode program (called "libsys") from the initrd, executing it, removing it's own execution code, remapping the initrd to userspace, jumping to libsys, and letting libsys then execute init from the initrd. It would be easier and less redundant for me if I could have GRUB do the actual loading of libsys (no parsing the initrd or ELF file). Let's say the kernel is to be mapped at 0x100000 physical and 0xFF100000 virtual; libsys would be mapped at 0x110000 physical and 0xF8000000 virtual. GRUB would load it into physical memory and then the kernel would move it to 0xF8000000 at the end of the booting process. Could I do this without changing the names of all the ELF segments in libsys and without sharing any symbols between the two programs, but still having both in one executable file? (If so, I would be able to cut out ~300 lines from my kernel, shrinking it down to a total of ~500!)
Here's what I would like:
readelf -l kernel:
readelf -l libsys:
and in the end, it should be something like this:
Impossible, or no?
Here's what I would like:
readelf -l kernel:
Code: Select all
Elf file type is EXEC (Executable file)
Entry point 0xff10000c
There is 1 program header, starting at offset 52
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x001000 0xff100000 0x00100000 0x08000 0x31740 RWE 0x1000
Section to Segment mapping:
Segment Sections...
00 .text .data .pdata .tdata .ttext .bss
Code: Select all
Elf file type is EXEC (Executable file)
Entry point 0xf8000000
There is 1 program header, starting at offset 52
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x001000 0xf8000000 0x00110000 0x01195 0x01220 RWE 0x1000
Section to Segment mapping:
Segment Sections...
00 .text .data .bss
Code: Select all
Elf file type is EXEC (Executable file)
Entry point 0xff10000c
There are 2 program headers, starting at offset 52
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x001000 0xff100000 0x00100000 0x08000 0x31740 RWE 0x1000
LOAD 0x001000 0xf8000000 0x00110000 0x01195 0x01220 RWE 0x1000