Kernel ELF Header - Not Present & Dynamic Linking for Module
Posted: Tue Oct 17, 2017 9:45 am
Hi OSDevers,
I am developing a OS kernel in the ELF format. I am implementing modules and required information on the kernel's symbol table to link up with the kernel modules. Understanding the ELF documentation is quite difficult for me, and I think it is a little incomplete about some things (maybe I am really wrong about this).
1. My kernel is loaded at 0xC0100000 (virtual address) and I check for the ELF magic numbers there and they aren't there. Does GRUB not write the ELF header there? Do I have to use the MULTIBOOT_ELF_SECTION type in Multiboot2.h instead of using the elf header for getting information on sections (no other information is there). Because then, I will have to write code specially for the 'core-kernel-binary'.
2. I am confused about the GOT (Global Offset Table) and PLT (Procedure Linkage Table). I have created a simple module - name KTERM. I am using GCC with -l MainKernel to (dynamically) link with the kernel. I found a relocation table using readelf. How should I locate and use the GOT and PLT to finish the linking of modules?
3. ELF Symbols - ELF32_SYMBOL contains the field 'Value' (see ELF documentation). It is the value of the symbol. Why is that needed and does it need to be bothered by my loader?
4. How do I locate the relocation table. readelf shows no DT_RELA or related tags in dynamic section. Do I use the section name ".rel.dyn" or type SHT_RELA (section type) to locate the relocation section?
5. How do I do relocation? I get what relocations are and what the entries are. I am confused by the specs in what to 'calculate'.
Thank You,
Shukant Pal
I am developing a OS kernel in the ELF format. I am implementing modules and required information on the kernel's symbol table to link up with the kernel modules. Understanding the ELF documentation is quite difficult for me, and I think it is a little incomplete about some things (maybe I am really wrong about this).
1. My kernel is loaded at 0xC0100000 (virtual address) and I check for the ELF magic numbers there and they aren't there. Does GRUB not write the ELF header there? Do I have to use the MULTIBOOT_ELF_SECTION type in Multiboot2.h instead of using the elf header for getting information on sections (no other information is there). Because then, I will have to write code specially for the 'core-kernel-binary'.
2. I am confused about the GOT (Global Offset Table) and PLT (Procedure Linkage Table). I have created a simple module - name KTERM. I am using GCC with -l MainKernel to (dynamically) link with the kernel. I found a relocation table using readelf. How should I locate and use the GOT and PLT to finish the linking of modules?
3. ELF Symbols - ELF32_SYMBOL contains the field 'Value' (see ELF documentation). It is the value of the symbol. Why is that needed and does it need to be bothered by my loader?
4. How do I locate the relocation table. readelf shows no DT_RELA or related tags in dynamic section. Do I use the section name ".rel.dyn" or type SHT_RELA (section type) to locate the relocation section?
5. How do I do relocation? I get what relocations are and what the entries are. I am confused by the specs in what to 'calculate'.
Thank You,
Shukant Pal