私はhello worldを出力する簡単なアセンブリ言語プログラムを持っています。 glibcのprintfとexit関数を動的にリンクして使用します。64ビットのubuntuで使用する動的リンカ
私は、リンカーのこのバージョンを使用する場合:その後、私はこのエラーを取得する
ld -dynamic-linker /lib64/ld-linux.so.2 -o helloworld-lib helloworld-lib.o -lc
、私は、実行可能ファイルを実行すると: のbash:./helloworld-libを:破損した共用ライブラリ
へのアクセス私が代わりに使用する場合:
ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o helloworld-lib helloworld-lib.o -lc
私はprintfと呼ばれる行でセグメンテーションフォールトを取得しています。私は64ビットのUbuntuシステムを使用してい
.section .data
helloworld:
.ascii "hello world\n\0"
.section .text
.globl _start
_start:
pushq $helloworld
call printf
pushq $0
call exit
:
これは私.Sファイルは次のようになります。ここで間違っていることを明確にしてください。ありがとう。
編集:
私は2つのライン交換する場合:と
pushq $helloworld
call printf
を:
movl $helloworld, %eax
movq %rax, %rdi
movl $0, %eax
call printf
movl $0, %eax
そして、それが正常に動作します。
Morale:アセンブリを書くときは、呼び出し規約に注意してください。 – ugoren