3 # Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
5 # Licensed under the OpenSSL license (the "License"). You may not use
6 # this file except in compliance with the License. You can obtain a copy
7 # in the file LICENSE in the source distribution or at
8 # https://www.openssl.org/source/license.html
11 use File::Spec::Functions qw(devnull);
12 use OpenSSL::Test qw(:DEFAULT srctop_file bldtop_dir bldtop_file);
13 use OpenSSL::Test::Utils;
15 setup("test_symbol_presence");
17 plan skip_all => "Only useful when building shared libraries"
18 if disabled("shared");
20 my @libnames = ("crypto", "ssl");
21 my $testcount = scalar @libnames;
23 plan tests => $testcount * 2;
26 "NOTE: developer test! It's possible that it won't run on your\n",
27 "platform, and that's perfectly fine. This is mainly for developers\n",
28 "on Unix to check that our shared libraries are consistent with the\n",
29 "ordinals (util/*.num in the source tree), something that should be\n",
30 "good enough a check for the other platforms as well.\n";
32 foreach my $libname (@libnames) {
35 my $shlibpath = bldtop_file("lib" . $libname . ".so");
38 open STDERR, ">", devnull();
39 open STDOUT, ">", devnull();
40 my @nm_lines = map { s|\R$||; $_ } `nm -Pg $shlibpath 2> /dev/null`;
45 skip "Can't run 'nm -Pg $shlibpath' => $?... ignoring", 2
48 my $bldtop = bldtop_dir();
50 indir $bldtop => sub {
51 my $mkdefpath = srctop_file("util", "mkdef.pl");
52 @def_lines = map { s|\R$||; $_ } `$^X $mkdefpath $libname linux 2> /dev/null`;
53 ok($? == 0, "running 'cd $bldtop; $^X $mkdefpath $libname linux' => $?");
54 }, create => 0, cleanup => 0;
56 note "Number of lines in \@nm_lines before massaging: ", scalar @nm_lines;
57 note "Number of lines in \@def_lines before massaging: ", scalar @def_lines;
59 # Massage the nm output to only contain defined symbols
60 @nm_lines = sort map { s| .*||; $_ } grep(m|.* [BCDST] .*|, @nm_lines);
62 # Massage the mkdef.pl output to only contain global symbols
63 # The output we got is in Unix .map format, which has a global
64 # and a local section. We're only interested in the global
69 map { s|;||; s|\s+||g; $_ }
70 grep { $in_global = 1 if m|global:|;
71 $in_global = 0 if m|local:|;
72 $in_global && m|;|; } @def_lines;
74 note "Number of lines in \@nm_lines after massaging: ", scalar @nm_lines;
75 note "Number of lines in \@def_lines after massaging: ", scalar @def_lines;
77 # Maintain lists of symbols that are missing in the shared library,
82 while (scalar @nm_lines || scalar @def_lines) {
83 my $nm_first = $nm_lines[0];
84 my $def_first = $def_lines[0];
86 if (!defined($nm_first)) {
87 push @missing, shift @def_lines;
88 } elsif (!defined($def_first)) {
89 push @extra, shift @nm_lines;
90 } elsif ($nm_first gt $def_first) {
91 push @missing, shift @def_lines;
92 } elsif ($nm_first lt $def_first) {
93 push @extra, shift @nm_lines;
100 if (scalar @missing) {
101 note "The following symbols are missing in lib$libname.so:";
107 note "The following symbols are extra in lib$libname.so:";
112 ok(scalar @missing == 0,
113 "check that there are no missing symbols in lib$libname.so");