Debian Codegraph @

test/symbols-static.pl

raw
1 #! /usr/bin/perl
2 # Written by Zack Weinberg <zackw at panix.com> in 2017 and 2020.
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 # Test that all global symbols in the static version of the library
10 # (libcrypt.a) are either listed as global and supported for new code
11 # in libcrypt.map.in, or begin with a _crypt prefix. Also test that
12 # all of the global, supported for new code, symbols mentioned in
13 # libcrypt.map.in are in fact defined.
14 #
15 # Due to limitations in Automake, this program takes parameters from
16 # the environment:
17 # $lib_la - full pathname of libcrypt.la
18 # $lib_map - full pathname of libcrypt.map.in
19 # $SYMBOL_PREFIX - prefix, if any, added to global symbols defined from C
20 # $NM, $CPP, $CPPFLAGS - nm utility, C preprocessor, and parameters
21
22 use v5.14; # implicit use strict, use feature ':5.14'
23 use warnings FATAL => 'all';
24 use utf8;
25 use open qw(:std :utf8);
26 no if $] >= 5.022, warnings => 'experimental::re_strict';
27 use if $] >= 5.022, re => 'strict';
28
29 use FindBin ();
30 use lib $FindBin::Bin;
31 use TestCommon qw(
32 error
33 ensure_C_locale
34 find_real_library
35 get_symbols
36 compare_symbol_lists
37 );
38
39 my $symbol_prefix = $ENV{SYMBOL_PREFIX} || q{};
40
41 sub list_library_globals {
42 # Symbols that begin with _crypt_ are private to the library.
43 # Symbols that begin with _[_A-Y] are private to the C
44 # implementation. All other symbols (including any that begin
45 # with _Z, which are C++ mangled names) are part of the library's
46 # public interface.
47 return get_symbols(
48 find_real_library(shift, 'static'),
49 sub { $_[0] !~ /^_(?:[_A-Y]|crypt_)/ },
50 );
51 }
52
53 sub list_expected_globals {
54 my ($lib_map) = @_;
55 open my $fh, '<', $lib_map
56 or error("$lib_map: $!");
57
58 local $_;
59 my %symbols;
60 while (<$fh>) {
61 chomp;
62 s/\s+$//;
63 next if /^($|#|%chain\b)/;
64
65 my @fields = split;
66 $symbols{$fields[0]} = 1 if $fields[1] ne '-';
67 }
68 return \%symbols;
69 }
70
71 #
72 # Main
73 #
74 my $lib_la = $ENV{lib_la} || '/nonexistent';
75 my $lib_map = $ENV{lib_map} || '/nonexistent';
76 if (!-f $lib_la || !-f $lib_map) {
77 print {*STDERR} "usage: lib_la=/p/lib.la lib_map=/p/lib.map $0";
78 exit 1;
79 }
80
81 ensure_C_locale();
82 exit compare_symbol_lists(
83 list_library_globals($lib_la),
84 list_expected_globals($lib_map),
85 'globals',
86 0, # extra symbols not allowed
87 );