Code: Select all
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: Intel 80386
Version: 0x1
Entry point address: 0xff50000c
Start of program headers: 52 (bytes into file)
Start of section headers: 4436 (bytes into file)
Flags: 0x0
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 1
Size of section headers: 40 (bytes)
Number of section headers: 3
Section header string table index: 2
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .text PROGBITS ff500000 001000 000140 00 AX 0 0 4
[ 2] .shstrtab STRTAB 00000000 001140 000011 00 0 0 1
Elf header
followed directly by the program header
~4kb of nulls
.text
followed directly by a null section header then by the .text s_header.
I've altered the binary to remove the .shstrtab and the kernel still boots.
I'm now trying to alter the binary so that the .text occurs directly after the program header, followed directly by the section headers. This renders the kernel unbootable by grub.
I'm not sure if I'm updating the header correctly or if there's actually a reason the .text is aligned at 0x1000. I would think that grub would load the .text to the physical address given and not need any alignment in the file itself?
Also, can I remove the null section header without causing problems? Ideally I just want a text section for my kernel.
Thanks
EDIT: I have now been able to relocate the .text section to occur right after the program header and still boot. The null section can also be removed. It turns out grub does need .shstrtab. I had only decreased the number of section headers before. When I actually remove the section's header and entry the kernel doesn't boot. This is a pain because it means to remove those 4kb of nulls, the entire file has to be restructured because of that worthless string table.
Does anyone know why ld puts all those nulls there in the first place? It's aparently not an issue of having to have the .text aligned in the file itself.