]>
Commit | Line | Data |
---|---|---|
4b260c20 BK |
1 | // -*- C++ -*- |
2 | ||
c9fd7c7b | 3 | // Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 |
1e2c0906 | 4 | // Free Software Foundation, Inc. |
4b260c20 BK |
5 | |
6 | // This library is free software; you can redistribute it and/or | |
7 | // modify it under the terms of the GNU General Public License as | |
748086b7 | 8 | // published by the Free Software Foundation; either version 3, or (at |
4b260c20 BK |
9 | // your option) any later version. |
10 | ||
11 | // This library is distributed in the hope that it will be useful, but | |
12 | // WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | // General Public License for more details. | |
15 | ||
16 | // You should have received a copy of the GNU General Public License | |
748086b7 JJ |
17 | // along with this library; see the file COPYING3. If not see |
18 | // <http://www.gnu.org/licenses/>. | |
4b260c20 | 19 | |
4b260c20 BK |
20 | |
21 | // Benjamin Kosnik <bkoz@redhat.com> | |
22 | ||
23 | #include "testsuite_abi.h" | |
0c3de900 | 24 | #include <cstdlib> |
4b260c20 BK |
25 | #include <sstream> |
26 | #include <fstream> | |
27 | #include <iostream> | |
0c3de900 | 28 | #include <vector> |
4f39bf5c | 29 | #include <algorithm> |
4b260c20 BK |
30 | |
31 | using namespace std; | |
32 | ||
c9fd7c7b | 33 | void |
4b260c20 BK |
34 | symbol::init(string& data) |
35 | { | |
36 | const char delim = ':'; | |
37 | const char version_delim = '@'; | |
38 | const string::size_type npos = string::npos; | |
39 | string::size_type n = 0; | |
40 | ||
41 | // Set the type. | |
42 | if (data.find("FUNC") == 0) | |
43 | type = symbol::function; | |
44 | else if (data.find("OBJECT") == 0) | |
45 | type = symbol::object; | |
bf718682 BK |
46 | else if (data.find("TLS") == 0) |
47 | type = symbol::tls; | |
bb2b2a24 | 48 | |
4b260c20 BK |
49 | n = data.find_first_of(delim); |
50 | if (n != npos) | |
51 | data.erase(data.begin(), data.begin() + n + 1); | |
52 | ||
bf718682 BK |
53 | // Iff object or TLS, get size info. |
54 | if (type == symbol::object || type == symbol::tls) | |
4b260c20 BK |
55 | { |
56 | n = data.find_first_of(delim); | |
57 | if (n != npos) | |
58 | { | |
69240fc2 SW |
59 | string objectsize(data.begin(), data.begin() + n); |
60 | istringstream iss(objectsize); | |
4b260c20 BK |
61 | int x; |
62 | iss >> x; | |
63 | if (!iss.fail()) | |
64 | size = x; | |
65 | data.erase(data.begin(), data.begin() + n + 1); | |
66 | } | |
67 | } | |
68 | ||
bb2b2a24 BK |
69 | // Set the name and raw_name. |
70 | raw_name = string(data.begin(), data.end()); | |
4b260c20 BK |
71 | n = data.find_first_of(version_delim); |
72 | if (n != npos) | |
73 | { | |
74 | // Found version string. | |
75 | name = string(data.begin(), data.begin() + n); | |
76 | n = data.find_last_of(version_delim); | |
77 | data.erase(data.begin(), data.begin() + n + 1); | |
78 | ||
79 | // Set version name. | |
80 | version_name = data; | |
81 | } | |
82 | else | |
83 | { | |
84 | // No versioning info. | |
85 | name = string(data.begin(), data.end()); | |
bb2b2a24 | 86 | version_status = symbol::none; |
4b260c20 BK |
87 | } |
88 | ||
89 | // Set the demangled name. | |
90 | demangled_name = demangle(name); | |
91 | } | |
92 | ||
93 | void | |
94 | symbol::print() const | |
95 | { | |
96 | const char tab = '\t'; | |
bb2b2a24 | 97 | cout << name << endl; |
4b260c20 | 98 | |
bb2b2a24 BK |
99 | if (demangled_name != name) |
100 | cout << demangled_name << endl; | |
101 | ||
102 | string vers; | |
103 | switch (version_status) | |
4b260c20 BK |
104 | { |
105 | case none: | |
bb2b2a24 BK |
106 | vers = "none"; |
107 | break; | |
108 | case compatible: | |
109 | vers = "compatible"; | |
110 | break; | |
111 | case incompatible: | |
112 | vers = "incompatible"; | |
113 | break; | |
114 | case unversioned: | |
115 | vers = "unversioned"; | |
4b260c20 | 116 | break; |
bb2b2a24 BK |
117 | default: |
118 | vers = "<default>"; | |
119 | } | |
120 | cout << "version status: " << vers << endl; | |
121 | ||
c9fd7c7b | 122 | if (version_name.size() |
bb2b2a24 | 123 | && (version_status == compatible || version_status == incompatible)) |
c9fd7c7b | 124 | cout << version_name << endl; |
bb2b2a24 BK |
125 | |
126 | string type_string; | |
127 | switch (type) | |
128 | { | |
4b260c20 BK |
129 | case function: |
130 | type_string = "function"; | |
131 | break; | |
132 | case object: | |
133 | type_string = "object"; | |
134 | break; | |
bf718682 BK |
135 | case tls: |
136 | type_string = "tls"; | |
137 | break; | |
bb2b2a24 BK |
138 | case uncategorized: |
139 | type_string = "uncategorized"; | |
4b260c20 BK |
140 | break; |
141 | default: | |
142 | type_string = "<default>"; | |
143 | } | |
bb2b2a24 | 144 | cout << "type: " << type_string << endl; |
c9fd7c7b | 145 | |
bf718682 | 146 | if (type == object || type == tls) |
bb2b2a24 | 147 | cout << "type size: " << size << endl; |
4b260c20 BK |
148 | |
149 | string status_string; | |
150 | switch (status) | |
151 | { | |
4b260c20 BK |
152 | case added: |
153 | status_string = "added"; | |
154 | break; | |
155 | case subtracted: | |
156 | status_string = "subtracted"; | |
157 | break; | |
bb2b2a24 BK |
158 | case undesignated: |
159 | status_string = "undesignated"; | |
4b260c20 BK |
160 | break; |
161 | default: | |
162 | status_string = "<default>"; | |
163 | } | |
bb2b2a24 BK |
164 | cout << "status: " << status_string << endl; |
165 | ||
166 | cout << endl; | |
4b260c20 BK |
167 | } |
168 | ||
169 | ||
170 | bool | |
bb2b2a24 | 171 | check_version(symbol& test, bool added) |
4b260c20 | 172 | { |
bb2b2a24 | 173 | // Construct list of compatible versions. |
4b260c20 BK |
174 | typedef std::vector<std::string> compat_list; |
175 | static compat_list known_versions; | |
176 | if (known_versions.empty()) | |
177 | { | |
bb2b2a24 BK |
178 | // NB: First version here must be the default version for this |
179 | // version of DT_SONAME. | |
4b260c20 | 180 | known_versions.push_back("GLIBCXX_3.4"); |
7c9fee34 | 181 | known_versions.push_back("GLIBCXX_3.4.1"); |
9e802114 | 182 | known_versions.push_back("GLIBCXX_3.4.2"); |
0e98ac62 | 183 | known_versions.push_back("GLIBCXX_3.4.3"); |
c9fd7c7b | 184 | known_versions.push_back("GLIBCXX_3.4.4"); |
36b72d8d | 185 | known_versions.push_back("GLIBCXX_3.4.5"); |
bb2b2a24 | 186 | known_versions.push_back("GLIBCXX_3.4.6"); |
18c75543 | 187 | known_versions.push_back("GLIBCXX_3.4.7"); |
45f388bb | 188 | known_versions.push_back("GLIBCXX_3.4.8"); |
0efaed01 | 189 | known_versions.push_back("GLIBCXX_3.4.9"); |
5dddb7e5 | 190 | known_versions.push_back("GLIBCXX_3.4.10"); |
31908b79 | 191 | known_versions.push_back("GLIBCXX_3.4.11"); |
efdb7347 | 192 | known_versions.push_back("GLIBCXX_3.4.12"); |
95bfca5e | 193 | known_versions.push_back("GLIBCXX_3.4.13"); |
41bc3c4a | 194 | known_versions.push_back("GLIBCXX_3.4.14"); |
1e2c0906 | 195 | known_versions.push_back("GLIBCXX_3.4.15"); |
07703a37 | 196 | known_versions.push_back("GLIBCXX_3.4.16"); |
43653c33 | 197 | known_versions.push_back("GLIBCXX_3.4.17"); |
6defecc2 JJ |
198 | known_versions.push_back("GLIBCXX_LDBL_3.4"); |
199 | known_versions.push_back("GLIBCXX_LDBL_3.4.7"); | |
7371aff8 | 200 | known_versions.push_back("GLIBCXX_LDBL_3.4.10"); |
4b260c20 | 201 | known_versions.push_back("CXXABI_1.3"); |
44dd2da2 | 202 | known_versions.push_back("CXXABI_1.3.1"); |
9b4fc32c | 203 | known_versions.push_back("CXXABI_1.3.2"); |
c466b2cd | 204 | known_versions.push_back("CXXABI_1.3.3"); |
fae927d3 | 205 | known_versions.push_back("CXXABI_1.3.4"); |
67275575 | 206 | known_versions.push_back("CXXABI_1.3.5"); |
50da34bb | 207 | known_versions.push_back("CXXABI_1.3.6"); |
6defecc2 | 208 | known_versions.push_back("CXXABI_LDBL_1.3"); |
c9fd7c7b | 209 | known_versions.push_back("CXXABI_TM_1"); |
4b260c20 BK |
210 | } |
211 | compat_list::iterator begin = known_versions.begin(); | |
212 | compat_list::iterator end = known_versions.end(); | |
213 | ||
bb2b2a24 BK |
214 | // Check for compatible version. |
215 | if (test.version_name.size()) | |
216 | { | |
217 | compat_list::iterator it1 = find(begin, end, test.version_name); | |
218 | compat_list::iterator it2 = find(begin, end, test.name); | |
219 | if (it1 != end) | |
220 | test.version_status = symbol::compatible; | |
221 | else | |
222 | test.version_status = symbol::incompatible; | |
c9fd7c7b BK |
223 | |
224 | // Check that added symbols are added in the latest pre-release version. | |
225 | bool latestp = (test.version_name == "GLIBCXX_3.4.17" | |
226 | || test.version_name == "CXXABI_1.3.6" | |
227 | || test.version_name == "CXXABI_TM_1"); | |
228 | if (added && !latestp) | |
bb2b2a24 | 229 | test.version_status = symbol::incompatible; |
c75bd36b | 230 | |
0c312c2d BK |
231 | // Check that long double compatibility symbols demangled as |
232 | // __float128 are put into some _LDBL_ version name. | |
233 | if (added && test.demangled_name.find("__float128") != std::string::npos) | |
234 | { | |
235 | // Has to be in _LDBL_ version name. | |
236 | if (test.version_name.find("_LDBL_") == std::string::npos) | |
237 | test.version_status = symbol::incompatible; | |
238 | } | |
239 | ||
bb2b2a24 BK |
240 | // Check for weak label. |
241 | if (it1 == end && it2 == end) | |
242 | test.version_status = symbol::incompatible; | |
c9fd7c7b BK |
243 | |
244 | // Check that | |
bb2b2a24 BK |
245 | // GLIBCXX_3.4 |
246 | // GLIBCXX_3.4.5 | |
247 | // version as compatible | |
248 | // XXX | |
249 | } | |
250 | else | |
251 | { | |
252 | if (added) | |
253 | { | |
254 | // New version labels are ok. The rest are not. | |
255 | compat_list::iterator it2 = find(begin, end, test.name); | |
256 | if (it2 != end) | |
6defecc2 | 257 | test.version_status = symbol::compatible; |
bb2b2a24 BK |
258 | else |
259 | test.version_status = symbol::incompatible; | |
260 | } | |
261 | } | |
262 | return test.version_status == symbol::compatible; | |
4b260c20 BK |
263 | } |
264 | ||
c9fd7c7b | 265 | bool |
bb2b2a24 | 266 | check_compatible(symbol& lhs, symbol& rhs, bool verbose) |
4b260c20 BK |
267 | { |
268 | bool ret = true; | |
269 | const char tab = '\t'; | |
270 | ||
271 | // Check to see if symbol_objects are compatible. | |
272 | if (lhs.type != rhs.type) | |
273 | { | |
274 | ret = false; | |
275 | if (verbose) | |
276 | cout << tab << "incompatible types" << endl; | |
277 | } | |
c9fd7c7b | 278 | |
4b260c20 BK |
279 | if (lhs.name != rhs.name) |
280 | { | |
281 | ret = false; | |
282 | if (verbose) | |
283 | cout << tab << "incompatible names" << endl; | |
284 | } | |
285 | ||
286 | if (lhs.size != rhs.size) | |
287 | { | |
288 | ret = false; | |
289 | if (verbose) | |
290 | { | |
291 | cout << tab << "incompatible sizes" << endl; | |
292 | cout << tab << lhs.size << endl; | |
293 | cout << tab << rhs.size << endl; | |
294 | } | |
295 | } | |
296 | ||
c9fd7c7b | 297 | if (lhs.version_name != rhs.version_name |
4b260c20 BK |
298 | && !check_version(lhs) && !check_version(rhs)) |
299 | { | |
300 | ret = false; | |
301 | if (verbose) | |
302 | { | |
303 | cout << tab << "incompatible versions" << endl; | |
304 | cout << tab << lhs.version_name << endl; | |
305 | cout << tab << rhs.version_name << endl; | |
306 | } | |
307 | } | |
308 | ||
309 | if (verbose) | |
310 | cout << endl; | |
311 | ||
312 | return ret; | |
313 | } | |
314 | ||
315 | ||
0c312c2d BK |
316 | inline bool |
317 | has_symbol(const string& name, const symbols& s) throw() | |
318 | { return s.find(name) != s.end(); } | |
4b260c20 | 319 | |
0c312c2d BK |
320 | const symbol& |
321 | get_symbol(const string& name, const symbols& s) | |
4b260c20 | 322 | { |
0c312c2d BK |
323 | symbols::const_iterator i = s.find(name); |
324 | if (i != s.end()) | |
4b260c20 | 325 | { |
0c312c2d | 326 | return i->second; |
4b260c20 BK |
327 | } |
328 | else | |
329 | { | |
330 | ostringstream os; | |
0c312c2d | 331 | os << "get_symbol failed for symbol " << name; |
56ffd9b3 | 332 | __throw_logic_error(os.str().c_str()); |
4b260c20 BK |
333 | } |
334 | } | |
335 | ||
c9fd7c7b | 336 | void |
4b260c20 BK |
337 | examine_symbol(const char* name, const char* file) |
338 | { | |
339 | try | |
340 | { | |
341 | symbols s = create_symbols(file); | |
0c312c2d | 342 | const symbol& sym = get_symbol(name, s); |
4b260c20 BK |
343 | sym.print(); |
344 | } | |
345 | catch(...) | |
d98fd134 | 346 | { __throw_exception_again; } |
4b260c20 BK |
347 | } |
348 | ||
fdbba6bc | 349 | int |
c9fd7c7b | 350 | compare_symbols(const char* baseline_file, const char* test_file, |
4b260c20 BK |
351 | bool verbose) |
352 | { | |
353 | // Input both lists of symbols into container. | |
354 | symbols baseline = create_symbols(baseline_file); | |
355 | symbols test = create_symbols(test_file); | |
4b260c20 BK |
356 | |
357 | // Sanity check results. | |
0c312c2d | 358 | if (!baseline.size() || !test.size()) |
4b260c20 BK |
359 | { |
360 | cerr << "Problems parsing the list of exported symbols." << endl; | |
361 | exit(2); | |
362 | } | |
363 | ||
4a49c70b BK |
364 | // Check to see if any long double compatibility symbols are produced. |
365 | bool ld_version_found(false); | |
0c312c2d BK |
366 | symbols::iterator li(test.begin()); |
367 | while (!ld_version_found && li != test.end()) | |
4a49c70b | 368 | { |
0c312c2d | 369 | if (li->second.version_name.find("_LDBL_") != std::string::npos) |
4a49c70b BK |
370 | ld_version_found = true; |
371 | ++li; | |
372 | } | |
373 | ||
4b260c20 | 374 | // Sort out names. |
0c312c2d BK |
375 | // Assuming all baseline names and test names are both unique w/ no |
376 | // duplicates. | |
4b260c20 | 377 | // |
0c312c2d | 378 | // The names added to missing_names are baseline names not found in |
c9fd7c7b | 379 | // test names |
4b260c20 BK |
380 | // -> symbols that have been deleted. |
381 | // | |
0c312c2d BK |
382 | // The names added to added_names are test names not in |
383 | // baseline names | |
4b260c20 | 384 | // -> symbols that have been added. |
0c312c2d | 385 | typedef std::vector<std::string> symbol_names; |
4b260c20 BK |
386 | symbol_names shared_names; |
387 | symbol_names missing_names; | |
0c312c2d BK |
388 | symbol_names added_names; |
389 | for (li = test.begin(); li != test.end(); ++li) | |
390 | added_names.push_back(li->first); | |
391 | ||
392 | for (symbols::iterator i = baseline.begin(); i != baseline.end(); ++i) | |
4b260c20 | 393 | { |
0c312c2d | 394 | string name(i->first); |
4b260c20 | 395 | symbol_names::iterator end = added_names.end(); |
0c312c2d | 396 | symbol_names::iterator it = find(added_names.begin(), end, name); |
4b260c20 BK |
397 | if (it != end) |
398 | { | |
399 | // Found. | |
0c312c2d | 400 | shared_names.push_back(name); |
4b260c20 BK |
401 | added_names.erase(it); |
402 | } | |
0c312c2d BK |
403 | else |
404 | { | |
405 | // Iff no test long double compatibility symbols at all and the symbol | |
406 | // missing is a baseline long double compatibility symbol, skip. | |
407 | string version_name(i->second.version_name); | |
408 | bool base_ld(version_name.find("_LDBL_") != std::string::npos); | |
409 | if (!base_ld || base_ld && ld_version_found) | |
410 | missing_names.push_back(name); | |
411 | } | |
4b260c20 BK |
412 | } |
413 | ||
0c312c2d | 414 | // Fill out list of incompatible symbols. |
4b260c20 BK |
415 | typedef pair<symbol, symbol> symbol_pair; |
416 | vector<symbol_pair> incompatible; | |
0c312c2d | 417 | |
c9fd7c7b BK |
418 | // Fill out list of undesignated symbols. |
419 | vector<symbol> undesignated; | |
420 | ||
0c312c2d BK |
421 | // Check missing names for compatibility. |
422 | for (size_t j = 0; j < missing_names.size(); ++j) | |
4b260c20 | 423 | { |
0c312c2d BK |
424 | symbol& sbase = baseline[missing_names[j]]; |
425 | sbase.status = symbol::subtracted; | |
426 | incompatible.push_back(symbol_pair(sbase, sbase)); | |
4b260c20 BK |
427 | } |
428 | ||
429 | // Check shared names for compatibility. | |
6defecc2 JJ |
430 | const symbol_names::size_type shared_size = shared_names.size(); |
431 | for (size_t k = 0; k < shared_size; ++k) | |
4b260c20 | 432 | { |
0c312c2d BK |
433 | symbol& sbase = baseline[shared_names[k]]; |
434 | symbol& stest = test[shared_names[k]]; | |
435 | stest.status = symbol::existing; | |
436 | if (!check_compatible(sbase, stest)) | |
437 | incompatible.push_back(symbol_pair(sbase, stest)); | |
4b260c20 BK |
438 | } |
439 | ||
440 | // Check added names for compatibility. | |
6defecc2 JJ |
441 | const symbol_names::size_type added_size = added_names.size(); |
442 | for (size_t l = 0; l < added_size; ++l) | |
4b260c20 | 443 | { |
0c312c2d | 444 | symbol& stest = test[added_names[l]]; |
c9fd7c7b BK |
445 | |
446 | // Mark TLS as undesignated, remove from added. | |
447 | if (stest.type == symbol::tls) | |
448 | { | |
449 | stest.status = symbol::undesignated; | |
450 | if (!check_version(stest, false)) | |
451 | incompatible.push_back(symbol_pair(stest, stest)); | |
452 | else | |
453 | undesignated.push_back(stest); | |
454 | } | |
455 | else | |
456 | { | |
457 | stest.status = symbol::added; | |
458 | if (!check_version(stest, true)) | |
459 | incompatible.push_back(symbol_pair(stest, stest)); | |
460 | } | |
4b260c20 BK |
461 | } |
462 | ||
c9fd7c7b BK |
463 | // Normalize added names and undesignated names. |
464 | const size_t undesignated_size = undesignated.size(); | |
465 | for (size_t l = 0; l < undesignated_size; ++l) | |
466 | { | |
467 | symbol& sundes = undesignated[l]; | |
468 | symbol_names::iterator end = added_names.end(); | |
469 | symbol_names::iterator it = find(added_names.begin(), end, sundes.name); | |
470 | if (it != end) | |
471 | { | |
472 | // Found. | |
473 | added_names.erase(it); | |
474 | } | |
475 | else | |
476 | __throw_runtime_error(sundes.name.c_str()); | |
477 | } | |
478 | ||
479 | ||
4b260c20 BK |
480 | // Report results. |
481 | if (verbose && added_names.size()) | |
482 | { | |
bb2b2a24 | 483 | cout << endl << added_names.size() << " added symbols " << endl; |
4b260c20 | 484 | for (size_t j = 0; j < added_names.size() ; ++j) |
bb2b2a24 BK |
485 | { |
486 | cout << j << endl; | |
0c312c2d | 487 | test[added_names[j]].print(); |
bb2b2a24 | 488 | } |
4b260c20 | 489 | } |
c9fd7c7b | 490 | |
4b260c20 BK |
491 | if (verbose && missing_names.size()) |
492 | { | |
bb2b2a24 | 493 | cout << endl << missing_names.size() << " missing symbols " << endl; |
4b260c20 | 494 | for (size_t j = 0; j < missing_names.size() ; ++j) |
bb2b2a24 BK |
495 | { |
496 | cout << j << endl; | |
0c312c2d | 497 | baseline[missing_names[j]].print(); |
bb2b2a24 | 498 | } |
4b260c20 | 499 | } |
c9fd7c7b BK |
500 | |
501 | if (verbose && undesignated.size()) | |
502 | { | |
503 | cout << endl << undesignated.size() << " undesignated symbols " << endl; | |
504 | for (size_t j = 0; j < undesignated.size() ; ++j) | |
505 | { | |
506 | // First, print index. | |
507 | cout << j << endl; | |
508 | ||
509 | // Second, report name. | |
510 | symbol& s = undesignated[j]; | |
511 | s.print(); | |
512 | } | |
513 | } | |
514 | ||
4b260c20 BK |
515 | if (verbose && incompatible.size()) |
516 | { | |
bb2b2a24 | 517 | cout << endl << incompatible.size() << " incompatible symbols " << endl; |
4b260c20 BK |
518 | for (size_t j = 0; j < incompatible.size() ; ++j) |
519 | { | |
bb2b2a24 BK |
520 | // First, print index. |
521 | cout << j << endl; | |
522 | ||
523 | // Second, report name. | |
0c312c2d BK |
524 | symbol& sbase = incompatible[j].first; |
525 | symbol& stest = incompatible[j].second; | |
526 | stest.print(); | |
c9fd7c7b BK |
527 | |
528 | // Third, report reason or reasons incompatible. | |
0c312c2d | 529 | check_compatible(sbase, stest, true); |
4b260c20 BK |
530 | } |
531 | } | |
c9fd7c7b | 532 | |
4b260c20 BK |
533 | cout << "\n\t\t=== libstdc++-v3 check-abi Summary ===" << endl; |
534 | cout << endl; | |
535 | cout << "# of added symbols:\t\t " << added_names.size() << endl; | |
536 | cout << "# of missing symbols:\t\t " << missing_names.size() << endl; | |
c9fd7c7b | 537 | cout << "# of undesignated symbols:\t " << undesignated.size() << endl; |
4b260c20 BK |
538 | cout << "# of incompatible symbols:\t " << incompatible.size() << endl; |
539 | cout << endl; | |
540 | cout << "using: " << baseline_file << endl; | |
fdbba6bc MM |
541 | |
542 | return !(missing_names.size() || incompatible.size()); | |
4b260c20 BK |
543 | } |
544 | ||
545 | ||
546 | symbols | |
547 | create_symbols(const char* file) | |
548 | { | |
549 | symbols s; | |
550 | ifstream ifs(file); | |
551 | if (ifs.is_open()) | |
552 | { | |
0c312c2d BK |
553 | // Organize file data into an associated container (symbols) of symbol |
554 | // objects mapped to mangled names without versioning | |
555 | // information. | |
4b260c20 BK |
556 | const string empty; |
557 | string line = empty; | |
558 | while (getline(ifs, line).good()) | |
559 | { | |
560 | symbol tmp; | |
561 | tmp.init(line); | |
0c312c2d | 562 | s[tmp.name] = tmp; |
4b260c20 BK |
563 | line = empty; |
564 | } | |
565 | } | |
566 | else | |
567 | { | |
568 | ostringstream os; | |
569 | os << "create_symbols failed for file " << file; | |
56ffd9b3 | 570 | __throw_runtime_error(os.str().c_str()); |
4b260c20 BK |
571 | } |
572 | return s; | |
573 | } | |
574 | ||
575 | ||
576 | const char* | |
577 | demangle(const std::string& mangled) | |
578 | { | |
579 | const char* name; | |
580 | if (mangled[0] != '_' || mangled[1] != 'Z') | |
581 | { | |
582 | // This is not a mangled symbol, thus has "C" linkage. | |
583 | name = mangled.c_str(); | |
584 | } | |
585 | else | |
586 | { | |
587 | // Use __cxa_demangle to demangle. | |
588 | int status = 0; | |
589 | name = abi::__cxa_demangle(mangled.c_str(), 0, 0, &status); | |
590 | if (!name) | |
591 | { | |
592 | switch (status) | |
593 | { | |
594 | case 0: | |
595 | name = "error code = 0: success"; | |
596 | break; | |
597 | case -1: | |
598 | name = "error code = -1: memory allocation failure"; | |
599 | break; | |
600 | case -2: | |
601 | name = "error code = -2: invalid mangled name"; | |
602 | break; | |
603 | case -3: | |
604 | name = "error code = -3: invalid arguments"; | |
605 | break; | |
606 | default: | |
607 | name = "error code unknown - who knows what happened"; | |
608 | } | |
609 | } | |
610 | } | |
611 | return name; | |
612 | } |