2017-10-13 468 views
1

我很难在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)。

+0

您使用gcc for riscv64,并希望它在32位模式下编译。但是,这个gcc会将64位模式的c运行时库添加到链接阶段(将-v选项添加到gcc以查看由gcc添加的其他crt文件),这是错误的(32位精灵和64位精灵对象不能链接一起)。你应该在64位模式下使用gcc作为64位目标;和gcc的32位目标与32位模式(实际上你需要32位crt;它可能会包含在你的海湾合作委员会,但它使用错误的版本) – osgx

+0

@osgx文档在https:// gnu-mcu-eclipse .github.io/toolchain/riscv/install /指出riscv64-unknown-elf-gcc.exe可以同时针对32位和64位。我如何暗示它做32位库? –

+0

使用riscv32-unknown-elf-gcc.exe,它将使用32位CRT的正确路径。比较'riscv64-unknown-elf-gcc.exe -v ...'与'riscv32-unknown-elf-gcc.exe -v ...'的输出,以便用CRT查找确切的目录。 – osgx

回答

0

riscv64未知的小精灵 - gcc.exe -c hello.c的-o你好-march = rv32imac -mabi = ILP32 -Os

这部分是错误的。你的gcc tolchain文档说https://gnu-mcu-eclipse.github.io/toolchain/riscv/

riscv64未知的小精灵 - GCC VS支持riscv32未知的小精灵 - GCC 随着大量的架构和系统,GCC建议具有独特的元组前缀的二进制代码:

<arch>-<vendor>-<os>-<libc/abi>- 

当前用于裸机工具链的RISC-V前缀是riscv64-unknown-elf-和riscv32-unknown-elf-。

那么,不要被这个不幸的名字混淆。 64或32附加到体系结构中......这并不意味着编译器生成64位或32位RISC-V二进制文件。实际上,编译器会生成基于-march和-mabi的32/64位二进制文​​件。唯一的区别是默认值,当编译器在命令行中显式设置-march和-mabi时调用编译器。

尝试使用riscv32未知的小精灵 - gcc.exe编译为32位riscv平台计划(拱& ABI有r32 & 32零件在自己的名字),它应该使用正确的32位CRT文件。

对于multilib,当riscv64将搜索32位库(https://gnu-mcu-eclipse.github.io/toolchain/riscv/#multiple-libraries,https://gnu-mcu-eclipse.github.io/blog/2017/09/13/riscv-none-gcc-v7-1-1-2-20170912-released/,https://gcc.gnu.org/onlinedocs/gccint/Target-Fragment.html MULTILIB_OPTIONS)时,会有一些支持,但出现了一些问题。请发布gcc -v .... -o your_program.bin riscv32编译器,riscv64编译器和几个march/mabi组合的结果。

+0

我可以在任何地方找不到预构建的riscv32-unknown-elf工具链(并且真的没有时间自行构建它)。这些库在标准安装中,似乎gcc.exe没有正确调用ld.exe ...或者我不是说正确的魔术字让它正确地调用ld.exe –