i386 architecture is incompatible with i386:x86-64 output

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
User avatar
tongko
Member
Member
Posts: 26
Joined: Wed Nov 07, 2012 2:40 am
Location: Petaling Jaya, Malaysia

i386 architecture is incompatible with i386:x86-64 output

Post by tongko »

I'm running 64 bit linux mint.
I've compile 32bit nasm source code using

Code: Select all

nasm start.asm -f aout -f start.o
Then I tried to linked this using ld

Code: Select all

ld -T link.ld -o kernel start.o
The link.ld script as follow:

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
phys =  0x00100000;
SECTIONS
{
    .text phys : AT(phys)
    {
        code = .;
        *(.text)
        *(.rodata)
        . = ALIGN(4096);
    }
    .data : AT(phys + (data - code))
    {
        data = .;
        *(.data)
        . = ALIGN(4096);
    }
    .bss : AT(phys + (bss - code))
    {
        bss = .;
        *(.bss)
        . = ALIGN(4096);
    }
    end = .;
}
I got this error message:

Code: Select all

[color=#FF0000]ld: i386 architecture of input file `start.o' is incompatible with i386:x86-64 output[/color]
When I check ld man page, I thought I could use the -m option to specify emulation, but when I did a -V to list available emulation, only this few are listed:

Code: Select all

GNU ld (GNU Binutils for Ubuntu) 2.23.52.20130913
  Supported emulations:
   elf_x86_64
   elf32_x86_64
   elf_i386
   i386linux
   elf_l1om
   elf_k1om
   i386pep
   i386pe
and non of them are binary...

Question: how can I use ld to link 32 bit output with flat format using 32 bit input?
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: i386 architecture is incompatible with i386:x86-64 outpu

Post by sortie »

Discard whatever tutorial you were using and follow these community-reviewed tutorials instead that doesn't have any of these problems:

http://wiki.osdev.org/GCC_Cross-Compiler
http://wiki.osdev.org/Bare_Bones

You really want a cross-compiler to work around these issues reliably. Note that you may be able to use -m32 to convert your x86_64 compiler into a i386 compiler, but that doesn't make it a real cross-compiler for the purpose of osdev. You can use objcopy(1) (using -O binary for instance) to convert an ELF executable to a flat binary. Mind that flat binaries are stupid in the sense they don't contain any information where they are loaded and gaps in the ELF's virtual address space of no data will be long sequences of zeroes in a flat binary.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: i386 architecture is incompatible with i386:x86-64 outpu

Post by Combuster »

FAQ wrote:Your build calls "gcc" and/or "ld". That's not how you should use a compiler
You might want to make sure you read these pages before asking your next question.
"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 ]
Post Reply