I want to cross-compile C src for MIPS machine, but the compilation fails. Executing cross compiled binary on Target machine outputs "illegal instruction". Could you please let me know how to compile C src for MIPS machine?
Details are as follows:
Executing "readelf -h host.bin" (host.bin is binary program running on HOST machine) outputs:
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: Intel 80386
Version: 0x1
Entry point address: 0x8048aac
Start of program headers: 52 (bytes into file)
Start of section headers: 8628 (bytes into file)
Flags: 0x0
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 9
Size of section headers: 40 (bytes)
Number of section headers: 30
Section header string table index: 27
Executing "readelf -h target.bin" (target.bin is binary program running on Target machine) outputs:
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: MIPS R3000
Version: 0x1
Entry point address: 0x403570
Start of program headers: 52 (bytes into file)
Start of section headers: 114040 (bytes into file)
Flags: 0x5, noreorder, cpic, mips1
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: 23
Section header string table index: 22
Executing "readelf -h cross_compiled.bin" outputs (cross_compiled.bin is binary that is cross compiled (by me) for Target machine):
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: MIPS R3000
Version: 0x1
Entry point address: 0x400170
Start of program headers: 52 (bytes into file)
Start of section headers: 16444 (bytes into file)
Flags: 0x1007, noreorder, pic, cpic, o32, mips1
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 5
Size of section headers: 40 (bytes)
Number of section headers: 21
Section header string table index: 20
For the cross compilation, I have used buildroot which supports MIPS1 cross compilation.
I expected cross_compiled.bin is executed normally on Target machine. However, when I execute "cross_compiled.bin" on Target machine, it outputs "illegal instruction".
Could you please let me know how to solve the above problem? Since I am new to cross compilation, I cannot find what the exact reason of the problem is.
Any comments would be appreciated.
On the target, executing "cat /proc/cpuinfo" outputs:
system type : Broadcom BCM5354 chip rev 3
processor : 0
cpu model : BCM3302 V2.9
BogoMIPS : 237.56
wait instruction : no
microsecond timers : yes
tlb_entries : 32
extra interrupt vector : no
hardware watchpoint : no
VCED exceptions : not available
VCEI exceptions : not available
unaligned_instructions : 1
dcache hits : 0
dcache misses : 0
icache hits : 0
icache misses : 0
instructions : 0
On the target, executing "cat /proc/version" outputs:
Linux version 2.4.20 ([email protected]) (gcc version 3.2.3 with Broadcom modifications) #1 Tue May 22 17:40:19 EDT 2007
Command line I used for cross-compilation (cross_compiled.bin):
mipsel-linux-gcc -static -o cross_compiled.bin cross_compiled.c
cross_compiled.c:
#include <stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}
Since my cross_compiled.c is very simple, I believe there are no issues related to libraries used.
Various things could be causing this; one thing I can see from your post is that the ELF flags are different between your binary and their binary. The kernel is very old too, and you also haven't reported the version of gcc in your own buildroot.
I note that that chipset (BCM5354) is the same as used in the DLINK DIR-320 and others, that happen to be supported by OpenWRT. Assuming you are not already using OpenWRT as a buildroot, I would try again using OpenWRT.
Conversely, you could download the DLink provided GPL sources which should include a buildroot, from the DLINK support website and try that. Given the age of the kernel and gcc used to build your destination, and the newness of the trunk OpenWRT, you might want to try and find the oldest release of OpenWRT that supports that router, or try the DLINK build root first.
If you have a couple of computers you could try both buildroots in parallel...
If this doesn't fix it you'd need to be posting a lot more information
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With