X-Git-Url: http://git.openwrt.org/?p=openwrt%2Fopenwrt.git;a=blobdiff_plain;f=scripts%2Fbundle-libraries.sh;h=620ee01bdedd6bc93ea3f763dea7ea860037a921;hp=f254d4da47058b9456d42efc288d2d19790c587f;hb=f9e7f193344fcee585b454e3884297f721187f4a;hpb=9e64874fb2508e49e52898c238d817bd152bf2c2 diff --git a/scripts/bundle-libraries.sh b/scripts/bundle-libraries.sh index f254d4da47..620ee01bde 100755 --- a/scripts/bundle-libraries.sh +++ b/scripts/bundle-libraries.sh @@ -87,7 +87,11 @@ _runas_so() { return 0; } + #ifdef __APPLE__ + __attribute__((section("__DATA,__mod_init_func"))) + #else __attribute__((section(".init_array"))) + #endif static void *mangle_arg0_constructor = &mangle_arg0; EOT @@ -97,6 +101,18 @@ _runas_so() { } } +_patch_ldso() { + _cp "$1" "$1.patched" + sed -i -e 's,/\(usr\|lib\|etc\)/,/###/,g' "$1.patched" + + if "$1.patched" 2>&1 | grep -q -- --library-path; then + _mv "$1.patched" "$1" + else + echo "binary patched ${1##*/} not executable, using original" >&2 + rm -f "$1.patched" + fi +} + for LDD in ${PATH//://ldd }/ldd; do "$LDD" --version >/dev/null 2>/dev/null && break LDD="" @@ -135,6 +151,7 @@ for BIN in "$@"; do [ -f "$token" -a ! -f "$dest" ] && { _md "$ddir" _cp "$token" "$dest" + [ -n "$LDSO" ] && _patch_ldso "$dest" } ;; esac done