1

everyone. I used newest cross_compiler(installed by sudo apt install gcc-arm-linux-gnueabi on Ubuntu 18.04,version is 7.3)to compile a simple "hello world" c program

#include <stdio.h>

int main()
{
    printf("Hello World!\r\n");
    return 0;
}

used command below to compile the code,i used static link

arm-linux-gnueabi-gcc -o hello hello.c -static

Then i first ran it on my raspberry pi0w,and it ran very well After that,i ran it on my s3c2440 board,which is ARM9 and very old core.However,it didnot run correctly.

# ./hello
Illegal instruction

I did not know why,and how to solve it.Then I used cross_compiler version 3.4.5 to compile it again,and the program ran smoothly this time.But it cannot run correctly on raspberry pi,after running the program,nothing happened."Hello World!" did not appear.

I used file command to check this two programs(don't know whether help or not ): the program compiled by newest compiler is:

hello: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, for GNU/Linux 3.2.0, BuildID[sha1]=6b0a4b6cb4bf672d4cf1fbd171ec62a96e622d69, not stripped

and by old compiler is:

hello_old: ELF 32-bit LSB executable, ARM, version 1 (ARM), statically linked, for GNU/Linux 2.4.3, with debug_info, not stripped

The newest arm-linux-gnueabi-gcc is

$ arm-linux-gnueabi-gcc -v
Using built-in specs.
COLLECT_GCC=arm-linux-gnueabi-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/arm-linux-gnueabi/7/lto-wrapper
Target: arm-linux-gnueabi
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 7.3.0-16ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --with-as=/usr/bin/arm-linux-gnueabi-as --with-ld=/usr/bin/arm-linux-gnueabi-ld --program-suffix=-7 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --disable-libquadmath-support --enable-plugin --with-system-zlib --with-target-system-zlib --enable-multiarch --enable-multilib --disable-sjlj-exceptions --with-arch=armv5t --with-float=soft --disable-werror --enable-multilib --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=arm-linux-gnueabi --program-prefix=arm-linux-gnueabi- --includedir=/usr/arm-linux-gnueabi/include
Thread model: posix
gcc version 7.3.0 (Ubuntu/Linaro 7.3.0-16ubuntu3)

And the old cross_compiler I used is

$ arm-gcc-old -v
Reading specs from /work/gcc-3.4.5-glibc-2.3.6/bin/../lib/gcc/arm-linux/3.4.5/specs
Configured with: /work/tools/create_crosstools/crosstool-0.43/build/arm-linux/gcc-3.4.5-glibc-2.3.6/gcc-3.4.5/configure --target=arm-linux --host=i686-host_pc-linux-gnu --prefix=/work/tools/gcc-3.4.5-glibc-2.3.6 --with-float=soft --with-headers=/work/tools/gcc-3.4.5-glibc-2.3.6/arm-linux/include --with-local-prefix=/work/tools/gcc-3.4.5-glibc-2.3.6/arm-linux --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-__cxa_atexit --enable-languages=c,c++ --enable-shared --enable-c99 --enable-long-long
Thread model: posix
gcc version 3.4.5

What should I do to compile code correctly using newest compiler? The kernel on s3c2440 is

# uname -a
Linux (none) 2.6.22.6 #1 Thu May 31 14:02:09 CST 2018 armv4tl unknown

And that kernel was compiled by newest cross_compiler 7.3

Thanks!

Edward
  • 13
  • 5
  • 1
    It looks like the kernel is running armv4tl and the compiler is producing code for -march=armv5t by default (see your configured with line)... You'll probably need to set an appropriate -march or -mcpu flag to compile for the older architecture. – Zrax May 31 '18 at 15:57
  • try something like -march=armv4t if you want to try to improve your portability. – old_timer Jun 01 '18 at 03:07
  • @old_timer Thanks for your reply. I tried to add -mcpu=arm920t,but wont work.I used newest compiler to compile this kernel,worked perfect.and bare-metal program(like lights a LED) compiled by newest compiler(without any option) can work fine too. – Edward Jun 01 '18 at 03:31
  • @old_timer I thought I found the problem.Although I add -mcpu=arm920t -march=armv4t, the executable was always for "v5t"(using readelf to check).that was because in link stage,other file like crts.0 was compiled for armv5t. I found it from this post https://stackoverflow.com/questions/12963209/why-does-arm-linux-gnueabi-g-4-4-always-build-a-7-a-binary – Edward Jun 01 '18 at 04:39
  • it didnt complain that the cpu and arch parameters disagreed with each other? whenever I mismatch them I get an error. – old_timer Jun 01 '18 at 11:59
  • dont use the mcpu in this case just use -march=armv4t and see what you get. your bootstrap may be built for you when the c library was built and that may very well be built for the latter armv5t (arm9) architecture. – old_timer Jun 01 '18 at 12:00
  • I guess some arm9s were armv4t but the 920t is an armv5 though right? – old_timer Jun 01 '18 at 12:01
  • you dont need both cpu and arch though in this case just use arch. you might have to go back and re-build the bootstrap code, inspect and confirm it doesnt have any non armv4 instructions. I would assume not but youll find out. – old_timer Jun 01 '18 at 12:02
  • @old_timer only using -march=armv4t ,still got "Illegal Instruction".I checked ARM920T manual,it is armv4t in fact.That compiler was installed by just typing sudo apt install gcc-arm-linux-gnueabi. It was not compiled by myself,I just want to try it. Although, I successfully compiled linux kernel(version 2.6.22) by using this compiler.And furthermore, bare-metal program compiled by this compiler can run smoothly too. – Edward Jun 01 '18 at 12:30
  • @old_timer I am learning crosstool-NG now, give up using that compiler already.I am going to build cross-tool chain for myself. Thanks for taking time to reply. : ) – Edward Jun 01 '18 at 12:33
  • there are gcc lib and C library items that are pre-built for you so you may be running into those, is the address at which you see the illegal instruction in a part of the binary that is from what you built or something that was linked in to what you built? – old_timer Jun 01 '18 at 17:51
  • @old_timer sorry,I dont know what is that address.I just run ./hello and only got "Illegal instruction",but no "Hello World".I succeeded to build a cross-tool for myself using ct-ng,which i configured for arm920t. then I compiled agian,and i got the problem again. but can run correctly on raspberry pi 0w. This time using readelf can get correct "v4T". – Edward Jun 02 '18 at 12:01
  • @old_timer using "file hello" for compiler by myself is "ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, for GNU/Linux 3.2.0, with debug_info, not stripped" and for compile which work correctly is "ELF 32-bit LSB executable, ARM, version 1 (ARM), statically linked, for GNU/Linux 2.4.3, with debug_info, not stripped" Is there any problem? What is "ARM EABI5 version 1(SYSV)" and "ARM version1 (ARM)"? – Edward Jun 02 '18 at 12:04

0 Answers0