From 864447dd2e45833c9dba34a28332c52a6afd8d61 Mon Sep 17 00:00:00 2001 From: Linus Witschen Date: Thu, 23 Apr 2026 09:38:33 +0100 Subject: [PATCH] tests: resolve native library paths via ldd for distro portability The library filter tests previously hardcoded `/lib64/libm.so.6` and `/lib64/libcrypt.so.2`. These paths only exist on RHEL-family layouts; on Debian/Ubuntu native libraries live under `/lib/x86_64-linux-gnu/`, causing `libfilter_exclude_libm` to report libm as still being instrumented, and `libfilter_include_extra` to fail because the path does not exist. Resolve the libm path at runtime from `ldd` against the test binary, which uses the dynamic linker's actual resolution and is independent of distro layout. The libcrypt path is derived from the same directory. An early-exit check ensures any failure to resolve libm produces a clear error message rather than running tests with empty filter paths. --- tests/run_library_filter_tests.sh | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/tests/run_library_filter_tests.sh b/tests/run_library_filter_tests.sh index cdcea38..4a9761c 100755 --- a/tests/run_library_filter_tests.sh +++ b/tests/run_library_filter_tests.sh @@ -98,6 +98,21 @@ if [ -x "$MEMORY_ANALYSIS_TEST" ]; then echo "Library Filter Tests" echo "================================================================================" + # Resolve native library paths from the test binary's own linkage. + # Architecture-agnostic: ldd returns the paths the dynamic linker + # would actually use for this binary, regardless of distro layout. + LIBM_PATH=$(ldd "$MEMORY_ANALYSIS_TEST" 2>/dev/null \ + | awk '$1 ~ /^libm\.so/{print $3; exit}') + if [ -z "$LIBM_PATH" ] || [ ! -e "$LIBM_PATH" ]; then + echo -e "${RED}ERROR: Could not resolve libm.so path from ${MEMORY_ANALYSIS_TEST}${NC}" >&2 + echo " ldd output:" >&2 + ldd "$MEMORY_ANALYSIS_TEST" 2>&1 | sed 's/^/ /' >&2 + exit 1 + fi + NATIVE_LIB_DIR=$(dirname "$LIBM_PATH") + LIBCRYPT_PATH=$(ls "${NATIVE_LIB_DIR}"/libcrypt.so.* 2>/dev/null \ + | head -1) + # Test: Baseline - exclude non-existent library (should PASS, no behavior change) run_library_filter_test "libfilter_exclude_nonexistent" \ "$MEMORY_ANALYSIS_TEST" \ @@ -105,17 +120,17 @@ if [ -x "$MEMORY_ANALYSIS_TEST" ]; then "present" \ "libm.so" - # Test: Exclude /lib64/libm.so.6 (should NOT appear in "Adding" output) + # Test: Exclude libm (should NOT appear in "Adding" output) run_library_filter_test "libfilter_exclude_libm" \ "$MEMORY_ANALYSIS_TEST" \ - '{"exclude": ["/lib64/libm.so.6"]}' \ + "{\"exclude\": [\"${LIBM_PATH}\"]}" \ "absent" \ "libm.so" # Test: Include a file that wouldn't normally be scanned run_library_filter_test "libfilter_include_extra" \ "$MEMORY_ANALYSIS_TEST" \ - '{"include": ["/lib64/libcrypt.so.2"]}' \ + "{\"include\": [\"${LIBCRYPT_PATH}\"]}" \ "present" \ "libcrypt.so"