summaryrefslogtreecommitdiff
path: root/test-symbols-static.sh
blob: 0720adedb47e242379b4a839a46d4b230af7e89c (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#! /bin/sh
# Written by Zack Weinberg <zackw at panix.com> in 2017.
# To the extent possible under law, Zack Weinberg has waived all
# copyright and related or neighboring rights to this work.
#
# See https://creativecommons.org/publicdomain/zero/1.0/ for further
# details.

# Test that all global symbols in the static version of the library
# (libcrypt.a) are either listed as global and supported for new code
# in libcrypt.map.in, or begin with a _crypt prefix.  Also test that
# all of the global, supported for new code, symbols mentioned in
# libcrypt.map.in are in fact defined.
#
# Due to limitations in Automake, this program takes parameters from
# the environment:
# $lib_la - full pathname of libcrypt.la
# $lib_map - full pathname of libcrypt.map.in

set -e
LC_ALL=C; export LC_ALL

list_library_globals ()
{
    eval $(grep old_library= "$1")
    nm -og "${1%/*}/.libs/${old_library}" |
        grep -v ' U ' | cut -d' ' -f3 | sort -u |
        grep -v '^_crypt_' | # our internal-symbol prefix
        grep -v '^_[_A-Y]'   # compiler's internal-symbol prefix
    unset old_library
}

list_allowed_globals ()
{
    ${AWK-awk} '
        NF == 0        { next }
        $1 == "#"      { next }
        $1 == "%chain" { next }
        $2 != "-"      { print $1 }
    ' "$1" | sort -u
}

if [ ! -f "$lib_la" ] || [ ! -f "$lib_map" ]; then
    echo "Usage: lib_la=/path/to/library.la lib_map=/path/to/library.map $0" >&2
    exit 1
fi

lib_globals=""
lib_xglobals=""

trap 'rm -f $lib_globals $lib_xglobals || :' 0

lib_globals="$(mktemp)"
lib_xglobals="$(mktemp)"

list_library_globals "$lib_la" > "$lib_globals"
list_allowed_globals "$lib_map" > "$lib_xglobals"

extra_globals="$(comm -23 "$lib_globals" "$lib_xglobals" | tr -s "$IFS" " ")"
missing_globals="$(comm -13 "$lib_globals" "$lib_xglobals"| tr -s "$IFS" " ")"

status=0
if [ -n "$extra_globals" ]; then
    printf '*** Extra symbols: %s\n' "$extra_globals" >&2
    status=1
fi
if [ -n "$missing_globals" ]; then
    printf '*** Missing symbols: %s\n' "$missing_globals" >&2
    status=1
fi
exit $status