Page 1 of 1
Linker problem
Posted: Sat Mar 22, 2008 10:44 am
by davidv1992
When I tried to compile my kernel into a nice object file on my system I met some strange behavior of the linker stopping me from setting the location I want my compiler compiled for, and as this number is high enough to fall out of the memory-area of bochs.
Somehow somewhere a symbol/variable __executable_start is defined and it influences the startadres of the kernel (setting it to 0x80000000 and a little more) and I haven't found a simple way to overide it's value yet.
Does somebody know a solution?
Posted: Sat Mar 22, 2008 11:58 am
by jzgriffin
Could you post the gcc and ld commands that you're running? Also, the linker script.
Posted: Sat Mar 22, 2008 12:40 pm
by lukem95
This really isn't an OSDEV specific question. Plus more information would really be helpful
Posted: Sat Mar 22, 2008 1:01 pm
by davidv1992
Makefile bits for GCC and LD (using cross compiler to i386-elf, gcc version 4.1.2, binutils 2.17)
Code: Select all
...
kernel: $(OBJFILES)
@i386-elf-ld -o kernel --oformat elf32-i386 -Map kernelmap $? General/linker.ld
...
%.o: %.c Makefile
@i386-elf-gcc -Wall ... -Wstrict-prototypes -DNDEBUG -MD -MP -std=c99 -c $< -o $@
...
And the linker script
Code: Select all
ENTRY (_loader)
SECTIONS{
. = 0x00100000;
.text :{
*(.text)
}
... /*usual section stuff like data, bss, etc*/
}
Perhaps useful, part of my linker map file
Code: Select all
...
LOAD Exceptions/IOStub.o
LOAD Exceptions/exceptions.o
LOAD General/linker.ld
0x00100000 . = 0x100000
0x00100000 __executable_start = .
0x08048000 PROVIDE (__executable_start, 0x8048000)
0x08048074 . = (0x8048000 + SIZEOF_HEADERS)
...
.plt
*(.plt)
.text 0x08048080 0xb35
*(.text .stub .text.* .gnu.linkonce.t.*)
.text 0x08048080 0x67 Boot/boot.o
0x080480ba _loader
...
Just in case other sections might be needed, the zipfile contains the files above in their form as created/used in the compiling/linking proces.
[/code]
Posted: Sat Mar 22, 2008 1:10 pm
by jzgriffin
You need to be linking with -TGeneral/linker.ld, not just General/linker.ld. And, your CFLAGS aren't removing enough default GCC stuff - try this:
Code: Select all
CFLAGS := -Wall -Werror -Wno-unused-variable -Wno-unused-function -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -fno-stack-protector
Your linker script is far too simple. Try this:
Code: Select all
OUTPUT_FORMAT("elf32-i386")
ENTRY(_loader)
physical = 0x00100000;
SECTIONS
{
.text physical : AT(physical)
{
code = .;
*(.text)
*(.rodata)
. = ALIGN(4096);
}
.data : AT(physical + (data - code))
{
data = .;
*(.data)
. = ALIGN(4096);
}
.bss : AT(physical + (bss - code))
{
bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .;
}