From 360b4b702305ca6d03b5f52675ce841af7a522ed Mon Sep 17 00:00:00 2001 From: josch Date: Tue, 18 Oct 2011 23:12:31 +0200 Subject: [PATCH] use FAKECHROOT_CMD_SUBST instead of backing up and replacing files in chroot --- default/root/sbin/ldconfig | 3 - default/root/usr/bin/ldd | 201 ------------------------------- kirkwood/root/sbin/ldconfig | 1 - kirkwood/root/usr/bin/ldd | 1 - notioninkadam/root/sbin/ldconfig | 1 - notioninkadam/root/usr/bin/ldd | 1 - om-gta02/root/sbin/ldconfig | 1 - om-gta02/root/usr/bin/ldd | 1 - polystrap.sh | 12 +- touchbook/root/sbin/ldconfig | 1 - touchbook/root/usr/bin/ldd | 1 - 11 files changed, 1 insertion(+), 223 deletions(-) delete mode 100755 default/root/sbin/ldconfig delete mode 100755 default/root/usr/bin/ldd delete mode 120000 kirkwood/root/sbin/ldconfig delete mode 120000 kirkwood/root/usr/bin/ldd delete mode 120000 notioninkadam/root/sbin/ldconfig delete mode 120000 notioninkadam/root/usr/bin/ldd delete mode 120000 om-gta02/root/sbin/ldconfig delete mode 120000 om-gta02/root/usr/bin/ldd delete mode 120000 touchbook/root/sbin/ldconfig delete mode 120000 touchbook/root/usr/bin/ldd diff --git a/default/root/sbin/ldconfig b/default/root/sbin/ldconfig deleted file mode 100755 index a7b8b6d..0000000 --- a/default/root/sbin/ldconfig +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -e - -exit diff --git a/default/root/usr/bin/ldd b/default/root/usr/bin/ldd deleted file mode 100755 index 53e9533..0000000 --- a/default/root/usr/bin/ldd +++ /dev/null @@ -1,201 +0,0 @@ -#!/usr/bin/perl - -# fakeldd -# -# Replacement for ldd with usage of objdump -# -# (c) 2003-2010 Piotr Roszatycki , LGPL - -use strict; - -my @Libs = (); -my %Libs = (); - -my $Status = 0; -my $Dynamic = 0; -my $Format = ''; - -my $Ldsodir = "/lib"; -my @Ld_Library_Path = qw(/usr/lib /lib /usr/lib32 /lib32 /usr/lib64 /lib64); - - -sub ldso { - my ($lib) = @_; - - return if $Libs{$lib}; - - my $path; - - if ($lib =~ /^\//) { - $path = $lib; - } - else { - foreach my $dir (@Ld_Library_Path) { - next unless -f "$dir/$lib"; - - my $badformat = 0; - local *PIPE; - open PIPE, "objdump -p '$dir/$lib' 2>/dev/null |"; - while (my $line = ) { - if ($line =~ /file format (\S*)$/) { - $badformat = 1 unless $1 eq $Format; - last; - } - } - close PIPE; - - next if $badformat; - - $path = "$dir/$lib"; - last; - } - } - - push @Libs, $lib; - if (-f $path) { - $Libs{$lib} = $path; - objdump($path); - } -} - - -sub objdump { - my (@files) = @_; - - foreach my $file (@files) { - local *PIPE; - open PIPE, "objdump -p '$file' 2>/dev/null |"; - while (my $line = ) { - $line =~ s/^\s+//; - - if ($line =~ /file format (\S*)$/) { - if (not $Format) { - $Format = $1; - - if ($^O eq 'linux') { - if ($Format =~ /^elf64-/) { - push @Libs, 'linux-vdso.so.1'; - $Libs{'linux-vdso.so.1'} = ''; - } - else { - push @Libs, 'linux-gate.so.1'; - $Libs{'linux-gate.so.1'} = ''; - } - } - - foreach my $lib (split /:/, $ENV{LD_PRELOAD}||'') { - ldso($lib); - } - } - else { - next unless $Format eq $1; - } - } - if (not $Dynamic and $line =~ /^Dynamic Section:/) { - $Dynamic = 1; - } - - next unless $line =~ /^ \s* NEEDED \s+ (.*) \s* $/x; - - my $needed = $1; - if ($needed =~ /^ld(-linux)?(\.|-)/) { - $needed = "$Ldsodir/$needed"; - } - - ldso($needed); - } - close PIPE; - } -} - - -sub load_ldsoconf { - my ($file) = @_; - - local *FH; - open FH, $file; - while (my $line = ) { - chomp $line; - $line =~ s/#.*//; - next if $line =~ /^\s*$/; - - if ($line =~ /^include\s+(.*)\s*/) { - my $include = $1; - foreach my $incfile (glob $include) { - load_ldsoconf($incfile); - } - next; - } - - unshift @Ld_Library_Path, $line; - } - close FH; -} - - -MAIN: { - my @args = @ARGV; - - if (not @args) { - print STDERR "fakeldd: missing file arguments\n"; - exit 1; - } - - if (not `which objdump`) { - print STDERR "fakeldd: objdump: command not found: install binutils package\n"; - exit 1; - } - - load_ldsoconf('/etc/ld.so.conf'); - unshift @Ld_Library_Path, split(/:/, $ENV{LD_LIBRARY_PATH}||''); - - while ($args[0] =~ /^-/) { - my $arg = $args[0]; - shift @ARGV; - last if $arg eq "--"; - } - - foreach my $file (@args) { - %Libs = (); - $Dynamic = 0; - - if (@args > 1) { - print "$file:\n"; - } - - if (not -f $file) { - print STDERR "ldd: $file: No such file or directory\n"; - $Status = 1; - next; - } - - objdump($file); - - if ($Dynamic == 0) { - print "\tnot a dynamic executable\n"; - $Status = 1; - } - elsif (scalar %Libs eq "0") { - print "\tstatically linked\n"; - } - - my $address = '0x' . '0' x ($Format =~ /^elf64-/ ? 16 : 8); - - foreach my $lib (@Libs) { - if ($lib =~ /^\//) { - printf "\t%s (%s)\n", $lib, $address; - } - elsif (defined $Libs{$lib}) { - printf "\t%s => %s (%s)\n", $lib, $Libs{$lib}, $address; - } - else { - printf "\t%s => not found\n", $lib; - } - } - - } -} - -END { - $? = $Status; -} diff --git a/kirkwood/root/sbin/ldconfig b/kirkwood/root/sbin/ldconfig deleted file mode 120000 index ba3ff23..0000000 --- a/kirkwood/root/sbin/ldconfig +++ /dev/null @@ -1 +0,0 @@ -../../../default/root/sbin/ldconfig \ No newline at end of file diff --git a/kirkwood/root/usr/bin/ldd b/kirkwood/root/usr/bin/ldd deleted file mode 120000 index adf2fbc..0000000 --- a/kirkwood/root/usr/bin/ldd +++ /dev/null @@ -1 +0,0 @@ -../../../../default/root/usr/bin/ldd \ No newline at end of file diff --git a/notioninkadam/root/sbin/ldconfig b/notioninkadam/root/sbin/ldconfig deleted file mode 120000 index ba3ff23..0000000 --- a/notioninkadam/root/sbin/ldconfig +++ /dev/null @@ -1 +0,0 @@ -../../../default/root/sbin/ldconfig \ No newline at end of file diff --git a/notioninkadam/root/usr/bin/ldd b/notioninkadam/root/usr/bin/ldd deleted file mode 120000 index adf2fbc..0000000 --- a/notioninkadam/root/usr/bin/ldd +++ /dev/null @@ -1 +0,0 @@ -../../../../default/root/usr/bin/ldd \ No newline at end of file diff --git a/om-gta02/root/sbin/ldconfig b/om-gta02/root/sbin/ldconfig deleted file mode 120000 index ba3ff23..0000000 --- a/om-gta02/root/sbin/ldconfig +++ /dev/null @@ -1 +0,0 @@ -../../../default/root/sbin/ldconfig \ No newline at end of file diff --git a/om-gta02/root/usr/bin/ldd b/om-gta02/root/usr/bin/ldd deleted file mode 120000 index adf2fbc..0000000 --- a/om-gta02/root/usr/bin/ldd +++ /dev/null @@ -1 +0,0 @@ -../../../../default/root/usr/bin/ldd \ No newline at end of file diff --git a/polystrap.sh b/polystrap.sh index 81081a9..2536a81 100755 --- a/polystrap.sh +++ b/polystrap.sh @@ -81,10 +81,8 @@ else PACKAGES="$_PACKAGES" fi -# binutils must always be installed for objdump for fake ldd -PACKAGES="$PACKAGES binutils" - export QEMU_LD_PREFIX="`readlink -m "$ROOTDIR"`" +export FAKECHROOT_CMD_SUBST=/usr/bin/ldd=/usr/bin/ldd.fakechroot:/sbin/ldconfig=/bin/true echo "I: --------------------------" echo "I: suite: $SUITE" @@ -112,11 +110,6 @@ multistrap $MSTRAP_SIM -f "$MULTISTRAPCONF" rm -f "$MULTISTRAPCONF" -# backup ldconfig and ldd -echo "I: backup ldconfig and ldd" -mv $ROOTDIR/sbin/ldconfig $ROOTDIR/sbin/ldconfig.REAL -mv $ROOTDIR/usr/bin/ldd $ROOTDIR/usr/bin/ldd.REAL - # copy initial directory tree - dereference symlinks echo "I: copy initial directory root tree $BOARD/root/ to $ROOTDIR/" if [ -r "$BOARD/root" ]; then @@ -152,9 +145,6 @@ fi #cleanup echo "I: cleanup" -rm $ROOTDIR/sbin/ldconfig $ROOTDIR/usr/bin/ldd -mv $ROOTDIR/sbin/ldconfig.REAL $ROOTDIR/sbin/ldconfig -mv $ROOTDIR/usr/bin/ldd.REAL $ROOTDIR/usr/bin/ldd rm $ROOTDIR/usr/sbin/policy-rc.d # need to generate tar inside fakechroot so that absolute symlinks are correct diff --git a/touchbook/root/sbin/ldconfig b/touchbook/root/sbin/ldconfig deleted file mode 120000 index ba3ff23..0000000 --- a/touchbook/root/sbin/ldconfig +++ /dev/null @@ -1 +0,0 @@ -../../../default/root/sbin/ldconfig \ No newline at end of file diff --git a/touchbook/root/usr/bin/ldd b/touchbook/root/usr/bin/ldd deleted file mode 120000 index adf2fbc..0000000 --- a/touchbook/root/usr/bin/ldd +++ /dev/null @@ -1 +0,0 @@ -../../../../default/root/usr/bin/ldd \ No newline at end of file