Last active
March 18, 2023 02:36
-
-
Save skull-squadron/1a0df1b7ff83809a7ecb5ade361750c3 to your computer and use it in GitHub Desktop.
Linux utility: Remove hard-coded absolute library paths and set a single DT_RUNPATH
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
TGT="$1" | |
NEW_RUNPATH="${2:-\$ORIGIN/../lib}" | |
_patchelf() { | |
(set -x; patchelf "$@") | |
} | |
_patchelf --remove-rpath "$TGT" | |
_patchelf --set-rpath "$NEW_RUNPATH" "$TGT" | |
readelf -d "$TGT" | awk '/Shared lib.*\//{sub(".*\\[","");sub("\\]","");print}' | while read -r LIB; do | |
SHORT_LIB="${LIB##*/}" | |
_patchelf --replace-needed "$LIB" "$SHORT_LIB" "$TGT" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment