Linker Starting Address

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Rudster816
Member
Member
Posts: 141
Joined: Thu Jun 17, 2010 2:36 am

Linker Starting Address

Post 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 = .;
    }
}
Rudster816
Member
Member
Posts: 141
Joined: Thu Jun 17, 2010 2:36 am

Re: Linker Starting Address

Post 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
}
Post Reply