How to relocate ELF file to 64-bit higher address (0xFFFFFF80********) ?
I use LD to link and set Ttext to the high address but it shouts "Relocation truncated to fit: R_X86_64_32 against ***(A series of symbols even .text)". How to fix it?
EDIT: I searched almost the whole Internet and found a lot of answers saying "add gcc option -fPIC", so I tried it. However, it didn't work.
Also, I found that some of ELF relocation table items' infos are R_X86_64_32 and others are R_X86_64_64. Why the compiler creates R_X86_64_32? Will it works if there's no *_32?
Thanks for any help.
Manufacturing ELF
Manufacturing ELF
Doing steadfastly, or doing nil.
Re: Manufacturing ELF
You need to compile your code using -mcmodel=large switch.
GCC's default code model is 'small', meaning that program and its symbols must be linked in the lower 2 GiB of the address space. It generates smaller and more efficient code than 'large'. You could also use '-mcmodel=kernel' (with similar benefits), but it means you have to move your kernel even further up - to uppermost 2 GiB (0xFFFFFFFF80000000) addresses.
Take a look at the very end of x86-64 Options manual page.
GCC's default code model is 'small', meaning that program and its symbols must be linked in the lower 2 GiB of the address space. It generates smaller and more efficient code than 'large'. You could also use '-mcmodel=kernel' (with similar benefits), but it means you have to move your kernel even further up - to uppermost 2 GiB (0xFFFFFFFF80000000) addresses.
Take a look at the very end of x86-64 Options manual page.
If something looks overcomplicated, most likely it is.
Re: Manufacturing ELF
Dear Velko,
I'll be grateful if there's another help.
EDIT: If there's no option, should I compile my own NASM?
Thanks a lot for help. Now I fix it for GCC. However, make the NASM generate R_X86_64_32 in the other part of my program, the code language of which are both C and assembly, though I write [bits 64] in the code. The symbol which has got the type *_32 is extern to pass the value between C and asm. Then how to fix the rest? Is there any options like GCC?Velko wrote:You need to compile your code using -mcmodel=large switch.
I'll be grateful if there's another help.
EDIT: If there's no option, should I compile my own NASM?
Doing steadfastly, or doing nil.