3 #will put all library dependencies in the elf interpreter directory
5 #we use readelf instead of objdump since we are dependent on elf dynamic
6 #loading technicalities
7 #the first argument is the path name of the target architecture readelf tool
10 #the second argument is a colon separated path list where to look for target
14 #the third argument is the path of the binary whose list of dependencies has
18 #the fourth argument is the location of the target elf interpreter
19 elf_interpreter_location
=$4
21 #the fith argument is the cpio files
24 ################################################################################
28 for p
in $lib_paths;do
29 if test -e "$p/$1"; then
30 if file "$p/$1" |
egrep -q ASCII
;then
31 echo "WARNING:library $p/$1 seems to be a GNU ld script (EVIL!), skipping"
38 echo "unable to find $1 in path=$lib_paths"
46 echo "LIB_PATHS=$LIB_PATHS"
47 for p
in $LIB_PATHS; do
50 *) paths_list
="$paths_list:$p";;
54 LIB_PATHS
="${paths_list#:*}"
59 local cur
=$
(dirname $1)
60 if test "$cur" = "/"; then
64 for p
in $CPIO_DIRS_EMITED; do
66 if test "$p" = "$cur"; then
71 echo "dir $cur 0755 0 0" >>$cpio
72 CPIO_DIRS_EMITED
=$CPIO_DIRS_EMITED:$cur
77 #we put the libs in "trusted" /lib (already emitted in the cpio file with modules)
78 #or the gnu dynamic loader will not find them while loading init
80 for p
in $LIB_PATHS; do
81 #the shared lib soname file, may be a symbolic link, use readlink -f to sort that out
82 echo "file /lib/$(basename $p) $(readlink -f $p) 0755 0 0" >>$cpio
86 #the parameters are lib sonames
90 if test "$soname" = "$(basename $ELF_BINARY_INTERPRETER)"; then
91 printf "soname $1 is elf interpreter, skipping\n--------\n"
95 echo "collecting needed for soname=$soname"
98 echo "lib location is $lib_path";
100 local needed
="$($target_readelf --dynamic "$lib_path" | egrep NEEDED | sed --regexp-extended 's/^.+\(NEEDED\).+Shared library:.+\[(.+)\]$/\1:/' | tr -d '\n')"
102 printf "needed=$needed\n--------\n"
103 lib_paths_collect
$needed
104 LIB_PATHS
="$LIB_PATHS:$lib_path"
106 LIB_PATHS
=${LIB_PATHS#:}
109 ################################################################################
112 ELF_BINARY_SONAMES
=$
($target_readelf --dynamic .
/init |
egrep NEEDED \
113 |
sed --regexp-extended \
114 's/^.+\(NEEDED\).+Shared library:.+\[(.+)\]$/\1:/' |
tr -d '\n')
115 ELF_BINARY_SONAMES
=${ELF_BINARY_SONAMES%:}
116 ELF_BINARY_INTERPRETER
=$
($target_readelf -l .
/init |
egrep 'Requesting program interpreter' |
sed -r 's/^.+interpreter:[[:space:]]*(.+)\]/\1/')
118 echo "$3 sonames=$ELF_BINARY_SONAMES"
119 echo "$3 elf interpreter=$ELF_BINARY_INTERPRETER"
122 echo '================================================================================'
123 lib_paths_collect
$ELF_BINARY_SONAMES
124 echo '================================================================================'
127 cpio_dirs_emit
$ELF_BINARY_INTERPRETER
129 #sort out with readlink -f the case where the elf interpreter is a symbolic link
130 echo "file $ELF_BINARY_INTERPRETER $(readlink -f "$elf_interpreter_location") 0755 0 0" >>$cpio