1

I have referred to the output of "readelf -h target.bin" (target.bin runs on target machine) for the configuration of cross-compiler. I assumed readelf output of a binary program compiled by a cross-compiler should be same as that of target.bin.

In the following case, however, two programs that have different "readelf" outputs from each other could successfully run on target machine. Morever, another program that have similar readelf outputs to the outputs of target.bin is not executable on target machine. It seems like that readelf outputs are not important for the configuration of cross compiler. Then... which things should I refer to for the correct configuration of cross compiler for the target machine?

Example:

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

readelf -h myfail_target.bin (compiled by me), which is not executable 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:               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

readelf -h mysuccess_target.bin (compiled by me), which is executable 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:               0x400140
Start of program headers:          52 (bytes into file)
Start of section headers:          28572 (bytes into file)
Flags:                             0x50001007, noreorder, pic, cpic, o32, mips32
Size of this header:               52 (bytes)
Size of program headers:           32 (bytes)
Number of program headers:         3
Size of section headers:           40 (bytes)
Number of section headers:         20
Section header string table index: 17

Any comments would be appreciated.

freddy
  • 463
  • 1
  • 8
  • 20
  • The first thing that struck me was that your working code has `mips32`, but then I realised your top example doesn't, so this really is a bit confusing! (Is this the same hello world program from your other question? you might want to post it here and the compiler command line & version for other people looking at this) PS I can identify with your frustration here, I hate it when something that should just work, and in my case has generally pretty much worked, suddenly doesn't... – 6EQUJ5 Jun 05 '14 at 11:59
  • 1
    I did some more digging and found a discussion about bugs in some 2.4.x kernels and MIPS ELF, although this may be only incidentally relevant if your non/working software runs on newer kernels. http://www.linux-mips.org/archives/linux-mips/2008-02/msg00060.html – 6EQUJ5 Jun 05 '14 at 12:00
  • TBH I am wondering whether the ELF actually has anything to do with it at all... it could be more a compiler idiosyncracy. Do you get the same error, say, in a debug (non-optimised) compile vs. a optimised compile? What about static vs. dynamic link? – 6EQUJ5 Jun 05 '14 at 12:03

0 Answers0