首页 > 解决方案 > gcc 交叉编译 -mips1 不生成 MIPS-I

问题描述

我的目标是旧路由器需要 MIPS-I 可执行文件,但 -mips1 会生成 MIPS32 可执行文件。

这是编译命令:

buildroot-2019.02.5/output/host/bin/mips-linux-gcc-7.4.0 -march=mips1 -mtune=mips1 -static ~/helloworld.c -o /tmp/hw.1013  -msoft-float

但文件是 MIPS32,而不是 MIPS-I

file /tmp/hw.1013

/tmp/hw.1013: ELF 32-bit MSB executable, MIPS, MIPS32 version 1 (SYSV), statically linked, not stripped

旧版本的 gcc 生成正确的 MIPS-I 二进制文件。

./mips-gcc --version
uClibc mips-rawgcc (GCC) 4.1.2

./mips-gcc -march=mips1  -static ~/helloworld.c -o /tmp/hw.1013  -msoft-float 
file /tmp/hw.1013
/tmp/hw.1013: ELF 32-bit MSB executable, MIPS, MIPS-I version 1 (SYSV), statically linked, not stripped

标签: gccmips

解决方案


我对 Debian buster gcc 8 mipsel 交叉编译器包也有同样的问题。原来是因为标准库是为 mips32r2 编译的。
gcc 实际上会生成 MIPS-I 程序集,您可以查看是否执行 agcc -c source.c并查看目标文件的 elf 标头中的标志readelf -h source.o。但是当链接到较新的 ISA 库时,ld将使用较新的 ISA 标记可执行文件。

我怀疑您遇到了同样的问题,因为 buildroot 自 2014 年以来不支持 MIPS-I。请查看readelf -h例如。你的静态 uClibc 库。在我的 buildroot-2014.11 工具链中,它位于output/host/usr/mipsel-buildroot-linux-uclibc/sysroot/usr/lib/libc.a


推荐阅读