[Linux-users] Strip ...

Kurt Wall kwall
Thu Aug 16 20:51:15 PDT 2007


On Thu, Aug 16, 2007 at 04:35:26PM -0500, Ben Duncan wrote:
> Ok, is there a way to SET the "strip" flag with the gcc options ?

No and yes. No, in that gcc is a compiler, actually, a collection of
language-specific front-ends or drivers to a back-end compilation unit. 
It doesn't perform linking and object manipulation itself. Rather, it
depends on an external progrram, the linker, ld. 

Yes, in that gcc invokes the linker on your behalf and you can
tell gcc to pass flags to the linker. In this case, the gcc option
you want is one (or more) of the following:
	-Wl,-s
	-Wl,--strip-debug
	-Wl,S
	-Wl,--strip-all

Now I'm going to be peevish. Why does this matter? What is it you hope
to accomplish? If you're stripping binaries to save disk space, you're
wasting your time. If you're stripping binaries as an optimization, you're
wasting your time. Using shared libraries instead of static linking will
save more space than stripping binaries. Consider the following program:

#include <stdio.h>

int main()
{
	printf("one");
	return 0;
}

Here are the sizes after compilation using static and dynamic linking:

$ ls -l *out
-rwxr-xr-x 1 kwall kwall   6644 2007-08-16 23:35 shared.out
-rwxr-xr-x 1 kwall kwall 536749 2007-08-16 23:34 static.out

Here are the sizes after after compiling statically and dynamically with
debugging symbols:

$ ls -l *out
-rwxr-xr-x 1 kwall kwall   7380 2007-08-16 23:37 shared.out
-rwxr-xr-x 1 kwall kwall 537485 2007-08-16 23:37 static.out

The same, after stripping debug symbols:

$ ls -l *out
-rwxr-xr-x 1 kwall kwall   4575 2007-08-16 23:41 shared.out
-rwxr-xr-x 1 kwall kwall 534680 2007-08-16 23:41 static.out

The same, after stripping all symbols:

$ ls -l *out
-rwxr-xr-x 1 kwall kwall   2988 2007-08-16 23:43 shared.out
-rwxr-xr-x 1 kwall kwall 475476 2007-08-16 23:42 static.out


Kurt
-- 
This is the first age that's paid much attention to the future, which is a
little ironic since we may not have one.
		-- Arthur Clarke



More information about the Linux-users mailing list