我很难在windows 7-64bit平台上的RISCV最新GCC for RISCV上进行基本编译&链接。GCC 7.1.1 RISCV编译(链接)失败,不兼容ABI
工具安装:从https://github.com/gnu-mcu-eclipse/riscv-none-gcc/releases/
平台得到7.1.1-2-20170912-2255:Windows 7中,64位,没有cygwin的
计划:
#include <stdint.h>
int32_t iBlahblah;
int main (void)
{
while(1)
iBlahblah++;
return 0;
}
命令行:
"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)。
您使用gcc for riscv64,并希望它在32位模式下编译。但是,这个gcc会将64位模式的c运行时库添加到链接阶段(将-v选项添加到gcc以查看由gcc添加的其他crt文件),这是错误的(32位精灵和64位精灵对象不能链接一起)。你应该在64位模式下使用gcc作为64位目标;和gcc的32位目标与32位模式(实际上你需要32位crt;它可能会包含在你的海湾合作委员会,但它使用错误的版本) – osgx
@osgx文档在https:// gnu-mcu-eclipse .github.io/toolchain/riscv/install /指出riscv64-unknown-elf-gcc.exe可以同时针对32位和64位。我如何暗示它做32位库? –
使用riscv32-unknown-elf-gcc.exe,它将使用32位CRT的正确路径。比较'riscv64-unknown-elf-gcc.exe -v ...'与'riscv32-unknown-elf-gcc.exe -v ...'的输出,以便用CRT查找确切的目录。 – osgx