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.
I met a problem on ldscript.
- Pype.Clicker
- 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.
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
Re:I met a problem on ldscript.
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.Pype.Clicker wrote: that sounds like the linker trying to write a 64-bit value in a instruction where 32-bit offset were expected.
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?I suggest you run objdump on your .o files to see if you might be missing a section,
How did you know?since from your linker script, it seems you're not planning to have your kernel requiring >4GB of virtual memory
- Pype.Clicker
- 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.
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 ) .I set -mcmodel option to medium and the problem never appeared again ;DPype.Clicker wrote: .rodata ?