Page 1 of 1

i386 architecture is incompatible with i386:x86-64 output

Posted: Wed May 28, 2014 11:51 am
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?

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

Posted: Wed May 28, 2014 12:37 pm
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.

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

Posted: Wed May 28, 2014 11:08 pm
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.