]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/scripts/extract_symvers.pl
Update copyright years in libstdc++-v3/
[thirdparty/gcc.git] / libstdc++-v3 / scripts / extract_symvers.pl
CommitLineData
e1208a57
RO
1#!/usr/bin/perl -w
2
aa118a03 3# Copyright (C) 2010-2014 Free Software Foundation, Inc.
e1208a57
RO
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
28my $lib = shift;
29
30open PVS, "pvs -dsvo $lib |" or die $!;
31while (<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";
9ac0b841
RO
70 if ($version eq $basever) {
71 $version{$symbol} = $version;
72 } else {
73 $version{$symbol} = $symbol;
74 }
e1208a57
RO
75 $size{$symbol} = 0;
76 } else {
77 # Everything else without a size field is a function.
78 $type{$symbol} = "FUNC";
79 $version{$symbol} = $version;
80 }
81}
82close PVS or die "pvs error";
83
84# Only look at .dynsym table, like readelf in extract_symvers.
85open ELFDUMP, "/usr/ccs/bin/elfdump -s -N .dynsym $lib |" or die $!;
86while (<ELFDUMP>) {
87 chomp;
88
89 # Ignore empty lines.
90 next if (/^$/);
91
92 # Ignore object name header.
93 next if (/:$/);
94
95 # Ignore table header lines.
96 next if (/^Symbol Table Section:/);
97 next if (/index.*value.*size/);
98
99 # Split table.
100 (undef, undef, undef, $type, $bind, $oth, undef, $shndx, $name) = split;
101
102 # Error out for unknown input.
103 die "unknown input line:\n$_" unless defined($bind);
104
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]/);
113
114 # Adapt to readelf type naming convention.
64574d41 115 $type = "NOTYPE" if ($type eq "NOTY");
e1208a57
RO
116 $type = "OBJECT" if ($type eq "OBJT");
117
118 # Use correct symbol type.
119 $type{$name} = $type if ($type{$name} ne $type);
120}
121close ELFDUMP or die "elfdump error";
122
123foreach $symbol (keys %type) {
64574d41 124 if ($type{$symbol} eq "FUNC" || $type{$symbol} eq "NOTYPE") {
e1208a57
RO
125 push @lines, "$type{$symbol}:$symbol\@\@$version{$symbol}\n";
126 } elsif ($type{$symbol} eq "OBJECT" and $size{$symbol} == 0) {
9ac0b841
RO
127 # Omit symbols bound to base version; details can differ depending
128 # on the toolchain used.
129 next if $version{$symbol} eq $basever;
130
e1208a57
RO
131 push @lines, "$type{$symbol}:$size{$symbol}:$version{$symbol}\n";
132 } else {
133 push @lines, "$type{$symbol}:$size{$symbol}:$symbol\@\@$version{$symbol}\n";
134 }
135}
136print sort @lines;