LD does not output correct VMAs
Posted: Wed Feb 01, 2017 4:16 pm
Hi,
I encountered this weird issue while trying to link object files.
LD seems to only put the very first segment into the correct VMA and everything else just goes wild.
OBJ files are compiled by gcc with mcmodel=kernel.
The VMA of the kernel is (0xFFFFFFFF8000000 or -2GB)
The PMA of the kernel is (0x4000000 or 64MB)
Here is my linker script:
Here is the output of the readelf:
As you can see the linker only put the first section which is the multiboot header has expected values: VMA at 0xffffffff84000000 and PMA at 0x4000000. All the other segments seem to have wild VMA and PMAs.
Not sure if I missed something small or I'm doing something fundamentally wrong.
Thanks!
I encountered this weird issue while trying to link object files.
LD seems to only put the very first segment into the correct VMA and everything else just goes wild.
OBJ files are compiled by gcc with mcmodel=kernel.
The VMA of the kernel is (0xFFFFFFFF8000000 or -2GB)
The PMA of the kernel is (0x4000000 or 64MB)
Here is my linker script:
Code: Select all
OUTPUT_FORMAT(elf64-x86-64)
ENTRY(HAL_ENTRY_PADDR)
OUTPUT_ARCH(i386:x86-64)
SECTIONS
{
. = HAL_KERNEL_BASE_VADDR + 0x4000000;
kernel_start = .;
.multiboot_header ALIGN(0x1000) : AT(ADDR(.multiboot_header) - HAL_KERNEL_BASE_VADDR)
{
*(.multiboot_header)
}
.text ALIGN(0x1000) : AT(ADDR(.text) - HAL_KERNEL_BASE_VADDR)
{
*(.text)
}
.data ALIGN(0x1000) : AT(ADDR(.data) - HAL_KERNEL_BASE_VADDR)
{
*(.data)
*(.rodata*)
}
.bss ALIGN(0x1000) : AT(ADDR(.bss) - HAL_KERNEL_BASE_VADDR)
{
*(.bss)
*(COMMON)
}
kernel_end = .;
}
Code: Select all
Elf file type is EXEC (Executable file)
Entry point 0x80411000
There are 4 program headers, starting at offset 64
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
LOAD 0x0000000000200000 0xffffffff84000000 0x0000000004000000
0x0000000000000030 0x0000000000000030 R 200000
LOAD 0x0000000000201000 0x0000000000401000 0x0000000080401000
0x0000000000012450 0x0000000000012450 R E 200000
LOAD 0x0000000000214000 0x0000000000614000 0x0000000080614000
0x0000000000007022 0x0000000000014560 RW 200000
GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 RWE 10
Section to Segment mapping:
Segment Sections...
00 .multiboot_header
01 .text .rodata .eh_frame
02 .data .bss
03
Not sure if I missed something small or I'm doing something fundamentally wrong.
Thanks!