前提
GNUアセンブラ初心者です。
アセンブリ言語のプログラムをC言語のプログラムで呼び出すプログラムを作成するつもりです。
c言語のプログラムとGASのプログラムをオブジェクトファイルに変換するときまではうまくいったのですが、gccで各オブジェクトファイルをリンクする際にエラーが発生しました。
発生している問題・エラーメッセージ
最終リンクに失敗しました:出力に対応するセクションがありません。
該当のソースコード
ファイル名はsum_asm.s
GNUAssembler(GAS)
1 .global sum_asm 2 .text 3sum_asm: 4 movl $0,%eax 5 movl $array,%edx 6 movl array_size,%ecx 7L1: 8 add (%edx),%eax 9 add $4,%edx 10 loop L1 11 ret 12
ファイル名はsum.c
C言語
1#include <stdio.h> 2extern int sum_asm(void); 3int array_size=10; 4int array[10]={0,1,2,3,4,5,6,7,8,9}; 5int main(void){ 6 int sum=sum_asm(); 7 printf("sum=%d\n",sum); 8 return 0; 9}
command
1as -o sum_asm.o sum_asm.s 2gcc -fno-pic -c -o sum.o sum.c 3 4gcc -o sum sum.o sum_asm.o 5ここでエラー
補足情報(FW/ツールのバージョンなど)
ホストOS:Windows 10 64bit
ゲストOS:ubuntu 64bit
gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)
Error
1/usr/bin/ld: sum_asm.o: relocation R_X86_64_32 against symbol `array' can not be used when making a PIE object。 -fPIC を付けて再コンパイルしてください。 2/usr/bin/ld: sum.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object。 -fPIC を付けて再コンパイルしてください。 3/usr/bin/ld: 最終リンクに失敗しました: 出力に対応するセクションがありません 4collect2: error: ld returned 1 exit status
回答1件
あなたの回答
tips
プレビュー