Debian Codegraph @

tools/webOS/verify-symbols.sh

raw
1 #!/bin/sh
2
3 # found on https://github.com/webosbrew/dev-utils/tree/main/scripts
4
5 EXE="$1"
6
7 if [ ! -f "${EXE}" ]; then
8 echo "Usage: $0 executable"
9 exit 1
10 fi
11
12 if [ ! -d "${WEBOS_ROOTFS}" ]; then
13 echo 'WEBOS_ROOTFS is not a directory'
14 exit 1
15 fi
16
17 lib_search_paths="${WEBOS_ROOTFS}/lib:${WEBOS_ROOTFS}/usr/lib:${WEBOS_LD_LIBRARY_PATH}"
18
19 required_syms=$(nm --dynamic --extern-only --undefined-only "${EXE}" | grep ' [U] ' | tr -s ' ' | cut -d ' ' -f 3)
20
21 needed_libs=$(objdump -p "${EXE}" | grep NEEDED | tr -s ' ' | cut -d ' ' -f 3)
22 found_libs=""
23 has_missing=0
24
25 for lib in ${needed_libs}; do
26 lib_found=0
27 OLDIFS=$IFS
28 IFS=:
29 for path in ${lib_search_paths}; do
30 lib_path="${path}/${lib}"
31 if [ -f "${lib_path}" ]; then
32 lib_found=1
33 found_libs="${found_libs} ${lib_path}"
34 fi
35 done
36 IFS=$OLDIFS
37 if [ ${lib_found} = 0 ]; then
38 has_missing=1
39 echo "Missing library: ${lib}"
40 fi
41 done
42
43 # shellcheck disable=SC2086
44 lib_syms=$(nm --dynamic --extern-only --defined-only ${found_libs} | grep ' [a-zA-Z] ' | cut -d ' ' -f 3 | tr -s '@')
45
46 for sym in ${required_syms}; do
47 if ! echo "${lib_syms}" | grep -q "${sym}"; then
48 has_missing=1
49 sym_name=$(echo "${sym}" | cut -d '@' -f 1 | c++filt)
50 if echo "${sym}" | grep -q '@'; then
51 sym_ver="@$(echo ${sym} | cut -d '@' -f 2)"
52 fi
53 echo "Missing symbol: ${sym_name}${sym_ver}"
54 fi
55 done
56
57 if [ ${has_missing} = 0 ]; then
58 echo "All OK."
59 fi
60
61 return $has_missing