2016-04-22 16:20:59 +08:00
|
|
|
#! /usr/bin/env perl
|
|
|
|
# -*- mode: Perl -*-
|
2021-06-17 20:24:59 +08:00
|
|
|
# Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
|
2016-04-22 16:20:59 +08:00
|
|
|
#
|
2018-12-06 20:05:25 +08:00
|
|
|
# Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-04-22 16:20:59 +08:00
|
|
|
# this file except in compliance with the License. You can obtain a copy
|
|
|
|
# in the file LICENSE in the source distribution or at
|
|
|
|
# https://www.openssl.org/source/license.html
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use File::Spec::Functions qw(devnull);
|
2021-06-15 23:43:02 +08:00
|
|
|
use OpenSSL::Test qw(:DEFAULT srctop_file srctop_dir bldtop_dir bldtop_file);
|
2016-04-22 16:20:59 +08:00
|
|
|
use OpenSSL::Test::Utils;
|
|
|
|
|
2021-06-15 23:43:02 +08:00
|
|
|
BEGIN {
|
|
|
|
setup("test_symbol_presence");
|
|
|
|
}
|
|
|
|
|
|
|
|
use lib srctop_dir('Configurations');
|
|
|
|
use lib bldtop_dir('.');
|
|
|
|
use platform;
|
2016-04-22 16:20:59 +08:00
|
|
|
|
2020-09-30 04:21:38 +08:00
|
|
|
plan skip_all => "Test is disabled on NonStop" if config('target') =~ m|^nonstop|;
|
2021-06-16 00:50:55 +08:00
|
|
|
# MacOS arranges symbol names differently
|
|
|
|
plan skip_all => "Test is disabled on MacOS" if config('target') =~ m|^darwin|;
|
2021-11-23 23:22:27 +08:00
|
|
|
plan skip_all => "This is unsupported on MSYS, MinGW or MSWin32"
|
|
|
|
if $^O eq 'msys' or $^O eq 'MSWin32' or config('target') =~ m|^mingw|;
|
2016-04-22 16:20:59 +08:00
|
|
|
plan skip_all => "Only useful when building shared libraries"
|
|
|
|
if disabled("shared");
|
|
|
|
|
|
|
|
my @libnames = ("crypto", "ssl");
|
|
|
|
my $testcount = scalar @libnames;
|
|
|
|
|
|
|
|
plan tests => $testcount * 2;
|
|
|
|
|
|
|
|
note
|
2016-08-06 01:56:58 +08:00
|
|
|
"NOTE: developer test! It's possible that it won't run on your\n",
|
2016-04-22 16:20:59 +08:00
|
|
|
"platform, and that's perfectly fine. This is mainly for developers\n",
|
|
|
|
"on Unix to check that our shared libraries are consistent with the\n",
|
|
|
|
"ordinals (util/*.num in the source tree), something that should be\n",
|
|
|
|
"good enough a check for the other platforms as well.\n";
|
|
|
|
|
|
|
|
foreach my $libname (@libnames) {
|
|
|
|
SKIP:
|
|
|
|
{
|
2021-06-16 00:15:52 +08:00
|
|
|
my $shlibname = platform->sharedlib("lib$libname");
|
|
|
|
my $shlibpath = bldtop_file($shlibname);
|
2016-04-22 16:20:59 +08:00
|
|
|
*OSTDERR = *STDERR;
|
|
|
|
*OSTDOUT = *STDOUT;
|
|
|
|
open STDERR, ">", devnull();
|
|
|
|
open STDOUT, ">", devnull();
|
2021-10-13 15:09:05 +08:00
|
|
|
my @nm_lines = map { s|\R$||; $_ } `nm -DPg $shlibpath 2> /dev/null`;
|
2016-04-22 16:20:59 +08:00
|
|
|
close STDERR;
|
|
|
|
close STDOUT;
|
|
|
|
*STDERR = *OSTDERR;
|
|
|
|
*STDOUT = *OSTDOUT;
|
2021-10-13 15:09:05 +08:00
|
|
|
skip "Can't run 'nm -DPg $shlibpath' => $?... ignoring", 2
|
2016-04-22 16:20:59 +08:00
|
|
|
unless $? == 0;
|
|
|
|
|
|
|
|
my $bldtop = bldtop_dir();
|
|
|
|
my @def_lines;
|
|
|
|
indir $bldtop => sub {
|
|
|
|
my $mkdefpath = srctop_file("util", "mkdef.pl");
|
2018-09-14 20:59:40 +08:00
|
|
|
my $libnumpath = srctop_file("util", "lib$libname.num");
|
|
|
|
@def_lines = map { s|\R$||; $_ } `$^X $mkdefpath --ordinals $libnumpath --name $libname --OS linux 2> /dev/null`;
|
|
|
|
ok($? == 0, "running 'cd $bldtop; $^X $mkdefpath --ordinals $libnumpath --name $libname --OS linux' => $?");
|
2016-04-22 16:20:59 +08:00
|
|
|
}, create => 0, cleanup => 0;
|
|
|
|
|
|
|
|
note "Number of lines in \@nm_lines before massaging: ", scalar @nm_lines;
|
|
|
|
note "Number of lines in \@def_lines before massaging: ", scalar @def_lines;
|
|
|
|
|
|
|
|
# Massage the nm output to only contain defined symbols
|
2021-10-15 00:49:11 +08:00
|
|
|
@nm_lines =
|
|
|
|
sort
|
|
|
|
map {
|
|
|
|
# Drop the first space and everything following it
|
|
|
|
s| .*||;
|
|
|
|
# Drop OpenSSL dynamic version information if there is any
|
2021-12-29 22:44:00 +08:00
|
|
|
s|\@\@.+$||;
|
2021-10-15 00:49:11 +08:00
|
|
|
# Return the result
|
|
|
|
$_
|
|
|
|
}
|
|
|
|
grep(m|.* [BCDST] .*|, @nm_lines);
|
2016-04-22 16:20:59 +08:00
|
|
|
|
|
|
|
# Massage the mkdef.pl output to only contain global symbols
|
|
|
|
# The output we got is in Unix .map format, which has a global
|
|
|
|
# and a local section. We're only interested in the global
|
|
|
|
# section.
|
|
|
|
my $in_global = 0;
|
|
|
|
@def_lines =
|
|
|
|
sort
|
|
|
|
map { s|;||; s|\s+||g; $_ }
|
|
|
|
grep { $in_global = 1 if m|global:|;
|
|
|
|
$in_global = 0 if m|local:|;
|
2016-09-06 06:48:13 +08:00
|
|
|
$in_global = 0 if m|\}|;
|
2016-04-22 16:20:59 +08:00
|
|
|
$in_global && m|;|; } @def_lines;
|
|
|
|
|
|
|
|
note "Number of lines in \@nm_lines after massaging: ", scalar @nm_lines;
|
|
|
|
note "Number of lines in \@def_lines after massaging: ", scalar @def_lines;
|
|
|
|
|
|
|
|
# Maintain lists of symbols that are missing in the shared library,
|
|
|
|
# or that are extra.
|
|
|
|
my @missing = ();
|
|
|
|
my @extra = ();
|
|
|
|
|
|
|
|
while (scalar @nm_lines || scalar @def_lines) {
|
|
|
|
my $nm_first = $nm_lines[0];
|
|
|
|
my $def_first = $def_lines[0];
|
|
|
|
|
|
|
|
if (!defined($nm_first)) {
|
|
|
|
push @missing, shift @def_lines;
|
|
|
|
} elsif (!defined($def_first)) {
|
|
|
|
push @extra, shift @nm_lines;
|
|
|
|
} elsif ($nm_first gt $def_first) {
|
|
|
|
push @missing, shift @def_lines;
|
|
|
|
} elsif ($nm_first lt $def_first) {
|
|
|
|
push @extra, shift @nm_lines;
|
|
|
|
} else {
|
|
|
|
shift @def_lines;
|
|
|
|
shift @nm_lines;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scalar @missing) {
|
2021-06-16 00:15:52 +08:00
|
|
|
note "The following symbols are missing in ${shlibname}:";
|
2016-04-22 16:20:59 +08:00
|
|
|
foreach (@missing) {
|
|
|
|
note " $_";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (scalar @extra) {
|
2021-06-16 00:15:52 +08:00
|
|
|
note "The following symbols are extra in ${shlibname}:";
|
2016-04-22 16:20:59 +08:00
|
|
|
foreach (@extra) {
|
|
|
|
note " $_";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ok(scalar @missing == 0,
|
2021-06-16 00:15:52 +08:00
|
|
|
"check that there are no missing symbols in ${shlibname}");
|
2016-04-22 16:20:59 +08:00
|
|
|
}
|
|
|
|
}
|