2010-02-11 3 views
5

Ich habe eine Probe Assembly-Datei, die ich mit nasm kompilieren:Montage/Linking Problem mit nasm und ld

nasm -f elf syscall.asm 

Dies erzeugt eine syscall.o Datei. Ich versuche es mit ld zu verknüpfen:

ld -o syscall syscall.o 

Der ld Befehl mit dem folgenden Fehler fehl:

ld: i386 architecture of input file `syscall.o' is incompatible with i386:x86-64 output 

Allerdings, wenn ich

ld -o syscall syscall.o -melf_i386 

der Befehl erfolgreich, und ich bekomme ein syscall ausführbar.

Herauszufinden, dass Nasm Objektcode im x86-64-Format nicht generiert Ich habe "BITS 64" -Direktive an den Anfang der syscall.asm-Datei hinzugefügt.

Dann mit nasm zusammen syscall.asm Versuch gab den folgenden Fehler:

error: elf output format does not support 64-bit code 

Das scheint seltsam, weil "Datei/usr/bin/nasm" auf meinem Terminal gibt tun:

/usr/bin/nasm: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped 

Mein 64-Bit Fedora Core 11 hat die neueste Version von Nasm installiert und meine CPU ist Intel Core 2 Duo E7200.

[EDIT]

Meine Frage ist, wie kann ich nasm bekommen zu Objektdateien zu emittieren, die mit i386 kompatibel: x86-64.

+0

Also, was ist die Frage? – wallyk

Antwort

8

Verwenden Sie als Ausgabeformat elf64.

Beispiel Lauf:

$ cat elf64.asm 
section .text 
     jmp [rax] 
$ nasm -f elf64 elf64.asm 
$ objdump -Sr elf64.o 

elf64.o:  file format elf64-x86-64 


Disassembly of section .text: 

0000000000000000 <.text>: 
    0: ff 20     jmpq *(%rax) 
+0

Wow, das hat funktioniert. Vielen Dank. – ardsrk