Linker problem

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
davidv1992
Member
Member
Posts: 223
Joined: Thu Jul 05, 2007 8:58 am

Linker problem

Post 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?
jzgriffin
Member
Member
Posts: 190
Joined: Tue Sep 26, 2006 1:40 pm
Libera.chat IRC: Nokurn
Location: Ontario, CA, USA
Contact:

Post by jzgriffin »

Could you post the gcc and ld commands that you're running? Also, the linker script.
User avatar
lukem95
Member
Member
Posts: 536
Joined: Fri Aug 03, 2007 6:03 am
Location: Cambridge, UK

Post by lukem95 »

This really isn't an OSDEV specific question. Plus more information would really be helpful ;)
~ Lukem95 [ Cake ]
Release: 0.08b
Image
davidv1992
Member
Member
Posts: 223
Joined: Thu Jul 05, 2007 8:58 am

Post 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]
Attachments
linkproblem.zip
All the above files complete and zipped
(3.23 KiB) Downloaded 53 times
jzgriffin
Member
Member
Posts: 190
Joined: Tue Sep 26, 2006 1:40 pm
Libera.chat IRC: Nokurn
Location: Ontario, CA, USA
Contact:

Post 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 = .;
}
Post Reply