check-exports.sh 1.03 KB
Newer Older
1 2 3 4 5 6
#!/bin/sh

LC_ALL=C
export LC_ALL

stat=0
7 8 9
so="$1"
def="$2"
PATTERN="_ANCHOR_"
10

11
TMPFILE="$(mktemp .nm-check-exports.XXXXXX)"
12 13


14
get_syms() {
15
    ${NM:-nm} "$1" |
16
    sed -n 's/^[[:xdigit:]]\+ [DT] //p' |
17 18
    sort
}
19

20
get_syms_from_def() {
21
    sed -n 's/^\t\(\([_a-zA-Z0-9]\+\)\|#\s*\([_a-zA-Z0-9]\+@@\?[_a-zA-Z0-9]\+\)\);$/\2\3/p' "$1" |
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
    sort
}

anchor() {
    sed "s/.*/$PATTERN\0$PATTERN/"
}

unanchor() {
    sed "s/^$PATTERN\(.*\)$PATTERN\$/\1/"
}


get_syms "$so" | anchor > "$TMPFILE"
WRONG="$(get_syms_from_def "$def" | anchor | grep -F -f - "$TMPFILE" -v)"
RESULT=$?
if [ $RESULT -eq 0 ]; then
    stat=1
    echo ">>library \"$so\" exports symbols that are not in linker script \"$def\":"
    echo "$WRONG" | unanchor | nl
fi

get_syms_from_def "$def" | anchor > "$TMPFILE"
WRONG="$(get_syms "$so" | anchor | grep -F -f - "$TMPFILE" -v)"
RESULT=$?
if [ $RESULT -eq 0 ]; then
    stat=1
    echo ">>linker script \"$def\" contains symbols that are not exported by library \"$so\":"
    echo "$WRONG" | unanchor | nl
fi

rm -rf "$TMPFILE"
53 54
exit $stat