Page 1 of 1

Problem linking with GNU ld

Posted: Wed Jul 02, 2008 10:51 am
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!

Re: Problem linking with GNU ld

Posted: Wed Jul 02, 2008 11:05 am
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

Re: Problem linking with GNU ld

Posted: Wed Jul 02, 2008 11:19 am
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...

Re: Problem linking with GNU ld

Posted: Wed Jul 02, 2008 11:46 am
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.

Re: Problem linking with GNU ld

Posted: Wed Jul 02, 2008 12:10 pm
by Combuster
My mind must be really clouded today ](*,)

Re: Problem linking with GNU ld

Posted: Thu Jul 03, 2008 1:30 am
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. ;)