Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Side by Side Diff: openssl/util/mkerr.pl

Issue 9254031: Upgrade chrome's OpenSSL to same version Android ships with. (Closed) Base URL: http://src.chromium.org/svn/trunk/deps/third_party/openssl/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « openssl/util/mkdef.pl ('k') | openssl/util/mkfiles.pl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/local/bin/perl -w 1 #!/usr/local/bin/perl -w
2 2
3 my $config = "crypto/err/openssl.ec"; 3 my $config = "crypto/err/openssl.ec";
4 my $hprefix = "openssl/";
4 my $debug = 0; 5 my $debug = 0;
5 my $rebuild = 0; 6 my $rebuild = 0;
6 my $static = 1; 7 my $static = 1;
7 my $recurse = 0; 8 my $recurse = 0;
8 my $reindex = 0; 9 my $reindex = 0;
9 my $dowrite = 0; 10 my $dowrite = 0;
10 my $staticloader = ""; 11 my $staticloader = "";
11 12
12 my $pack_errcode; 13 my $pack_errcode;
13 my $load_errcode; 14 my $load_errcode;
14 15
16 my $errcount;
17
15 while (@ARGV) { 18 while (@ARGV) {
16 my $arg = $ARGV[0]; 19 my $arg = $ARGV[0];
17 if($arg eq "-conf") { 20 if($arg eq "-conf") {
18 shift @ARGV; 21 shift @ARGV;
19 $config = shift @ARGV; 22 $config = shift @ARGV;
23 } elsif($arg eq "-hprefix") {
24 shift @ARGV;
25 $hprefix = shift @ARGV;
20 } elsif($arg eq "-debug") { 26 } elsif($arg eq "-debug") {
21 $debug = 1; 27 $debug = 1;
22 shift @ARGV; 28 shift @ARGV;
23 } elsif($arg eq "-rebuild") { 29 } elsif($arg eq "-rebuild") {
24 $rebuild = 1; 30 $rebuild = 1;
25 shift @ARGV; 31 shift @ARGV;
26 } elsif($arg eq "-recurse") { 32 } elsif($arg eq "-recurse") {
27 $recurse = 1; 33 $recurse = 1;
28 shift @ARGV; 34 shift @ARGV;
29 } elsif($arg eq "-reindex") { 35 } elsif($arg eq "-reindex") {
30 $reindex = 1; 36 $reindex = 1;
31 shift @ARGV; 37 shift @ARGV;
32 } elsif($arg eq "-nostatic") { 38 } elsif($arg eq "-nostatic") {
33 $static = 0; 39 $static = 0;
34 shift @ARGV; 40 shift @ARGV;
35 } elsif($arg eq "-staticloader") { 41 } elsif($arg eq "-staticloader") {
36 $staticloader = "static "; 42 $staticloader = "static ";
37 shift @ARGV; 43 shift @ARGV;
38 } elsif($arg eq "-write") { 44 } elsif($arg eq "-write") {
39 $dowrite = 1; 45 $dowrite = 1;
40 shift @ARGV; 46 shift @ARGV;
47 } elsif($arg eq "-help" || $arg eq "-h" || $arg eq "-?" || $arg eq "--he lp") {
48 print STDERR <<"EOF";
49 mkerr.pl [options] ...
50
51 Options:
52
53 -conf F Use the config file F instead of the default one:
54 crypto/err/openssl.ec
55
56 -hprefix P Prepend the filenames in generated #include <header>
57 statements with prefix P. Default: 'openssl/' (without
58 the quotes, naturally)
59
60 -debug Turn on debugging verbose output on stderr.
61
62 -rebuild Rebuild all header and C source files, irrespective of the
63 fact if any error or function codes have been added/removed.
64 Default: only update files for libraries which saw change
65 (of course, this requires '-write' as well, or no
66 files will be touched!)
67
68 -recurse scan a preconfigured set of directories / files for error and
69 function codes:
70 (<crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>, <apps/*.c>)
71 When this option is NOT specified, the filelist is taken from
72 the commandline instead. Here, wildcards may be embedded. (Be
73 sure to escape those to prevent the shell from expanding them
74 for you when you wish mkerr.pl to do so instead.)
75 Default: take file list to scan from the command line.
76
77 -reindex Discard the numeric values previously assigned to the error
78 and function codes as extracted from the scanned header files;
79 instead renumber all of them starting from 100. (Note that
80 the numbers assigned through 'R' records in the config file
81 remain intact.)
82 Default: keep previously assigned numbers. (You are warned
83 when collisions are detected.)
84
85 -nostatic Generates a different source code, where these additional
86 functions are generated for each library specified in the
87 config file:
88 void ERR_load_<LIB>_strings(void);
89 void ERR_unload_<LIB>_strings(void);
90 void ERR_<LIB>_error(int f, int r, char *fn, int ln);
91 #define <LIB>err(f,r) ERR_<LIB>_error(f,r,__FILE__,__LINE__)
92 while the code facilitates the use of these in an environment
93 where the error support routines are dynamically loaded at
94 runtime.
95 Default: 'static' code generation.
96
97 -staticloader Prefix generated functions with the 'static' scope modifier.
98 Default: don't write any scope modifier prefix.
99
100 -write Actually (over)write the generated code to the header and C
101 source files as assigned to each library through the config
102 file.
103 Default: don't write.
104
105 -help / -h / -? / --help Show this help text.
106
107 ... Additional arguments are added to the file list to scan,
108 assuming '-recurse' was NOT specified on the command line.
109
110 EOF
111 exit 1;
41 } else { 112 } else {
42 last; 113 last;
43 } 114 }
44 } 115 }
45 116
46 if($recurse) { 117 if($recurse) {
47 » @source = ( <crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>, 118 » @source = (<crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>);
48 » » » <fips/*.c>, <fips/*/*.c>);
49 } else { 119 } else {
50 @source = @ARGV; 120 @source = @ARGV;
51 } 121 }
52 122
53 # Read in the config file 123 # Read in the config file
54 124
55 open(IN, "<$config") || die "Can't open config file $config"; 125 open(IN, "<$config") || die "Can't open config file $config";
56 126
57 # Parse config file 127 # Parse config file
58 128
59 while(<IN>) 129 while(<IN>)
60 { 130 {
61 if(/^L\s+(\S+)\s+(\S+)\s+(\S+)/) { 131 if(/^L\s+(\S+)\s+(\S+)\s+(\S+)/) {
62 $hinc{$1} = $2; 132 $hinc{$1} = $2;
63 $libinc{$2} = $1; 133 $libinc{$2} = $1;
64 $cskip{$3} = $1; 134 $cskip{$3} = $1;
65 if($3 ne "NONE") { 135 if($3 ne "NONE") {
66 $csrc{$1} = $3; 136 $csrc{$1} = $3;
67 » » » $fmax{$1} = 99; 137 » » » $fmax{$1} = 100;
68 » » » $rmax{$1} = 99; 138 » » » $rmax{$1} = 100;
69 $fassigned{$1} = ":"; 139 $fassigned{$1} = ":";
70 $rassigned{$1} = ":"; 140 $rassigned{$1} = ":";
71 $fnew{$1} = 0; 141 $fnew{$1} = 0;
72 $rnew{$1} = 0; 142 $rnew{$1} = 0;
73 } 143 }
74 } elsif (/^F\s+(\S+)/) { 144 } elsif (/^F\s+(\S+)/) {
75 # Add extra function with $1 145 # Add extra function with $1
76 } elsif (/^R\s+(\S+)\s+(\S+)/) { 146 } elsif (/^R\s+(\S+)\s+(\S+)/) {
77 $rextra{$1} = $2; 147 $rextra{$1} = $2;
78 $rcodes{$1} = $2; 148 $rcodes{$1} = $2;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 $name = $1; 254 $name = $1;
185 $code = $2; 255 $code = $2;
186 next if $name =~ /^${lib}err/; 256 next if $name =~ /^${lib}err/;
187 unless($name =~ /^${lib}_([RF])_(\w+)$/) { 257 unless($name =~ /^${lib}_([RF])_(\w+)$/) {
188 print STDERR "Invalid error code $name\n"; 258 print STDERR "Invalid error code $name\n";
189 next; 259 next;
190 } 260 }
191 if($1 eq "R") { 261 if($1 eq "R") {
192 $rcodes{$name} = $code; 262 $rcodes{$name} = $code;
193 if ($rassigned{$lib} =~ /:$code:/) { 263 if ($rassigned{$lib} =~ /:$code:/) {
194 » » » » » print STDERR "!! ERROR: $lib reason code $code assigned twice\n"; 264 » » » » » print STDERR "!! ERROR: $lib reason code $code assigned twice (collision at $name)\n";
265 » » » » » ++$errcount;
195 } 266 }
196 $rassigned{$lib} .= "$code:"; 267 $rassigned{$lib} .= "$code:";
197 if(!(exists $rextra{$name}) && 268 if(!(exists $rextra{$name}) &&
198 ($code > $rmax{$lib}) ) { 269 ($code > $rmax{$lib}) ) {
199 $rmax{$lib} = $code; 270 $rmax{$lib} = $code;
200 } 271 }
201 } else { 272 } else {
202 if ($fassigned{$lib} =~ /:$code:/) { 273 if ($fassigned{$lib} =~ /:$code:/) {
203 » » » » » print STDERR "!! ERROR: $lib function co de $code assigned twice\n"; 274 » » » » » print STDERR "!! ERROR: $lib function co de $code assigned twice (collision at $name)\n";
275 » » » » » ++$errcount;
204 } 276 }
205 $fassigned{$lib} .= "$code:"; 277 $fassigned{$lib} .= "$code:";
206 if($code > $fmax{$lib}) { 278 if($code > $fmax{$lib}) {
207 $fmax{$lib} = $code; 279 $fmax{$lib} = $code;
208 } 280 }
209 $fcodes{$name} = $code; 281 $fcodes{$name} = $code;
210 } 282 }
211 } 283 }
212 } 284 }
213 } 285 }
(...skipping 10 matching lines...) Expand all
224 $rassigned{$lib} =~ m/^:(.*):$/; 296 $rassigned{$lib} =~ m/^:(.*):$/;
225 @rassigned = sort {$a <=> $b} split(":", $1); 297 @rassigned = sort {$a <=> $b} split(":", $1);
226 print STDERR " @rassigned\n"; 298 print STDERR " @rassigned\n";
227 } 299 }
228 } 300 }
229 301
230 if ($lib eq "SSL") { 302 if ($lib eq "SSL") {
231 if ($rmax{$lib} >= 1000) { 303 if ($rmax{$lib} >= 1000) {
232 print STDERR "!! ERROR: SSL error codes 1000+ are reserv ed for alerts.\n"; 304 print STDERR "!! ERROR: SSL error codes 1000+ are reserv ed for alerts.\n";
233 print STDERR "!! Any new alerts must be added to $config.\n"; 305 print STDERR "!! Any new alerts must be added to $config.\n";
306 ++$errcount;
234 print STDERR "\n"; 307 print STDERR "\n";
235 } 308 }
236 } 309 }
237 close IN; 310 close IN;
238 } 311 }
239 312
240 # Scan each C source file and look for function and reason codes 313 # Scan each C source file and look for function and reason codes
241 # This is done by looking for strings that "look like" function or 314 # This is done by looking for strings that "look like" function or
242 # reason codes: basically anything consisting of all upper case and 315 # reason codes: basically anything consisting of all upper case and
243 # numerics which has _F_ or _R_ in it and which has the name of an 316 # numerics which has _F_ or _R_ in it and which has the name of an
244 # error library at the start. This seems to work fine except for the 317 # error library at the start. This seems to work fine except for the
245 # oddly named structure BIO_F_CTX which needs to be ignored. 318 # oddly named structure BIO_F_CTX which needs to be ignored.
246 # If a code doesn't exist in list compiled from headers then mark it 319 # If a code doesn't exist in list compiled from headers then mark it
247 # with the value "X" as a place holder to give it a value later. 320 # with the value "X" as a place holder to give it a value later.
248 # Store all function and reason codes found in %ufcodes and %urcodes 321 # Store all function and reason codes found in %ufcodes and %urcodes
249 # so all those unreferenced can be printed out. 322 # so all those unreferenced can be printed out.
250 323
251 324
252 foreach $file (@source) { 325 foreach $file (@source) {
253 # Don't parse the error source file. 326 # Don't parse the error source file.
254 next if exists $cskip{$file}; 327 next if exists $cskip{$file};
255 print STDERR "File loaded: ".$file."\r" if $debug; 328 print STDERR "File loaded: ".$file."\r" if $debug;
256 open(IN, "<$file") || die "Can't open source file $file\n"; 329 open(IN, "<$file") || die "Can't open source file $file\n";
257 while(<IN>) { 330 while(<IN>) {
331 # skip obsoleted source files entirely!
332 last if(/^#error\s+obsolete/);
333
258 if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) { 334 if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
259 next unless exists $csrc{$2}; 335 next unless exists $csrc{$2};
260 next if($1 eq "BIO_F_BUFFER_CTX"); 336 next if($1 eq "BIO_F_BUFFER_CTX");
261 $ufcodes{$1} = 1; 337 $ufcodes{$1} = 1;
262 if(!exists $fcodes{$1}) { 338 if(!exists $fcodes{$1}) {
263 $fcodes{$1} = "X"; 339 $fcodes{$1} = "X";
264 $fnew{$2}++; 340 $fnew{$2}++;
265 } 341 }
266 $notrans{$1} = 1 unless exists $ftrans{$3}; 342 $notrans{$1} = 1 unless exists $ftrans{$3};
343 print STDERR "Function: $1\t= $fcodes{$1} (lib: $2, name : $3)\n" if $debug;
267 } 344 }
268 if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) { 345 if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) {
269 next unless exists $csrc{$2}; 346 next unless exists $csrc{$2};
270 $urcodes{$1} = 1; 347 $urcodes{$1} = 1;
271 if(!exists $rcodes{$1}) { 348 if(!exists $rcodes{$1}) {
272 $rcodes{$1} = "X"; 349 $rcodes{$1} = "X";
273 $rnew{$2}++; 350 $rnew{$2}++;
274 } 351 }
352 print STDERR "Reason: $1\t= $rcodes{$1} (lib: $2)\n" if $debug;
275 } 353 }
276 } 354 }
277 close IN; 355 close IN;
278 } 356 }
279 print STDERR " \n" if $debug; 357 print STDERR " \n" if $debug;
280 358
281 # Now process each library in turn. 359 # Now process each library in turn.
282 360
283 foreach $lib (keys %csrc) 361 foreach $lib (keys %csrc)
284 { 362 {
(...skipping 21 matching lines...) Expand all
306 if (open(IN, "<$hfile")) { 384 if (open(IN, "<$hfile")) {
307 # Copy across the old file 385 # Copy across the old file
308 while(<IN>) { 386 while(<IN>) {
309 push @out, $_; 387 push @out, $_;
310 last if (/BEGIN ERROR CODES/); 388 last if (/BEGIN ERROR CODES/);
311 } 389 }
312 close IN; 390 close IN;
313 } else { 391 } else {
314 push @out, 392 push @out,
315 "/* ====================================================================\n", 393 "/* ====================================================================\n",
316 " * Copyright (c) 2001-2010 The OpenSSL Project. All rights reserved.\n", 394 " * Copyright (c) 2001-2011 The OpenSSL Project. All rights reserved.\n",
317 " *\n", 395 " *\n",
318 " * Redistribution and use in source and binary forms, with or without\n", 396 " * Redistribution and use in source and binary forms, with or without\n",
319 " * modification, are permitted provided that the following conditions\n", 397 " * modification, are permitted provided that the following conditions\n",
320 " * are met:\n", 398 " * are met:\n",
321 " *\n", 399 " *\n",
322 " * 1. Redistributions of source code must retain the above copyright\n", 400 " * 1. Redistributions of source code must retain the above copyright\n",
323 " * notice, this list of conditions and the following disclaimer. \n", 401 " * notice, this list of conditions and the following disclaimer. \n",
324 " *\n", 402 " *\n",
325 " * 2. Redistributions in binary form must reproduce the above copyright\n", 403 " * 2. Redistributions in binary form must reproduce the above copyright\n",
326 " * notice, this list of conditions and the following disclaimer in\n", 404 " * notice, this list of conditions and the following disclaimer in\n",
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 " *\n", 440 " *\n",
363 " * This product includes cryptographic software written by Eric Young\n", 441 " * This product includes cryptographic software written by Eric Young\n",
364 " * (eay\@cryptsoft.com). This product includes software written by Tim\n", 442 " * (eay\@cryptsoft.com). This product includes software written by Tim\n",
365 " * Hudson (tjh\@cryptsoft.com).\n", 443 " * Hudson (tjh\@cryptsoft.com).\n",
366 " *\n", 444 " *\n",
367 " */\n", 445 " */\n",
368 "\n", 446 "\n",
369 "#ifndef HEADER_${lib}_ERR_H\n", 447 "#ifndef HEADER_${lib}_ERR_H\n",
370 "#define HEADER_${lib}_ERR_H\n", 448 "#define HEADER_${lib}_ERR_H\n",
371 "\n", 449 "\n",
450 "#ifdef __cplusplus\n",
451 "extern \"C\" {\n",
452 "#endif\n",
453 "\n",
372 "/* BEGIN ERROR CODES */\n"; 454 "/* BEGIN ERROR CODES */\n";
373 } 455 }
374 open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n"; 456 open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n";
375 457
376 print OUT @out; 458 print OUT @out;
377 undef @out; 459 undef @out;
378 print OUT <<"EOF"; 460 print OUT <<"EOF";
379 /* The following lines are auto generated by the script mkerr.pl. Any changes 461 /* The following lines are auto generated by the script mkerr.pl. Any changes
380 * made after this point may be overwritten when the script is next run. 462 * made after this point may be overwritten when the script is next run.
381 */ 463 */
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 530
449 # Rewrite the C source file containing the error details. 531 # Rewrite the C source file containing the error details.
450 532
451 # First, read any existing reason string definitions: 533 # First, read any existing reason string definitions:
452 my %err_reason_strings; 534 my %err_reason_strings;
453 if (open(IN,"<$cfile")) { 535 if (open(IN,"<$cfile")) {
454 while (<IN>) { 536 while (<IN>) {
455 if (/\b(${lib}_R_\w*)\b.*\"(.*)\"/) { 537 if (/\b(${lib}_R_\w*)\b.*\"(.*)\"/) {
456 $err_reason_strings{$1} = $2; 538 $err_reason_strings{$1} = $2;
457 } 539 }
540 if (/\b${lib}_F_(\w*)\b.*\"(.*)\"/) {
541 if (!exists $ftrans{$1} && ($1 ne $2)) {
542 print STDERR "WARNING: Mismatched functi on string $2\n";
543 $ftrans{$1} = $2;
544 }
545 }
458 } 546 }
459 close(IN); 547 close(IN);
460 } 548 }
461 549
550
462 my $hincf; 551 my $hincf;
463 if($static) { 552 if($static) {
464 $hfile =~ /([^\/]+)$/; 553 $hfile =~ /([^\/]+)$/;
465 » » $hincf = "<openssl/$1>"; 554 » » $hincf = "<${hprefix}$1>";
466 } else { 555 } else {
467 $hincf = "\"$hfile\""; 556 $hincf = "\"$hfile\"";
468 } 557 }
469 558
470 # If static we know the error code at compile time so use it 559 # If static we know the error code at compile time so use it
471 # in error definitions. 560 # in error definitions.
472 561
473 if ($static) 562 if ($static)
474 { 563 {
475 $pack_errcode = "ERR_LIB_${lib}"; 564 $pack_errcode = "ERR_LIB_${lib}";
476 $load_errcode = "0"; 565 $load_errcode = "0";
477 } 566 }
478 else 567 else
479 { 568 {
480 $pack_errcode = "0"; 569 $pack_errcode = "0";
481 $load_errcode = "ERR_LIB_${lib}"; 570 $load_errcode = "ERR_LIB_${lib}";
482 } 571 }
483 572
484 573
485 open (OUT,">$cfile") || die "Can't open $cfile for writing"; 574 open (OUT,">$cfile") || die "Can't open $cfile for writing";
486 575
487 print OUT <<"EOF"; 576 print OUT <<"EOF";
488 /* $cfile */ 577 /* $cfile */
489 /* ==================================================================== 578 /* ====================================================================
490 * Copyright (c) 1999-2010 The OpenSSL Project. All rights reserved. 579 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved.
491 * 580 *
492 * Redistribution and use in source and binary forms, with or without 581 * Redistribution and use in source and binary forms, with or without
493 * modification, are permitted provided that the following conditions 582 * modification, are permitted provided that the following conditions
494 * are met: 583 * are met:
495 * 584 *
496 * 1. Redistributions of source code must retain the above copyright 585 * 1. Redistributions of source code must retain the above copyright
497 * notice, this list of conditions and the following disclaimer. 586 * notice, this list of conditions and the following disclaimer.
498 * 587 *
499 * 2. Redistributions in binary form must reproduce the above copyright 588 * 2. Redistributions in binary form must reproduce the above copyright
500 * notice, this list of conditions and the following disclaimer in 589 * notice, this list of conditions and the following disclaimer in
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 ERR_PUT_error(${lib}_lib_error_code,function,reason,file,line); 762 ERR_PUT_error(${lib}_lib_error_code,function,reason,file,line);
674 } 763 }
675 EOF 764 EOF
676 765
677 } 766 }
678 767
679 close OUT; 768 close OUT;
680 undef %err_reason_strings; 769 undef %err_reason_strings;
681 } 770 }
682 771
683 if($debug && defined(%notrans)) { 772 if($debug && %notrans) {
684 print STDERR "The following function codes were not translated:\n"; 773 print STDERR "The following function codes were not translated:\n";
685 foreach(sort keys %notrans) 774 foreach(sort keys %notrans)
686 { 775 {
687 print STDERR "$_\n"; 776 print STDERR "$_\n";
688 } 777 }
689 } 778 }
690 779
691 # Make a list of unreferenced function and reason codes 780 # Make a list of unreferenced function and reason codes
692 781
693 foreach (keys %fcodes) { 782 foreach (keys %fcodes) {
(...skipping 12 matching lines...) Expand all
706 } 795 }
707 } 796 }
708 797
709 if($debug && defined(@runref) ) { 798 if($debug && defined(@runref) ) {
710 print STDERR "The following reason codes were not referenced:\n"; 799 print STDERR "The following reason codes were not referenced:\n";
711 foreach(sort @runref) 800 foreach(sort @runref)
712 { 801 {
713 print STDERR "$_\n"; 802 print STDERR "$_\n";
714 } 803 }
715 } 804 }
805
806 if($errcount) {
807 print STDERR "There were errors, failing...\n\n";
808 exit $errcount;
809 }
810
OLDNEW
« no previous file with comments | « openssl/util/mkdef.pl ('k') | openssl/util/mkfiles.pl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698