Skip to content

Instantly share code, notes, and snippets.

@JCash
Created January 8, 2021 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JCash/d8dbfb3fb5d25c9aaa60055d8ec55eec to your computer and use it in GitHub Desktop.
Save JCash/d8dbfb3fb5d25c9aaa60055d8ec55eec to your computer and use it in GitHub Desktop.
Unpacks a static library (.a) and strips all the debug symbols, then repacks the library again. Overwrites original file!
#!/bin/bash
# usage: repack.sh file.a
# used on macOS
# Originally from https://stackoverflow.com/a/49632127/468516
if [ -z "$1" ]; then
echo "usage: repack file.a"
exit 1
fi
if [ -d tmprepack ]; then
/bin/rm -rf tmprepack
fi
mkdir tmprepack
cp $1 tmprepack
pushd tmprepack
basename=${1##*/}
ar xv $basename
/bin/rm -f $basename
ls -la .
i=1000
for p in *.o ; do
if [[ $p == *.o ]]; then
strip -S $p
mv $p ${i}.o
((i++))
fi
done
ar crus $basename *.o
mv $basename ..
popd
/bin/rm -rf tmprepack
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment