J. Jones jjones at darkside.dynup.net
Wed Jul 18 14:37:31 PDT 2001

On Wed, Jul 18, 2001 at 02:34:39PM -0400, Gerard Beekmans wrote:
> "man strip" is very forthcoming. Just remember to only strip debug
> symbols from libraries and nothing more than that. You are able to strip
> more kinds of symbols from regular programs.

I suggest you follow the above advice before proceeding with this.  The
following script was adapted from a few of RPM's binary stripping programs.
It is for the true space monkey.  There are a couple of issues you need to
be aware of first.

  1)  Do NOT run this script on a 'live' system.  This issue could possibly
      (don't take my word for it, I haven't tried it) be overcome by using a
      static strip binary.  When it hits libc, strip will fail, truncating 

  2)  XFree86's drivers appear to have issues with the level of stripping this
      script thinks they can handle.  A strip -g works fine on them.  Again, I
      haven't thoroughly investigated this issue, so it may or may not even be
      an issue (may have been something else, eh?).

  3)  I was responsible for ruining many people's fresh 3.0-pre3 installs with
      my strip recommendation to Gerard.  *wink*

I use this script on everything I build.  Above are the only issues I have run
into so far.  It's not perfect, so if anyone sees room for improvement, please

I recommend one of two uses:  1) Rebooting into the host distro and mounting
the lfs partition, then running this script on /path/to/lfs, and 2) using the
$DESTDIR or a $prefix hack to temporarily move the new package into some other
directory, and running it from there.

Here ya go.

-------------- next part --------------
if [ -z "$1" -o "$1" = "/" ]; then
	exit 0

# Libraries
for f in `find $1 -type f`; do
	FILE=`file $f`
	# Shared libraries..
	UNNEEDED=`echo $FILE | grep ' shared object,' | sed -n -e 's/^\(.*\):.*ELF.*, not stripped/\1/p'`
	if [ ! -z "$UNNEEDED" ]; then
		strip --strip-unneeded $f && echo strip unneeded $f
		# Static libraries.. no way to tell if they're stripped already? :/
		DEBUG=`echo $FILE | grep -v ' shared object,' | grep ' ar archive'`
		if [ ! -z "$DEBUG" ]; then
			strip --strip-debug $f && echo strip debug $f
			# Unstripped binary
			BINARY=`echo $FILE | grep -v ' shared object' | sed -n -e 's/^\(.*\):.*ELF.*, not stripped/\1/p'`
			if [ ! -z "$BINARY" -a -x $f ]; then
				strip $f && echo strip $f
	FILE=`file $f`
	# .comment's and .note's
	COMNOTE=`echo $FILE | sed -n -e 's/^\(.*\):.*ELF.*, stripped/\1/p'`
	if [ ! -z "$COMNOTE" -a -x $f ]; then
		note="-R .note"
		if objdump -h $f | grep '^[   ]*[0-9]*[      ]*.note[  ]' -A 1 | grep ALLOC >/dev/null; then
		strip -R .comment $note $f || :

More information about the lfs-dev mailing list