- Used command: readelf -lWS -------------------------------------------------------------------------------------------- - (1) The original layout -------------------------------------------------------------------------------------------- Section Headers: [Nr] Name Type Address Off Size ES Flg Lk Inf Al [ 0] NULL 0000000000000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 0000000000100000 001000 017717 00 WAX 0 0 4096 <--- .text section has 0x1000 offset and begins with multiboot, which is fine because < 0x2000 [ 2] .uk_ctortab PROGBITS 0000000000118000 019000 000004 00 WA 0 0 1 [ 3] .rodata PROGBITS 0000000000119000 01a000 002cf2 00 A 0 0 32 [ 4] .tbss NOBITS 000000000011bcf8 01ccf2 001008 00 WAT 0 0 4 [ 5] .data PROGBITS 000000000011c000 01d000 000080 00 WA 0 0 32 [ 6] .got.plt PROGBITS 000000000011c080 01d080 000018 08 WA 0 0 8 [ 7] .bss NOBITS 000000000011d000 01d098 016000 00 WA 0 0 32 [ 8] .comment PROGBITS 0000000000000000 01d098 00002d 01 MS 0 0 1 [ 9] .shstrtab STRTAB 0000000000000000 01d0c5 000048 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), I (info), L (link order), O (extra OS processing required), G (group), T (TLS), C (compressed), x (unknown), o (OS specific), E (exclude), l (large), p (processor specific) Elf file type is EXEC (Executable file) Entry point 0x107cf3 There are 3 program headers, starting at offset 64 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align LOAD 0x001000 0x0000000000100000 0x0000000000100000 0x01c098 0x033000 RWE 0x1000 <--- First segment has 0x1000 alignment TLS 0x01ccf2 0x000000000011bcf8 0x000000000011bcf8 0x000000 0x001008 R 0x4 GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RWE 0x10 Section to Segment mapping: Segment Sections... 00 .text .uk_ctortab .rodata .data .got.plt .bss 01 .tbss 02 -------------------------------------------------------------------------------------------- - (2) After we align cpu_intr_stack to 0x10000, multiboot is moved beyond 0x2000 -------------------------------------------------------------------------------------------- Section Headers: [Nr] Name Type Address Off Size ES Flg Lk Inf Al [ 0] NULL 0000000000000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 0000000000100000 010000 017717 00 WAX 0 0 4096 <--- .text section has 0x10000 offset, but now multiboot is at > 0x2000 [ 2] .uk_ctortab PROGBITS 0000000000118000 028000 000004 00 WA 0 0 1 [ 3] .rodata PROGBITS 0000000000119000 029000 002cf2 00 A 0 0 32 [ 4] .tbss NOBITS 000000000011bcf8 02bcf2 001008 00 WAT 0 0 4 [ 5] .data PROGBITS 000000000011c000 02c000 000080 00 WA 0 0 32 [ 6] .got.plt PROGBITS 000000000011c080 02c080 000018 08 WA 0 0 8 [ 7] .bss NOBITS 0000000000120000 02c098 021000 00 WA 0 0 65536 <-- .bss new 0x10000 alignment [ 8] .comment PROGBITS 0000000000000000 02c098 00002d 01 MS 0 0 1 [ 9] .shstrtab STRTAB 0000000000000000 02c0c5 000048 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), I (info), L (link order), O (extra OS processing required), G (group), T (TLS), C (compressed), x (unknown), o (OS specific), E (exclude), l (large), p (processor specific) Elf file type is EXEC (Executable file) Entry point 0x107cf3 There are 3 program headers, starting at offset 64 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align LOAD 0x010000 0x0000000000100000 0x0000000000100000 0x01c098 0x041000 RWE 0x10000 <--- First segment has 0x10000 (> 0x1000) alignment TLS 0x02bcf2 0x000000000011bcf8 0x000000000011bcf8 0x000000 0x001008 R 0x4 GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RWE 0x10 Section to Segment mapping: Segment Sections... 00 .text .uk_ctortab .rodata .data .got.plt .bss 01 .tbss 02 -------------------------------------------------------------------------------------------- - (3) We keep cpu_intr_stack aligned to 0x10000, but try to move multiboot info in a - section of its own, putting it before .text section in the linker file. -------------------------------------------------------------------------------------------- Section Headers: [Nr] Name Type Address Off Size ES Flg Lk Inf Al [ 0] NULL 0000000000000000 000000 000000 00 0 0 0 [ 1] .multiboot PROGBITS 0000000000000000 01d098 000020 00 0 0 4 <-- It has a bad offset, 0x1d098, because we cannot control the offset inside binary at this stage [ 2] .text PROGBITS 0000000000100000 001000 017717 00 WAX 0 0 4096 [ 3] .uk_ctortab PROGBITS 0000000000118000 019000 000004 00 WA 0 0 1 [ 4] .rodata PROGBITS 0000000000119000 01a000 002cf2 00 A 0 0 32 [ 5] .tbss NOBITS 000000000011bcf8 01ccf2 001008 00 WAT 0 0 4 [ 6] .data PROGBITS 000000000011c000 01d000 000080 00 WA 0 0 32 [ 7] .got.plt PROGBITS 000000000011c080 01d080 000018 08 WA 0 0 8 [ 8] .bss NOBITS 000000000011d000 01d098 016000 00 WA 0 0 32 [ 9] .comment PROGBITS 0000000000000000 01d0b8 00002d 01 MS 0 0 1 [10] .shstrtab STRTAB 0000000000000000 01d0e5 000053 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), I (info), L (link order), O (extra OS processing required), G (group), T (TLS), C (compressed), x (unknown), o (OS specific), E (exclude), l (large), p (processor specific) Elf file type is EXEC (Executable file) Entry point 0x107cf3 There are 3 program headers, starting at offset 64 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align LOAD 0x001000 0x0000000000100000 0x0000000000100000 0x01c098 0x033000 RWE 0x1000 TLS 0x01ccf2 0x000000000011bcf8 0x000000000011bcf8 0x000000 0x001008 R 0x4 GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RWE 0x10 Section to Segment mapping: Segment Sections... 00 .text .uk_ctortab .rodata .data .got.plt .bss 01 .tbss 02 -------------------------------------------------------------------------------------------- - (4) We move cpu_intr_stack to .intrstack section -------------------------------------------------------------------------------------------- Section Headers: [Nr] Name Type Address Off Size ES Flg Lk Inf Al [ 0] NULL 0000000000000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 0000000000100000 001000 017717 00 WAX 0 0 4096 [ 2] .uk_ctortab PROGBITS 0000000000118000 019000 000004 00 WA 0 0 1 [ 3] .rodata PROGBITS 0000000000119000 01a000 002cf2 00 A 0 0 32 [ 4] .tbss NOBITS 000000000011bcf8 01ccf2 001008 00 WAT 0 0 4 [ 5] .data PROGBITS 000000000011c000 01d000 000080 00 WA 0 0 32 [ 6] .got.plt PROGBITS 000000000011c080 01d080 000018 08 WA 0 0 8 [ 7] .bss NOBITS 000000000011d000 01d098 006000 00 WA 0 0 32 [ 8] .intrstack PROGBITS 0000000000130000 020000 010000 00 WA 0 0 65536 [ 9] .comment PROGBITS 0000000000000000 030000 00002d 01 MS 0 0 1 [10] .shstrtab STRTAB 0000000000000000 03002d 000053 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), I (info), L (link order), O (extra OS processing required), G (group), T (TLS), C (compressed), x (unknown), o (OS specific), E (exclude), l (large), p (processor specific) Elf file type is EXEC (Executable file) Entry point 0x107cf3 There are 4 program headers, starting at offset 64 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align LOAD 0x001000 0x0000000000100000 0x0000000000100000 0x01c098 0x023000 RWE 0x1000 LOAD 0x020000 0x0000000000130000 0x0000000000130000 0x010000 0x010000 RW 0x10000 TLS 0x01ccf2 0x000000000011bcf8 0x000000000011bcf8 0x000000 0x001008 R 0x4 GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RWE 0x10 Section to Segment mapping: Segment Sections... 00 .text .uk_ctortab .rodata .data .got.plt .bss 01 .intrstack 02 .tbss 03