remove obstack support
[uclibc-ng.git] / extra / libstrip / libstrip
blob69a10438a179fff7a16f732ba244dc3966a4e6da
1 #!/usr/bin/perl -w
2 # vi: set ts=4:
4 # Libstrip - A utility to optimize libraries for specific executables
5 # Copyright (C) 2001 David A. Schleef <ds@schleef.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of version 2 of the GNU General Public License as
9 # published by the Free Software Foundation.
11 # This is a surprisingly simple script that gets a list of
12 # unresolved symbols in a list of executables specified on the
13 # command line, and then relinks the uClibc shared object file
14 # with only the those symbols and their dependencies. This
15 # results in a shared object that is optimized for the executables
16 # listed, and thus may not work with other executables.
18 # Example: optimizing uClibc for BusyBox
19 # Compile uClibc and BusyBox as normal. Then, in this
20 # directory, run:
21 # libstrip path/to/busybox
22 # After the script completes, there should be a new
23 # libuClibc-0.9.5.so in the current directory, which
24 # is optimized for busybox.
26 # How it works:
27 # The uClibc Makefiles create libuClibc.so by first creating
28 # the ar archive libc.a with all the object files, then links
29 # the final libuClibc.so by using 'ld --shared --whole-archive'.
30 # We take advantage of the linker command line option --undefined,
31 # which pulls in a symbol and all its dependencies, and so relink
32 # the library using --undefined for each symbol in place of
33 # --whole-archive. The linker script is used only to avoid
34 # having very long command lines.
36 $topdir="../..";
38 # This is the name of the default ldscript for shared libs. The
39 # file name will be different for other architectures.
40 $ldscript="/usr/lib/ldscripts/elf_i386.xs";
42 my @syms;
43 my @allsyms;
44 my $s;
46 while($exec = shift @ARGV){
47 #print "$exec\n";
48 @syms=`nm --dynamic $exec`;
49 for $s (@syms){
50 chomp $s;
51 if($s =~ m/^.{8} [BUV] (.+)/){
52 my $x = $1;
53 if(!grep { m/^$x$/; } @allsyms){
54 unshift @allsyms, $x;
60 open(LDSCRIPT, ">ldscript");
61 print LDSCRIPT "INCLUDE $ldscript\n";
62 for $s (@allsyms) {
63 print LDSCRIPT "EXTERN($s)\n";
67 `gcc -s -nostdlib -Wl,-warn-common -shared \\
68 -o libuClibc-0.9.5.so \\
69 -Wl,-soname,libc.so.0 -Wl,--script=ldscript \\
70 $topdir/libc/libc.a \\
71 $topdir/libc/tmp/libgcc-need.a`