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?
Linker problem
-
- Member
- Posts: 223
- Joined: Thu Jul 05, 2007 8:58 am
Makefile bits for GCC and LD (using cross compiler to i386-elf, gcc version 4.1.2, binutils 2.17)
And the linker script
Perhaps useful, part of my linker map file
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]
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 $@
...
Code: Select all
ENTRY (_loader)
SECTIONS{
. = 0x00100000;
.text :{
*(.text)
}
... /*usual section stuff like data, bss, etc*/
}
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
...
[/code]
- Attachments
-
- linkproblem.zip
- All the above files complete and zipped
- (3.23 KiB) Downloaded 54 times
-
- Member
- Posts: 190
- Joined: Tue Sep 26, 2006 1:40 pm
- Libera.chat IRC: Nokurn
- Location: Ontario, CA, USA
- Contact:
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:
Your linker script is far too simple. 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
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 = .;
}