Page 1 of 1

Linking as elf32-i686

Posted: Sun Jun 22, 2014 3:30 pm
by therll
I've been trying to link my kernel as i686 however even running

Code: Select all

i686-elf-objdump -i
doesn't show an option to link as elf32-i686, only as elf32-i386. Is it possible to link as elf32-i686?

Re: Linking as elf32-i686

Posted: Sun Jun 22, 2014 5:28 pm
by alexfru
Is objdump even supposed to link anything?

What's the difference between elf32-i386 and elf32-i686? I'm working on an ELF linker and I can't recall there being multiple 32-bit x86 formats.

Re: Linking as elf32-i686

Posted: Sun Jun 22, 2014 5:31 pm
by Nessphoro
Well, are you using a cross-compiler? If so then you should recompile your toolchain for i686.

Re: Linking as elf32-i686

Posted: Sun Jun 22, 2014 5:39 pm
by therll
@alexfru objdump can list the available formats just like ld. And I don't know if elf32-i686 exists but since i686 and i386 are different I assume it does.
@Nessphoro I am using a cross compiler for i686-elf which is why I'm confused about why I have to link as elf32-i386.

Re: Linking as elf32-i686

Posted: Sun Jun 22, 2014 6:32 pm
by thepowersgang
Actually, the only option is elf32-i386 because that's the name used for elf32 for 32-bit intel machines. This format can contain any code you want (targeting i386, i686, or even x86-64)

Re: Linking as elf32-i686

Posted: Sun Jun 22, 2014 6:45 pm
by sortie
elf32-i386 is a BFD target. This is distinct from i686-elf which is a Target Triplet. The BFD target here is a container format, the same container format is used for all the ix86-elf targets. Thus there is no elf32-i486 / elf32-i586 / elf32-i686 and such. i386-elf and i686-elf is basically the same thing, except i686-elf has a few more instructions enabled by default I'd assume. However, the same BFD target is used for both of them. Thus you use the i686-elf target triplet but the elf32-i386 bfd target.

Actually, elf32-i386 isn't usable for x86_64 in general due to pointers being larger and the fact it would confuse the hell out of debugging tools. Though, if all the addresses are below 4 GiB and you accept debugging stuff will be confused, you can convert a elf64-x86_64 (or whatever is it called, I forgot) into a elf32-i386 container. I actually do that when feeding GRUB my x86-64 kernel as a 32-bit kernel.