$ gcc -c -o test.o test.c
$ ld -e kmain -Ttext 0x7e00 test.o -o kernel.elf
$ ld -e kmain -Ttext 0x7e00 test.o --oformat=binary -o kernel.bin
$ hexdump -Cv kernel.bin
00000000 55 48 89 e5 b8 01 00 00 00 5d c3 00 00 00 00 00 |UH.......]......|
00000010 14 00 00 00 00 00 00 00 01 7a 52 00 01 78 10 01 |.........zR..x..|
00000020 1b 0c 07 08 90 01 00 00 1c 00 00 00 1c 00 00 00 |................|
00000030 d0 ff ff ff 0b 00 00 00 00 41 0e 10 86 02 43 0d |.........A....C.|
00000040 06 46 0c 07 08 00 00 00 |.F......|
00000048
$ objdump -xd kernel.elf
kernel.elf: file format elf64-x86-64
kernel.elf
architecture: i386:x86-64, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x0000000000007e00
Program Header:
LOAD off 0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**21
filesz 0x0000000000007e48 memsz 0x0000000000007e48 flags r-x
STACK off 0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**3
filesz 0x0000000000000000 memsz 0x0000000000000000 flags rw-
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 0000000b 0000000000007e00 0000000000007e00 00007e00 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .eh_frame 00000038 0000000000007e10 0000000000007e10 00007e10 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .comment 0000002c 0000000000000000 0000000000000000 00007e48 2**0
CONTENTS, READONLY
SYMBOL TABLE:
0000000000007e00 l d .text 0000000000000000 .text
0000000000007e10 l d .eh_frame 0000000000000000 .eh_frame
0000000000000000 l d .comment 0000000000000000 .comment
0000000000000000 l df *ABS* 0000000000000000 test.c
0000000000208000 g *ABS* 0000000000000000 __bss_start
0000000000208000 g *ABS* 0000000000000000 _edata
0000000000208000 g *ABS* 0000000000000000 _end
0000000000007e00 g F .text 000000000000000b kmain
Disassembly of section .text:
0000000000007e00 <kmain>:
7e00: 55 push %rbp
7e01: 48 89 e5 mov %rsp,%rbp
7e04: b8 01 00 00 00 mov $0x1,%eax
7e09: 5d pop %rbp
7e0a: c3 retq
$ objcopy -O binary -j .text kernel.elf kernel-copy.bin
$ hexdump -Cv kernel-copy.bin
00000000 55 48 89 e5 b8 01 00 00 00 5d c3 |UH.......].|
0000000b
приходит ООМ и стреляет себе в ногу уничтожая процесс init