OSDN Git Service

2011-02-28 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / scripts / extract_symvers.pl
1 #!/usr/bin/perl -w
2
3 # Copyright (C) 2010 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 # Extract symbol version information on Solaris 2.
21 #
22 # Sun ld doesn't record symbol versions in .dynsym entries and they cannot
23 # easily be extracted from readelf --versions output, so use pvs instead.
24 # This way, we don't require GNU binutils in the native case.  Also ensures
25 # that baseline_symbols.txt is identical between native (pvs, elfdump) and
26 # cross (readelf) cases.
27
28 my $lib = shift;
29
30 open PVS, "pvs -dsvo $lib |" or die $!;
31 while (<PVS>) {
32     chomp;
33
34     # Remove trailing semicolon.
35     s/;$//;
36
37     # shared object, dash, version, symbol, [size]
38     (undef, undef, $version, $symbol, $size) = split;
39
40     # Remove colon separator from version field.
41     $version =~ s/:$//;
42     
43     # Record base version.  The [BASE] field was only added in Solaris 11,
44     # so simply use the first record instead.
45     if ($. == 1) {
46         $basever = $version;
47         next;
48     }
49
50     # Skip version declarations.
51     next unless defined ($symbol);
52
53     # Ignore version dependencies.
54     next if ($symbol =~ /\{.*\}/);
55
56     # Emit objects.
57     if (defined ($size)) {
58         # Strip parens from object size.
59         $size =~ s/\((\d+)\)/$1/;
60
61         $type{$symbol} = "OBJECT";
62         $version{$symbol} = $version;
63         $size{$symbol} = $size;
64         next;
65     }
66
67     if ($version eq $symbol or $version eq $basever) {
68         # Emit versions or symbols bound to base versions as objects.
69         $type{$symbol} = "OBJECT";
70         $version{$symbol} = $symbol;
71         $size{$symbol} = 0;
72     } else {
73         # Everything else without a size field is a function.
74         $type{$symbol} = "FUNC";
75         $version{$symbol} = $version;
76     }
77 }
78 close PVS or die "pvs error";
79
80 # Only look at .dynsym table, like readelf in extract_symvers.
81 open ELFDUMP, "/usr/ccs/bin/elfdump -s -N .dynsym $lib |" or die $!;
82 while (<ELFDUMP>) {
83     chomp;
84
85     # Ignore empty lines.
86     next if (/^$/);
87
88     # Ignore object name header.
89     next if (/:$/);
90
91     # Ignore table header lines.
92     next if (/^Symbol Table Section:/);
93     next if (/index.*value.*size/);
94
95     # Split table.
96     (undef, undef, undef, $type, $bind, $oth, undef, $shndx, $name) = split;
97
98     # Error out for unknown input.
99     die "unknown input line:\n$_" unless defined($bind);
100
101     # Ignore local symbols.
102     next if ($bind eq "LOCL");
103     # Ignore hidden symbols.
104     next if ($oth eq "H");
105     # Ignore undefined symbols.
106     next if ($shndx eq "UNDEF");
107     # Error out for unhandled cases.   _GLOBAL_OFFSET_TABLE_ is P (protected).
108     die "unhandled symbol:\n$_" if ($bind !~ /^(GLOB|WEAK)/ or $oth !~ /[DP]/);
109
110     # Adapt to readelf type naming convention.
111     $type = "OBJECT" if ($type eq "OBJT");
112
113     # Use correct symbol type.
114     $type{$name} = $type if ($type{$name} ne $type);
115 }
116 close ELFDUMP or die "elfdump error";
117
118 foreach $symbol (keys %type) {
119     if ($type{$symbol} eq "FUNC") {
120         push @lines, "$type{$symbol}:$symbol\@\@$version{$symbol}\n";
121     } elsif ($type{$symbol} eq "OBJECT" and $size{$symbol} == 0) {
122         push @lines, "$type{$symbol}:$size{$symbol}:$version{$symbol}\n";
123     } else {
124         push @lines, "$type{$symbol}:$size{$symbol}:$symbol\@\@$version{$symbol}\n";
125     }
126 }
127 print sort @lines;