]> git.ipfire.org Git - thirdparty/glibc.git/blame - scripts/versions.awk
Use --enable-obsolete in build-many-glibcs.py for nios2-linux-gnu
[thirdparty/glibc.git] / scripts / versions.awk
CommitLineData
d3564d01 1# Combine version map fragments into version scripts for our shared objects.
dff8da6b 2# Copyright (C) 1998-2024 Free Software Foundation, Inc.
b0b67c47 3
4bae5567
UD
4# This script expects the following variables to be defined:
5# defsfile name of Versions.def file
6# buildroot name of build directory with trailing slash
7# move_if_change move-if-change command
8
b0b67c47
UD
9# Read definitions for the versions.
10BEGIN {
2fb9a65c
RM
11 lossage = 0;
12
b0b67c47 13 nlibs=0;
8eaaffde 14 while (getline < defsfile) {
8d8c6efa 15 if (/^[a-zA-Z0-9_.]+ \{/) {
b0b67c47
UD
16 libs[$1] = 1;
17 curlib = $1;
8eaaffde 18 while (getline < defsfile && ! /^}/) {
2fb9a65c 19 if ($2 == "=") {
d3564d01 20 renamed[curlib "::" $1] = $3;
2fb9a65c 21 }
361742ed 22 else
2fb9a65c 23 versions[curlib "::" $1] = 1;
b0b67c47
UD
24 }
25 }
26 }
8eaaffde 27 close(defsfile);
b0b67c47 28
4bae5567 29 tmpfile = buildroot "Versions.tmp";
8680179f
UD
30 # POSIX sort needed.
31 sort = "sort -t. -k 1,1 -k 2n,2n -k 3 > " tmpfile;
b0b67c47
UD
32}
33
a64af8c9
FW
34# GNU awk does not implement the ord and chr functions.
35# <https://www.gnu.org/software/gawk/manual/html_node/Ordinal-Functions.html>
36# says that they are "written very nicely", using code similar to what
37# is included here.
38function chr(c) {
39 return sprintf("%c", c)
40}
41
42BEGIN {
43 for (c = 1; c < 127; c++) {
44 ord_table[chr(c)] = c;
45 }
46}
47
48function ord(c) {
49 if (ord_table[c]) {
50 return ord_table[c];
51 } else {
52 printf("Invalid character reference: '%c'\n", c) > "/dev/stderr";
53 ++lossage;
54 }
55}
56
b0b67c47
UD
57# Remove comment lines.
58/^ *#/ {
59 next;
60}
61
62# This matches the beginning of the version information for a new library.
8d8c6efa 63/^[a-zA-Z0-9_.]+/ {
b0b67c47 64 actlib = $1;
8eaaffde
UD
65 if (!libs[$1]) {
66 printf("no versions defined for %s\n", $1) > "/dev/stderr";
2fb9a65c 67 ++lossage;
b0b67c47
UD
68 }
69 next;
70}
71
72# This matches the beginning of a new version for the current library.
73/^ [A-Za-z_]/ {
d3564d01
RM
74 if (renamed[actlib "::" $1])
75 actver = renamed[actlib "::" $1];
8ac78e60 76 else if (!versions[actlib "::" $1] && $1 != "GLIBC_PRIVATE") {
48a5e010 77 printf("version %s not defined for %s\n", $1, actlib) > "/dev/stderr";
2fb9a65c 78 ++lossage;
b0b67c47 79 }
361742ed
RM
80 else
81 actver = $1;
b0b67c47
UD
82 next;
83}
84
85# This matches lines with names to be added to the current version in the
86# current library. This is the only place where we print something to
87# the intermediate file.
88/^ / {
1e06620a
UD
89 sortver=actver
90 # Ensure GLIBC_ versions come always first
91 sub(/^GLIBC_/," GLIBC_",sortver)
92 printf("%s %s %s\n", actlib, sortver, $0) | sort;
b0b67c47
UD
93}
94
c44838eb
FW
95# Some targets do not set the ABI baseline for libdl. As a result,
96# symbols originally in libdl need to be moved under historic symbol
97# versions, without altering the baseline version for libc itself.
98/^ *!libc_pre_versions/ {
99 libc_pre_versions_active = 1;
100}
101
102function libc_pre_versions() {
103 # No local: * here, so that we do not have to update this script
104 # if symbols are moved into libc. The abilist files and the other
105 # targets (with a real GLIBC_2.0 baseline) provide testing
106 # coverage.
107 printf("\
108GLIBC_2.0 {\n\
109};\n\
110GLIBC_2.1 {\n\
111} GLIBC_2.0;\n\
112") > outfile;
113 return "GLIBC_2.1";
114}
b0b67c47 115
da6d7d38 116function closeversion(name, oldname) {
d32ee64d 117 printf(" local:\n *;\n") > outfile;
48a5e010
RM
118 # This version inherits from the last one only if they
119 # have the same nonnumeric prefix, i.e. GLIBC_x.y and GLIBC_x.z
120 # or FOO_x and FOO_y but not GLIBC_x and FOO_y.
121 pfx = oldname;
122 sub(/[0-9.]+/,".+",pfx);
123 if (oldname == "" || name !~ pfx) print "};" > outfile;
124 else printf("} %s;\n", oldname) > outfile;
b0b67c47
UD
125}
126
4bae5567
UD
127function close_and_move(name, real_name) {
128 close(name);
129 system(move_if_change " " name " " real_name " >&2");
130}
131
a64af8c9
FW
132# ELF hash, for use with symbol versions.
133function elf_hash(s, i, acc) {
134 acc = 0;
135 for (i = 1; i <= length(s); ++i) {
136 acc = and(lshift(acc, 4) + ord(substr(s, i, 1)), 0xffffffff);
137 top = and(acc, 0xf0000000);
138 acc = and(xor(acc, rshift(top, 24)), compl(top));
139 }
140 return acc;
141}
142
b0b67c47
UD
143# Now print the accumulated information.
144END {
145 close(sort);
2fb9a65c
RM
146
147 if (lossage) {
148 system("rm -f " tmpfile);
149 exit 1;
150 }
151
4bae5567
UD
152 oldlib = "";
153 oldver = "";
8f2e1830
JM
154 real_first_ver_header = buildroot "first-versions.h"
155 first_ver_header = real_first_ver_header "T"
156 printf("#ifndef _FIRST_VERSIONS_H\n") > first_ver_header;
157 printf("#define _FIRST_VERSIONS_H\n") > first_ver_header;
9aa4965c
JM
158 real_ldbl_compat_header = buildroot "ldbl-compat-choose.h"
159 ldbl_compat_header = real_ldbl_compat_header "T"
160 printf("#ifndef _LDBL_COMPAT_CHOOSE_H\n") > ldbl_compat_header;
161 printf("#define _LDBL_COMPAT_CHOOSE_H\n") > ldbl_compat_header;
162 printf("#ifndef LONG_DOUBLE_COMPAT\n") > ldbl_compat_header;
163 printf("# error LONG_DOUBLE_COMPAT not defined\n") > ldbl_compat_header;
164 printf("#endif\n") > ldbl_compat_header;
4bae5567 165 printf("version-maps =");
48a5e010 166 while (getline < tmpfile) {
b0b67c47
UD
167 if ($1 != oldlib) {
168 if (oldlib != "") {
da6d7d38 169 closeversion(oldver, veryoldver);
b0b67c47 170 oldver = "";
4bae5567 171 close_and_move(outfile, real_outfile);
b0b67c47
UD
172 }
173 oldlib = $1;
4bae5567
UD
174 real_outfile = buildroot oldlib ".map";
175 outfile = real_outfile "T";
c44838eb
FW
176 if ($1 == "libc" && libc_pre_versions_active) {
177 veryoldver = libc_pre_versions();
178 } else {
179 veryoldver = "";
180 }
4bae5567 181 printf(" %s.map", oldlib);
b0b67c47
UD
182 }
183 if ($2 != oldver) {
184 if (oldver != "") {
da6d7d38
UD
185 closeversion(oldver, veryoldver);
186 veryoldver = oldver;
b0b67c47 187 }
b0b67c47 188 oldver = $2;
57292f57
L
189 # Skip the placeholder symbol used only for empty version map.
190 if ($3 == "__placeholder_only_for_empty_version_map;") {
191 printf("%s {\n", $2) > outfile;
192 continue;
193 }
194 printf("%s {\n global:\n", $2) > outfile;
b0b67c47
UD
195 }
196 printf(" ") > outfile;
197 for (n = 3; n <= NF; ++n) {
198 printf(" %s", $n) > outfile;
8f2e1830
JM
199 sym = $n;
200 sub(";", "", sym);
201 first_ver_macro = "FIRST_VERSION_" oldlib "_" sym;
202 if (!(first_ver_macro in first_ver_seen) \
203 && oldver ~ "^GLIBC_[0-9]" \
204 && sym ~ "^[A-Za-z0-9_]*$") {
205 ver_val = oldver;
a64af8c9
FW
206 printf("#define %s_STRING \"%s\"\n", first_ver_macro, ver_val) > first_ver_header;
207 printf("#define %s_HASH 0x%x\n", first_ver_macro, elf_hash(ver_val)) > first_ver_header;
8f2e1830
JM
208 gsub("\\.", "_", ver_val);
209 printf("#define %s %s\n", first_ver_macro, ver_val) > first_ver_header;
210 first_ver_seen[first_ver_macro] = 1;
9aa4965c
JM
211 if (oldlib == "libc" || oldlib == "libm") {
212 printf("#if LONG_DOUBLE_COMPAT (%s, %s)\n",
213 oldlib, ver_val) > ldbl_compat_header;
214 printf("# define LONG_DOUBLE_COMPAT_CHOOSE_%s_%s(a, b) a\n",
215 oldlib, sym) > ldbl_compat_header;
216 printf("#else\n") > ldbl_compat_header;
217 printf("# define LONG_DOUBLE_COMPAT_CHOOSE_%s_%s(a, b) b\n",
218 oldlib, sym) > ldbl_compat_header;
219 printf("#endif\n") > ldbl_compat_header;
220 }
8f2e1830 221 }
b0b67c47
UD
222 }
223 printf("\n") > outfile;
224 }
8eaaffde 225 printf("\n");
8f2e1830 226 printf("#endif /* first-versions.h */\n") > first_ver_header;
9aa4965c 227 printf("#endif /* ldbl-compat-choose.h */\n") > ldbl_compat_header;
da6d7d38 228 closeversion(oldver, veryoldver);
4bae5567 229 close_and_move(outfile, real_outfile);
8f2e1830 230 close_and_move(first_ver_header, real_first_ver_header);
9aa4965c 231 close_and_move(ldbl_compat_header, real_ldbl_compat_header);
8680179f 232 #system("rm -f " tmpfile);
b0b67c47 233}