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.
Hey,
I'm trying to link my 64bit kernel. When the kernel laid at 0xF0100000 virtual address the relocation problem
solved with -mcmodel=large flag. But now I decided to change memory layout and place the kernel
at 0xFFFFFE0000000000 (~2TB). The relocation errors appeared again. Here's part of my linker script:
bootentry section(entry.o) contains code that setup long mode environment and jumps to kernel address.
What can cause the relocation troubles here?
Thanks!
ern/printf.c:25: relocation truncated to fit: R_X86_64_32 against `.text'
obj/kern/printf.o: In function `putch':
kern/printf.c:18: relocation truncated to fit: R_X86_64_32 against symbol `vcprintf' defined in .text section in obj/kern/printf.o
kern/printf.c:18: relocation truncated to fit: R_X86_64_32 against symbol `cprintf' defined in .text section in obj/kern/printf.o
kern/printf.c:18: relocation truncated to fit: R_X86_64_32 against `.text'
kern/printf.c:18: relocation truncated to fit: R_X86_64_32 against `.text'
obj/kern/picirq.o: In function `dummyfunc':
./inc/x86.h:99: relocation truncated to fit: R_X86_64_32 against `.text'
obj/kern/picirq.o: In function `pic_init':
kern/picirq.c:68: relocation truncated to fit: R_X86_64_32 against symbol `irq_eoi' defined in .text section in obj/kern/picirq.o
kern/picirq.c:68: relocation truncated to fit: R_X86_64_32 against `.text'
kern/picirq.c:68: relocation truncated to fit: R_X86_64_32 against `.text'
kern/picirq.c:68: relocation truncated to fit: R_X86_64_32 against symbol `dummyfunc' defined in .text section in obj/kern/picirq.o
kern/picirq.c:68: relocation truncated to fit: R_X86_64_32 against `.text'
kern/picirq.c:68: relocation truncated to fit: R_X86_64_32 against `.text'
kern/picirq.c:68: relocation truncated to fit: R_X86_64_32 against symbol `irq_setmask_8259A' defined in .text section in obj/kern/picirq.o
kern/picirq.c:68: relocation truncated to fit: R_X86_64_32 against `.text'
kern/picirq.c:68: relocation truncated to fit: R_X86_64_32 against `.text'
kern/picirq.c:68: relocation truncated to fit: R_X86_64_32 against symbol `pic_init' defined in .text section in obj/kern/picirq.o
kern/picirq.c:68: relocation truncated to fit: R_X86_64_32 against `.text'
kern/picirq.c:68: relocation truncated to fit: R_X86_64_32 against `.text'
kern/picirq.c:68: relocation truncated to fit: R_X86_64_32 against `.bss'
kern/picirq.c:68: relocation truncated to fit: R_X86_64_32 against `.text'
obj/kern/printfmt.o: In function `printnum':
lib/printfmt.c:51: relocation truncated to fit: R_X86_64_32 against `.text'
obj/kern/printfmt.o: In function `vprintfmt':
lib/printfmt.c:106: relocation truncated to fit: R_X86_64_32 against `.text'
lib/printfmt.c:195: relocation truncated to fit: R_X86_64_32 against `.text'
lib/printfmt.c:220: relocation truncated to fit: R_X86_64_32 against `.text'
lib/printfmt.c:224: relocation truncated to fit: R_X86_64_32 against symbol `vprintfmt' defined in .text section in obj/kern/printfmt.o
obj/kern/printfmt.o: In function `printfmt':
lib/printfmt.c:307: relocation truncated to fit: R_X86_64_32 against symbol `vsnprintf' defined in .text section in obj/kern/printfmt.o
XenOS wrote:Are you possibly trying to jump from 32 bit code to some high 64 bit address?
I have a small .code64 stub in my entry file, which does that:
Apparently it still consistently uses 32-bit addresses to something that requires them to be 64-bit
Older GCC manual wrote:-mcmodel=large
Generate code for the large model: This model makes no assumptions about addresses and sizes of sections. Currently GCC does not implement this model.
What's your GCC version? (and post the entire command line for compilation while you're at it)
"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 ]
Combuster wrote:Currently GCC does not implement this model.
?
EDIT: I've tried with latest binutils/gcc. Same result. I'd be thankful for some ideas or your working examples like
ld script, long mode switch code, gcc/ld flags.
.rela.stab section relocation type seems to be 32bit. How can I force GCC to generate relocation type of R_X86_64_64?
Recall, -m64 -mcmode=large already there....
Relocation section '.rela.stab' at offset 0x1fc8 contains 5 entries:
Offset Info Type Sym. Value Sym. Name + Addend
000000000014 00020000000a R_X86_64_32 0000000000000000 .text + 0
0000000003ec 000a0000000a R_X86_64_32 0000000000000000 is_bootstrap + 0
Very helpful update!
The stabs debug format (IIRC) only has 32 bits of relocation. For 64-bit code, you definitely want dwarf debug information. (And nowadays, I'd use dwarf for 32-bit code too, it's just that much richer.)
I think the option is -gdwarf2, but you should check the gcc docs. This should replace -gstabs on your compilation line.
Thanks a lot for respond! How this will affect the output file format? It still will be "elf"ish with
only "dwarf"ish stab section? It's important, because I have my own bootloader.
Now I feel a little silly about my previous question . Worked like a charm! Now I can see properly linked kernel file.
Still need to figure out how to deal with new sections of dwarf (facing him first time), but It's a matter of time.