aboutsummaryrefslogtreecommitdiff
path: root/utils/check_symbols.sh
blob: 5ab064c184def42b653941f4143de635cce70c32 (plain)
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
#!/usr/bin/env sh

set -e

SCRIPT_DIR="$(realpath $(dirname ${0}))"
NDPI_LIB="${1:-${SCRIPT_DIR}/../src/lib/libndpi.a}"

if [ ! -r "${NDPI_LIB}" ]; then
    printf '%s\n' "${0}: nDPI static library '$(realpath ${NDPI_LIB})' not found."
    exit 1
fi

FAIL_COUNT=0
CURRENT_OBJECT=''
for line in `nm -P -u "${NDPI_LIB}"`; do
    OBJECT="$(printf '%s' "${line}" | grep -E "^${NDPI_LIB}\[.*\.o\]:" | grep -oE "\[.*\.o\]" || true)"
    if [ ! -z "${OBJECT}" ]; then
        CURRENT_OBJECT="${OBJECT}"
    fi

    #printf '%s\n' "${line}"
    FOUND_SYMBOL="$(printf '%s' "${line}" | grep '^\(malloc\|calloc\|realloc\|free\)$' || true)"

    if [ ! -z "${FOUND_SYMBOL}" ]; then
        SKIP=0
        case "${CURRENT_OBJECT}" in
            '[roaring.o]')
                case "${FOUND_SYMBOL}" in
                    'malloc'|'calloc'|'realloc'|'free') SKIP=1 ;;
                esac
            ;;
            '[ndpi_utils.o]'|'[ndpi_memory.o]'|'[roaring.o]')
                case "${FOUND_SYMBOL}" in
                    'malloc'|'calloc'|'free') SKIP=1 ;;
                esac
            ;;
            '[gcrypt_light.o]')
                case "${FOUND_SYMBOL}" in
                    'free') SKIP=1 ;;
                esac
            ;;
        esac

        if [ ${SKIP} -eq 0 ]; then
            FAIL_COUNT="$(expr ${FAIL_COUNT} + 1)"
            printf '%s: %s\n' "${CURRENT_OBJECT}" "${FOUND_SYMBOL}"
        fi
    fi
done

printf 'Unwanted symbols found: %s\n' "${FAIL_COUNT}"
if [ ${FAIL_COUNT} -gt 0 ]; then
    printf '%s\n' 'Please make sure to use only ndpi_malloc/ndpi_calloc/ndpi_realloc/ndpi_free wrapper instead of malloc/calloc/realloc/free'
fi
exit ${FAIL_COUNT}