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 for p
in $LIB_PATHS; do
49 *) paths_list
="$paths_list:$p";;
53 LIB_PATHS
="${paths_list#:*}"
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
78 for p
in $LIB_PATHS; do
79 #the shared lib soname file, may be a symbolic link, use realpath to sort that out
80 echo "file $(dirname $ELF_BINARY_INTERPRETER)/$(basename $p) $(realpath $p) 0755 0 0" >>$cpio
84 #the parameters are lib sonames
88 if test "$soname" == "$(basename $ELF_BINARY_INTERPRETER)"; then
89 echo -e "soname $1 is elf interpreter, skipping\n--------"
93 echo -e "collecting needed for soname=$soname"
96 echo "lib location is $lib_path";
98 local needed
=$
($target_readelf --dynamic "$lib_path" |
egrep NEEDED |
sed --regexp-extended 's/^.+\(NEEDED\).+Shared library:.+\[(.+)\]$/\1:/' |
tr -d '\n')
100 echo -e "needed=$needed\n--------"
101 lib_paths_collect
$needed
102 LIB_PATHS
="$LIB_PATHS:$lib_path"
104 LIB_PATHS
=${LIB_PATHS#:}
107 ################################################################################
110 ELF_BINARY_SONAMES
=$
($target_readelf --dynamic .
/init |
egrep NEEDED \
111 |
sed --regexp-extended \
112 's/^.+\(NEEDED\).+Shared library:.+\[(.+)\]$/\1:/' |
tr -d '\n')
113 ELF_BINARY_SONAMES
=${ELF_BINARY_SONAMES%:}
114 ELF_BINARY_INTERPRETER
=$
($target_readelf -l .
/init |
egrep 'Requesting program interpreter' |
sed -r 's/^.+interpreter:[[:space:]]*(.+)\]/\1/')
116 echo "$3 sonames=$ELF_BINARY_SONAMES"
117 echo "$3 elf interpreter=$ELF_BINARY_INTERPRETER"
120 echo '================================================================================'
121 lib_paths_collect
$ELF_BINARY_SONAMES
122 echo '================================================================================'
125 cpio_dirs_emit
$ELF_BINARY_INTERPRETER
127 #sort out with realpath the case where the elf interpreter is a symbolic link
128 echo "file $ELF_BINARY_INTERPRETER $(realpath "$elf_interpreter_location") 0755 0 0" >>$cpio