annotate libstdc++-v3/scripts/extract_symvers.pl @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 #!/usr/bin/perl -w
kono
parents:
diff changeset
2
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
3 # Copyright (C) 2010-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
4 #
kono
parents:
diff changeset
5 # This file is part of the GNU ISO C++ Library. This library is free
kono
parents:
diff changeset
6 # software; you can redistribute it and/or modify it under the
kono
parents:
diff changeset
7 # terms of the GNU General Public License as published by the
kono
parents:
diff changeset
8 # Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
9 # any later version.
kono
parents:
diff changeset
10 #
kono
parents:
diff changeset
11 # This library is distributed in the hope that it will be useful,
kono
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
14 # GNU General Public License for more details.
kono
parents:
diff changeset
15 #
kono
parents:
diff changeset
16 # You should have received a copy of the GNU General Public License along
kono
parents:
diff changeset
17 # with this library; see the file COPYING3. If not see
kono
parents:
diff changeset
18 # <http://www.gnu.org/licenses/>.
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 # Extract symbol version information on Solaris 2.
kono
parents:
diff changeset
21 #
kono
parents:
diff changeset
22 # Sun ld doesn't record symbol versions in .dynsym entries and they cannot
kono
parents:
diff changeset
23 # easily be extracted from readelf --versions output, so use pvs instead.
kono
parents:
diff changeset
24 # This way, we don't require GNU binutils in the native case. Also ensures
kono
parents:
diff changeset
25 # that baseline_symbols.txt is identical between native (pvs, elfdump) and
kono
parents:
diff changeset
26 # cross (readelf) cases.
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 my $lib = shift;
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 open PVS, "pvs -dsvo $lib |" or die $!;
kono
parents:
diff changeset
31 while (<PVS>) {
kono
parents:
diff changeset
32 chomp;
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 # Remove trailing semicolon.
kono
parents:
diff changeset
35 s/;$//;
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 # shared object, dash, version, symbol, [size]
kono
parents:
diff changeset
38 (undef, undef, $version, $symbol, $size) = split;
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 # Remove colon separator from version field.
kono
parents:
diff changeset
41 $version =~ s/:$//;
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 # Record base version. The [BASE] field was only added in Solaris 11,
kono
parents:
diff changeset
44 # so simply use the first record instead.
kono
parents:
diff changeset
45 if ($. == 1) {
kono
parents:
diff changeset
46 $basever = $version;
kono
parents:
diff changeset
47 next;
kono
parents:
diff changeset
48 }
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 # Skip version declarations.
kono
parents:
diff changeset
51 next unless defined ($symbol);
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 # Ignore version dependencies.
kono
parents:
diff changeset
54 next if ($symbol =~ /\{.*\}/);
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 # Emit objects.
kono
parents:
diff changeset
57 if (defined ($size)) {
kono
parents:
diff changeset
58 # Strip parens from object size.
kono
parents:
diff changeset
59 $size =~ s/\((\d+)\)/$1/;
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 $type{$symbol} = "OBJECT";
kono
parents:
diff changeset
62 $version{$symbol} = $version;
kono
parents:
diff changeset
63 $size{$symbol} = $size;
kono
parents:
diff changeset
64 next;
kono
parents:
diff changeset
65 }
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 if ($version eq $symbol or $version eq $basever) {
kono
parents:
diff changeset
68 # Emit versions or symbols bound to base versions as objects.
kono
parents:
diff changeset
69 $type{$symbol} = "OBJECT";
kono
parents:
diff changeset
70 if ($version eq $basever) {
kono
parents:
diff changeset
71 $version{$symbol} = $version;
kono
parents:
diff changeset
72 } else {
kono
parents:
diff changeset
73 $version{$symbol} = $symbol;
kono
parents:
diff changeset
74 }
kono
parents:
diff changeset
75 $size{$symbol} = 0;
kono
parents:
diff changeset
76 } else {
kono
parents:
diff changeset
77 # Everything else without a size field is a function.
kono
parents:
diff changeset
78 $type{$symbol} = "FUNC";
kono
parents:
diff changeset
79 $version{$symbol} = $version;
kono
parents:
diff changeset
80 }
kono
parents:
diff changeset
81 }
kono
parents:
diff changeset
82 close PVS or die "pvs error";
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 # Only look at .dynsym table, like readelf in extract_symvers.
kono
parents:
diff changeset
85 # Ignore error output to avoid getting confused by
kono
parents:
diff changeset
86 # .gnu.version_r: zero sh_entsize information, expected 0x1
kono
parents:
diff changeset
87 # warning with Solaris 11 elfdump on gld-produced shared objects.
kono
parents:
diff changeset
88 open ELFDUMP, "/usr/ccs/bin/elfdump -s -N .dynsym $lib 2>/dev/null |" or die $!;
kono
parents:
diff changeset
89 while (<ELFDUMP>) {
kono
parents:
diff changeset
90 chomp;
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 # Ignore empty lines.
kono
parents:
diff changeset
93 next if (/^$/);
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 # Ignore object name header.
kono
parents:
diff changeset
96 next if (/:$/);
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 # Ignore table header lines.
kono
parents:
diff changeset
99 next if (/^Symbol Table Section:/);
kono
parents:
diff changeset
100 next if (/index.*value.*size/);
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 # Split table.
kono
parents:
diff changeset
103 (undef, undef, undef, $type, $bind, $oth, undef, $shndx, $name) = split;
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 # Error out for unknown input.
kono
parents:
diff changeset
106 die "unknown input line:\n$_" unless defined($bind);
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 # Ignore local symbols.
kono
parents:
diff changeset
109 next if ($bind eq "LOCL");
kono
parents:
diff changeset
110 # Ignore hidden symbols.
kono
parents:
diff changeset
111 next if ($oth eq "H");
kono
parents:
diff changeset
112 # Ignore undefined symbols.
kono
parents:
diff changeset
113 next if ($shndx eq "UNDEF");
kono
parents:
diff changeset
114 # Error out for unhandled cases. _GLOBAL_OFFSET_TABLE_ is P (protected).
kono
parents:
diff changeset
115 die "unhandled symbol:\n$_" if ($bind !~ /^(GLOB|WEAK)/ or $oth !~ /[DP]/);
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 # Adapt to readelf type naming convention.
kono
parents:
diff changeset
118 $type = "NOTYPE" if ($type eq "NOTY");
kono
parents:
diff changeset
119 $type = "OBJECT" if ($type eq "OBJT");
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 # Use correct symbol type.
kono
parents:
diff changeset
122 $type{$name} = $type if ($type{$name} ne $type);
kono
parents:
diff changeset
123 }
kono
parents:
diff changeset
124 close ELFDUMP or die "elfdump error";
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 foreach $symbol (keys %type) {
kono
parents:
diff changeset
127 if ($type{$symbol} eq "FUNC" || $type{$symbol} eq "NOTYPE") {
kono
parents:
diff changeset
128 push @lines, "$type{$symbol}:$symbol\@\@$version{$symbol}\n";
kono
parents:
diff changeset
129 } elsif ($type{$symbol} eq "OBJECT" and $size{$symbol} == 0) {
kono
parents:
diff changeset
130 # Omit symbols bound to base version; details can differ depending
kono
parents:
diff changeset
131 # on the toolchain used.
kono
parents:
diff changeset
132 next if $version{$symbol} eq $basever;
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 push @lines, "$type{$symbol}:$size{$symbol}:$version{$symbol}\n";
kono
parents:
diff changeset
135 } else {
kono
parents:
diff changeset
136 push @lines, "$type{$symbol}:$size{$symbol}:$symbol\@\@$version{$symbol}\n";
kono
parents:
diff changeset
137 }
kono
parents:
diff changeset
138 }
kono
parents:
diff changeset
139 print sort @lines;