0

I'm trying to compile this for Linux Arch x64, I'm trying:

section .text
global _start
_start:
        mov edx, len
        mov ecx, msg
        mov ebx, 1
        mov eax, 4
        int 0x80

        mov eax, 1
        int 0x80

section .data
msg db 'hi123', 0xa
len equ $ - msg

And

$ nasm -f elf test1.asm
$ ld -s -o test1 test1.o

But an error:

/usr/bin/ld: i386 architecture of input file `test1.o' is incompatible with i386:x86-64 output
Jodooomi
  • 369
  • 5
  • 12
  • 4
    Possible duplicate of [Use ld on 64-bit platform to generate 32-bit executable](http://stackoverflow.com/questions/30184929/use-ld-on-64-bit-platform-to-generate-32-bit-executable) – Margaret Bloom Jan 04 '17 at 16:25
  • You are telling your linker to create a 64-bit binary, but your assembly code was assembled for 32-bit. Pass the `-m elf_i386` flag to your linker. – Cody Gray - on strike Jan 04 '17 at 16:26
  • Duplicate here too http://stackoverflow.com/questions/19200333/architecture-of-i386-input-file-is-incompatible-with-i386x86-64 – Dendi Suhubdy Jan 04 '17 at 16:31

1 Answers1

0

When linking 32-bit apps on x86_64, setting emulation to elf_i386 provides the correct elf format. So, for example, if you compile an assembler app with nasm -f elf file.asm -o file.o, the link command is ld -m elf_i386 -o exename file.o.

So use this instead

nasm -f elf test1.asm
ld -m elf_i386 -o test1 test1.o
Dendi Suhubdy
  • 2,877
  • 3
  • 19
  • 20