From b3d87e167fc697b09e0b6de280e64a4f051882ee Mon Sep 17 00:00:00 2001 From: Lukasz Dorau Date: Fri, 13 Dec 2024 15:39:23 +0100 Subject: [PATCH] Add get_umf_debug_info.sh to print saved strings Add the `get_umf_debug_info.sh` script to print saved strings. It can be used with any user binary: $ scripts/get_umf_debug_info.sh ./build/test/umf_test-base ./build/test/umf_test-base does not contain magic strings of the UMF library. $ scripts/get_umf_debug_info.sh ./build/test/umf_test-ipc ./build/test/umf_test-ipc is statically linked with the UMF library. Strings in /mnt/wsl/files/repos/unified-memory-framework/build/test/umf_test-ipc: @(#) Intel(R) UMF version: 0.10.0-git4.gbf701ee8 @(#) Intel(R) UMF CMake variables: "CMAKE_BUILD_TYPE:Debug, ..." $ scripts/get_umf_debug_info.sh ./build/test/umf_test-c_api_disjoint_pool ./build/test/umf_test-c_api_disjoint_pool is dynamically linked with the UMF library \ (/mnt/wsl/files/repos/unified-memory-framework/build/lib/libumf.so.0.10.0). Strings in /mnt/wsl/files/repos/unified-memory-framework/build/lib/libumf.so.0.10.0: @(#) Intel(R) UMF version: 0.10.0-git4.gbf701ee8 @(#) Intel(R) UMF CMake variables: "CMAKE_BUILD_TYPE:Debug, ..." $ scripts/get_umf_debug_info.sh ./build/lib/libumf.so ./build/lib/libumf.so is the UMF library (/mnt/wsl/files/repos/unified-memory-framework/build/lib/libumf.so.0.10.0). Strings in /mnt/wsl/files/repos/unified-memory-framework/build/lib/libumf.so.0.10.0: @(#) Intel(R) UMF version: 0.10.0-git4.g806ce00c @(#) Intel(R) UMF CMake variables: "CMAKE_BUILD_TYPE:Debug, ..." Signed-off-by: Lukasz Dorau --- CONTRIBUTING.md | 19 +++++++++++++++ scripts/get_umf_debug_info.sh | 44 +++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100755 scripts/get_umf_debug_info.sh diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7b9749c491..0bbb77ab6e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -239,6 +239,25 @@ $ strings libumf.so | grep "@(#)" @(#) Intel(R) UMF CMake variables: "CMAKE_BUILD_TYPE:Debug,... ``` +or using the dedicated `scripts/get_umf_debug_info.sh` script with any user binary: + +```bash +$ scripts/get_umf_debug_info.sh ./build/test/umf_test-base +./build/test/umf_test-base is not linked with the UMF library. + +$ scripts/get_umf_debug_info.sh ./build/test/umf_test-ipc +./build/test/umf_test-ipc is statically linked with the UMF library. +Strings: +@(#) Intel(R) UMF version: 0.10.0-git4.gbf701ee8 +@(#) Intel(R) UMF CMake variables: "CMAKE_BUILD_TYPE:Debug,UMF_BUILD_BENCHMARKS:OFF, ..." + +$ scripts/get_umf_debug_info.sh ./build/test/umf_test-c_api_disjoint_pool +./build/test/umf_test-c_api_disjoint_pool is dynamically linked with the UMF library. +Strings: +@(#) Intel(R) UMF version: 0.10.0-git4.gbf701ee8 +@(#) Intel(R) UMF CMake variables: "CMAKE_BUILD_TYPE:Debug,UMF_BUILD_BENCHMARKS:OFF, ..." +``` + #### Requirements - binutils package (Linux) diff --git a/scripts/get_umf_debug_info.sh b/scripts/get_umf_debug_info.sh new file mode 100755 index 0000000000..3ccef71b88 --- /dev/null +++ b/scripts/get_umf_debug_info.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# Copyright (C) 2024 Intel Corporation +# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +BINARY=$1 + +if [ "$BINARY" = "" ]; then + echo "Usage: $(basename $0) " + exit 1 +fi + +if ! which strings >/dev/null; then + echo "strings command not found. Please install the binutils package." + exit 1 +fi + +# check if the binary is statically linked with libumf +# or if it is the UMF library itself +if [ $(strings $BINARY | grep -c -e "@(#) Intel(R) UMF") -gt 0 ]; then + BIN_NO_LINK=$(readlink -f "$BINARY") + FILE_INFO=$(file $BIN_NO_LINK) + if [[ "$FILE_INFO" == *"libumf.so"*"ELF 64-bit LSB shared object"*"dynamically linked"* ]]; then + echo "$BINARY is the UMF library ($BIN_NO_LINK)." + else + echo "$BINARY is statically linked with the UMF library." + fi + + echo "Strings in $BIN_NO_LINK:" + strings $BIN_NO_LINK | grep "@(#) Intel(R) UMF" + exit 0 +fi + +# check if the binary is dynamically linked with libumf +if [ $(ldd $BINARY | grep -c -e "libumf.so") -gt 0 ]; then + UMF_LIB=$(ldd $BINARY | grep libumf.so | awk '{ print $3 }') + UMF_LIB=$(readlink -f "$UMF_LIB") + echo "$BINARY is dynamically linked with the UMF library ($UMF_LIB)." + echo "Strings in $UMF_LIB:" + strings $UMF_LIB | grep "@(#) Intel(R) UMF" + exit 0 +fi + +echo "$BINARY does not contain magic strings of the UMF library."