forked from che-incubator/che-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-runtime-libs.sh
More file actions
executable file
·80 lines (65 loc) · 2.01 KB
/
check-runtime-libs.sh
File metadata and controls
executable file
·80 lines (65 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/sh
set -eu
RUNTIME_DIR="${1:-/checode/checode-linux-libc/ubi9}"
LIBS_DIR="${RUNTIME_DIR}/ld_libs"
NODE_BIN="${RUNTIME_DIR}/node"
echo "Runtime: ${RUNTIME_DIR}"
echo "Libs: ${LIBS_DIR}"
echo "Node: ${NODE_BIN}"
echo
if [ ! -x "${NODE_BIN}" ]; then
echo "ERROR: node binary not found: ${NODE_BIN}" >&2
exit 1
fi
if [ ! -d "${LIBS_DIR}" ]; then
echo "ERROR: libs dir not found: ${LIBS_DIR}" >&2
exit 1
fi
if ! command -v objdump >/dev/null 2>&1; then
echo "ERROR: objdump is required (install binutils in the container)." >&2
exit 1
fi
TMP_NEEDS="$(mktemp)"
TMP_HAVE="$(mktemp)"
TMP_MISS="$(mktemp)"
trap 'rm -f "$TMP_NEEDS" "$TMP_HAVE" "$TMP_MISS"' EXIT
# Collect what we have in ld_libs (basename only).
find "${LIBS_DIR}" -maxdepth 1 -type f -name '*.so*' -exec basename {} \; | sort -u > "${TMP_HAVE}"
scan_needed() {
f="$1"
objdump -p "$f" 2>/dev/null | awk '/NEEDED/ {print $2}' || true
}
# Scan node and all native addons.
scan_needed "${NODE_BIN}" >> "${TMP_NEEDS}"
find "${RUNTIME_DIR}" -type f -name '*.node' 2>/dev/null | while read -r so; do
# Ignore non-linux prebuilt addons to reduce noise.
case "$so" in
*win32*|*windows*|*darwin*|*macos*) continue ;;
esac
scan_needed "$so" >> "${TMP_NEEDS}"
done
sort -u "${TMP_NEEDS}" -o "${TMP_NEEDS}"
echo "=== NEEDED (unique) ==="
cat "${TMP_NEEDS}"
echo
echo "=== HAVE in ld_libs ==="
cat "${TMP_HAVE}"
echo
# Ignore glibc core, usually expected from the host/container base.
grep -Ev '^(linux-vdso\.so\.1|libc\.so\.6|libm\.so\.6|libpthread\.so\.0|libdl\.so\.2|librt\.so\.1|ld-linux-.*\.so.*)$' "${TMP_NEEDS}" > "${TMP_MISS}" || true
echo "=== MISSING in ld_libs (excluding glibc core) ==="
MISSING_COUNT=0
while read -r need; do
[ -z "$need" ] && continue
if ! grep -qx "$need" "${TMP_HAVE}"; then
echo "$need"
MISSING_COUNT=$((MISSING_COUNT + 1))
fi
done < "${TMP_MISS}"
echo
if [ "${MISSING_COUNT}" -eq 0 ]; then
echo "OK: no missing non-glibc SONAMEs in ld_libs"
else
echo "FAIL: missing ${MISSING_COUNT} SONAME(s)"
exit 2
fi