Page 1 of 1

Linker Starting Address

Posted: Fri Apr 22, 2011 10:48 am
by Rudster816
I cant seem to figure out why my linker is setting my base address to something seemingly random (but the same for each link). Im using the C Bare Bones linker script seen below, but when I print out the address of my kmain function, its 0x80480C1. Looking at the ELF header, the entry point is in the same range.

What can I do to it to make it so GRUB will load the kernel image at 0x100000? I have an i686-elf cross compiler\binutils setup and am using that to compile\link everything. Linker options are the same as the C Bare Bones tutorial as well (just a couple extra object files).

Code: Select all

ENTRY (loader)

SECTIONS{
    . = 0x00100000;

    .text :{
        *(.text)
    }

    .rodata ALIGN (0x1000) : {
        *(.rodata)
    }

    .data ALIGN (0x1000) : {
        *(.data)
    }

    .bss : {
        sbss = .;
        *(COMMON)
        *(.bss)
        ebss = .;
    }
}

Re: Linker Starting Address

Posted: Fri Apr 22, 2011 9:14 pm
by Rudster816
Solved this:

http://ftp.gnu.org/old-gnu/Manuals/ld-2 ... ld_16.html

I had to add a section like this to my linker script.

Code: Select all

MEMORY
{
	all (wx) : ORIGIN = 0x100000, LENGTH = 256K
}