Thursday, June 16, 2011

embedded libc hell

Sometimes embedded world is a real hell place. Lets look

# cd /bin/
# ./lscgroup
-sh: ./lscgroup: not found
# ls -la lscgroup
-rwxr-xr-x 1 65534 65534 23138 May 27 2011 lscgroup

wtf??? it's executable but some strange error message. Let's look deeply

# ldd ./lscgroup
.......
libc.so.0 => /lib/libc.so.0 (0x4000e000)
ld-uClibc.so.0 => /lib/ld-uClibc.so.0 (0x40000000)
.......
libc.so.6 => not found (0x00000000)
.......
#

I compiled libcgroups with glibc and try to run under uClibc. I spent to investigate this issue whole day(( I dont have crosslaform with uClibc and I cant change board environment to glibc. And what we can do??? I found (my friends told me that it's the common way to solve problem like this). We can chroot into a new envornment. For example from uClibc chroot to glibc. Ok.
Download fedore core rootfs
http://ftp.linux.org.uk/pub/linux/arm/fedora/rootfs/fc6-arm-root-with-gcc.tar.bz2
it contains gcc!!! very usefull sometimes when all crash with cross building. Setup NFS server, unpack arch into dir, export dir (restart NFS server and check it with the command exportfs) and mount fedore core root to the device folder. After that you must mount /dev /proc /sys into chroot environment and chroot

mount -o bind /proc/ /root_fc/proc
mount -o bind /dev/ /root_fc/dev/
mount -o bind /sys/ /root_fc/sys/
chroot /root_fc/ /bin/sh

And....

# lscgroup
cgroups can't be listed: Cgroup is not mounted
#

it's working, check with ldd that all works fine.

3 comments:

  1. I don't know actually, but if uClibc has compatible binary interface with glibc, then creating of symbolic link from uClibc to glibc may help.

    ReplyDelete
  2. it will works with programs, but it wont with library. i've tested it under qemu and real HW. =( may be i missing something, btw with chroot works fine.

    ReplyDelete
  3. about symlink, i tried, but it's not working at all, system falling. For example when you compile sources with glibc it links with libc.so.6, and when you compile it with uClibc it links with libc.so.0 (or something near this - dont remember and dont have ARM here). when you try to make symlink from current libc to linked name (libc.so.6) all system crush and you need unmount and restore target /lib from host

    ReplyDelete