1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
# Generate macros that control the symbol versions of the public
# library API, from a .map.in file.
#
# Written by Zack Weinberg <zackw at panix.com> in 2017.
# To the extent possible under law, Zack Weinberg has waived all
# copyright and related or neighboring rights to this work.
#
# See https://creativecommons.org/publicdomain/zero/1.0/ for further
# details.
# The .map.in file is the first input file, and we expect the Makefile
# to have set the variables SYMVER_MIN, SYMVER_FLOOR, and COMPAT_ABI.
# See libcrypt.map.in and gen-vers.awk for explanations of the format
# of .map.in files. See crypt-port.h for an explanation of how to use
# the macros generated by this program.
#
# Note: if you change the format of .map.in files you probably need to
# update gen-map.awk too.
#
# Note: we currently don't support compatibility symbols that need
# a different definition from the default version.
BEGIN {
split("", SYMBOLS) # ensure SYMBOLS is an array
split("", VCHAIN) # ditto VCHAIN
NVCHAIN = 0
# This arranges for sorted output if gawk is in use, and is
# harmless otherwise.
PROCINFO["sorted_in"] = "@ind_str_asc"
}
NF == 0 { next } # blank line, discard
$1 == "#" { next } # comment, discard
$1 == "%chain" {
for (i = 2; i <= NF; i++) {
VCHAIN[++NVCHAIN] = $i
}
next
}
{
if ($2 == "-") {
compat_only[$1] = 1
} else {
compat_only[$1] = 0
if ($2 in SYMBOLS) {
SYMBOLS[$2] = SYMBOLS[$2] SUBSEP $1
} else {
SYMBOLS[$2] = $1
}
}
for (i = 3; i <= NF; i++) {
sym=$i
n=split(sym, a, ":")
if (n > 1) {
sym=""
for (j = 2; j <= n; j++) {
if (COMPAT_ABI == "yes" || COMPAT_ABI == a[j]) {
sym=a[1]
}
}
}
if (sym != "") {
if (sym in SYMBOLS) {
SYMBOLS[sym] = SYMBOLS[sym] SUBSEP $1
} else {
SYMBOLS[sym] = $1
}
}
}
}
END {
if (NVCHAIN == 0) {
print ARGV[1] ": error: missing %chain directive" > "/dev/stderr"
close("/dev/stderr")
exit 1
}
symver_min_idx = 0
symver_floor_idx = 0
for (i = 1; i <= NVCHAIN; i++) {
if (VCHAIN[i] == SYMVER_MIN) {
symver_min_idx = i
}
if (VCHAIN[i] == SYMVER_FLOOR) {
symver_floor_idx = i
}
}
if (symver_min_idx == 0) {
print ARGV[1] ": error: SYMVER_MIN (" SYMVER_MIN ") " \
"not found in %chain directives" > "/dev/stderr"
close("/dev/stderr")
exit 1
}
if (symver_floor_idx == 0) {
print ARGV[1] ": error: SYMVER_FLOOR (" SYMVER_FLOOR ") " \
"not found in %chain directives" > "/dev/stderr"
close("/dev/stderr")
exit 1
}
if (symver_floor_idx < symver_min_idx) {
print ARGV[1] ": error: SYMVER_FLOOR (" SYMVER_FLOOR ") " \
"is lower than SYMVER_MIN (" SYMVER_MIN ")" > "/dev/stderr"
close("/dev/stderr")
exit 1
}
# Construct a pruned set of symbols and versions, including only
# versions with symbols, discarding all symbols associated with
# versions below SYMVER_MIN, raising symbols below SYMVER_FLOOR to
# SYMVER_FLOOR, and removing duplicates.
# Note: unlike in gen-map.awk, symbols all of whose versions are
# below SYMVER_MIN must still be counted in 'allsyms' so their
# INCLUDE macros are generated.
for (i = 1; i <= NVCHAIN; i++) {
v = VCHAIN[i]
if (v in SYMBOLS) {
nsyms = split(SYMBOLS[v], syms, SUBSEP)
j = i;
if (j < symver_floor_idx)
j = symver_floor_idx;
vr = VCHAIN[j]
for (s = 1; s <= nsyms; s++) {
if (syms[s]) {
allsyms[syms[s]] = 1
if (i >= symver_min_idx) {
symset[vr, syms[s]] = 1
}
}
}
}
}
print "/* Generated from " ARGV[1] " by gen-vers.awk. DO NOT EDIT. */"
print ""
print "#ifndef _CRYPT_SYMBOL_VERS_H"
print "#define _CRYPT_SYMBOL_VERS_H 1"
print ""
print "/* For each public symbol <sym>, INCLUDE_<sym> is true if it"
print " has any versions above the backward compatibility minimum."
print " Compatibility-only symbols are not included in the static"
print " library, or in the shared library when configured with"
print " --disable-obsolete-api. */"
print "#if defined PIC && ENABLE_OBSOLETE_API"
print ""
for (sym in allsyms) {
include = 0
for (i = symver_floor_idx; i <= NVCHAIN; i++) {
if ((VCHAIN[i], sym) in symset) {
include++
}
}
includesym[sym] = include
printf("#define INCLUDE_%s %d\n", sym, include)
}
print ""
print "#else"
print ""
for (sym in allsyms) {
printf("#define INCLUDE_%s %d\n", sym,
(includesym[sym] && !compat_only[sym]))
}
print ""
print "#endif"
print ""
print "/* For each public symbol <sym> that is included, define its"
print " highest version as the default, and aliases at each"
print " compatibility version. */"
for (sym in allsyms) {
if (includesym[sym]) {
seq = 0
for (i = NVCHAIN; i >= symver_floor_idx; i--) {
v = VCHAIN[i]
if ((v, sym) in symset) {
if (seq == 0) {
if (compat_only[sym] || includesym[sym] > 0) {
printf("#ifdef PIC\n#define %s _crypt_%s\n#endif\n",
sym, sym);
}
printf("#define SYMVER_%s \\\n", sym)
if (compat_only[sym]) {
printf(" symver_compat0 (\"%s\", %s, %s)", sym, sym, v)
} else if (includesym[sym] > 0) {
printf(" symver_default (\"%s\", %s, %s)", sym, sym, v)
} else {
# Due to what appears to be a bug in GNU ld,
# we must not issue symver_default() if there
# aren't going to be any other versions.
printf(" symver_nop ()")
}
} else {
printf("; \\\n symver_compat (%d, \"%s\", %s, %s, %s)",
seq, sym, sym, sym, v)
}
seq++
}
}
print ""
} else {
printf("#define SYMVER_%s symver_nop()\n", sym)
}
}
print ""
print "#endif /* crypt-symbol-vers.h */"
}
|