login about faq

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

asked 08 Feb, 23:38

mayur's gravatar image

mayur
1112
accept rate: 0%

edited 04 Apr, 02:04

Michael%20Opdenacker's gravatar image

Michael Opde... ♦♦
440139


Hi Mayur,

I don't think that your calls to gcc in the Linaro toolchain worked as you expected it to:

  • the C library (glibc in Linaro toolchains) is hardcoded in the toolchain. AFAIK, you can't change it. Therefore, even if you compile with -L<path to="" your="" different="" libc="">, your executable will be compiled against the libc built into Linaro's toolchain. This is what your test with 'objdump -x' showed.

  • Your dynamic linking experiment with eglibc probably worked because eglibc is supposed to be binary compatible with glibc.

  • AFAIK, LD_LIBRARY_PATH has no impact on compiling. This environment variable is just used to run executables with shared libraries.

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.

link

answered 09 Feb, 16:50

Michael%20Opdenacker's gravatar image

Michael Opde... ♦♦
440139
accept rate: 5%

edited 09 Feb, 16:53

Hi Michael,

 Thanks a lot for your suggestion.I thought that this may be the issue.

 Now i am using the tool chain that i downloaded from the linaro web site.
 I try to statically link the application with the default libc.so.6 that is present in the tool chain ( i guess in gcc-linaro-arm-2012-01-20120125/arm-linux-gnueabi/libc/usr/lib/arm-linux-gnueabi/libc.a) by below command.

 $ arm-linux-gnueabi-gcc -static test.c -o static_test_tc_web
 When i run this on my panda-board,

 $ ./static_test_tc_web 
    Illegal instruction

is the result i get.I am not able to run the statically linked application.Is there any mistake in my method or issue with the tool chain? Please throw some light on this.

thanks and regards

mayur

link

answered 10 Feb, 02:48

mayur's gravatar image

mayur
1112
accept rate: 0%

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.

link

answered 10 Feb, 10:34

Michael%20Opdenacker's gravatar image

Michael Opde... ♦♦
440139
accept rate: 5%

Hi Michael,

      Thanks for the interest that you show in this issue. And this is the output i get for the file on my executable.

      $ file static_test_tc_web

      static_test_tc_web: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.16, not stripped.

      And for your information, the size of the statically linked executable is only 430 KB. Is it linking with some other .a file that is not compiled for ARM itself? .

      thanks and regards
      mayur
link

answered 13 Feb, 01:37

mayur's gravatar image

mayur
1112
accept rate: 0%

Please run the program on the target under GDB, catch the illegal instruction, disassemble it, and see where the problem originates.

link

answered 13 Feb, 07:57

Andrew%20Stubbs's gravatar image

Andrew Stubbs
286
accept rate: 0%

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):

$ arm-linux-gnueabi-gcc -g hello.c -o hello

Then you can disassemble and you will see source code (at least for your program) mixed with assembly:

$ arm-linux-gnueabi-objdump -S hello > hello.S

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.

link

answered 13 Feb, 08:11

Michael%20Opdenacker's gravatar image

Michael Opde... ♦♦
440139
accept rate: 5%

Hi Michael,

        Thanks a lot for your help.

        Having not  debugged the code yet , i found that when i ran your hello (http://free-electrons.com/tmp/hello), even that was failing with the same illegal instruction error.

        I cross compiled an application with another cross compiler (Code-Sourcery 2009) statically, and it ran well.

        i  am baffled with this.

        I shall try debugging the code.

thanks and regards

mayur

link

answered 14 Feb, 01:43

mayur's gravatar image

mayur
1112
accept rate: 0%

edited 14 Feb, 06:01

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×31
×3
×2
×1

Asked: 08 Feb, 23:38

Seen: 440 times

Last updated: 04 Apr, 02:04