2017-01-04 5 views
0

Ich versuche, das für Linux Arch x64 zu kompilieren, ich versuche:kann nicht eine einfache Anwendung kompilieren

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 

Und

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

aber einen Fehler:

/usr/bin/ld: i386 architecture of input file `test1.o' is incompatible with i386:x86-64 output 
+4

Mögliche Duplikat [Use ld auf 64-Bit-Plattform 32-Bit ausführbare Datei zu erzeugen] (http://stackoverflow.com/questions/30184929/use-ld-on -64-Bit-Plattform-zu-generieren-32-Bit-ausführbar –

+0

Sie sagen Ihrem Linker, um eine 64-Bit-Binärdatei zu erstellen, aber Ihr Assembly-Code wurde für 32-Bit zusammengestellt. Übergeben Sie das Flag "-m elf_i386" an Ihren Linker. –

+0

Duplizieren Sie auch hier http://stackoverflow.com/questions/19200333/architecture-of-i386-input-file-isincompatible-with-i386x86-64 –

Antwort

0

Beim Verknüpfen von 32-Bit-Apps auf x86_64 stellt das Festlegen der Emulation auf elf_i386 das korrekte Elf-Format bereit. Wenn Sie beispielsweise eine Assembler-App mit nasm -f elf file.asm -o file.o kompilieren, lautet der Linkbefehl ld -m elf_i386 -o exename file.o.

Also diese anstelle

nasm -f elf test1.asm 
ld -m elf_i386 -o test1 test1.o 
Verwandte Themen