2

I have installed all cross compile packages on my ubuntu system so far but am having a problem and need some help.

Linux 2.6.28.7 #1  CST 2012 armv5tejl unknown

$ cat /proc/cpuinfo
Processor       : ARM926EJ-S rev 5 (v5l)
BogoMIPS        : 199.47
Features        : swp half fastmult edsp java
CPU implementer : 0x41
CPU architecture: 5TEJ
CPU variant     : 0x0
CPU part        : 0x926
CPU revision    : 5

Hardware        : ServerEngines PILOT3
Revision        : 0000
Serial          : 0000000000000000


user@ubuntu:~/code$ arm-linux-gnueabi-readelf -h xxx.bin 
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 61 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            ARM
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           ARM
  Version:                           0x1
  Entry point address:               0xa27c
  Start of program headers:          52 (bytes into file)
  Start of section headers:          128752 (bytes into file)
  Flags:                             0x2, GNU EABI, <unknown>
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         6
  Size of section headers:           40 (bytes)
  Number of section headers:         25
  Section header string table index: 24

This is the target machine I need to cross compile for. What flags should I use when compiling?

arm-linux-gnueabi-gcc simple.c -march=armv5 -static -o simplev5
arm-linux-gnueabi-gcc simple.c -mcpu=arm926ej-s -static -o simple926

when I run the simplev5 or simple926, show:

Segmentation fault

follow @Steven P advice, I checked the file format, as follows:

user@ubuntu:~/code$ file simplev5
simplev5: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, for GNU/Linux 3.2.0, BuildID[sha1]=f0607da1d809a7d98636d76ee0e538fc828e3b65, not stripped
user@ubuntu:~/code$ file simple926 
simple926: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, for GNU/Linux 3.2.0, BuildID[sha1]=ed1e6fdade02c0d2c985a503dafb6efadd13522f, not stripped
user6903
  • 133
  • 7
  • Possible duplicate of http://stackoverflow.com/questions/17336236/cross-compile-from-linux-to-arm-elf-arm926ej-s-mt7108 – nomem May 11 '17 at 10:09
  • Possible duplicate of [Cross compile from linux to ARM-ELF (ARM926EJ-S/MT7108)](http://stackoverflow.com/questions/17336236/cross-compile-from-linux-to-arm-elf-arm926ej-s-mt7108) ... This 'Linux 2.6.28.7' is rather old and the newest Ubuntu cross-arm is probably configured for a much more recent Linux. Even if '-static' is successful, you still have `swi` calls which might not map. – artless noise May 11 '17 at 13:05
  • [Building a cross compiler from scratch](http://frank.harvard.edu/~coldwell/toolchain/) might be helpful. [Crosstool-ng](http://crosstool-ng.github.io/) might be useful, but it has drop support for at least older GCC versions and possibly Linux versions as well. Often things need small patches to get the compiler to build with out of date dependencies. – artless noise May 11 '17 at 13:14
  • [Selecting static library to be linked with for cross-arm](http://stackoverflow.com/questions/24616226/how-can-i-select-a-static-library-to-be-linked-while-arm-cross-compiling) might be helpful as well. You can use the sample 'freestanding' to see if it works with your ARM Ubuntu compiler to at least eliminate ELF container issues. – artless noise May 11 '17 at 13:38

1 Answers1

2

You most likely have the right compilation or you would get an error about Invalid Format. You can confirm you have the proper file format by using:

file simple926

Try a simpler program:

int main() { return 123; }

Then you can check the result code when you run it to confirm it did something.

./simple926
echo $?

To solve your segmentation fault, you probably need to get out gdb and examine the stack (backtrace).

Steven P
  • 185
  • 2
  • 10
  • I have checked the file format, which is listed as above. Moreover, the gdb does not exist and cannot be installed in the target machine. My test code is similar to yours. – user6903 May 12 '17 at 07:42
  • Sorry, I can't comment on the post or I would have not answered. But, based on artless noise comment, you should make sure you are building with the toolchain that matches your installed release. Match the kernel version as best you can. – Steven P May 15 '17 at 01:04
  • Did you get this going? Try without no march or mcpu option. – Steven P Mar 14 '19 at 17:47