re PR tree-optimization/59374 (-ftree-slp-vectorize breaks unique_ptr's move constructor)
[official-gcc.git] / libstdc++-v3 / scripts / extract_symvers.pl
blobd43c53e231f361362cd8606f4eaabae5f213a659
1 #!/usr/bin/perl -w
3 # Copyright (C) 2010-2013 Free Software Foundation, Inc.
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.
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.
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/>.
20 # Extract symbol version information on Solaris 2.
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.
28 my $lib = shift;
30 open PVS, "pvs -dsvo $lib |" or die $!;
31 while (<PVS>) {
32 chomp;
34 # Remove trailing semicolon.
35 s/;$//;
37 # shared object, dash, version, symbol, [size]
38 (undef, undef, $version, $symbol, $size) = split;
40 # Remove colon separator from version field.
41 $version =~ s/:$//;
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;
50 # Skip version declarations.
51 next unless defined ($symbol);
53 # Ignore version dependencies.
54 next if ($symbol =~ /\{.*\}/);
56 # Emit objects.
57 if (defined ($size)) {
58 # Strip parens from object size.
59 $size =~ s/\((\d+)\)/$1/;
61 $type{$symbol} = "OBJECT";
62 $version{$symbol} = $version;
63 $size{$symbol} = $size;
64 next;
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 if ($version eq $basever) {
71 $version{$symbol} = $version;
72 } else {
73 $version{$symbol} = $symbol;
75 $size{$symbol} = 0;
76 } else {
77 # Everything else without a size field is a function.
78 $type{$symbol} = "FUNC";
79 $version{$symbol} = $version;
82 close PVS or die "pvs error";
84 # Only look at .dynsym table, like readelf in extract_symvers.
85 open ELFDUMP, "/usr/ccs/bin/elfdump -s -N .dynsym $lib |" or die $!;
86 while (<ELFDUMP>) {
87 chomp;
89 # Ignore empty lines.
90 next if (/^$/);
92 # Ignore object name header.
93 next if (/:$/);
95 # Ignore table header lines.
96 next if (/^Symbol Table Section:/);
97 next if (/index.*value.*size/);
99 # Split table.
100 (undef, undef, undef, $type, $bind, $oth, undef, $shndx, $name) = split;
102 # Error out for unknown input.
103 die "unknown input line:\n$_" unless defined($bind);
105 # Ignore local symbols.
106 next if ($bind eq "LOCL");
107 # Ignore hidden symbols.
108 next if ($oth eq "H");
109 # Ignore undefined symbols.
110 next if ($shndx eq "UNDEF");
111 # Error out for unhandled cases. _GLOBAL_OFFSET_TABLE_ is P (protected).
112 die "unhandled symbol:\n$_" if ($bind !~ /^(GLOB|WEAK)/ or $oth !~ /[DP]/);
114 # Adapt to readelf type naming convention.
115 $type = "NOTYPE" if ($type eq "NOTY");
116 $type = "OBJECT" if ($type eq "OBJT");
118 # Use correct symbol type.
119 $type{$name} = $type if ($type{$name} ne $type);
121 close ELFDUMP or die "elfdump error";
123 foreach $symbol (keys %type) {
124 if ($type{$symbol} eq "FUNC" || $type{$symbol} eq "NOTYPE") {
125 push @lines, "$type{$symbol}:$symbol\@\@$version{$symbol}\n";
126 } elsif ($type{$symbol} eq "OBJECT" and $size{$symbol} == 0) {
127 # Omit symbols bound to base version; details can differ depending
128 # on the toolchain used.
129 next if $version{$symbol} eq $basever;
131 push @lines, "$type{$symbol}:$size{$symbol}:$version{$symbol}\n";
132 } else {
133 push @lines, "$type{$symbol}:$size{$symbol}:$symbol\@\@$version{$symbol}\n";
136 print sort @lines;