On 18/04/2010 18:47, Matthias Hofmann wrote:
Hello,
i use a uclibc crosscompiler toolchain to build programs for my target
system which is based on embedded linux, but my programs are not running
properly there, especially shared libraries.
how to install uclibc on my embedded target system?
I just copied the files across that I needed into /lib. You might not
have copied all files that you need across. I've got a Perl script I
wrote 3 years ago to tell me what dependencies I have. YMMV as I haven't
used the script for some time. But it was explicitly for my system with
BusyBox and uClibc 0.9.29 and later.
I ran it on my host system. Both were x86. If you have a different
target, the script might need some adjustments. In particular, all
information comes from the "readelf" program.
thank you,
matthias
#!/usr/bin/perl
##############################################################################
# File: librarydeps.pl
#
# $Source: $
# $Id: $
#
# Description
# This perl module uses the 'readelf' command available on Linux and Cygwin
# to determine what are libraries, their 'soname' and what binaries use
# what libraries.
#
# It then prints dependencies, finally printing a reference count for each
# time a library is explicitly included. This can then be used to determine
# what shared libraries exist on a system that are not linked to any binaries
# (including other libaries)
#
# Usage
# Change to the root filesystem in question. Execute this command.
#
# Requirements
# * You will need 'readelf' that understands the option '-d' and prints
# output in the format:
#
# File: ./lib/libutil-0.9.29.so
#
# Dynamic section at offset 0xefc contains 14 entries:
# Tag Type Name/Value
# 0x00000001 (NEEDED) Shared library: [libc.so.0]
# 0x0000000e (SONAME) Library soname: [libutil.so.0]
#
# * You will need 'find' that understands the option '-f' to find files only
# (ignoring symlinks).
#
# Design
#
# Revision History
#
# Notes
#
# To Do
#
##############################################################################
use warnings;
use strict;
# Function Prototypes
sub ParseData();
sub PrintDeps($$);
# The contents of the data
my @data;
# A hash converting an 'soname' to a filename
my %soname;
# A hash of arrays, the key being the 'filename', the array being the list of
# sonames this file needs
my %needs;
# A hash of arrays, the key being the 'soname', the array being the files to
# use this library
my %neededby;
# A hash of scalars that indicates the count each library is needed
my %needcount;
# A has of missing libraries
my %missing;
#############################################################################
# Function: ParseData
#
# Inputs:
# None
#
# Outputs:
# None
#
# Description:
# Reads @data, populating %soname, %needs and %neededby
#
# Design
#
# Return
#
# Error Handling
#
#############################################################################
sub ParseData()
{
my $file;
my $lib;
my $libfile;
my $unique;
# Step 1: Build the mapping from SONAME to FILENAME
# Build the dependency tree
open(READELF, "readelf -d `find . -type f` 2>/dev/null |") || die;
while(<READELF>) {
chomp $_;
if ($_ =~ m/File:\s*(\S+)/) {
$file = $1;
}
if ($_ =~ m/\(SONAME\)\s+Library soname:\s+\[(.+)\]/) {
# $1 - Library soname
# $soname{SONAME} = $FILENAME
$soname{$1} = $file;
}
if ($_ =~ m/\(NEEDED\)\s+Shared library:\s+\[(.+)\]/) {
# $1 - Library soname
# $needs{$FILENAME} = $SONAME;
push @{ $needs{$file} }, $1;
}
}
close(READELF);
# Step 2: Reverse dependency checking
foreach $file ( keys %needs ) {
foreach $lib ( @{ $needs{$file} } ) {
if (defined($soname{$lib})) {
$libfile = $soname{$lib};
} else {
$libfile = $lib;
$missing{$lib} = $lib;
}
$unique = 1;
foreach ( @{ $neededby{$libfile} }) {
if ($_ eq $file) {
$unique = 0;
}
}
if ($unique) {
push @{ $neededby{$libfile} }, $file;
}
$needcount{$libfile}++;
}
}
# Step 3: Update dependency count, for those that have no dependencies
foreach $lib ( keys %soname ) {
unless(defined($needcount{$soname{$lib}})) {
$needcount{$soname{$lib}} = 0;
}
}
}
#############################################################################
# Function: PrintDeps
#
# Inputs:
# $depth - Current depth
# $file - File to print the dependencies of
#
# Outputs:
# None
#
# Description:
# Prints the dependencies for the library $soname recursively
#
# Design
#
# Return
#
# Error Handling
#
#############################################################################
sub PrintDeps($$)
{
my $i;
my $depth = shift(@_);
my $file = shift(@_);
my $son;
if ($depth) {
for ($i=0; $i<$depth; $i++) {
print " ";
}
} else {
print "\n";
}
print "$file\n";
foreach $son ( @{ $needs{$file} } ) {
if (defined($soname{$son})) {
PrintDeps($depth+1, $soname{$son});
} else {
PrintDeps($depth+1, $son);
}
}
}
#############################################################################
# readelf -d `find . -name '*' -type f`
ParseData();
# Print the mapping from SONAME to FILE
print "=================================================================\n";
print "Library -> Filename mapping\n";
print "=================================================================\n";
print "Library SONAME Filename\n";
print "-------------------- --------------------------------------------\n";
foreach ( sort keys %soname ) {
printf "%-20s %-44s\n", $_, $soname{$_};
}
print "\n\n";
# Print missing libraries
print "=================================================================\n";
print "Detected missing libraries\n";
print "=================================================================\n";
foreach ( sort keys %missing ) {
print "$_\n";
}
print "\n\n";
# Print what libraries each file needs
print "=================================================================\n";
print "Library resolution\n";
print "=================================================================\n";
foreach ( sort keys %needs ) {
PrintDeps(0, $_);
}
print "\n\n";
# Print what files are used by each library
print "=================================================================\n";
print "Library used\n";
print "=================================================================\n";
foreach ( sort keys %neededby ) {
print "$_\n";
foreach ( sort @{ $neededby{$_} } ) {
print " $_\n";
}
}
print "\n\n";
# Print reference counts
print "=================================================================\n";
print "Direct Reference Counts\n";
print "=================================================================\n";
foreach ( sort keys %needcount ) {
printf "%3d %s\n", $needcount{$_}, $_;
}
_______________________________________________
uClibc mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/uclibc