| 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 an ELF-style "symbol version script" from a .map.in file. |
| 10 |
# See libcrypt.map.in for an explanation of the format of .map.in |
| 11 |
# files. |
| 12 |
|
| 13 |
use v5.14; # implicit use strict, use feature ':5.14' |
| 14 |
use warnings FATAL => 'all'; |
| 15 |
use utf8; |
| 16 |
use open qw(:std :utf8); |
| 17 |
no if $] >= 5.022, warnings => 'experimental::re_strict'; |
| 18 |
use if $] >= 5.022, re => 'strict'; |
| 19 |
|
| 20 |
use FindBin (); |
| 21 |
use lib $FindBin::Bin; |
| 22 |
use BuildCommon qw( |
| 23 |
parse_version_map_in |
| 24 |
); |
| 25 |
|
| 26 |
sub output { |
| 27 |
my ($symvers) = @_; |
| 28 |
my $basemap = $symvers->basemap; |
| 29 |
print "/* Generated from $basemap by ${FindBin::Script}. " |
| 30 |
. "DO NOT EDIT. */\n"; |
| 31 |
|
| 32 |
my %symbols_for_ver; |
| 33 |
for my $sym (@{$symvers->symbols}) { |
| 34 |
next if !$sym->included; |
| 35 |
for my $v (@{$sym->versions}) { |
| 36 |
push @{$symbols_for_ver{$v}}, $sym->name; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
my $vp; |
| 41 |
for my $v (@{$symvers->versions}) { |
| 42 |
next unless exists $symbols_for_ver{$v}; |
| 43 |
print "$v {\n global:\n"; |
| 44 |
for my $s (sort @{$symbols_for_ver{$v}}) { |
| 45 |
print " $s;\n"; |
| 46 |
} |
| 47 |
if (defined $vp) { |
| 48 |
print "} $vp;\n"; |
| 49 |
} else { |
| 50 |
print " local:\n *;\n};\n"; |
| 51 |
} |
| 52 |
$vp = $v; |
| 53 |
} |
| 54 |
close STDOUT or die "write error: $!\n"; |
| 55 |
return; |
| 56 |
} |
| 57 |
|
| 58 |
# |
| 59 |
# Main |
| 60 |
# |
| 61 |
exit 0 if eval { |
| 62 |
output(parse_version_map_in(@ARGV)); |
| 63 |
1; |
| 64 |
}; |
| 65 |
|
| 66 |
print {*STDERR} "${FindBin::Script}: $@"; |
| 67 |
exit 1; |