OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 6:44 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Manufacturing ELF
PostPosted: Fri Apr 07, 2017 3:13 am 
Offline
Member
Member
User avatar

Joined: Sat Dec 31, 2016 1:43 am
Posts: 48
Location: China
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.

_________________
Doing steadfastly, or doing nil.


Top
 Profile  
 
 Post subject: Re: Manufacturing ELF
PostPosted: Fri Apr 07, 2017 4:27 am 
Offline
Member
Member
User avatar

Joined: Fri Oct 03, 2008 4:13 am
Posts: 153
Location: Ogre, Latvia, EU
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.

_________________
If something looks overcomplicated, most likely it is.


Top
 Profile  
 
 Post subject: Re: Manufacturing ELF
PostPosted: Fri Apr 07, 2017 4:58 am 
Offline
Member
Member
User avatar

Joined: Sat Dec 31, 2016 1:43 am
Posts: 48
Location: China
Dear Velko,

Velko wrote:
You need to compile your code using -mcmodel=large switch.


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?

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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 32 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group