Debian Codegraph @

build-aux/scripts/gen-crypt-symbol-vers-h

raw
1 #! /usr/bin/perl
2 # Written by Zack Weinberg <zackw at panix.com> in 2017 and 2021.
3 # To the extent possible under law, Zack Weinberg has waived all
4 # copyright and related or neighboring rights to this work.
5 #
6 # See https://creativecommons.org/publicdomain/zero/1.0/ for further
7 # details.
8
9 # Generate macros that control the symbol versions of the public
10 # library API, from a .map.in file.
11 #
12 # See libcrypt.map.in for an explanation of the format of .map.in
13 # files. See crypt-port.h for an explanation of how to use the macros
14 # generated by this program.
15 #
16 # Note: we currently don't support compatibility symbols that need
17 # a different definition from the default version.
18
19 use v5.14; # implicit use strict, use feature ':5.14'
20 use warnings FATAL => 'all';
21 use utf8;
22 use open qw(:std :utf8);
23 no if $] >= 5.022, warnings => 'experimental::re_strict';
24 use if $] >= 5.022, re => 'strict';
25
26 use FindBin ();
27 use lib $FindBin::Bin;
28 use BuildCommon qw(
29 parse_version_map_in
30 );
31
32 sub output {
33 my ($apply_symvers, $symvers) = @_;
34 my $basemap = $symvers->basemap;
35 print "/* Generated from $basemap by ${FindBin::Script}. "
36 . "DO NOT EDIT. */\n";
37
38 print <<'EOT';
39
40 #ifndef _CRYPT_SYMBOL_VERS_H
41 #define _CRYPT_SYMBOL_VERS_H 1
42
43 /* For each public symbol <sym>, INCLUDE_<sym> is true if it
44 has any versions above the backward compatibility minimum.
45 Compatibility-only symbols are not included in the static
46 library, or in the shared library when configured with
47 --disable-obsolete-api. */
48 #if defined PIC && ENABLE_OBSOLETE_API
49
50 EOT
51
52 for my $sym (@{$symvers->symbols}) {
53 printf "#define INCLUDE_%-*s %d\n",
54 $symvers->max_symlen, $sym->name, $sym->included;
55 }
56 print "\n#else\n\n";
57 for my $sym (@{$symvers->symbols}) {
58 printf "#define INCLUDE_%-*s %d\n",
59 $symvers->max_symlen, $sym->name,
60 $sym->included && !$sym->compat_only;
61 }
62
63 if ($apply_symvers =~ m/no/) {
64 print <<'EOT';
65
66 #endif
67
68 /* We are building this library with no symbol versioning
69 enabled, so let's define all macros for SYMVER_ to do
70 nothing. */
71 EOT
72 for my $sym (@{$symvers->symbols}) {
73 my $name = $sym->name;
74 print "#define SYMVER_$name symver_nop()\n";
75 }
76 print <<'EOT';
77 #endif
78 EOT
79 close STDOUT or die "write error: $!\n";
80 return;
81 }
82
83 print <<'EOT';
84
85 #endif
86
87 /* When the public symbols are being given versions, they must be
88 defined under a different, private name first. */
89 #ifdef PIC
90 EOT
91
92 for my $sym (@{$symvers->symbols}) {
93 if ($sym->included) {
94 printf "#define %-*s _crypt_%s\n",
95 $symvers->max_symlen, $sym->name, $sym->name;
96 }
97 }
98
99 print <<'EOT';
100 #endif
101
102 /* For each public symbol <sym> that is included, define its
103 highest version as the default, and aliases at each
104 compatibility version. */
105 EOT
106
107 for my $sym (@{$symvers->symbols}) {
108 my $name = $sym->name;
109 if (!$sym->included) {
110 print "#define SYMVER_$name symver_nop()\n";
111 next;
112 }
113
114 my $seq = 0;
115 for my $v (@{$sym->versions}) {
116 if ($seq == 0) {
117 print "#define SYMVER_$name \\\n";
118 if ($sym->compat_only) {
119 print " symver_compat0 (\"$name\", $name, $v)";
120 } else {
121 print " symver_default (\"$name\", $name, $v)";
122 }
123 } else {
124 print "; \\\n"
125 . " symver_compat ($seq, \"$name\", $name, $name, $v)";
126 }
127 $seq++;
128 }
129 print "\n";
130 }
131
132 print <<'EOT';
133
134 #endif /* crypt-symbol-vers.h */
135 EOT
136
137 close STDOUT or die "write error: $!\n";
138 return;
139 }
140
141 #
142 # Main
143 #
144 exit 0 if eval {
145 output($ARGV[0], parse_version_map_in(@ARGV[1 .. 4]));
146 1;
147 };
148
149 print {*STDERR} "${FindBin::Script}: $@";
150 exit 1;