Page 1 of 1

I met a problem on ldscript.

Posted: Tue Apr 18, 2006 6:38 am
by hendric
Hi all.I wrote a simple ldscript file to generate my kernel image.But as I typed the command x86_64-pc-linux-gnu-ld -T kernel.ld -o kernel.img *.o in , a list of error messages are shown. Messages are something as bellow:
relocation truncated to fit : R_X86_64_32 against '.bss'
relocation truncated to fit : R_X86_64_32S against '.bss'

Here is my simple script:

OUTPUT_FORMAT("elf64-x86-64")
ENTRY(_start_kernel_stage1)
__image_addr__ = 0xFFC000000000+12;
SECTIONS
{
.start __image_addr__ : AT( __image_addr__ )
{
*(.start)
}
.init __image_addr__ : AT( ADDR(.start) + SIZEOF(.start) )
{
init_size = .;
*(.init)
init_size = . - init_size + 12;
}
.text : AT( ADDR(.init) + SIZEOF(.init))
{
kernel_size = .;
*(.text)
*(.data)
*(.bss)
kernel_size= . -kernel_size;

}
}

I feel crazy,any help is appreciated.
hendric.

Re:I met a problem on ldscript.

Posted: Tue Apr 18, 2006 9:00 am
by Pype.Clicker
that sounds like the linker trying to write a 64-bit value in a instruction where 32-bit offset were expected. I suggest you run objdump on your .o files to see if you might be missing a section, since from your linker script, it seems you're not planning to have your kernel requiring >4GB of virtual memory :P

Re:I met a problem on ldscript.

Posted: Wed Apr 19, 2006 12:03 am
by hendric
Pype.Clicker wrote: that sounds like the linker trying to write a 64-bit value in a instruction where 32-bit offset were expected.
Yea I do agree with you. As I ran readelf and objdump to see detail of my .o file, I found that the very location ld tried to relocate was of 4 bytes.
I suggest you run objdump on your .o files to see if you might be missing a section,
I have already run objdump and readelf to see if there is something missed,but I found none. Would you please show me a possible section?
since from your linker script, it seems you're not planning to have your kernel requiring >4GB of virtual memory :P
How did you know?

Re:I met a problem on ldscript.

Posted: Wed Apr 19, 2006 7:02 am
by Pype.Clicker
.rodata ?

Re:I met a problem on ldscript.

Posted: Thu Apr 20, 2006 6:44 am
by hendric
Pype.Clicker wrote: .rodata ?
I do not think there is any relationship between .rodata and my problem. But the problem has already been solved. As I disassembly the source of the very .o file, I found that .bss section must be relocated at lower 4G. As reading about gcc manuals, I noticed that there is an option "-mcmodel" to controll code generation. GCC sets -mcmodel to small by default,that is to say,data must be relocated at lower 2G(as my thought :P ) .I set -mcmodel option to medium and the problem never appeared again ;D