Identical (almost) ELF headers but executables won't run on each other's system Identical (almost) ELF headers but executables won't run on each other's system linux linux

Identical (almost) ELF headers but executables won't run on each other's system


You clearly need a different toolchain. On your Debian-mipsel, your toolchain uses glibc while your target uses uClibc.

So, maybe you would like to generate it by yourself using Buildroot:

wget http://buildroot.uclibc.org/downloads/buildroot-2014.11.tar.gztar zxf http://buildroot.uclibc.org/downloads/buildroot-2014.11.tar.gzcd buildroot-2014.11

A trick to preconfigure for mipsel, R1 without soft-float (my will, check yours):

cat <<_EOF > .configBR2_HAVE_DOT_CONFIG=yBR2_mipsel=yBR2_ARCH="mipsel"BR2_ENDIAN="LITTLE"BR2_GCC_TARGET_ARCH="mips32"BR2_GCC_TARGET_ABI="32"BR2_ARCH_HAS_ATOMICS=yBR2_mips_32=y# BR2_MIPS_SOFT_FLOAT is not setBR2_MIPS_OABI32=y_EOF

Finish your choice in Buildroot menuconfig, but you canalso keep it like this with save and exit.

make menuconfig   # tweak options at your will,make -j8          # takes 8 minutes on my machine

Then, your compiler can be found in ./output/host/usr/bin

A real example:

echo '#include <stdio.h>                                                                                                                                                                    int main(int argc, char* argv[]) {     printf("Hello World.\n");     return 0; }' > hello.c

And compile it with your brand-new uClibc GCC compiler

output/host/usr/bin/mipsel-buildroot-linux-uclibc-gcc -o hello hello.c

A glimpse into the hello program: (didn't had time to fix my ldd...)

$ file hellohello: ELF 32-bit LSB executable, MIPS, MIPS32 version 1 (SYSV), dynamically linked (uses shared libs), not stripped$ strings hello | grep "lib.*so*"/lib/ld-uClibc.so.0libgcc_s.so.1libc.so.0

It's done with the toolchain and compile your program.Now that you have time :-) see what Buildroot offers :a complete distribution (in output/target/) for embedded systems in many architectures.

EDIT: Better chance to execute

You can statically link your program in order to maximize the chances to run your code on any target.

$ output/host/usr/bin/mipsel-linux-gcc -Wall -o hello -static hello.c$ file ./hello./hello: ELF 32-bit LSB executable, MIPS, MIPS32 version 1 (SYSV), dynamically linked (uses shared libs), not stripped

And now, as that static version doesn't depend anymore on any external lib (only uClibc, here), this MIPS executable can even run on my x86_64 machine (thanks to binfmt and Qemu) :

$ uname -mo   x86_64 GNU/Linux$ ./helloHello World.

Cheers.


Maybe i'm wrong but a simple fix (but not elegant way) in such cases could be to link the missing files to the existing ones:

ln -s /lib/libc.so.6 /lib/libc.so.0

like in this situation:https://dev.openwrt.org/ticket/3083