X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=scripts%2Fbundle-libraries.sh;h=d3c7206a4dddd2b44a5b7d506f88212de850e0b4;hb=2fe5319d587c9c66ecbd7acbd5efbc1ff6fac8a8;hp=f254d4da47058b9456d42efc288d2d19790c587f;hpb=9e64874fb2508e49e52898c238d817bd152bf2c2;p=oweals%2Fopenwrt.git diff --git a/scripts/bundle-libraries.sh b/scripts/bundle-libraries.sh index f254d4da47..d3c7206a4d 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,30 @@ _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 +} + +_patch_glibc() { + _cp "$1" "$1.patched" + sed -i -e 's,/usr/\(\(lib\|share\)/locale\),/###/\1,g' "$1.patched" + + if "$1.patched" 2>&1 | grep -q -- GNU; 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="" @@ -125,16 +153,20 @@ for BIN in "$@"; do [ -n "$LDD" ] && [ -x "$BIN" ] && file "$BIN" | grep -sqE "ELF.*(executable|interpreter)" && { for token in $("$LDD" "$BIN" 2>/dev/null); do case "$token" in */*.so*) - case "$token" in - *ld-*.so*) LDSO="${token##*/}" ;; - esac - dest="$DIR/lib/${token##*/}" ddir="${dest%/*}" + case "$token" in + */ld-*.so*) LDSO="${token##*/}" ;; + esac + [ -f "$token" -a ! -f "$dest" ] && { _md "$ddir" _cp "$token" "$dest" + case "$token" in + */ld-*.so*) _patch_ldso "$dest" ;; + */libc.so.6) _patch_glibc "$dest" ;; + esac } ;; esac done