]>
Commit | Line | Data |
---|---|---|
111349c7 | 1 | # Generate an ELF symbol version map a-la Solaris and GNU ld. |
f1717362 | 2 | # Copyright (C) 2007-2016 Free Software Foundation, Inc. |
111349c7 | 3 | # Contributed by Richard Henderson <rth@cygnus.com> |
4 | # | |
f12b58b3 | 5 | # This file is part of GCC. |
111349c7 | 6 | # |
f12b58b3 | 7 | # GCC is free software; you can redistribute it and/or modify it under |
8 | # the terms of the GNU General Public License as published by the Free | |
8c4c00c1 | 9 | # Software Foundation; either version 3, or (at your option) any later |
f12b58b3 | 10 | # version. |
111349c7 | 11 | # |
f12b58b3 | 12 | # GCC is distributed in the hope that it will be useful, but WITHOUT |
13 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
14 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public | |
15 | # License for more details. | |
111349c7 | 16 | # |
17 | # You should have received a copy of the GNU General Public License | |
8c4c00c1 | 18 | # along with GCC; see the file COPYING3. If not see |
19 | # <http://www.gnu.org/licenses/>. | |
111349c7 | 20 | |
21 | BEGIN { | |
22 | state = "nm"; | |
5484670c | 23 | sawsymbol = 0; |
c7921ee9 | 24 | if (leading_underscore) |
25 | prefix = "_"; | |
26 | else | |
27 | prefix = ""; | |
111349c7 | 28 | } |
29 | ||
30 | # Remove comment and blank lines. | |
31 | /^ *#/ || /^ *$/ { | |
32 | next; | |
33 | } | |
34 | ||
35 | # We begin with nm input. Collect the set of symbols that are present | |
36 | # so that we can not emit them into the final version script -- Solaris | |
37 | # complains at us if we do. | |
38 | ||
39 | state == "nm" && /^%%/ { | |
40 | state = "ver"; | |
41 | next; | |
42 | } | |
43 | ||
44 | state == "nm" && ($1 == "U" || $2 == "U") { | |
45 | next; | |
46 | } | |
47 | ||
48 | state == "nm" && NF == 3 { | |
b3fd46a0 | 49 | split ($3, s, "@") |
50 | def[s[1]] = 1; | |
5484670c | 51 | sawsymbol = 1; |
111349c7 | 52 | next; |
53 | } | |
54 | ||
55 | state == "nm" { | |
56 | next; | |
57 | } | |
58 | ||
59 | # Now we process a simplified variant of the Solaris symbol version | |
60 | # script. We have one symbol per line, no semicolons, simple markers | |
61 | # for beginning and ending each section, and %inherit markers for | |
f0b5f617 | 62 | # describing version inheritance. A symbol may appear in more than |
111349c7 | 63 | # one symbol version, and the last seen takes effect. |
c7921ee9 | 64 | # The magic version name '%exclude' causes all the symbols given that |
65 | # version to be dropped from the output (unless a later version overrides). | |
111349c7 | 66 | |
67 | NF == 3 && $1 == "%inherit" { | |
68 | inherit[$2] = $3; | |
69 | next; | |
70 | } | |
71 | ||
72 | NF == 2 && $2 == "{" { | |
c7921ee9 | 73 | if ($1 != "%exclude") |
74 | libs[$1] = 1; | |
111349c7 | 75 | thislib = $1; |
76 | next; | |
77 | } | |
78 | ||
79 | $1 == "}" { | |
80 | thislib = ""; | |
81 | next; | |
82 | } | |
83 | ||
84 | { | |
c7921ee9 | 85 | sym = prefix $1; |
b3fd46a0 | 86 | symbols[sym] = 1 |
c7921ee9 | 87 | if (thislib != "%exclude") |
b3fd46a0 | 88 | ver[sym, thislib] = 1; |
89 | else { | |
90 | for (l in libs) | |
91 | ver[sym, l] = 0; | |
92 | } | |
111349c7 | 93 | next; |
94 | } | |
95 | ||
96 | END { | |
5484670c | 97 | if (!sawsymbol) |
98 | { | |
99 | print "No symbols seen -- broken or mis-installed nm?" | "cat 1>&2"; | |
100 | exit 1; | |
101 | } | |
111349c7 | 102 | for (l in libs) |
103 | output(l); | |
104 | } | |
105 | ||
106 | function output(lib) { | |
107 | if (done[lib]) | |
108 | return; | |
109 | done[lib] = 1; | |
110 | if (inherit[lib]) | |
111 | output(inherit[lib]); | |
112 | ||
f8ecef74 | 113 | empty=1 |
b3fd46a0 | 114 | for (sym in symbols) |
115 | if ((ver[sym, lib] != 0) && (sym in def)) | |
1a17e78f | 116 | { |
f8ecef74 | 117 | if (empty) |
5484670c | 118 | { |
f8ecef74 | 119 | printf("%s {\n", lib); |
5484670c | 120 | printf(" global:\n"); |
f8ecef74 | 121 | empty = 0; |
5484670c | 122 | } |
1a17e78f | 123 | printf("\t%s;\n", sym); |
1a17e78f | 124 | } |
111349c7 | 125 | |
f8ecef74 | 126 | if (empty) |
127 | { | |
128 | for (l in libs) | |
129 | if (inherit[l] == lib) | |
130 | inherit[l] = inherit[lib]; | |
131 | } | |
132 | else if (inherit[lib]) | |
111349c7 | 133 | printf("} %s;\n", inherit[lib]); |
134 | else | |
135 | printf ("\n local:\n\t*;\n};\n"); | |
136 | } |