From a5b0a665368cc80931a037eecf1f79ede98f397e Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Wed, 30 Dec 2020 14:24:41 -0500 Subject: =?UTF-8?q?test/symbols-compat.sh:=20Don=E2=80=99t=20rely=20on=20-?= =?UTF-8?q?lcrypt=20to=20find=20libcrypt.so.1.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some Linux distributions are now shipping libcrypt.so as a symlink to libcrypt.so.2, but still providing libcrypt.so.1 as a compatibility library. The symbols-compat.sh test is still relevant on these systems, but linking a test program against -lcrypt will not find libcrypt.so.1. Instead use gcc -print-file-name=libcrypt.so.1, which will find that library regardless of what other libcrypt* files are present. This also has the nice fringe benefit that we don’t have to parse ldd output anymore. This does *not* fix the symbols-compat failures in CI, but it should not make them worse. --- test/symbols-compat.sh | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) (limited to 'test') diff --git a/test/symbols-compat.sh b/test/symbols-compat.sh index f00334a..661d2ef 100755 --- a/test/symbols-compat.sh +++ b/test/symbols-compat.sh @@ -44,31 +44,19 @@ get_our_symbols_with_versions () get_their_symbols_with_versions () { - ( - set -e - cd "$1" - cat >test.c <<\EOF -extern char *crypt(const char *, const char *); -int main(int argc, char **argv) -{ - return !!crypt(argv[0], argv[1]); -} -EOF - ${CC-cc} test.c -lcrypt >&2 || exit 77 + # Ask the compiler whether a libcrypt.so.1 exists in its search + # path. The compiler option -print-file-name should be supported + # on all operating systems where there's an older libcrypt that we + # can be backward compatible with. + their_library=$(${CC-cc} $CFLAGS $LDFLAGS -print-file-name=libcrypt.so.1) - their_library=$(ldd ./a.out | - grep -F libcrypt.so.1 | - cut -d' ' -f3) + if [ -z "$their_library" ] || [ "$their_library" = "libcrypt.so.1" ]; then + printf '%s\n' '- No libcrypt.so.1 to be compatible with' >&2 + exit 77 + fi - if [ -n "$their_library" ]; then - printf '%s%s\n' '- Their library: ' "$their_library" >&2 - get_symbols_with_versions "$their_library" - else - printf '%s\n' '- No libcrypt.so.1 to be compatible with' - exit 77 - fi - ) - if [ $? -ne 0 ]; then exit $?; fi + printf '%s%s\n' '- Their library: ' "$their_library" >&2 + get_symbols_with_versions "$their_library" } if [ ! -f "$lib_la" ] || [ -z "$host_os" ]; then @@ -104,7 +92,7 @@ trap '[ -z "$workdir" ] || rm -rf "$workdir" || :' 0 workdir="$(mktemp -d)" get_our_symbols_with_versions "$lib_la" > "$workdir/our_symbols" -get_their_symbols_with_versions "$workdir" > "$workdir/their_symbols" +get_their_symbols_with_versions > "$workdir/their_symbols" # It's okay if we define more symbol (versions) than they do, but every # symbol they define should have a matching definition in our library. -- cgit v1.2.3