Can't longer load elf executable kernel
Posted: Tue Jun 15, 2010 12:03 pm
Hi,
I've been developing a kernel in C & asm based on the skeleton kernel of the osdev tutorial.
I can run everything fine. But as i added more pieces (drivers) my executable becomes bigger
and i can not boot it directly from grub using block loading method (kernel 200+size), or
grub elf executable loading method (kernel /boot/kernel.bin).
Whenever i try to load the kernel, i always get grub error 13: Invalid or unsupported executable format.
However, the kernel.bin is indeed a valid elf executable format.
If i remove part of the kernel code to the ata driver and not linking it with ata.o; the grub boots it just fine.
I am not sure what happen, is there a restriction to the size of the elf executable?
here's my elf kernel header (without ata driver, when kernel is lean and bootable)
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: 0x101402
Start of program headers: 52 (bytes into file)
Start of section headers: 501912 (bytes into file)
Flags: 0x0
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 3
Size of section headers: 40 (bytes)
Number of section headers: 17
Section header string table index: 14
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 00100000 001000 00fd39 00 AX 0 0 16
[ 2] .rodata PROGBITS 00110000 011000 024ce0 00 A 0 0 32
[ 3] .data PROGBITS 00135000 036000 013204 00 WA 0 0 32
[ 4] .bss NOBITS 00148220 049204 0058c0 00 WA 0 0 32
[ 5] .debug_abbrev PROGBITS 00000000 049204 002d59 00 0 0 1
[ 6] .debug_info PROGBITS 00000000 04bf5d 022895 00 0 0 1
[ 7] .debug_line PROGBITS 00000000 06e7f2 003364 00 0 0 1
[ 8] .debug_frame PROGBITS 00000000 071b58 0028d4 00 0 0 4
[ 9] .debug_loc PROGBITS 00000000 07442c 003364 00 0 0 1
[10] .debug_pubnames PROGBITS 00000000 077790 001883 00 0 0 1
[11] .debug_aranges PROGBITS 00000000 079013 000420 00 0 0 1
[12] .debug_str PROGBITS 00000000 079433 0009fb 00 0 0 1
[13] .comment PROGBITS 00000000 079e2e 0009c2 00 0 0 1
[14] .shstrtab STRTAB 00000000 07a7f0 0000a5 00 0 0 1
[15] .symtab SYMTAB 00000000 07ab40 002320 10 16 169 4
[16] .strtab STRTAB 00000000 07ce60 0017c2 00 0 0 1
here's my elf kernel header (without the ata driver, when kernel is big and non-bootable)
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: 0x101f66
Start of program headers: 52 (bytes into file)
Start of section headers: 514256 (bytes into file)
Flags: 0x0
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 3
Size of section headers: 40 (bytes)
Number of section headers: 17
Section header string table index: 14
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 00100000 001000 010899 00 AX 0 0 16
[ 2] .rodata PROGBITS 00111000 012000 024dc0 00 A 0 0 32
[ 3] .data PROGBITS 00136000 037000 013224 00 WA 0 0 32
[ 4] .bss NOBITS 00149240 04a224 005920 00 WA 0 0 32
[ 5] .debug_abbrev PROGBITS 00000000 04a224 002f13 00 0 0 1
[ 6] .debug_info PROGBITS 00000000 04d137 023eed 00 0 0 1
[ 7] .debug_line PROGBITS 00000000 071024 0035b9 00 0 0 1
[ 8] .debug_frame PROGBITS 00000000 0745e0 002a9c 00 0 0 4
[ 9] .debug_loc PROGBITS 00000000 07707c 0035a0 00 0 0 1
[10] .debug_pubnames PROGBITS 00000000 07a61c 001967 00 0 0 1
[11] .debug_aranges PROGBITS 00000000 07bf83 000440 00 0 0 1
[12] .debug_str PROGBITS 00000000 07c3c3 000a65 00 0 0 1
[13] .comment PROGBITS 00000000 07ce28 000a03 00 0 0 1
[14] .shstrtab STRTAB 00000000 07d82b 0000a5 00 0 0 1
[15] .symtab SYMTAB 00000000 07db78 002420 10 16 172 4
[16] .strtab STRTAB 00000000 07ff98 00185c 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings)
I (info), L (link order), G (group), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
There are no section groups in this file.
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x001000 0x00100000 0x00100000 0x35dc0 0x35dc0 R E 0x1000
LOAD 0x037000 0x00136000 0x00136000 0x13224 0x18b60 RW 0x1000
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RWE 0x4
I've been developing a kernel in C & asm based on the skeleton kernel of the osdev tutorial.
I can run everything fine. But as i added more pieces (drivers) my executable becomes bigger
and i can not boot it directly from grub using block loading method (kernel 200+size), or
grub elf executable loading method (kernel /boot/kernel.bin).
Whenever i try to load the kernel, i always get grub error 13: Invalid or unsupported executable format.
However, the kernel.bin is indeed a valid elf executable format.
If i remove part of the kernel code to the ata driver and not linking it with ata.o; the grub boots it just fine.
I am not sure what happen, is there a restriction to the size of the elf executable?
here's my elf kernel header (without ata driver, when kernel is lean and bootable)
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: 0x101402
Start of program headers: 52 (bytes into file)
Start of section headers: 501912 (bytes into file)
Flags: 0x0
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 3
Size of section headers: 40 (bytes)
Number of section headers: 17
Section header string table index: 14
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 00100000 001000 00fd39 00 AX 0 0 16
[ 2] .rodata PROGBITS 00110000 011000 024ce0 00 A 0 0 32
[ 3] .data PROGBITS 00135000 036000 013204 00 WA 0 0 32
[ 4] .bss NOBITS 00148220 049204 0058c0 00 WA 0 0 32
[ 5] .debug_abbrev PROGBITS 00000000 049204 002d59 00 0 0 1
[ 6] .debug_info PROGBITS 00000000 04bf5d 022895 00 0 0 1
[ 7] .debug_line PROGBITS 00000000 06e7f2 003364 00 0 0 1
[ 8] .debug_frame PROGBITS 00000000 071b58 0028d4 00 0 0 4
[ 9] .debug_loc PROGBITS 00000000 07442c 003364 00 0 0 1
[10] .debug_pubnames PROGBITS 00000000 077790 001883 00 0 0 1
[11] .debug_aranges PROGBITS 00000000 079013 000420 00 0 0 1
[12] .debug_str PROGBITS 00000000 079433 0009fb 00 0 0 1
[13] .comment PROGBITS 00000000 079e2e 0009c2 00 0 0 1
[14] .shstrtab STRTAB 00000000 07a7f0 0000a5 00 0 0 1
[15] .symtab SYMTAB 00000000 07ab40 002320 10 16 169 4
[16] .strtab STRTAB 00000000 07ce60 0017c2 00 0 0 1
here's my elf kernel header (without the ata driver, when kernel is big and non-bootable)
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: 0x101f66
Start of program headers: 52 (bytes into file)
Start of section headers: 514256 (bytes into file)
Flags: 0x0
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 3
Size of section headers: 40 (bytes)
Number of section headers: 17
Section header string table index: 14
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 00100000 001000 010899 00 AX 0 0 16
[ 2] .rodata PROGBITS 00111000 012000 024dc0 00 A 0 0 32
[ 3] .data PROGBITS 00136000 037000 013224 00 WA 0 0 32
[ 4] .bss NOBITS 00149240 04a224 005920 00 WA 0 0 32
[ 5] .debug_abbrev PROGBITS 00000000 04a224 002f13 00 0 0 1
[ 6] .debug_info PROGBITS 00000000 04d137 023eed 00 0 0 1
[ 7] .debug_line PROGBITS 00000000 071024 0035b9 00 0 0 1
[ 8] .debug_frame PROGBITS 00000000 0745e0 002a9c 00 0 0 4
[ 9] .debug_loc PROGBITS 00000000 07707c 0035a0 00 0 0 1
[10] .debug_pubnames PROGBITS 00000000 07a61c 001967 00 0 0 1
[11] .debug_aranges PROGBITS 00000000 07bf83 000440 00 0 0 1
[12] .debug_str PROGBITS 00000000 07c3c3 000a65 00 0 0 1
[13] .comment PROGBITS 00000000 07ce28 000a03 00 0 0 1
[14] .shstrtab STRTAB 00000000 07d82b 0000a5 00 0 0 1
[15] .symtab SYMTAB 00000000 07db78 002420 10 16 172 4
[16] .strtab STRTAB 00000000 07ff98 00185c 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings)
I (info), L (link order), G (group), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
There are no section groups in this file.
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x001000 0x00100000 0x00100000 0x35dc0 0x35dc0 R E 0x1000
LOAD 0x037000 0x00136000 0x00136000 0x13224 0x18b60 RW 0x1000
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RWE 0x4