checkplatformsyms.pl 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. use warnings;
  9. use strict;
  10. use Config;
  11. my $expectedsyms=$ARGV[0];
  12. shift(@ARGV);
  13. my $objlist;
  14. my $objfilelist = join(" ", @ARGV);
  15. my $expsyms;
  16. my $exps;
  17. my $OBJFH;
  18. my $cmd;
  19. if ($Config{osname} eq "MSWin32") {
  20. my $currentdll = "";
  21. $cmd = "dumpbin /imports " . $objfilelist;
  22. my @symlist;
  23. open $expsyms, '<', $expectedsyms or die;
  24. {
  25. local $/;
  26. $exps=<$expsyms>;
  27. }
  28. close($expsyms);
  29. open($OBJFH, "$cmd|") or die "Cannot open process: $!";
  30. while (<$OBJFH>)
  31. {
  32. chomp;
  33. my $dllfile = $_;
  34. $dllfile =~ s/( +)(.*)(\.dll)(.*)/DLLFILE \2/;
  35. if (index($dllfile, "DLLFILE") >= 0) {
  36. $currentdll = substr($dllfile, 8);
  37. $currentdll =~ s/^\s+|s+$//g;
  38. }
  39. # filter imports from our own library
  40. if ("$currentdll" ne "libcrypto-3-x64") {
  41. my $line = $_;
  42. $line =~ s/ [0-9a-fA-F]{1,2} /SYMBOL /;
  43. if (index($line, "SYMBOL") != -1) {
  44. $line =~ s/.*SYMBOL //;
  45. push(@symlist, $line);
  46. }
  47. }
  48. }
  49. foreach (@symlist) {
  50. if (index($exps, $_) < 0) {
  51. print "Symbol $_ not in the allowed platform symbols list\n";
  52. exit 1;
  53. }
  54. }
  55. exit 0;
  56. }
  57. else {
  58. $cmd = "objdump -t " . $objfilelist . " | grep UND | grep -v \@OPENSSL";
  59. $cmd = $cmd . " | awk '{print \$NF}' |";
  60. $cmd = $cmd . " sed -e\"s/@.*\$//\" | sort | uniq";
  61. open $expsyms, '<', $expectedsyms or die;
  62. {
  63. local $/;
  64. $exps=<$expsyms>;
  65. }
  66. close($expsyms);
  67. open($OBJFH, "$cmd|") or die "Cannot open process: $!";
  68. while (<$OBJFH>)
  69. {
  70. if (index($exps, $_) < 0) {
  71. print "Symbol $_ not in the allowed platform symbols list\n";
  72. exit 1;
  73. }
  74. }
  75. close($OBJFH);
  76. exit 0;
  77. }