我希望为运行 Linux 2.6.32.2 内核的三星 S3C2440 SoC(基于 ARM920T 内核)编译 C 程序。我有一个在 ARM926EJS 上运行的现有 Gentoo Linux 安装。
我使用以下 gcc 选项为 S3C2440 编译 C 程序:
gcc -mcpu=arm920t -o hello hello.c
运行编译后的可执行文件(单个 printf “hello world”)后,我只是得到“非法指令”。我没有为目标编译 GDB,并且 dmesg 没有报告错误指令的地址。
我看到在可执行文件上运行“objdump -d”会列出一条显然在 ARM920T 内核上不受支持的 BLX 指令。
# 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)