Merge pull request #25820 from hribz/master
[xbmc.git] / tools / webOS / verify-symbols.sh
blob095570bb4735f727273b3e1ea45a218918f65d0a
1 #!/bin/sh
3 # found on https://github.com/webosbrew/dev-utils/tree/main/scripts
5 EXE="$1"
7 if [ ! -f "${EXE}" ]; then
8 echo "Usage: $0 executable"
9 exit 1
12 if [ ! -d "${WEBOS_ROOTFS}" ]; then
13 echo 'WEBOS_ROOTFS is not a directory'
14 exit 1
17 lib_search_paths="${WEBOS_ROOTFS}/lib:${WEBOS_ROOTFS}/usr/lib:${WEBOS_LD_LIBRARY_PATH}"
19 required_syms=$(nm --dynamic --extern-only --undefined-only "${EXE}" | grep ' [U] ' | tr -s ' ' | cut -d ' ' -f 3)
21 needed_libs=$(objdump -p "${EXE}" | grep NEEDED | tr -s ' ' | cut -d ' ' -f 3)
22 found_libs=""
23 has_missing=0
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}"
35 done
36 IFS=$OLDIFS
37 if [ ${lib_found} = 0 ]; then
38 has_missing=1
39 echo "Missing library: ${lib}"
41 done
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 '@')
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)"
53 echo "Missing symbol: ${sym_name}${sym_ver}"
55 done
57 if [ ${has_missing} = 0 ]; then
58 echo "All OK."
61 return $has_missing