gcc - 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
解决方案
我对 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
推荐阅读
- angular - Angular4 +表单控件的无值访问器
- python - 内存错误是系统错误的直接原因
- python - 为什么从我的 csv 文件创建的 Numpy 数组中充满了 NaN 值?
- sql - 使用数据库中的数据禁用按钮
- azure - Azure 事件网格 - 为混合连接配置客户端证书
- mysql - Get count of particular category and further bifurcated sub category using SQL query
- sharepoint - 将人员选取器添加到 sharepoint 联机 Web 部件
- c++ - 对象超出范围后引用成员设置为 0
- java - 如何将鼠标侦听器添加到 JOptionPane 按钮?
- reactjs - 如何从另一个组件获取 props 并将其提供给应用程序