使用 armv4 目标时 binutils ld 发出 ARM BLX 指令
我希望为运行Linux 2.6.32.2内核的Samsung S3C2440 SoC(基于ARM920T内核)编译C程序。我已经在 ARM926EJS 上运行了现有的 Gentoo Linux。
我使用以下 gcc 选项为 S3C2440 编译 C 程序:
gcc -mcpu=arm920t -o hello hello.c
运行编译后的可执行文件(单个 printf“hello world”)时,我只是得到“非法指令”。我没有为目标编译 GDB,并且 dmesg 不报告错误指令的地址。
我看到在可执行文件上运行“objdump -d”会列出一条 BLX 指令,该指令显然在 ARM920T 内核上不受支持。
# gcc -mcpu=arm920t -o hello hello.c && objdump -d hello|grep blx
83cc: e12fff33 blx r3
经过进一步调查,BLX 似乎用于 GNU-EABI 二进制文件的 Thumb 支持,并且由“ld”生成。使用 GCC 的“-c”选项进行编译似乎证实了这一点,因为单独的目标文件的 objdump -d 输出中没有 BLX 指令。
BLX 指令是否是我遇到的问题?如果是,我如何告诉“ld”不在最终链接的可执行文件中生成 BLX 指令?
软件版本:
# ld -V
GNU ld (GNU Binutils) 2.20.1.20100303
Supported emulations:
armelf_linux_eabi
armelfb_linux_eabi
# gcc -v
Using built-in specs.
Target: armv5tel-softfloat-linux-gnueabi
Configured with: /var/tmp/portage/sys-devel/gcc-4.4.5/work/gcc-4.4.5/configure --prefix=/usr --bindir=/usr/armv5tel-softfloat-linux-gnueabi/gcc-bin/4.4.5 --includedir=/usr/lib/gcc/armv5tel-softfloat-linux-gnueabi/4.4.5/include --datadir=/usr/share/gcc-data/armv5tel-softfloat-linux-gnueabi/4.4.5 --mandir=/usr/share/gcc-data/armv5tel-softfloat-linux-gnueabi/4.4.5/man --infodir=/usr/share/gcc-data/armv5tel-softfloat-linux-gnueabi/4.4.5/info --with-gxx-include-dir=/usr/lib/gcc/armv5tel-softfloat-linux-gnueabi/4.4.5/include/g++-v4 --host=armv5tel-softfloat-linux-gnueabi --build=armv5tel-softfloat-linux-gnueabi --disable-altivec --disable-fixed-point --without-ppl --without-cloog --with-float=soft --enable-nls --without-included-gettext --with-system-zlib --disable-werror --enable-secureplt --disable-multilib --enable-libmudflap --disable-libssp --enable-libgomp --with-python-dir=/share/gcc-data/armv5tel-softfloat-linux-gnueabi/4.4.5/python --enable-checking=release --disable-libgcj --with-arch=armv5te --enable-languages=c,c++,fortran --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.4.5 p1.2, pie-0.4.5'
Thread model: posix
gcc version 4.4.5 (Gentoo 4.4.5 p1.2, pie-0.4.5)
I wish to compile C programs for a Samsung S3C2440 SoC (based on ARM920T core) running Linux 2.6.32.2 kernel. I have an existing Gentoo Linux install running on an ARM926EJS.
I compile C programs for the S3C2440 using the following gcc options :
gcc -mcpu=arm920t -o hello hello.c
Upon running the compiled executable (a single printf "hello world"), I simply get 'Illegal Instruction'. I have no GDB compiled for the target, and dmesg doesn't report the address of a faulting instruction.
I see that running "objdump -d" on the executable lists a BLX instruction which apparently is not supported on the ARM920T core.
# gcc -mcpu=arm920t -o hello hello.c && objdump -d hello|grep blx
83cc: e12fff33 blx r3
With further investigation, it seems that BLX is used for Thumb support with GNU-EABI binaries, and is generated by 'ld'. Using GCC's '-c' option to just compile seems to confirm this, as no BLX instruction are in the objdump -d output for the object file alone.
Would the BLX instructions be the problem I'm having, and if so, how do I tell 'ld' to not generate BLX instructions in the final linked executable?
Software versions :
# ld -V
GNU ld (GNU Binutils) 2.20.1.20100303
Supported emulations:
armelf_linux_eabi
armelfb_linux_eabi
# gcc -v
Using built-in specs.
Target: armv5tel-softfloat-linux-gnueabi
Configured with: /var/tmp/portage/sys-devel/gcc-4.4.5/work/gcc-4.4.5/configure --prefix=/usr --bindir=/usr/armv5tel-softfloat-linux-gnueabi/gcc-bin/4.4.5 --includedir=/usr/lib/gcc/armv5tel-softfloat-linux-gnueabi/4.4.5/include --datadir=/usr/share/gcc-data/armv5tel-softfloat-linux-gnueabi/4.4.5 --mandir=/usr/share/gcc-data/armv5tel-softfloat-linux-gnueabi/4.4.5/man --infodir=/usr/share/gcc-data/armv5tel-softfloat-linux-gnueabi/4.4.5/info --with-gxx-include-dir=/usr/lib/gcc/armv5tel-softfloat-linux-gnueabi/4.4.5/include/g++-v4 --host=armv5tel-softfloat-linux-gnueabi --build=armv5tel-softfloat-linux-gnueabi --disable-altivec --disable-fixed-point --without-ppl --without-cloog --with-float=soft --enable-nls --without-included-gettext --with-system-zlib --disable-werror --enable-secureplt --disable-multilib --enable-libmudflap --disable-libssp --enable-libgomp --with-python-dir=/share/gcc-data/armv5tel-softfloat-linux-gnueabi/4.4.5/python --enable-checking=release --disable-libgcj --with-arch=armv5te --enable-languages=c,c++,fortran --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.4.5 p1.2, pie-0.4.5'
Thread model: posix
gcc version 4.4.5 (Gentoo 4.4.5 p1.2, pie-0.4.5)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
BLX 是来自用户代码还是库代码?既然你没有通过 -mthumb 我敢打赌图书馆。您的 GCC 似乎是针对 armv5tel 配置的,因此可能 libc 或启动代码是使用 BLX 进行编译的,BLX 在 ARMv5 上受支持。如果您不确定,请将二进制文件上传到某个地方。
我看到您可以尝试以下几件事:
Is the BLX coming from user code or library code? Since you're not passing -mthumb I'd bet on the library. It seems your GCC was configured for armv5tel, so probably either libc or the startup code was compiled with use of BLX, which is supported on ARMv5. If you're not sure, upload the binary somewhere.
I see several things you can try: