@@ -27,28 +27,38 @@ usage() {
2727 if [ $# -ne 0 ]; then
2828 echo " ERROR: $@ "
2929 fi
30- echo -e " \nUsage: $0 <imagedirpath> [symtabprefix] [-a additionalsymbolspath]"
30+ echo -e " \nUsage: $0 <imagedirpath1> [imagedirpath2 ...] [symtabprefix] [-a additionalsymbolspath]"
3131 exit 1
3232}
3333
34- # Check for the required directory path
34+ # Collect all image directory/file paths until we hit a non-path argument
35+ dirs=()
36+ prefix=" "
3537
36- dir=$1
37- if [ -z " $dir " ]; then
38- usage " Missing <imagedirpath>"
39- fi
40-
41- # Get the symbol table prefix
38+ while [ $# -gt 0 ]; do
39+ # Check if this is an option flag
40+ if [ " x${1: 0: 1} " = " x-" ]; then
41+ break
42+ fi
43+
44+ # Check if this is a valid path (file or directory)
45+ if [ -e " $1 " ]; then
46+ dirs+=(" $1 " )
47+ shift
48+ else
49+ # Not a valid path, treat as prefix
50+ prefix=$1
51+ shift
52+ break
53+ fi
54+ done
4255
43- if [ " x${2: 0: 1} " != " x-" ]; then
44- prefix=$2
45- OPTIND=3
46- else
47- OPTIND=2
56+ # Check we have at least one directory
57+ if [ ${# dirs[@]} -eq 0 ]; then
58+ usage " Missing <imagedirpath>"
4859fi
4960
50- # Parse remaining arguments
51-
61+ # Parse remaining arguments for options
5262while getopts a: opt; do
5363 case $opt in
5464 a)
@@ -63,28 +73,60 @@ if [ $OPTIND != $(($# + 1)) ]; then
6373 usage " Arguments remaining: \" ${@: $OPTIND } \" "
6474fi
6575
76+ # Function to get exec list from a path (file or directory)
77+ get_exec_list () {
78+ local path=$1
79+ if [ -f " $path " ]; then
80+ echo " $path "
81+ elif [ -d " $path " ]; then
82+ find " $path " -type f 2> /dev/null
83+ fi
84+ }
85+
6686# Extract all of the undefined symbols from the ELF files and create a
6787# list of sorted, unique undefined variable names.
6888
69- varlist=` find $dir -name * -thunk.S 2> /dev/null | xargs grep -h asciz | cut -f3 | sort | uniq`
89+ # First try to find thunk files from all directories
90+ varlist=" "
91+ for dir in " ${dirs[@]} " ; do
92+ if [ -d " $dir " ]; then
93+ thunklist=` find $dir -name * -thunk.S 2> /dev/null | xargs grep -h asciz 2> /dev/null | cut -f3`
94+ if [ ! -z " $thunklist " ]; then
95+ varlist=" ${varlist} ${thunklist} "
96+ fi
97+ fi
98+ done
99+
70100if [ -z " $varlist " ]; then
71- execlist=` find $dir -type f 2> /dev/null`
101+ # Collect all executable files from all paths
102+ execlist=" "
103+ for dir in " ${dirs[@]} " ; do
104+ pathlist=` get_exec_list " $dir " `
105+ if [ ! -z " $pathlist " ]; then
106+ execlist=" ${execlist} ${pathlist} "
107+ fi
108+ done
109+
72110 if [ ! -z " $execlist " ]; then
73-
74- # Get all undefined symbol names
75- varlist=` nm $execlist 2> /dev/null | grep -F ' U ' | sed -e " s/^[ ]*//g" | cut -d' ' -f2 | sort | uniq`
76-
77- # Get all defined symbol names
78- deflist=` nm $execlist 2> /dev/null | grep -F -v -e ' U ' -e ' :' | sed -e " s/^[0-9a-z]* //g" | cut -d' ' -f2 | sort | uniq`
79-
80- # Remove the intersection between them, and the remaining symbols are found in the main image
81- common=` echo " $varlist " | tr ' ' ' \n' | grep -Fxf <( echo " $deflist " | tr ' ' ' \n' ) | tr ' \n' ' ' `
82- if [ " x$common " != " x" ]; then
83- varlist=` echo $varlist | sed " s/$common //g" `
111+ # Get all undefined symbol names
112+ varlist=` nm $execlist 2> /dev/null | grep -F ' U ' | sed -e " s/^[ ]*//g" | cut -d' ' -f2`
113+
114+ # Get all defined symbol names
115+ deflist=` nm $execlist 2> /dev/null | grep -F -v -e ' U ' -e ' :' | sed -e " s/^[0-9a-z]* //g" | cut -d' ' -f2`
116+
117+ # Remove the intersection between them, and the remaining symbols are found in the main image
118+ if [ ! -z " $varlist " ] && [ ! -z " $deflist " ]; then
119+ common=` echo " $varlist " | tr ' ' ' \n' | sort | uniq | grep -Fxf <( echo " $deflist " | tr ' ' ' \n' | sort | uniq) | tr ' \n' ' ' `
120+ if [ " x$common " != " x" ]; then
121+ varlist=` echo $varlist | sed " s/$common //g" `
122+ fi
84123 fi
85124 fi
86125fi
87126
127+ # Sort and unique the varlist
128+ varlist=` echo " $varlist " | tr ' ' ' \n' | sort | uniq | tr ' \n' ' ' `
129+
88130for addsym in ${addlist[@]} ; do
89131 if [ -f $addsym ]; then
90132 varlist=" ${varlist} \n$( cat $addsym | grep -v " ^,.*" ) "
0 commit comments