|
1 # Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 # All rights reserved. |
|
3 # This component and the accompanying materials are made available |
|
4 # under the terms of "Eclipse Public License v1.0" |
|
5 # which accompanies this distribution, and is available |
|
6 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 # |
|
8 # Initial Contributors: |
|
9 # Nokia Corporation - initial contribution. |
|
10 # |
|
11 # Contributors: |
|
12 # |
|
13 # Description: |
|
14 # |
|
15 |
|
16 use Getopt::Long; |
|
17 use strict; |
|
18 |
|
19 my $outputFileName = "default.inf"; |
|
20 my $discard_noncallable_exports = 0; |
|
21 my @inputFiles; |
|
22 my @exports = (); |
|
23 my %symsSeen = (); |
|
24 |
|
25 # |
|
26 |
|
27 &args; |
|
28 &main; |
|
29 |
|
30 |
|
31 sub args () |
|
32 { |
|
33 my %opts = (); |
|
34 my $result = GetOptions(\%opts, "output:s", "discard_noncallable_exports"); |
|
35 $outputFileName = $opts{'output'} if $opts{'output'} ; |
|
36 $discard_noncallable_exports = 1 if $opts{'discard_noncallable_exports'}; |
|
37 @inputFiles = @ARGV; |
|
38 } |
|
39 |
|
40 sub main () |
|
41 { |
|
42 |
|
43 foreach my $file (@inputFiles){ |
|
44 ReadFromElf($file); |
|
45 } |
|
46 open( INFFILE, ">$outputFileName") or |
|
47 die "Error: can't open $outputFileName\n"; |
|
48 foreach my $export (sort {$a cmp $b } @exports) { |
|
49 print INFFILE $export; |
|
50 } |
|
51 close INFFILE; |
|
52 } |
|
53 |
|
54 sub ReadFromElf ($) |
|
55 { |
|
56 my ($filename) = @_; |
|
57 my $line; |
|
58 %symsSeen = (); |
|
59 open(FROMELF, "getexports $filename|") |
|
60 or die "Error: can't open $filename\n"; |
|
61 |
|
62 while ($_ = <FROMELF> ) |
|
63 { |
|
64 if ($_ =~ /^\s*(\S+)\s+((DATA)\s+(\d+))?\s*$/) { |
|
65 my $sym = $1; |
|
66 my $data = ""; |
|
67 unless ($symsSeen{$sym}) { |
|
68 $symsSeen{$sym} = $sym; |
|
69 |
|
70 if($2){ |
|
71 # Indicate if this is a data symbol along with its size. |
|
72 if($4){ |
|
73 $data = " DATA $4"; |
|
74 } |
|
75 } |
|
76 |
|
77 if ($sym =~ /^_ZTV/ && !$discard_noncallable_exports) { # allow vtables thru |
|
78 push @exports, " _$sym (#<VT>#)\n"; |
|
79 } elsif ($sym =~ /^_ZTI/ && !$discard_noncallable_exports) { # allow type info thru: comment out if we don't want it |
|
80 push @exports, " _$sym (#<TI>#)\n"; |
|
81 } elsif ($sym =~ /^_ZThn\d/) { # allow thunk thru |
|
82 push @exports, " _$sym (#<thunk>#)\n"; |
|
83 } elsif ($sym =~ /^_ZT/) { # punt all other type stuff: shouldn't be exported anyway |
|
84 next; |
|
85 } elsif (C9Ctor($sym)) { #work around non-export of constructors |
|
86 PushCtors($sym, $filename); |
|
87 } elsif (D9Dtor($sym)) { #work around non-export of constructors |
|
88 PushDtors($sym, $filename); |
|
89 } else { |
|
90 push @exports, " _$sym$data\n"; |
|
91 } |
|
92 } |
|
93 } |
|
94 } |
|
95 close FROMELF; |
|
96 } |
|
97 |
|
98 sub PushSym($$) |
|
99 { |
|
100 my ($s, $f) = @_; |
|
101 unless ($symsSeen{$s}) { |
|
102 $symsSeen{$s} = $s; |
|
103 push @exports, " _$s\n"; |
|
104 } |
|
105 } |
|
106 |
|
107 sub simpleC9Ctor($) |
|
108 { |
|
109 my ($sym) = @_; |
|
110 if ($sym =~ /_ZN(\d+)(.+)C9E.*$/) { |
|
111 # Really check it |
|
112 return 1 if ($1 == length($2)); |
|
113 } |
|
114 return 0; |
|
115 } |
|
116 |
|
117 sub simpleD9Ctor($) |
|
118 { |
|
119 my ($sym) = @_; |
|
120 if ($sym =~ /_ZN(\d+)(.+)D9E.*$/) { |
|
121 # Really check it |
|
122 return 1 if ($1 == length($2)); |
|
123 } |
|
124 return 0; |
|
125 } |
|
126 |
|
127 sub C9Ctor($) |
|
128 { |
|
129 my ($sym) = @_; |
|
130 return 1 if simpleC9Ctor($sym); |
|
131 if ($sym =~ /_ZN(\d+)(.+)C9E.*$/) { |
|
132 my $l = $1; |
|
133 my $s = $2; |
|
134 my $t_params = substr $s, $l; |
|
135 return 1 if ($t_params =~ /^I.*I$/); # not totally convincing check for templated ctor |
|
136 } |
|
137 return 0; |
|
138 } |
|
139 |
|
140 sub PushCtors($$) |
|
141 { |
|
142 my ($sym, $filename) = @_; |
|
143 return PushSimpleCtors($sym, $filename) if (simpleC9Ctor($sym)); |
|
144 |
|
145 my ($sym, $filename) = @_; |
|
146 $sym =~ /(_ZN\d+.+IC)9E.*$/o; |
|
147 my $s = $1; |
|
148 my $i = length $s; |
|
149 my $e = substr $sym, $i + 1; |
|
150 my $C1 = "$s"."1"."$e"; |
|
151 my $C2 = "$s"."2"."$e"; |
|
152 push @exports, " _$sym\n"; |
|
153 PushSym($C1, $filename); |
|
154 PushSym($C2, $filename); |
|
155 |
|
156 } |
|
157 |
|
158 sub PushSimpleCtors($$) |
|
159 { |
|
160 my ($sym, $filename) = @_; |
|
161 $sym =~ /(_ZN\d+.+C)9E.*$/o; |
|
162 my $s = $1; |
|
163 my $i = length $s; |
|
164 my $e = substr $sym, $i + 1; |
|
165 my $C1 = "$s"."1"."$e"; |
|
166 my $C2 = "$s"."2"."$e"; |
|
167 push @exports, " _$sym\n"; |
|
168 PushSym($C1, $filename); |
|
169 PushSym($C2, $filename); |
|
170 } |
|
171 |
|
172 sub D9Dtor($) |
|
173 { |
|
174 my ($sym) = @_; |
|
175 return 1 if simpleD9Ctor($sym); |
|
176 if ($sym =~ /_ZN(\d+)(.+)D9E.*$/) { |
|
177 my $l = $1; |
|
178 my $s = $2; |
|
179 my $t_params = substr $s, $l; |
|
180 return 1 if ($t_params =~ /^I.*I$/); # not totally convincing check for templated ctor |
|
181 } |
|
182 return 0; |
|
183 } |
|
184 |
|
185 sub PushDtors($$) |
|
186 { |
|
187 my ($sym, $filename) = @_; |
|
188 return PushSimpleDtors($sym, $filename) if (simpleD9Ctor($sym)); |
|
189 |
|
190 my ($sym, $filename) = @_; |
|
191 $sym =~ /(_ZN\d+.+ID)9E.*$/o; |
|
192 my $s = $1; |
|
193 my $i = length $s; |
|
194 my $e = substr $sym, $i + 1; |
|
195 my $D0 = "$s"."0"."$e"; |
|
196 my $D1 = "$s"."1"."$e"; |
|
197 my $D2 = "$s"."2"."$e"; |
|
198 push @exports, " _$sym\n"; |
|
199 PushSym($D0, $filename); |
|
200 PushSym($D1, $filename); |
|
201 PushSym($D2, $filename); |
|
202 } |
|
203 |
|
204 |
|
205 sub PushSimpleDtors($$) |
|
206 { |
|
207 my ($sym, $filename) = @_; |
|
208 $sym =~ /(_ZN\d+.+D)9E.*$/o; |
|
209 my $s = $1; |
|
210 my $i = length $s; |
|
211 my $e = substr $sym, $i + 1; |
|
212 my $D0 = "$s"."0"."$e"; |
|
213 my $D1 = "$s"."1"."$e"; |
|
214 my $D2 = "$s"."2"."$e"; |
|
215 push @exports, " _$sym\n"; |
|
216 PushSym($D0, $filename); |
|
217 PushSym($D1, $filename); |
|
218 PushSym($D2, $filename); |
|
219 } |
|
220 |