xref: /minix3/crypto/external/bsd/heimdal/dist/cf/w32-list-externs-from-objs.pl (revision ebfedea0ce5bbe81e252ddf32d732e40fb633fae)
1*ebfedea0SLionel Sambuc########################################################################
2*ebfedea0SLionel Sambuc#
3*ebfedea0SLionel Sambuc# Copyright (c) 2010, Secure Endpoints Inc.
4*ebfedea0SLionel Sambuc# All rights reserved.
5*ebfedea0SLionel Sambuc#
6*ebfedea0SLionel Sambuc# Redistribution and use in source and binary forms, with or without
7*ebfedea0SLionel Sambuc# modification, are permitted provided that the following conditions
8*ebfedea0SLionel Sambuc# are met:
9*ebfedea0SLionel Sambuc#
10*ebfedea0SLionel Sambuc# - Redistributions of source code must retain the above copyright
11*ebfedea0SLionel Sambuc#   notice, this list of conditions and the following disclaimer.
12*ebfedea0SLionel Sambuc#
13*ebfedea0SLionel Sambuc# - Redistributions in binary form must reproduce the above copyright
14*ebfedea0SLionel Sambuc#   notice, this list of conditions and the following disclaimer in
15*ebfedea0SLionel Sambuc#   the documentation and/or other materials provided with the
16*ebfedea0SLionel Sambuc#   distribution.
17*ebfedea0SLionel Sambuc#
18*ebfedea0SLionel Sambuc# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19*ebfedea0SLionel Sambuc# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20*ebfedea0SLionel Sambuc# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21*ebfedea0SLionel Sambuc# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22*ebfedea0SLionel Sambuc# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23*ebfedea0SLionel Sambuc# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24*ebfedea0SLionel Sambuc# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25*ebfedea0SLionel Sambuc# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26*ebfedea0SLionel Sambuc# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*ebfedea0SLionel Sambuc# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28*ebfedea0SLionel Sambuc# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*ebfedea0SLionel Sambuc# POSSIBILITY OF SUCH DAMAGE.
30*ebfedea0SLionel Sambuc#
31*ebfedea0SLionel Sambuc
32*ebfedea0SLionel Sambucmy $show_module_name = 1;
33*ebfedea0SLionel Sambucmy $use_indent = 1;
34*ebfedea0SLionel Sambucmy $strip_leading_underscore = 0;
35*ebfedea0SLionel Sambuc
36*ebfedea0SLionel Sambuc# Dump all symbols for the given object file that are defined and have
37*ebfedea0SLionel Sambuc# external scope.
38*ebfedea0SLionel Sambuc
39*ebfedea0SLionel Sambucsub dump_symbols_for_file($)
40*ebfedea0SLionel Sambuc{
41*ebfedea0SLionel Sambuc    $fn = shift;
42*ebfedea0SLionel Sambuc
43*ebfedea0SLionel Sambuc    print STDERR "Opening dump of object [$fn]\n";
44*ebfedea0SLionel Sambuc
45*ebfedea0SLionel Sambuc    open(SP, '-|', "dumpbin /symbols \"".$fn."\"") or die "Can't open pipe for $fn";
46*ebfedea0SLionel Sambuc
47*ebfedea0SLionel Sambuc  LINE:
48*ebfedea0SLionel Sambuc    while (<SP>) {
49*ebfedea0SLionel Sambuc	# 008 00000000 SECT3  notype ()    External     | _encode_AccessDescription
50*ebfedea0SLionel Sambuc
51*ebfedea0SLionel Sambuc	/^[[:xdigit:]]{3,}\s[[:xdigit:]]{8,}\s(\w+)\s+\w*\s+(\(\)|  )\s+(\w+)\s+\|\s+([0-9a-zA-Z\@\_]+)$/ && do {
52*ebfedea0SLionel Sambuc	    my ($section, $type, $visibility, $symbol) = ($1, $2, $3, $4);
53*ebfedea0SLionel Sambuc
54*ebfedea0SLionel Sambuc	    if ($section ne "UNDEF" && $visibility eq "External") {
55*ebfedea0SLionel Sambuc		print $fn if $show_module_name;
56*ebfedea0SLionel Sambuc		print "\t" if $use_indent || $show_module_name;
57*ebfedea0SLionel Sambuc
58*ebfedea0SLionel Sambuc		if ($strip_leading_underscore && $symbol =~ /_(.*)/) {
59*ebfedea0SLionel Sambuc		    $symbol = $1;
60*ebfedea0SLionel Sambuc		}
61*ebfedea0SLionel Sambuc		if ($strip_leading_underscore && $symbol =~ /(.*)\@.*$/) {
62*ebfedea0SLionel Sambuc		    $symbol = $1;
63*ebfedea0SLionel Sambuc		}
64*ebfedea0SLionel Sambuc		print $symbol;
65*ebfedea0SLionel Sambuc                if ($type ne "()") {
66*ebfedea0SLionel Sambuc                    print "\tDATA";
67*ebfedea0SLionel Sambuc                }
68*ebfedea0SLionel Sambuc		print "\n";
69*ebfedea0SLionel Sambuc	    }
70*ebfedea0SLionel Sambuc	};
71*ebfedea0SLionel Sambuc    }
72*ebfedea0SLionel Sambuc
73*ebfedea0SLionel Sambuc    close SP;
74*ebfedea0SLionel Sambuc}
75*ebfedea0SLionel Sambuc
76*ebfedea0SLionel Sambucsub use_response_file($)
77*ebfedea0SLionel Sambuc{
78*ebfedea0SLionel Sambuc    $fn = shift;
79*ebfedea0SLionel Sambuc
80*ebfedea0SLionel Sambuc    open (RF, '<', $fn) or die "Can't open response file $fn";
81*ebfedea0SLionel Sambuc
82*ebfedea0SLionel Sambuc    while (<RF>) {
83*ebfedea0SLionel Sambuc	/(\S+)/ && do {
84*ebfedea0SLionel Sambuc	    dump_symbols_for_file($1);
85*ebfedea0SLionel Sambuc	}
86*ebfedea0SLionel Sambuc    }
87*ebfedea0SLionel Sambuc    close RF;
88*ebfedea0SLionel Sambuc}
89*ebfedea0SLionel Sambuc
90*ebfedea0SLionel Sambucfor (@ARGV) {
91*ebfedea0SLionel Sambuc    ARG: {
92*ebfedea0SLionel Sambuc	/^-q$/ && do {
93*ebfedea0SLionel Sambuc	    $show_module_name = 0;
94*ebfedea0SLionel Sambuc	    last ARG;
95*ebfedea0SLionel Sambuc	};
96*ebfedea0SLionel Sambuc
97*ebfedea0SLionel Sambuc	/^-1$/ && do {
98*ebfedea0SLionel Sambuc	    $use_indent = 0;
99*ebfedea0SLionel Sambuc	    last ARG;
100*ebfedea0SLionel Sambuc	};
101*ebfedea0SLionel Sambuc
102*ebfedea0SLionel Sambuc	/^-u$/ && do {
103*ebfedea0SLionel Sambuc	    $strip_leading_underscore = 1;
104*ebfedea0SLionel Sambuc	    last ARG;
105*ebfedea0SLionel Sambuc	};
106*ebfedea0SLionel Sambuc
107*ebfedea0SLionel Sambuc	/^@(.*)$/ && do {
108*ebfedea0SLionel Sambuc	    use_response_file($1);
109*ebfedea0SLionel Sambuc	    last ARG;
110*ebfedea0SLionel Sambuc	};
111*ebfedea0SLionel Sambuc
112*ebfedea0SLionel Sambuc	dump_symbols_for_file($_);
113*ebfedea0SLionel Sambuc    }
114*ebfedea0SLionel Sambuc}
115