#!/bin/bash # Copyright Advanced Micro Devices, Inc. # SPDX-License-Identifier: MIT # Patches installed binaries from the external build system. # Args: install_dir patchelf_binary set -e PREFIX="${1:?Expected install prefix argument}" # update_library_links # --------------------- # Purpose: # Normalize a shared library so that its real file is named exactly as its ELF SONAME, # and rename the input file (usually a symlink) to a desired linker name (e.g., libfoo.so). # # Synopsis: # update_library_links # # Arguments: # libfile Path to the library file or symlink. # Example: $PREFIX/lib/librocm_sysdeps_numa.so # linker_name Desired linker-name filename to exist in the same directory. # Example: libnuma.so update_library_links() { local libfile="$1" # e.g. $PREFIX/lib/librocm_sysdeps_numa.so local linker_name="$2" # e.g. libnuma.so if [ ! -e "$libfile" ]; then echo "Error: File '$libfile' not found" >&2 return 1 fi local dir="$(dirname -- "$libfile")" # Get the soname and realname local lib_soname="$("$PATCHELF" --print-soname "$libfile" 2>/dev/null || true)" local realname="$(readlink -f -- "$libfile" 2>/dev/null || true)" if [[ -z "$lib_soname" || -z "$realname" ]]; then [[ -z "$lib_soname" ]] && echo "Error: No SONAME found in '$libfile'" >&2 [[ -z "$realname" ]] && echo "Error: readlink -f failed for '$libfile'" >&2 return 1 fi if [[ "$realname" != "$dir/$lib_soname" ]]; then # Move the real file to $dir/$lib_soname mv -v -- "$realname" "$dir/$lib_soname" pushd "$dir" > /dev/null ln -sf "$lib_soname" "$linker_name" popd > /dev/null rm "$libfile" else # Rename symlink in the same directory mv "$libfile" "$dir/$linker_name" fi } update_library_links "$PREFIX/lib/librocm_sysdeps_drm.so" "libdrm.so" update_library_links "$PREFIX/lib/librocm_sysdeps_drm_amdgpu.so" "libdrm_amdgpu.so"