Windows 7-64bitプラットフォーム上で最新のGCC for RISCVでRISCV用の基本的なコンパイルを実行するのに問題があります。&インストールGCC 7.1.1 RISCVコンパイル(リンク)エラー:互換性がありませんABI
ツール:Windows 7の64ビット、ノーcygwinの
プログラム:
#include <stdint.h>
int32_t iBlahblah;
int main (void)
{
while(1)
iBlahblah++;
return 0;
}
コマンドライン:
https://github.com/gnu-mcu-eclipse/riscv-none-gcc/releases/プラットフォームから得7.1.1-2-20170912-2255
"c:\Program Files\GNU MCU Eclipse\RISC-V Embedded GCC\7.1.1-2-20170912-2255\bin\riscv64-unknown-elf-gcc.exe" -c hello.c -o hello -march=rv32imac -mabi=ilp32 -Os
"c:\Program Files\GNU MCU Eclipse\RISC-V Embedded GCC\7.1.1-2-20170912-2255\bin\riscv64-unknown-elf-gcc.exe" -o hello.elf -march=rv32imac -mabi=ilp32 -Os -Wl,-Map=hello.lst hello.o
出力:
c:/program files/gnu mcu eclipse/risc-v embedded gcc/7.1.1-2-20170912-2255/bin/../lib/gcc/riscv64-unknown-elf/7.1.1/../../../../riscv64-unknown-elf/bin/ld.exe: hello.o: ABI is incompatible with that of the selected emulation: target emulation `elf64-littleriscv' does not match `elf32-littleriscv'
c:/program files/gnu mcu eclipse/risc-v embedded gcc/7.1.1-2-20170912-2255/bin/../lib/gcc/riscv64-unknown-elf/7.1.1/../../../../riscv64-unknown-elf/bin/ld.exe: failed to merge target specific data of file hello.o
c:/program files/gnu mcu eclipse/risc-v embedded gcc/7.1.1-2-20170912-2255/bin/../lib/gcc/riscv64-unknown-elf/7.1.1/../../../../riscv64-unknown-elf/lib/rv32imac/ilp32\libg.a(lib_a-exit.o): In function `.L0 ': exit.c:(.text.exit+0x1e): undefined reference to `_exit'
c:/program files/gnu mcu eclipse/risc-v embedded gcc/7.1.1-2-20170912-2255/bin/../lib/gcc/riscv64-unknown-elf/7.1.1/../../../../riscv64-unknown-elf/bin/ld.exe: hello.elf(.text): relocation "iBlahblah+0x0 (type R_RISCV_HI20)" goes out of range
c:/program files/gnu mcu eclipse/risc-v embedded gcc/7.1.1-2-20170912-2255/bin/../lib/gcc/riscv64-unknown-elf/7.1.1/../../../../riscv64-unknown-elf/bin/ld.exe: hello.o: file class ELFCLASS64 incompatible with ELFCLASS32
c:/program files/gnu mcu eclipse/risc-v embedded gcc/7.1.1-2-20170912-2255/bin/../lib/gcc/riscv64-unknown-elf/7.1.1/../../../../riscv64-unknown-elf/bin/ld.exe: final link failed: File in wrong format
collect2.exe: error: ld returned 1 exit status
「ABIは選択したエミュレーションのものと互換性がありません」というのが大きな問題です。再配置、終了などの問題は無視できます。私の大規模なビルド環境ではそれが処理されます(これは現時点ではRISCVではない多くのプラットフォーム用です)。
riscv64にはgccを使用し、32ビットモードでコンパイルします。しかし、このgccは、64ビットモード用のcランタイムライブラリをリンク段階に追加します(追加のcrtファイルをgccで追加するには-vオプションをgccに追加します)。これは間違っています(32ビットのelfと64ビットのelfオブジェクトはリンクできません一緒に)。64ビットモードの64ビットターゲットにはgccを使用する必要があります。 32ビットモードの32ビットターゲット用のgcc(実際には32ビットのcrtが必要ですがgccに含まれていますが間違ったバージョンを使用しています) – osgx
@osgx https:// gnu-mcu-eclipseのドキュメント.github.io/toolchain/riscv/install /は、riscv64-unknown-elf-gcc.exeが32ビットと64ビットの両方をターゲットにできることを示しています。 32ビットライブラリを行うにはどうすればよいですか? –
32ビットCRTへの正しいパスを使用するriscv32-unknown-elf-gcc.exeを使用してください。 'riscv64-unknown-elf-gcc.exe -v ...' vs 'riscv32-unknown-elf-gcc.exe -v ...'の出力を比較して、CRTの正確なディレクトリを探します。 – osgx