OSDN Git Service

2010-10-01 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / scripts / extract_symvers
1 #!/bin/sh
2
3 # Copyright (C) 2002, 2003, 2009 Free Software Foundation, Inc.
4 #
5 # This file is part of the GNU ISO C++ Library.  This library is free
6 # software; you can redistribute it and/or modify it under the
7 # terms of the GNU General Public License as published by the
8 # Free Software Foundation; either version 3, or (at your option)
9 # any later version.
10 #
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with this library; see the file COPYING3.  If not see
18 # <http://www.gnu.org/licenses/>.
19
20
21 if test ${#} -lt 2 || test $1 = '--help'; then
22   echo "Usage:  extract_symvers  shared_lib output_file" 1>&2
23   exit 1
24 fi
25
26 lib=$1
27 output=$2
28
29 # Sun ld doesn't record symbol versions in .dynsym entries and they cannot
30 # easily be extracted from readelf --versions output, so use pvs instead.
31 if type pvs 2>&1 | grep 'not found' > /dev/null; then
32     :
33 else
34     pvs="pvs -dsvo"
35 fi
36
37 # GNU binutils, somewhere after version 2.11.2, requires -W/--wide to avoid
38 # default line truncation.  -W is not supported and truncation did not occur
39 # by default before that point.
40 readelf="readelf --symbols"
41 if readelf --help | grep -- --wide > /dev/null; then
42     readelf="$readelf --wide"
43 fi
44
45 # This avoids weird sorting problems later.
46 LC_ALL=C
47 export LC_ALL
48 LANG=C
49 export LANG
50
51 tmp=extract.$$
52
53 # Prefer pvs if found.  Need to use nawk on Solaris 2 since Solaris 8/9 awk
54 # (oawk) cannot handle sub.
55 if [ -n ${pvs} ]; then
56     ${pvs} ${lib} | \
57     nawk '# Remove colon separator from version field, trailing semicolon.
58          {
59            sub (/:$/, "", $3);
60            sub (/;$/, "");
61          }
62          # Record base version.  The [BASE] field was only added in Solaris 11,
63          # so simply use the first record instead.
64          NR == 1 {
65            basever = $3;
66            next;
67          }
68          # Ignore version dependencies.
69          $4 ~ /\{.*\}/ {
70            next;
71          }
72          NF == 4 {
73            if ($3 == $4 || $3 == basever)
74              # Emit versions or symbols bound to base versions as objects.
75              printf "OBJECT:0:%s\n", $4;
76            else
77              # Everything else without a size field is a function.
78              printf "FUNC:%s@@%s\n", $4, $3;
79            next;
80          }
81          # Emit objects.
82          NF == 5 {
83            # Strip parens from object size.
84            sub (/^\(/, "", $5);
85            sub (/\)$/, "", $5);
86            printf "OBJECT:%s:%s@@%s\n", $5, $4, $3;
87            next;
88          }' | sort | uniq > $tmp 2>&1
89 else
90     ${readelf} ${lib} |\
91     sed -e 's/ \[<other>: [A-Fa-f0-9]*\] //' -e '/\.dynsym/,/^$/p;d' |\
92     egrep -v ' (LOCAL|UND) ' |\
93     awk '{ if ($4 == "FUNC" || $4 == "NOTYPE")
94              printf "%s:%s\n", $4, $8;
95            else if ($4 == "OBJECT" || $4 == "TLS")
96              printf "%s:%s:%s\n", $4, $3, $8;
97          }' | sort | uniq > $tmp 2>&1
98 #          else printf "Huh?  What is %s?\n", $8;
99 fi
100
101
102 # I think we'll be doing some more with this file, but for now, dump.
103 mv $tmp $output
104
105 exit 0