2

I installed codesourcery cross compile toolchain for mips32 architecture on my WIN 7 machince. I want to first compile a simple 'factorial' binary for my router which is based on MIPS32. From little search on the internet, I found it is based on MIPS32 big-endian.

#cat /proc/cpuinfo
system type             : 96338W2
processor               : 0
cpu model               : BCM6338 V1.0
BogoMIPS                : 239.20
wait instruction        : no
microsecond timers      : yes
tlb_entries             : 32
extra interrupt vector  : yes
hardware watchpoint     : no
unaligned access        : 1269919
VCED exceptions         : not available
VCEI exceptions         : not available

# cat /proc/version
Linux version 2.6.8.1 (root@WangHaiTao) (gcc version 3.4.2) #1 Wed Sep 2 10:13:53 CST 2009

The router's LIB dir contains:

ld-uClibc.so.0 libc.so.0 libcrypt.so.0 libcrypto.so.0.9.7 libdl.so.0 libm.so.0 libnvram.so libpsi.so libpsixml.so libresolv.so.0 libssl.so.0.9.7 libutil.so.0 libwlbcmcrypto.so libwlbcmshared.so libwlctl.so modules

Toolchain info: (on the host WIN 7 system)

C:\code>mips-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=mips-linux-gnu-gcc
COLLECT_LTO_WRAPPER=f:/program files/codesourcery/sourcery_codebench_lite_for_mi
ps_gnu_linux/bin/../libexec/gcc/mips-linux-gnu/4.6.3/lto-wrapper.exe
Target: mips-linux-gnu
Configured with: /scratch/cmoore/2012.03-63-linux-lite/src/gcc-4.6-2012.03/confi
gure --build=i686-pc-linux-gnu --host=i686-mingw32 --target=mips-linux-gnu --ena
ble-threads --disable-libmudflap --disable-libssp --disable-libstdcxx-pch --with
-arch-32=mips32r2 --with-arch-64=mips64r2 --with-float=hard --with-mips-plt --en
able-extra-sgxxlite-multilibs --with-gnu-as --with-gnu-ld --with-specs='%{save-t
emps: -fverbose-asm} -D__CS_SOURCERYGXX_MAJ__=2012 -D__CS_SOURCERYGXX_MIN__=3 -D
__CS_SOURCERYGXX_REV__=63 %{O2:%{!fno-remove-local-statics: -fremove-local-stati
cs}} %{O*:%{O|O0|O1|O2|Os:;:%{!fno-remove-local-statics: -fremove-local-statics}
}}' --enable-languages=c,c++ --enable-shared --enable-lto --enable-symvers=gnu -
-enable-__cxa_atexit --with-pkgversion='Sourcery CodeBench Lite 2012.03-63' --wi
th-bugurl=https://support.codesourcery.com/GNUToolchain/ --disable-nls --prefix=
/opt/codesourcery --with-sysroot=/opt/codesourcery/mips-linux-gnu/libc --with-bu
ild-sysroot=/scratch/cmoore/2012.03-63-linux-lite/install/host-i686-mingw32/mips
-linux-gnu/libc --with-libiconv-prefix=/scratch/cmoore/2012.03-63-linux-lite/obj
/host-libs-2012.03-63-mips-linux-gnu-i686-mingw32/usr --with-gmp=/scratch/cmoore
/2012.03-63-linux-lite/obj/host-libs-2012.03-63-mips-linux-gnu-i686-mingw32/usr
--with-mpfr=/scratch/cmoore/2012.03-63-linux-lite/obj/host-libs-2012.03-63-mips-
linux-gnu-i686-mingw32/usr --with-mpc=/scratch/cmoore/2012.03-63-linux-lite/obj/
host-libs-2012.03-63-mips-linux-gnu-i686-mingw32/usr --with-ppl=/scratch/cmoore/
2012.03-63-linux-lite/obj/host-libs-2012.03-63-mips-linux-gnu-i686-mingw32/usr -
-with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with
-cloog=/scratch/cmoore/2012.03-63-linux-lite/obj/host-libs-2012.03-63-mips-linux
-gnu-i686-mingw32/usr --with-libelf=/scratch/cmoore/2012.03-63-linux-lite/obj/ho
st-libs-2012.03-63-mips-linux-gnu-i686-mingw32/usr --disable-libgomp --enable-po
ison-system-directories --with-build-time-tools=/scratch/cmoore/2012.03-63-linux
-lite/obj/tools-i686-pc-linux-gnu-2012.03-63-mips-linux-gnu-i686-mingw32/mips-li
nux-gnu/bin --with-build-time-tools=/scratch/cmoore/2012.03-63-linux-lite/obj/to
ols-i686-pc-linux-gnu-2012.03-63-mips-linux-gnu-i686-mingw32/mips-linux-gnu/bin
Thread model: posix
gcc version 4.6.3 (Sourcery CodeBench Lite 2012.03-63)



I tried the following compile parameters:

  1. mips-linux-gnu-gcc -mips32 -muclibc -o factorial factorial.c

When I ran the output binary on the MIPS box, it just printed "can't load library 'libgcc_s.so.1' ".

  1. mips-linux-gnu-gcc -muclibc -mips32 -static-libgcc -s -o factorial factorial.c

When I run its output, it prints 'sigsegv'.

What is wrong here? What compiler parameter should I enter? Please help me.

2
  • Does factorial.c compile and run successfully with gcc on an x86 box? Have you tried stepping through the code with mips-linux-gnu-gdb?
    – markgz
    Commented Aug 30, 2012 at 1:05
  • The code compiles and runs fine for x86. I dont know about stepping with GDB. :/ Commented Aug 30, 2012 at 19:09

2 Answers 2

3

Do you have libgcc_s.so.1 on teh file system? If not, the toolchain will have a folder to copy onto the file system. Do that.

If you do, ensure LD_LIBRARY_PATH is correctly set.

EDIT: Generic issue resolution

When you create a executable, you link to libraries. Those libraries must also be present in the environment where you run the executable. Hence in general in a embedded system 3 things must match

  1. The kernel headers
  2. The toolchain
  3. The file system

Here is how they are related

Your kernel headers are used as #include in your program in some form finally. So what headers the toolchain uses must match the actual one running and will be present in the file system.

The toolchain will consist of libraries to link to, so that the executable can be created [think libc and others]. These must be the same present in your runtime environment which is your filesystem

The toolchain must create a format agreable to your kernel. Executable format.

So in general if you don't have a file in your filesystem while trying to execute it should come from some sdk or your toolchain. If you have it in the filesystem then you can instruct your toolchain to use it from there.

One way to get around the problem if you do not have the libraries in the filesystem for some reason is to build static executables. But you must be sure you know what you are doing.

EDIT: Specific issue you are facing If you filesystem is readonly then either you already have everything on it and a sdk is provided to develop against. If you dont have that you can still develop by getting your toolchain to use libraries from your filesystem [think -I, -L].

EDIT 2: Your file system seems to be a ucLibc one. Your toolchain seems to be built against a libc. There is your mismatch.

Now you seem to have a read only file system with no development sdk. So I am not sure the following will work. Your toolchain has to be configured to use only the files from your filesystem and configured for ucLibc. If the router guys have made sure all files needed for development is available in the rilesystem its good enough. Else you need their sdk. See above edit for explanation.

8
  • The router has a readonly filesystem. Only some dir's like VAR are writable. I think the LIB dir is readonly. Commented Aug 30, 2012 at 19:05
  • How can I compile one which doesn't need any external libraries?? Commented Aug 30, 2012 at 19:07
  • Well, then the router guys should have given you a sdk or something. Or you copy the router file system and use the libraries in there. I will edit my answer and explain a bit more
    – av501
    Commented Aug 30, 2012 at 19:28
  • How can I check and match the kernal headers? I cant find source files for the router firmware. I have included some info like router's linux version and my toolchain version info. Please check that out. Commented Aug 31, 2012 at 15:43
  • I am new to linux environment. I tried to static compile using '-static-libgcc' parameter. But when I try to run that binary, it just prints 'sigsegv'. Commented Aug 31, 2012 at 15:45
0

I have successfully compiled this

#include <iostream>
using namespace std;

int main() {
  cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
  return 0;
}

mips-linux-gnu-g++ -muclibc -mips32  main.cpp -o main

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.