|
Hi, I am facing an issue with cross compiling Eglibc and uClibc with Linaro tool chain.I dont know whether it is my error or as somebody suggested,an issue with the tool chain.Guide me experts. I have downloaded linaro tool chain on ubuntu box by $ sudo apt-get install gcc-arm-linux-gnueabi I wanted to have Eglibc and uClibc for ARM, so that I can compile my application and link against them. So i followed the below steps: Eglibc: i)Downloaded Eglibc 2.15.90. ii)Cross compiled for ARM using the below commands: Followed some steps as said above in this forum. $ BUILD_CC=gcc CC=arm-linux-gnueabi-gcc CXX=arm-linux-gnueabi-cpp AR=arm-linux-gnueabi-ar RANLIB=arm-linux-gnueabi-ranlib /home/user/EGLIBC/eglibc/libc/configure –prefix=/home/user/EGLIBC/eglibc/INSTALL –with-headers=/usr/arm-linux-gnueabi/include –build=i686-linux-gnu –host=arm-linux-gnueabi –enable-kernel=2.6.15–enable-add-ons=libidn,ports,nptl –with-tls –with-__thread $ make $ sudo make install By the above steps got libc.so.6 in the prefix directory. iii)I checked the library by linking against an example application both statically and dynamically.Below is the steps i followed. DYNAMIC LINKING: $ arm-linux-gnueabi-gcc -L/home/user/EGLIBC/eglibc/INSTALL/lib test.c -lc -o dynamic_test Into the pandaboard i copied the neccessary libraries and app binary. $ ./dynamic_test Hello world!!! //It works STATIC LINKING: $ arm-linux-gnueabi-gcc -static -L/home/user/EGLIBC/eglibc/INSTALL/lib test.c -lc -o static_test Into the pandaboard i copied the static app binary. $ ./static_test Illegal instruction //It doesn’t work The size of the static application binary is only 2.7Mb and the size of the Eglibc static library libc.a is 15.2Mb. Even i tried the static compilation of application using the default libc.so.6 present in the Linaro tool chain. That also gave the same illegal instruction. uClibc: i)Downloaded uClibc 0.9.32.1 ii)In the menuconfig,chose some basic options iii)make CROSS=arm-linux-gnueabi- iv)make PREFIX=/home/user/uClibc-0.9.32.1/install_dir libc.so.0 is the library produced. v)I checked the library by linking against an example application both statically and dynamically.Below is the steps i followed DYNAMIC LINKING: $ export LD_LIBRARY_PATH=/home/nishanthv/uClibc-0.9.32.1/install_dir/usr/arm-linux-uclibc/lib:/home/nishanthv/uClibc-0.9.32.1/install_dir/usr/arm-linux-uclibc/usr/lib $ arm-linux-gnueabi-gcc test.c -o dynamic_test $ file dynamic_test dynamic_test: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, not stripped $ objdump -x dynamic_test | grep NEEDED NEEDED libc.so.6 It is not taking the libc.so.0 that i am including via LD_LIBRARY_PATH. It is taking libc.so.6 from the default location of the Linaro tool chain. STATIC LINKING: $ arm-linux-gnueabi-gcc -static test.c -o static_test If i run it on pandaboard it shows Illegal Instruction The thing is only Eglibc/dynamic pair works in the Eglibc,uClibc Dynamic,static pair. Please give me your suggestions on it. thanks and regards mayur |
|
Hi Mayur, I don't think that your calls to gcc in the Linaro toolchain worked as you expected it to:
If I were you, I would build complete uClibc and eglibc toolchains directly from Linaro gcc sources. I would use Crosstool-ng to do this (http://crosstool-ng.org/). See https://wiki.linaro.org/WorkingGroups/ToolChain/Using/CrosstoolNg for tips about using Crosstool-ng. Hope this helps, Cheers, Michael. |
|
Hi Michael,
thanks and regards mayur |
|
Hi Mayur. Weird, I tried to reproduce your issue, but with the same command, the binary I produce just works on my Panda board. No illegal instruction! /usr/bin/arm-linux-gnueabi-gcc -static hello.c -o hello And here's what 'file' report about my executable: $ file hello hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.16, not stripped Here's my cross-toolchain package: $ dpkg -l | grep gcc-arm-linux-gnueabi ii gcc-arm-linux-gnueabi 4:4.6.0-8 The GNU C compiler for armel architecture Would you mind sharing the output of 'file' on your executable, please? Thanks, Michael. |
|
Hi Michael,
|
|
Please run the program on the target under GDB, catch the illegal instruction, disassemble it, and see where the problem originates. |
|
Hi Mayur, I get the same size as you do. Weird (don't hesitate to try my binary: http://free-electrons.com/tmp/hello). I am not surprised about the size. The compiler "just" took the parts of glibc that it needed in the static binary, not the whole of it. It's a good idea to follow Andrew's suggestion. It should let us know where the illegal instruction happens. Before disassembling your executable, I'd suggest you to recompile it with debug information (gcc -g):
Then you can disassemble and you will see source code (at least for your program) mixed with assembly:
Then, run the program with gdb, and once you get the IP (Instruction Pointer), you can find the corresponding address in the disassembled source code. Hope this helps. Cheers, Michael. |
|
Hi Michael,
thanks and regards mayur |