ELF64 RELA with type R_X86_64_PLT32

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
Kieran
Member
Member
Posts: 54
Joined: Mon Apr 11, 2005 11:00 pm

ELF64 RELA with type R_X86_64_PLT32

Post by Kieran »

Hi guys,

Im having some trouble with loading a Relocatable ELF64...

At the moment GRUB loads my ELF64 Loader and the 64 bit ELF kernel as a module.
The ELF64 Loader then proceeds to locate the kernel_main symbol whils also going through any RELA section and applying any relocations.

I know my Kernel shouldnt need anything from the ELF64 Loader, but I have put in some undefined functions to test the loader.

However, all of my undefined symbols have a type of 0x4 (R_X86_64_PLT32).

I cannot find any info on how to handle a symbol of this type and my kernel has no .*.plt.

Im just wandering if anyone has any information that may help me.

EDIT: It seems a few more minutes spent googling and I found the answer, however Id still like any info regarding to the above :P
The fix was to compile the kernel with '-mcmodel=kernel' :D
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: ELF64 RELA with type R_X86_64_PLT32

Post by gerryg400 »

There is a small amount of info in http://www.x86-64.org/documentation/abi.pdf. I guess you have this though.
If a trainstation is where trains stop, what is a workstation ?
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: ELF64 RELA with type R_X86_64_PLT32

Post by Candy »

I very recently found out you may have parts of your plt (what's usually in the plt) inlined into the code if it's used only once. So you don't have a .plt section but there may still be a little bit of plt... :-)
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: ELF64 RELA with type R_X86_64_PLT32

Post by xenos »

A very useful source of information about relocations is the Sun Linker and Libraries Guide. In chapter 7 you find a lot of information about the ELF format, both 32 and 64 bit, and some tables containing relocation types. Table 7-16 should contain the information you are looking for (x86_64 relocation types).

Just out of curiosity: What is your kernel's base address? Mine is located at 0xffffc00000000000 (= the topmost quarter of virtual memory) and uses -mcmodel=huge in order to avoid confusion with 32 bit relocations.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
Kieran
Member
Member
Posts: 54
Joined: Mon Apr 11, 2005 11:00 pm

Re: ELF64 RELA with type R_X86_64_PLT32

Post by Kieran »

@Candy - OK, I see.. But then how does one do a plt based relocation without the plt, not that I know how to do a plt relocation.

@XenOS - Thanks for the pointer, I shall take a look at it. Im currently compiling with the GCC '-r' oprion and '-mc-model=kernel', Ill try '-mc-model=huge' and see if it still results in non-plt relocations.

NOTE: Oops no '-mc-model=huge' in 64 Bit

I'm going to simplify the 2nd Stage ELF64 Loader and work on expanding it for Kernel use because, as I stated before my kernel will not need linking to the loader. But, I'm still wandering if I should build with '-r' or specify a base...

I assume that just using a relocatable code or maybe position independant code would be the best way forward.
Post Reply