diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:54:46 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:54:46 +0000 |
commit | cd7b005519ade8ab6c97fcb21590b71b7d1be6e3 (patch) | |
tree | c611a8d0cd5e8f68f41b8c2d16ba580e0f40a38d /scripts/check-exports.sh | |
parent | Initial commit. (diff) | |
download | librtr-cd7b005519ade8ab6c97fcb21590b71b7d1be6e3.tar.xz librtr-cd7b005519ade8ab6c97fcb21590b71b7d1be6e3.zip |
Adding upstream version 0.8.0.upstream/0.8.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rwxr-xr-x | scripts/check-exports.sh | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/scripts/check-exports.sh b/scripts/check-exports.sh new file mode 100755 index 0000000..2b7dcad --- /dev/null +++ b/scripts/check-exports.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +# ---HELP--- +# check if exported symbols match up with header content and the shared object symbol table +# Must be run from rtrlibs root dir. +# ---HELP--- + +SO_SYMBOL_WHITELIST=(__bss_start _edata _end _fini _init __gcov_master __gcov_sort_n_vals __gcov_var) + +ERROR=0 + +# Functions annoted with RTRLIB_EXPORT +EXPORTS=$( + ctags -x --c-kinds=fp $(find rtrlib -iname '*.c' ! -name '*tommy*') | + grep 'RTRLIB_EXPORT' | awk '{ print $1 }' | + sort) + +# Functions found in public headers +HEADER_SYMBOLS=$( + ctags -x --c-kinds=fp $(find rtrlib -iname '*.h' -type f ! -name '*_private.h' ! -name '*tommy*') | + awk '{ print $1 }' | + sort) + +# Symbols found in librtrs dynamic export table +SO_SYMBOLS=$(nm -g --defined-only librtr.so | awk '{ print $3 }' | sort) + +# Filter known false positives in dynamic symbol table +for symbol in "${SO_SYMBOL_WHITELIST[@]}"; do + SO_SYMBOLS=$(echo "${SO_SYMBOLS}" | grep -v "^${symbol}\$") +done + +# check for equality of $EXPORTS AND $HEADER_SYMBOLS +diff -q <(echo "$EXPORTS") <(echo "$HEADER_SYMBOLS") > /dev/null +if [[ $? -ne 0 ]]; then + echo "Functions annotated for export are not equal to functions found in public header!" + comm <(echo "$EXPORTS") <(echo "$HEADER_SYMBOLS") + ERROR=1 +fi + +echo + +# check for equality of $HEADER_SYMBOLS and $SO_SYMBOLS +diff -q <(echo "$HEADER_SYMBOLS") <(echo "$SO_SYMBOLS") > /dev/null +if [[ $? -ne 0 ]]; then + echo "Functions found in public header are not equal to exported functions!" + comm <(echo "$HEADER_SYMBOLS") <(echo "$SO_SYMBOLS") + ERROR=1 +fi + + +exit $ERROR |