OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [extra/] [libstrip/] [libstrip] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
#!/usr/bin/perl -w
2
# vi: set ts=4:
3
 
4
# Libstrip - A utility to optimize libraries for specific executables
5
# Copyright (C) 2001  David A. Schleef 
6
#
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.
10
#
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.
17
#
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.
25
#
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.
35
 
36
$topdir="../..";
37
 
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";
41
 
42
my @syms;
43
my @allsyms;
44
my $s;
45
 
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;
55
                        }
56
                }
57
        }
58
}
59
 
60
open(LDSCRIPT, ">ldscript");
61
print LDSCRIPT "INCLUDE $ldscript\n";
62
for $s (@allsyms) {
63
        print LDSCRIPT "EXTERN($s)\n";
64
}
65
 
66
 
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`
72
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.