or32-uclinux-gcc 给出汇编消息:没有这样的指令

or32-uclinux-gcc gives assembler messages: no such instruction

我想使用交叉编译器对 or1200 设计进行一些测试,我曾在该设计中在另一台机器上执行一些基准测试。另一台机器有 or32-uclinux- 工具链的二进制文件,我将它们复制到我的 Ubuntu 20.04 机器上。

二进制文件似乎工作正常,但是当我尝试使用

编译我的汇编代码时
or32-uclinux-gcc -c custom.S -o assembly_code_obj.o 

它给了我一堆错误,比如

custom.S: Assembler messages:
custom.S:19: Error: no such instruction: `l.nop 0x0'
custom.S:20: Error: no such instruction: `l.nop 0x0'
custom.S:23: Error: no such instruction: `l.movhi r3,hi(_simple_test_asm)'
custom.S:24: Error: no such instruction: `l.ori r3,r3,lo(_simple_test_asm)'
custom.S:25: Error: no such instruction: `l.jr r3'
custom.S:33: Error: no such instruction: `l.addi r1,r0,0xff'
custom.S:34: Error: no such instruction: `l.addi r2,r0,0x06'
custom.S:35: Error: no such instruction: `l.nop'
custom.S:36: Error: no such instruction: `l.nop'
custom.S:37: Error: no such instruction: `l.nop'
custom.S:38: Error: no such instruction: `l.nop'
custom.S:39: Error: no such instruction: `l.nop'
custom.S:40: Error: no such instruction: `l.div r3,r1,r2'
custom.S:42: Error: no such instruction: `l.nop 0x0001'

这里会有什么问题?

调试信息

[A] 在我的 Ubuntu 机器上

or32-uclinux-gcc -c custom.S -o custom.o -v

的输出
or32-uclinux-gcc -c custom.S -o custom.o -v
Reading specs from /home/broxigar/utilities/or32/bin/../lib/gcc-lib/or32-uclinux/3.2.3/specs
Configured with: ./configure --target=or32-uclinux --prefix=/opt/or32-uclinux --local-prefix=/opt/or32-uclinux/or32-uclinux --with-gnu-as --with-gnu-ld --verbose --enable-languages=c : (reconfigured) ./configure --host=i686-pc-linux --target=arm-elf --prefix=/usr/local -v --with-newlib : (reconfigured) ./configure --target=or32-uclinux --prefix=/opt/or32-uclinux --local-prefix=/opt/or32-uclinux/or32-uclinux --with-gnu-as --with-gnu-ld --verbose --enable-languages=c : (reconfigured) ./configure --target=or32-uclinux --prefix=/opt/or32-uclinux --local-prefix=/opt/or32-uclinux/or32-uclinux --with-gnu-as --with-gnu-ld --verbose --enable-languages=c
Thread model: single
gcc version 3.2.3
 /home/broxigar/utilities/or32/bin/../lib/gcc-lib/or32-uclinux/3.2.3/cpp0 -lang-asm -v -iprefix /home/broxigar/utilities/or32/bin/../lib/gcc-lib/or32-uclinux/3.2.3/ -D__GNUC__=3 -D__GNUC_MINOR__=2 -D__GNUC_PATCHLEVEL__=3 -D__GXX_ABI_VERSION=102 -Dunix -Dlinux -D__ELF__ -DOR1K -Dor1k -D__or1k__ -D__OR1K__ -D__unix__ -D__linux__ -D__ELF__ -D__OR1K__ -D__or1k__ -D__or1k__ -D__OR1K__ -D__unix -D__linux -D__OR1K -D__or1k -Asystem=unix -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 custom.S -o /tmp/ccmryjef.s
GNU CPP version 3.2.3 (cpplib) (OR32 GNU/Linux with ELF)
ignoring nonexistent directory "/home/broxigar/utilities/or32/lib/gcc-lib/or32-uclinux/../../../or32-uclinux/sys-include"
ignoring nonexistent directory "/home/broxigar/utilities/or32/lib/gcc-lib/or32-uclinux/../../../or32-uclinux/include"
ignoring nonexistent directory "/opt/or32-uclinux/include"
ignoring nonexistent directory "/opt/or32-uclinux/lib/gcc-lib/or32-uclinux/3.2.3/include"
ignoring nonexistent directory "/opt/or32-uclinux/lib/gcc-lib/or32-uclinux/3.2.3/../../../../or32-uclinux/sys-include"
ignoring nonexistent directory "/opt/or32-uclinux/lib/gcc-lib/or32-uclinux/3.2.3/../../../../or32-uclinux/include"
#include "..." search starts here:
#include <...> search starts here:
 /home/broxigar/utilities/or32/lib/gcc-lib/or32-uclinux/3.2.3/include
End of search list.
 as --traditional-format -o custom.o /tmp/ccmryjef.s // <====== Invoking the wrong assembler for the x86 architecture
custom.S: Assembler messages:
custom.S:19: Error: no such instruction: `l.nop 0x0'
custom.S:20: Error: no such instruction: `l.nop 0x0'
custom.S:23: Error: no such instruction: `l.movhi r3,hi(_simple_test_asm)'
custom.S:24: Error: no such instruction: `l.ori r3,r3,lo(_simple_test_asm)'
custom.S:25: Error: no such instruction: `l.jr r3'
custom.S:33: Error: no such instruction: `l.addi r1,r0,0xff'
custom.S:34: Error: no such instruction: `l.addi r2,r0,0x06'
custom.S:35: Error: no such instruction: `l.nop'
custom.S:36: Error: no such instruction: `l.nop'
custom.S:37: Error: no such instruction: `l.nop'
custom.S:38: Error: no such instruction: `l.nop'
custom.S:39: Error: no such instruction: `l.nop'
custom.S:40: Error: no such instruction: `l.div r3,r1,r2'
custom.S:42: Error: no such instruction: `l.nop 0x0001'

[B]在原机上

or32-uclinux-gcc -c custom.S -o custom.o -v

的输出
Reading specs from /software/or32-uclinux/bin/../lib/gcc-lib/or32-uclinux/3.2.3/specs
Configured with: ./configure --target=or32-uclinux --prefix=/opt/or32-uclinux --local-prefix=/opt/or32-uclinux/or32-uclinux --with-gnu-as --with-gnu-ld --verbose --enable-languages=c : (reconfigured) ./configure --host=i686-pc-linux --target=arm-elf --prefix=/usr/local -v --with-newlib : (reconfigured) ./configure --target=or32-uclinux --prefix=/opt/or32-uclinux --local-prefix=/opt/or32-uclinux/or32-uclinux --with-gnu-as --with-gnu-ld --verbose --enable-languages=c : (reconfigured) ./configure --target=or32-uclinux --prefix=/opt/or32-uclinux --local-prefix=/opt/or32-uclinux/or32-uclinux --with-gnu-as --with-gnu-ld --verbose --enable-languages=c
Thread model: single
gcc version 3.2.3
 /software/or32-uclinux/bin/../lib/gcc-lib/or32-uclinux/3.2.3/cpp0 -lang-asm -v -iprefix /software/or32-uclinux/bin/../lib/gcc-lib/or32-uclinux/3.2.3/ -D__GNUC__=3 -D__GNUC_MINOR__=2 -D__GNUC_PATCHLEVEL__=3 -D__GXX_ABI_VERSION=102 -Dunix -Dlinux -D__ELF__ -DOR1K -Dor1k -D__or1k__ -D__OR1K__ -D__unix__ -D__linux__ -D__ELF__ -D__OR1K__ -D__or1k__ -D__or1k__ -D__OR1K__ -D__unix -D__linux -D__OR1K -D__or1k -Asystem=unix -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 custom.S -o /tmp/ccUm7N9j.s
GNU CPP version 3.2.3 (cpplib) (OR32 GNU/Linux with ELF)
ignoring nonexistent directory "/software/or32-uclinux/or32-uclinux/sys-include"
ignoring nonexistent directory "/software/or32-uclinux/or32-uclinux/include"
ignoring nonexistent directory "/opt/or32-uclinux/include"
ignoring nonexistent directory "/opt/or32-uclinux/lib/gcc-lib/or32-uclinux/3.2.3/include"
ignoring nonexistent directory "/opt/or32-uclinux/lib/gcc-lib/or32-uclinux/3.2.3/../../../../or32-uclinux/sys-include"
ignoring nonexistent directory "/opt/or32-uclinux/lib/gcc-lib/or32-uclinux/3.2.3/../../../../or32-uclinux/include"
#include "..." search starts here:
#include <...> search starts here:
 /software/or32-uclinux/lib/gcc-lib/or32-uclinux/3.2.3/include
End of search list.
 /software/or32-uclinux/bin/../lib/gcc-lib/or32-uclinux/3.2.3/../../../../or32-uclinux/bin/as --traditional-format -o custom.o /tmp/ccUm7N9

错误的原因是 gcc 是 运行 本地汇编器而不是 or1200 汇编器。事实证明,汇编程序的可执行二进制文件位于具有 64 位 inode 的大文件系统上,并且碰巧得到一个超出 32 位整数范围的文件系统。 gcc 使用 stat C 库函数来定位辅助程序,在这种情况下失败并返回 EOVERFLOW。不幸的是,系统调用成功,所以在 strace 中查找并没有提示为什么没有检测到文件的存在:

stat64("/home/<snip>/or32-uclinux/bin/as", {..}) = 0 

ltrace 至少告诉我们它失败了​​:

__xstat(3, "/home/<snip>/or32-uclinux/bin/as", 0xffed1f00) = -1 

但实际上我们不得不使用 gdb 进行调试以检查 errno

如果重建 gcc 不是一个选项,那么解决方法是使用较小的文件系统。