blob: 6c142cecff968c528fa1e4d90b014097400c8a55 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
#!/bin/bash
# pulled right out of mkinitrd....
export LD_HWCAP_MASK=0
DSO_DEPS=""
LDSO=""
get_dso_deps() {
root="$1" ; shift
bin="$1" ; shift
LDSODIR="$1" ; shift
DSO_DEPS=""
declare -a FILES
declare -a NAMES
[ -z "$LDSODIR" ] && LDSODIR=$LIBDIR
# this is a hack, but the only better way requires binutils or elfutils
# be installed. i.e., we need readelf to find the interpretter.
if [ -n "$LDSO" ]; then
$LDSO --verify $root/$bin >/dev/null 2>&1
case $? in
[02]) ;;
*) unset LDSO ;;
esac
fi
if [ -z "$LDSO" ]; then
for ldso in $root/$LDSODIR/ld*.so* ; do
[ -L $ldso ] && continue
[ -x $ldso ] || continue
$ldso --verify $root/$bin >/dev/null 2>&1
case $? in
[02]) LDSO=$(echo $ldso |sed -e "s,$root,,") ; break ;;
esac
done
fi
# I still hate shell.
declare -i n=0
while read NAME I0 FILE ADDR I1 ; do
[ "$FILE" == "not" ] && FILE="$FILE $ADDR"
NAMES[$n]="$NAME"
FILES[$n]="$FILE"
let n++
# try to find a generic version
local basedir=$(dirname $(dirname "$FILE"))
local basefile=$(basename "$FILE")
if [ -f "$basedir/$basefile" ]; then
NAMES[$n]="$NAME"
FILES[$n]="$basedir/$basefile"
let n++
fi
done << EOF
$(/usr/sbin/chroot $root env --unset=LD_LIBRARY_PATH \
LD_TRACE_PRELINKING=1 LD_WARN= \
LD_TRACE_LOADED_OBJECTS=1 $LDSO $bin)
EOF
[ ${#FILES[*]} -eq 0 ] && return 1
# we don't want the name of the binary in the list
if [ "${FILES[0]}" == "$bin" ]; then
FILES[0]=""
NAMES[0]=""
[ ${#FILES[*]} -eq 1 ] && return 1
fi
declare -i n=0
while [ $n -lt ${#FILES[*]} ]; do
FILE="${FILES[$n]}"
if [ "$FILE" == "not found" ]; then
echo "WARNING: The dynamic object $bin requires ${NAMES[$n]} n order to properly function."
continue
fi
case "$FILE" in
/lib*)
TLIBDIR=`echo "$FILE" | sed 's,\(/lib[^/]*\)/.*$,\1,'`
BASE=`basename "$FILE"`
# Prefer nosegneg libs over direct segment accesses on i686.
if [ -f "$TLIBDIR/i686/nosegneg/$BASE" ]; then
FILE="$TLIBDIR/i686/nosegneg/$BASE"
# Otherwise, prefer base libraries rather than their optimized
# variants.
elif [ -f "$TLIBDIR/$BASE" ]; then
FILE="$TLIBDIR/$BASE"
fi
;;
esac
dynamic="yes"
let n++
done
DSO_DEPS="${FILES[@]}"
for l in $(/usr/sbin/chroot $root find /$LDSODIR -maxdepth 1 -type l -name ld*.so*); do
[ "$(/usr/sbin/chroot $root readlink -f $l)" == "$LDSO" ] && DSO_DEPS="$DSO_DEPS $l"
done
if [ "$(uname -m)" == "s390x" ]; then
for l in $(/usr/sbin/chroot $root find /lib -maxdepth 1 -type l -name ld*.so*); do
[ "$(/usr/sbin/chroot $root readlink -f $l)" == "$LDSO" ] && DSO_DEPS="$DSO_DEPS $l"
done
fi
[ -n "$DEBUG" ] && echo "DSO_DEPS for $bin are $DSO_DEPS"
}
instFile() {
FILE=$1
DESTROOT=$2
[ -n "$DEBUG" ] && echo "Installing $FILE"
if [ -e $DESTROOT/$FILE -o -L $DESTROOT/$FILE ]; then
return
elif [ ! -d $DESTROOT/`dirname $FILE` ]; then
mkdir -p $DESTROOT/`dirname $FILE`
fi
if [ -L $FILE ]; then
cp -al $FILE $DESTROOT/`dirname $FILE`
instFile ./`dirname $FILE`/`readlink $FILE` $DESTROOT
return
else
cp -aL $FILE $DESTROOT/`dirname $FILE`
fi
f=$(file $FILE)
echo $f | egrep -q ": (setuid )?ELF" &&
echo $f | egrep -qv "statically linked" && {
if echo $f | grep -q " 64-bit " ; then
get_dso_deps $(pwd) "$FILE" lib64
else
get_dso_deps $(pwd) "$FILE" lib
fi
local DEPS="$DSO_DEPS"
for x in $DEPS ; do
instFile ./$x $DESTROOT
done
}
unset f
}
instDir() {
DIR=$1
DESTROOT=$2
[ -n "$DEBUG" ] && echo "Installing $DIR"
if [ -d $DESTROOT/$DIR -o -h $DESTROOT/$DIR ]; then
return
fi
cp -a --parents $DIR $DESTROOT/
}
|