Problem linking with GNU ld

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
deather
Posts: 5
Joined: Wed Jun 25, 2008 8:42 am

Problem linking with GNU ld

Post by deather »

Hello guys,

We've been linking our "operating system" using GNU ld, which worked well for a while.
Now, the kernel is growing up in size, and when it exceeds ~36KB, ld fails to link it:

Code: Select all

ld --print-map -o jade.krn -T misc/ld.conf source/kernel/main.o source/common/lists.o source/kernel/fpu.o source/kernel/global.o source/kernel/handlers.o source/kernel/intr.o source/kernel/kalloc.o source/kernel/memory.o source/kernel/mutex.o source/kernel/pic.o source/kernel/process.o source/kernel/segments.o source/kernel/shell/shell.o source/kernel/shell/builtin.o source/kernel/shell/exec.o source/kernel/shell/builtin_funcs.o source/kernel/syscall.o source/kernel/time.o source/kernel/intr_asm.o source/kernel/bios.o source/drivers/ata/ata.o source/drivers/fs/dir.o source/drivers/fs/init.o source/drivers/fs/open.o source/drivers/fs/read.o source/drivers/fs/unlink.o source/drivers/fs/write.o source/drivers/fs/misc.o source/drivers/fs/fstat.o source/drivers/sound/sound.o source/drivers/vga/vga.o source/drivers/vga/vga_hw.o source/drivers/kbd/kbd.o source/drivers/serial/serial.o source/ulib/ctype.o source/ulib/curses.o source/ulib/stdio.o source/ulib/string.o source/ulib/unistd.o > map
source/kernel/bios.o(.text+0x8c): In function `bioscall.n1':
: relocation truncated to fit: R_386_16 .data
*** Error code 1
A workaround is to use -Os on GCC-compiled objects, making the kernel fiting in about ~34KB. However, this won't work for a long, and of course we want to know why ld is complaining.

I've googled the error message, but I didn't find anything useful.
Here is the ld script we are using:

Code: Select all

jade-dev>cat misc/ld.conf
OUTPUT_FORMAT(binary)

SECTIONS {
        .text 0x7E00 : AT (0) { *(.text) }
        .data 0x7E00 + SIZEOF(.text) : AT (SIZEOF(.text)) { *(.data) *(.rodata*) }
        .bss : { *(.bss) *(COMMON) }
}
Any ideas?

Thanks!
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Problem linking with GNU ld

Post by Combuster »

Well, it complains about a 16-bit address not fitting (the question is why it does that near the 32K size mark rather than the 64K size)

could you post a copy of the bioscall function, as that is where LD says you do that 16-bit memory reference
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Re: Problem linking with GNU ld

Post by suthers »

ld normally gives that error message when, somewhere in your code you attempt to move a 32bit value (probably address) into a 16bit field...
Jules

edit: damn, combuster beat me...
User avatar
Candy
Member
Member
Posts: 3883
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: Problem linking with GNU ld

Post by Candy »

Combuster wrote:Well, it complains about a 16-bit address not fitting (the question is why it does that near the 32K size mark rather than the 64K size)
Because the 16-bit offsets are signed offsets.

You can probably fix it by manually putting the 16-bit files together in the linker script to make sure the jumps are within 32k. Right now, they're about the maximum distance apart.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Problem linking with GNU ld

Post by Combuster »

My mind must be really clouded today ](*,)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
deather
Posts: 5
Joined: Wed Jun 25, 2008 8:42 am

Re: Problem linking with GNU ld

Post by deather »

Hi guys,

OK, the problem was segmentation-related. There were 16-bit code in the bioscall function, which was accessing data located in another segment.

Problem fixed by putting the appropriate data in the text section, so that they stay close with the code... A bit ugly, but heh, it's as the x86 architecture... :roll:

Thanks again!

P.S.: the limit of ~34KB was due to the fact that the kernel starting address is 0x7e00, not 0x0, as shown in the ld script. ;)
Post Reply