I met a problem on ldscript.

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
hendric

I met a problem on ldscript.

Post 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.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:I met a problem on ldscript.

Post 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
hendric

Re:I met a problem on ldscript.

Post 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?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:I met a problem on ldscript.

Post by Pype.Clicker »

.rodata ?
hendric

Re:I met a problem on ldscript.

Post 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
Post Reply