1#! /usr/bin/env perl 2# Copyright 2006-2023 The OpenSSL Project Authors. All Rights Reserved. 3# 4# Licensed under the Apache License 2.0 (the "License"). You may not use 5# this file except in compliance with the License. You can obtain a copy 6# in the file LICENSE in the source distribution or at 7# https://www.openssl.org/source/license.html 8 9use warnings; 10use strict; 11use Config; 12 13my $expectedsyms=$ARGV[0]; 14 15shift(@ARGV); 16 17my $objlist; 18my $objfilelist = join(" ", @ARGV); 19my $expsyms; 20my $exps; 21my $OBJFH; 22my $cmd; 23 24if ($Config{osname} eq "MSWin32") { 25 my $currentdll = ""; 26 $cmd = "dumpbin /imports " . $objfilelist; 27 my @symlist; 28 open $expsyms, '<', $expectedsyms or die; 29 { 30 local $/; 31 $exps=<$expsyms>; 32 } 33 close($expsyms); 34 open($OBJFH, "$cmd|") or die "Cannot open process: $!"; 35 while (<$OBJFH>) 36 { 37 chomp; 38 my $dllfile = $_; 39 $dllfile =~ s/( +)(.*)(\.dll)(.*)/DLLFILE \2/; 40 if (index($dllfile, "DLLFILE") >= 0) { 41 $currentdll = substr($dllfile, 8); 42 $currentdll =~ s/^\s+|s+$//g; 43 } 44 # filter imports from our own library 45 if ("$currentdll" ne "libcrypto-3-x64") { 46 my $line = $_; 47 $line =~ s/ [0-9a-fA-F]{1,2} /SYMBOL /; 48 if (index($line, "SYMBOL") != -1) { 49 $line =~ s/.*SYMBOL //; 50 push(@symlist, $line); 51 } 52 } 53 } 54 foreach (@symlist) { 55 if (index($exps, $_) < 0) { 56 print "Symbol $_ not in the allowed platform symbols list\n"; 57 exit 1; 58 } 59 } 60 exit 0; 61 } 62else { 63 $cmd = "objdump -t " . $objfilelist . " | grep UND | grep -v \@OPENSSL"; 64 $cmd = $cmd . " | awk '{print \$NF}' |"; 65 $cmd = $cmd . " sed -e\"s/@.*\$//\" | sort | uniq"; 66 67 open $expsyms, '<', $expectedsyms or die; 68 { 69 local $/; 70 $exps=<$expsyms>; 71 } 72 close($expsyms); 73 74 open($OBJFH, "$cmd|") or die "Cannot open process: $!"; 75 while (<$OBJFH>) 76 { 77 if (index($exps, $_) < 0) { 78 print "Symbol $_ not in the allowed platform symbols list\n"; 79 exit 1; 80 } 81 } 82 close($OBJFH); 83 exit 0; 84 } 85