Blame test-symbols-static

Packit 13e0ca
#! /bin/sh
Packit 13e0ca
# Written by Zack Weinberg <zackw at panix.com> in 2017.
Packit 13e0ca
# To the extent possible under law, Zack Weinberg has waived all
Packit 13e0ca
# copyright and related or neighboring rights to this work.
Packit 13e0ca
#
Packit 13e0ca
# See https://creativecommons.org/publicdomain/zero/1.0/ for further
Packit 13e0ca
# details.
Packit 13e0ca
Packit 13e0ca
# Test that all global symbols in the static version of the library
Packit 13e0ca
# (libcrypt.a) are either listed as global and supported for new code
Packit 13e0ca
# in libcrypt.map.in, or begin with a _crypt prefix.  Also test that
Packit 13e0ca
# all of the global, supported for new code, symbols mentioned in
Packit 13e0ca
# libcrypt.map.in are in fact defined.
Packit 13e0ca
#
Packit 13e0ca
# Due to limitations in Automake, this program takes parameters from
Packit 13e0ca
# the environment:
Packit 13e0ca
# $lib_la - full pathname of libcrypt.la
Packit 13e0ca
# $lib_map - full pathname of libcrypt.map.in
Packit 13e0ca
Packit 13e0ca
set -e
Packit 13e0ca
LC_ALL=C; export LC_ALL
Packit 13e0ca
Packit 13e0ca
list_library_globals ()
Packit 13e0ca
{
Packit 13e0ca
    eval $(grep old_library= "$1")
Packit 13e0ca
    nm -og "${1%/*}/.libs/${old_library}" |
Packit 13e0ca
        grep -v ' U ' | cut -d' ' -f3 | sort -u |
Packit 13e0ca
        grep -v '^_crypt_' | # our internal-symbol prefix
Packit 13e0ca
        grep -v '^_[_A-Y]'   # compiler's internal-symbol prefix
Packit 13e0ca
    unset old_library
Packit 13e0ca
}
Packit 13e0ca
Packit 13e0ca
list_allowed_globals ()
Packit 13e0ca
{
Packit 13e0ca
    ${AWK-awk} '
Packit 13e0ca
        NF == 0        { next }
Packit 13e0ca
        $1 == "#"      { next }
Packit 13e0ca
        $1 == "%chain" { next }
Packit 13e0ca
        $2 != "-"      { print $1 }
Packit 13e0ca
    ' "$1" | sort -u
Packit 13e0ca
}
Packit 13e0ca
Packit 13e0ca
if [ ! -f "$lib_la" ] || [ ! -f "$lib_map" ]; then
Packit 13e0ca
    echo "Usage: lib_la=/path/to/library.la lib_map=/path/to/library.map $0" >&2
Packit 13e0ca
    exit 1
Packit 13e0ca
fi
Packit 13e0ca
Packit 13e0ca
lib_globals=""
Packit 13e0ca
lib_xglobals=""
Packit 13e0ca
Packit 13e0ca
trap 'rm -f $lib_globals $lib_xglobals || :' 0
Packit 13e0ca
Packit 13e0ca
lib_globals="$(mktemp)"
Packit 13e0ca
lib_xglobals="$(mktemp)"
Packit 13e0ca
Packit 13e0ca
list_library_globals "$lib_la" > "$lib_globals"
Packit 13e0ca
list_allowed_globals "$lib_map" > "$lib_xglobals"
Packit 13e0ca
Packit 13e0ca
extra_globals="$(comm -23 "$lib_globals" "$lib_xglobals" | tr -s "$IFS" " ")"
Packit 13e0ca
missing_globals="$(comm -13 "$lib_globals" "$lib_xglobals"| tr -s "$IFS" " ")"
Packit 13e0ca
Packit 13e0ca
status=0
Packit 13e0ca
if [ -n "$extra_globals" ]; then
Packit 13e0ca
    printf '*** Extra symbols: %s\n' "$extra_globals" >&2
Packit 13e0ca
    status=1
Packit 13e0ca
fi
Packit 13e0ca
if [ -n "$missing_globals" ]; then
Packit 13e0ca
    printf '*** Missing symbols: %s\n' "$missing_globals" >&2
Packit 13e0ca
    status=1
Packit 13e0ca
fi
Packit 13e0ca
exit $status