From 453e66aa6dd796c74a0cb23f3b9ed63a0da2317a Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Mon, 17 May 2021 11:24:47 -0400 Subject: [PATCH] fix: disable some abi conflict tests on FreeBSD On FreeBSD, symbol resolution when dlopening a shared object will always favor symbols local to this shared object and thus our canary function will never be called which breaks our abi conflict detection when abi1 is loaded first. Disable the test cases with this scenario on FreeBSD as we have no way to fix this at the moment. Change-Id: Ic0451ce61e21f94ece55429b41bf76db3ad74b3a Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- src/lib/lttng-ust/lttng-ust-comm.c | 4 ++ .../abi0-conflict/test_abi0_conflict | 44 ++++++++++++------- tests/utils/utils.sh | 30 +++++++++++++ 3 files changed, 63 insertions(+), 15 deletions(-) diff --git a/src/lib/lttng-ust/lttng-ust-comm.c b/src/lib/lttng-ust/lttng-ust-comm.c index 2c902dc2..2a105bd7 100644 --- a/src/lib/lttng-ust/lttng-ust-comm.c +++ b/src/lib/lttng-ust/lttng-ust-comm.c @@ -2125,6 +2125,10 @@ void lttng_ust_check_soname_0(void) * Expose a canary symbol of the previous ABI to ensure we catch uses of a * liblttng-ust.so.0 dlopen'd after .so.1 has been loaded. Use a different * symbol than the detection code to ensure we don't detect ourself. + * + * This scheme will only work on systems where the global symbol table has + * priority when resolving the symbols of a dlopened shared object, which is + * the case on Linux but not on FreeBSD. */ void init_usterr(void); void init_usterr(void) diff --git a/tests/regression/abi0-conflict/test_abi0_conflict b/tests/regression/abi0-conflict/test_abi0_conflict index e79e3772..cc5966ea 100755 --- a/tests/regression/abi0-conflict/test_abi0_conflict +++ b/tests/regression/abi0-conflict/test_abi0_conflict @@ -24,10 +24,20 @@ LIBUST1="${LIBUST1_PATH}/liblttng-ust.so.1" STD_OUTPUT="/dev/null" STD_ERROR="/dev/null" +NUM_TESTS=22 + +# On FreeBSD, symbol resolution when dlopening a shared object will always +# favor symbols local to this shared object and thus our canary function will +# never be called which breaks our abi conflict detection when abi1 is loaded +# first. +if [ "$UST_OS_TYPE" = "freebsd" ]; then + NUM_TESTS=$((NUM_TESTS - 4)) +fi + # Force abort on CRIT() to detect ABI conflicts export LTTNG_UST_ABORT_ON_CRITICAL=1 -plan_tests 22 +plan_tests $NUM_TESTS ### ## LD_PRELOAD tests @@ -35,7 +45,7 @@ plan_tests 22 diag "LD_PRELOAD" -## App NOT linked on liblttn-ust +## App NOT linked on liblttng-ust "${CURDIR}/app_noust" >"$STD_OUTPUT" 2>"$STD_ERROR" ok $? "LD_PRELOAD: no-ust app works" @@ -50,7 +60,7 @@ LD_PRELOAD="${LIBUST1}:${LIBFAKEUST0}" "${CURDIR}/app_noust" >"$STD_OUTPUT" 2>"$ isnt $? 0 "LD_PRELOAD: no-ust app with abi1 and abi0 preload fails" -## App linked on liblttn-ust.so.1 +## App linked on liblttng-ust.so.1 "${CURDIR}/app_ust" >"$STD_OUTPUT" 2>"$STD_ERROR" ok $? "LD_PRELOAD: ust app works" @@ -71,7 +81,7 @@ isnt $? 0 "LD_PRELOAD: ust app with abi1 and abi0 preload fails" diag "dlopen" -## App NOT linked on liblttn-ust +## App NOT linked on liblttng-ust LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_noust_dlopen" abi0 >"$STD_OUTPUT" 2>"$STD_ERROR" ok $? "dlopen: no-ust app works" @@ -82,22 +92,26 @@ ok $? "dlopen: no-ust app with abi1 and abi1 succeeds" LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_noust_dlopen" abi0_abi1 >"$STD_OUTPUT" 2>"$STD_ERROR" isnt $? 0 "dlopen: no-ust app with abi0 and abi1 fails" -LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_noust_dlopen" abi1_abi0 >"$STD_OUTPUT" 2>"$STD_ERROR" -isnt $? 0 "dlopen: no-ust app with abi1 and abi0 fails" +if [ "$UST_OS_TYPE" != "freebsd" ]; then + LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_noust_dlopen" abi1_abi0 >"$STD_OUTPUT" 2>"$STD_ERROR" + isnt $? 0 "dlopen: no-ust app with abi1 and abi0 fails" +fi -## App linked on liblttn-ust.so.1 +## App linked on liblttng-ust.so.1 LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_ust_dlopen" abi1 >"$STD_OUTPUT" 2>"$STD_ERROR" ok $? "dlopen: ust app works" -LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_ust_dlopen" abi0 >"$STD_OUTPUT" 2>"$STD_ERROR" -isnt $? 0 "dlopen: ust app with abi0 fails" +if [ "$UST_OS_TYPE" != "freebsd" ]; then + LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_ust_dlopen" abi0 >"$STD_OUTPUT" 2>"$STD_ERROR" + isnt $? 0 "dlopen: ust app with abi0 fails" -LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_ust_dlopen" abi0_abi1 >"$STD_OUTPUT" 2>"$STD_ERROR" -isnt $? 0 "dlopen: ust app with abi0 and abi1 fails" + LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_ust_dlopen" abi0_abi1 >"$STD_OUTPUT" 2>"$STD_ERROR" + isnt $? 0 "dlopen: ust app with abi0 and abi1 fails" -LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_ust_dlopen" abi1_abi0 >"$STD_OUTPUT" 2>"$STD_ERROR" -isnt $? 0 "dlopen: ust app with abi1 and abi0 fails" + LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_ust_dlopen" abi1_abi0 >"$STD_OUTPUT" 2>"$STD_ERROR" + isnt $? 0 "dlopen: ust app with abi1 and abi0 fails" +fi ### @@ -106,7 +120,7 @@ isnt $? 0 "dlopen: ust app with abi1 and abi0 fails" diag "Indirect linking" -## App NOT linked on liblttn-ust +## App NOT linked on liblttng-ust "${CURDIR}/app_noust_indirect_abi0" >"$STD_OUTPUT" 2>"$STD_ERROR" ok $? "indirect: no-ust app with abi0 succeeds" @@ -117,7 +131,7 @@ ok $? "indirect: no-ust app with abi1 succeeds" "${CURDIR}/app_noust_indirect_abi0_abi1" >"$STD_OUTPUT" 2>"$STD_ERROR" isnt $? 0 "indirect: no-ust app with abi0 and abi1 fails" -## App linked on liblttn-ust +## App linked on liblttng-ust "${CURDIR}/app_ust_indirect_abi0" >"$STD_OUTPUT" 2>"$STD_ERROR" isnt $? 0 "indirect: ust app with abi0 fails" diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index cefb782c..212807bb 100755 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -31,3 +31,33 @@ if [ "x${UST_TESTS_BUILDDIR:-}" = "x" ]; then UST_TESTS_BUILDDIR="$testsdir" fi export UST_TESTS_BUILDDIR + +# The OS on which we are running. See [1] for possible values of 'uname -s'. +# We do a bit of translation to ease our life down the road for comparison. +# Export it so that called executables can use it. +# [1] https://en.wikipedia.org/wiki/Uname#Examples +if [ "x${UST_OS_TYPE:-}" = "x" ]; then + UST_OS_TYPE="$(uname -s)" + case "$UST_OS_TYPE" in + MINGW*) + UST_OS_TYPE="mingw" + ;; + Darwin) + UST_OS_TYPE="darwin" + ;; + Linux) + UST_OS_TYPE="linux" + ;; + CYGWIN*) + UST_OS_TYPE="cygwin" + ;; + FreeBSD) + UST_OS_TYPE="freebsd" + ;; + *) + UST_OS_TYPE="unsupported" + ;; + esac +fi +export UST_OS_TYPE + -- 2.34.1