text section is located at 2M offset. If I separate multiboot and text sections (3), linker store multiboot section after text section. How to fix that problem?
Linker scripts and "x86_64-elf-readelf" outputs for executables files:
(1)
Code: Select all
ENTRY(loader)
SECTIONS
{
. = 1M;
.text BLOCK(4K) : ALIGN(4K)
{
*(.multiboot)
*(.text)
}
/* Read-only data. */
.rodata BLOCK(4K) : ALIGN(4K)
{
*(.rodata)
}
/* Read-write data (initialized) */
.data BLOCK(4K) : ALIGN(4K)
{
*(.data)
}
/* Read-write data (uninitialized) and stack */
.bss BLOCK(4K) : ALIGN(4K)
{
*(COMMON)
*(.bss)
}
}
Code: Select all
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .text PROGBITS 0000000000100000 00100000
00000000000003ac 0000000000000000 AX 0 0 4096
[ 2] .rodata PROGBITS 0000000000101000 00101000
000000000000000c 0000000000000000 A 0 0 4096
[ 3] .eh_frame PROGBITS 0000000000101010 00101010
000000000000010c 0000000000000000 A 0 0 8
[ 4] .data PROGBITS 0000000000102000 00102000
0000000000000008 0000000000000000 WA 0 0 4096
[ 5] .bss NOBITS 0000000000103000 00102008
0000000000004018 0000000000000000 WA 0 0 4096
[ 6] .comment PROGBITS 0000000000000000 00102008
0000000000000011 0000000000000001 MS 0 0 1
[ 7] .symtab SYMTAB 0000000000000000 00102020
0000000000000408 0000000000000018 8 17 8
[ 8] .strtab STRTAB 0000000000000000 00102428
00000000000001b2 0000000000000000 0 0 1
[ 9] .shstrtab STRTAB 0000000000000000 001025da
0000000000000047 0000000000000000 0 0 1
Code: Select all
ENTRY(loader)
SECTIONS
{
.text BLOCK(4K) : ALIGN(4K)
{
*(.multiboot)
*(.text)
}
/* Read-only data. */
.rodata BLOCK(4K) : ALIGN(4K)
{
*(.rodata)
}
/* Read-write data (initialized) */
.data BLOCK(4K) : ALIGN(4K)
{
*(.data)
}
/* Read-write data (uninitialized) and stack */
.bss BLOCK(4K) : ALIGN(4K)
{
*(COMMON)
*(.bss)
}
}
Code: Select all
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .text PROGBITS 0000000000000000 00200000
00000000000003ac 0000000000000000 AX 0 0 4096
[ 2] .rodata PROGBITS 0000000000001000 00201000
000000000000000c 0000000000000000 A 0 0 4096
[ 3] .eh_frame PROGBITS 0000000000001010 00201010
000000000000010c 0000000000000000 A 0 0 8
[ 4] .data PROGBITS 0000000000002000 00202000
0000000000000008 0000000000000000 WA 0 0 4096
[ 5] .bss NOBITS 0000000000003000 00202008
0000000000004018 0000000000000000 WA 0 0 4096
[ 6] .comment PROGBITS 0000000000000000 00202008
0000000000000011 0000000000000001 MS 0 0 1
[ 7] .symtab SYMTAB 0000000000000000 00202020
0000000000000408 0000000000000018 8 17 8
[ 8] .strtab STRTAB 0000000000000000 00202428
00000000000001b2 0000000000000000 0 0 1
[ 9] .shstrtab STRTAB 0000000000000000 002025da
0000000000000047 0000000000000000 0 0 1
Code: Select all
ENTRY(loader)
SECTIONS
{
. = 1M;
.multiboot :
{
*(.multiboot)
}
.text BLOCK(4K) : ALIGN(4K)
{
*(.text)
}
/* Read-only data. */
.rodata BLOCK(4K) : ALIGN(4K)
{
*(.rodata)
}
/* Read-write data (initialized) */
.data BLOCK(4K) : ALIGN(4K)
{
*(.data)
}
/* Read-write data (uninitialized) and stack */
.bss BLOCK(4K) : ALIGN(4K)
{
*(COMMON)
*(.bss)
}
}
Code: Select all
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .multiboot PROGBITS 0000000000100000 00003008
000000000000000c 0000000000000000 0 0 4
[ 2] .comment PROGBITS 0000000000000000 00003014
0000000000000011 0000000000000001 MS 0 0 1
[ 3] .text PROGBITS 0000000000001000 00001000
000000000000039c 0000000000000000 AX 0 0 4096
[ 4] .rodata PROGBITS 0000000000002000 00002000
000000000000000c 0000000000000000 A 0 0 4096
[ 5] .eh_frame PROGBITS 0000000000002010 00002010
000000000000010c 0000000000000000 A 0 0 8
[ 6] .data PROGBITS 0000000000003000 00003000
0000000000000008 0000000000000000 WA 0 0 4096
[ 7] .bss NOBITS 0000000000004000 00003008
0000000000004018 0000000000000000 WA 0 0 4096
[ 8] .symtab SYMTAB 0000000000000000 00003028
0000000000000420 0000000000000018 9 18 8
[ 9] .strtab STRTAB 0000000000000000 00003448
00000000000001b2 0000000000000000 0 0 1
[10] .shstrtab STRTAB 0000000000000000 000035fa
0000000000000052 0000000000000000 0 0 1