3 // Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2, or (at
8 // your option) any later version.
10 // This library is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this library; see the file COPYING. If not, write to
17 // the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
18 // MA 02110-1301, USA.
20 // As a special exception, you may use this file as part of a free
21 // software library without restriction. Specifically, if other files
22 // instantiate templates or use macros or inline functions from this
23 // file, or you compile this file and link it with other files to
24 // produce an executable, this file does not by itself cause the
25 // resulting executable to be covered by the GNU General Public
26 // License. This exception does not however invalidate any other
27 // reasons why the executable file might be covered by the GNU General
30 // Benjamin Kosnik <bkoz@redhat.com>
32 #include "testsuite_abi.h"
41 symbol::init(string
& data
)
43 const char delim
= ':';
44 const char version_delim
= '@';
45 const string::size_type npos
= string::npos
;
46 string::size_type n
= 0;
49 if (data
.find("FUNC") == 0)
50 type
= symbol::function
;
51 else if (data
.find("OBJECT") == 0)
52 type
= symbol::object
;
54 n
= data
.find_first_of(delim
);
56 data
.erase(data
.begin(), data
.begin() + n
+ 1);
58 // Iff object, get size info.
59 if (type
== symbol::object
)
61 n
= data
.find_first_of(delim
);
64 string
objectsize(data
.begin(), data
.begin() + n
);
65 istringstream
iss(objectsize
);
70 data
.erase(data
.begin(), data
.begin() + n
+ 1);
74 // Set the name and raw_name.
75 raw_name
= string(data
.begin(), data
.end());
76 n
= data
.find_first_of(version_delim
);
79 // Found version string.
80 name
= string(data
.begin(), data
.begin() + n
);
81 n
= data
.find_last_of(version_delim
);
82 data
.erase(data
.begin(), data
.begin() + n
+ 1);
89 // No versioning info.
90 name
= string(data
.begin(), data
.end());
91 version_status
= symbol::none
;
94 // Set the demangled name.
95 demangled_name
= demangle(name
);
101 const char tab
= '\t';
102 cout
<< name
<< endl
;
104 if (demangled_name
!= name
)
105 cout
<< demangled_name
<< endl
;
108 switch (version_status
)
117 vers
= "incompatible";
120 vers
= "unversioned";
125 cout
<< "version status: " << vers
<< endl
;
127 if (version_name
.size()
128 && (version_status
== compatible
|| version_status
== incompatible
))
129 cout
<< version_name
<< endl
;
135 type_string
= "function";
138 type_string
= "object";
141 type_string
= "uncategorized";
144 type_string
= "<default>";
146 cout
<< "type: " << type_string
<< endl
;
149 cout
<< "type size: " << size
<< endl
;
151 string status_string
;
155 status_string
= "added";
158 status_string
= "subtracted";
161 status_string
= "undesignated";
164 status_string
= "<default>";
166 cout
<< "status: " << status_string
<< endl
;
173 check_version(symbol
& test
, bool added
)
175 // Construct list of compatible versions.
176 typedef std::vector
<std::string
> compat_list
;
177 static compat_list known_versions
;
178 if (known_versions
.empty())
180 // NB: First version here must be the default version for this
181 // version of DT_SONAME.
182 known_versions
.push_back("GLIBCXX_3.4");
183 known_versions
.push_back("GLIBCXX_3.4.1");
184 known_versions
.push_back("GLIBCXX_3.4.2");
185 known_versions
.push_back("GLIBCXX_3.4.3");
186 known_versions
.push_back("GLIBCXX_3.4.4");
187 known_versions
.push_back("GLIBCXX_3.4.5");
188 known_versions
.push_back("GLIBCXX_3.4.6");
189 known_versions
.push_back("GLIBCXX_3.4.7");
190 known_versions
.push_back("GLIBCXX_3.4.8");
191 known_versions
.push_back("GLIBCXX_3.4.9");
192 known_versions
.push_back("GLIBCXX_3.4.10");
193 known_versions
.push_back("GLIBCXX_LDBL_3.4");
194 known_versions
.push_back("GLIBCXX_LDBL_3.4.7");
195 known_versions
.push_back("CXXABI_1.3");
196 known_versions
.push_back("CXXABI_1.3.1");
197 known_versions
.push_back("CXXABI_1.3.2");
198 known_versions
.push_back("CXXABI_LDBL_1.3");
200 compat_list::iterator begin
= known_versions
.begin();
201 compat_list::iterator end
= known_versions
.end();
203 // Check for compatible version.
204 if (test
.version_name
.size())
206 compat_list::iterator it1
= find(begin
, end
, test
.version_name
);
207 compat_list::iterator it2
= find(begin
, end
, test
.name
);
209 test
.version_status
= symbol::compatible
;
211 test
.version_status
= symbol::incompatible
;
213 // Check that added symbols aren't added in the base version.
214 if (added
&& test
.version_name
== known_versions
[0])
215 test
.version_status
= symbol::incompatible
;
217 // Check for weak label.
218 if (it1
== end
&& it2
== end
)
219 test
.version_status
= symbol::incompatible
;
224 // version as compatible
231 // New version labels are ok. The rest are not.
232 compat_list::iterator it2
= find(begin
, end
, test
.name
);
234 test
.version_status
= symbol::compatible
;
236 test
.version_status
= symbol::incompatible
;
239 return test
.version_status
== symbol::compatible
;
243 check_compatible(symbol
& lhs
, symbol
& rhs
, bool verbose
)
246 const char tab
= '\t';
248 // Check to see if symbol_objects are compatible.
249 if (lhs
.type
!= rhs
.type
)
253 cout
<< tab
<< "incompatible types" << endl
;
256 if (lhs
.name
!= rhs
.name
)
260 cout
<< tab
<< "incompatible names" << endl
;
263 if (lhs
.size
!= rhs
.size
)
268 cout
<< tab
<< "incompatible sizes" << endl
;
269 cout
<< tab
<< lhs
.size
<< endl
;
270 cout
<< tab
<< rhs
.size
<< endl
;
274 if (lhs
.version_name
!= rhs
.version_name
275 && !check_version(lhs
) && !check_version(rhs
))
280 cout
<< tab
<< "incompatible versions" << endl
;
281 cout
<< tab
<< lhs
.version_name
<< endl
;
282 cout
<< tab
<< rhs
.version_name
<< endl
;
294 has_symbol(const string
& mangled
, const symbols
& s
) throw()
296 const symbol_names
& names
= s
.first
;
297 symbol_names::const_iterator i
= find(names
.begin(), names
.end(), mangled
);
298 return i
!= names
.end();
302 get_symbol(const string
& mangled
, const symbols
& s
)
304 const symbol_names
& names
= s
.first
;
305 symbol_names::const_iterator i
= find(names
.begin(), names
.end(), mangled
);
306 if (i
!= names
.end())
308 symbol_objects objects
= s
.second
;
309 return objects
[mangled
];
314 os
<< "get_symbol failed for symbol " << mangled
;
315 __throw_logic_error(os
.str().c_str());
320 examine_symbol(const char* name
, const char* file
)
324 symbols s
= create_symbols(file
);
325 symbol
& sym
= get_symbol(name
, s
);
329 { __throw_exception_again
; }
333 compare_symbols(const char* baseline_file
, const char* test_file
,
336 // Input both lists of symbols into container.
337 symbols baseline
= create_symbols(baseline_file
);
338 symbols test
= create_symbols(test_file
);
339 symbol_names
& baseline_names
= baseline
.first
;
340 symbol_objects
& baseline_objects
= baseline
.second
;
341 symbol_names
& test_names
= test
.first
;
342 symbol_objects
& test_objects
= test
.second
;
344 // Sanity check results.
345 const symbol_names::size_type baseline_size
= baseline_names
.size();
346 const symbol_names::size_type test_size
= test_names
.size();
347 if (!baseline_size
|| !test_size
)
349 cerr
<< "Problems parsing the list of exported symbols." << endl
;
354 // Assuming baseline_names, test_names are both unique w/ no duplicates.
356 // The names added to missing_names are baseline_names not found in
358 // -> symbols that have been deleted.
360 // The names added to added_names are test_names not in
362 // -> symbols that have been added.
363 symbol_names shared_names
;
364 symbol_names missing_names
;
365 symbol_names added_names
= test_names
;
366 for (size_t i
= 0; i
< baseline_size
; ++i
)
368 string
what(baseline_names
[i
]);
369 symbol_names::iterator end
= added_names
.end();
370 symbol_names::iterator it
= find(added_names
.begin(), end
, what
);
374 shared_names
.push_back(what
);
375 added_names
.erase(it
);
378 missing_names
.push_back(what
);
381 // Check missing names for compatibility.
382 typedef pair
<symbol
, symbol
> symbol_pair
;
383 vector
<symbol_pair
> incompatible
;
384 const symbol_names::size_type missing_size
= missing_names
.size();
385 for (size_t j
= 0; j
< missing_size
; ++j
)
387 symbol
& base
= baseline_objects
[missing_names
[j
]];
388 base
.status
= symbol::subtracted
;
389 incompatible
.push_back(symbol_pair(base
, base
));
392 // Check shared names for compatibility.
393 const symbol_names::size_type shared_size
= shared_names
.size();
394 for (size_t k
= 0; k
< shared_size
; ++k
)
396 symbol
& base
= baseline_objects
[shared_names
[k
]];
397 symbol
& test
= test_objects
[shared_names
[k
]];
398 test
.status
= symbol::existing
;
399 if (!check_compatible(base
, test
))
400 incompatible
.push_back(symbol_pair(base
, test
));
403 // Check added names for compatibility.
404 const symbol_names::size_type added_size
= added_names
.size();
405 for (size_t l
= 0; l
< added_size
; ++l
)
407 symbol
& test
= test_objects
[added_names
[l
]];
408 test
.status
= symbol::added
;
409 if (!check_version(test
, true))
410 incompatible
.push_back(symbol_pair(test
, test
));
414 if (verbose
&& added_names
.size())
416 cout
<< endl
<< added_names
.size() << " added symbols " << endl
;
417 for (size_t j
= 0; j
< added_names
.size() ; ++j
)
420 test_objects
[added_names
[j
]].print();
424 if (verbose
&& missing_names
.size())
426 cout
<< endl
<< missing_names
.size() << " missing symbols " << endl
;
427 for (size_t j
= 0; j
< missing_names
.size() ; ++j
)
430 baseline_objects
[missing_names
[j
]].print();
434 if (verbose
&& incompatible
.size())
436 cout
<< endl
<< incompatible
.size() << " incompatible symbols " << endl
;
437 for (size_t j
= 0; j
< incompatible
.size() ; ++j
)
439 // First, print index.
442 // Second, report name.
443 symbol
& base
= incompatible
[j
].first
;
444 symbol
& test
= incompatible
[j
].second
;
447 // Second, report reason or reasons incompatible.
448 check_compatible(base
, test
, true);
452 cout
<< "\n\t\t=== libstdc++-v3 check-abi Summary ===" << endl
;
454 cout
<< "# of added symbols:\t\t " << added_names
.size() << endl
;
455 cout
<< "# of missing symbols:\t\t " << missing_names
.size() << endl
;
456 cout
<< "# of incompatible symbols:\t " << incompatible
.size() << endl
;
458 cout
<< "using: " << baseline_file
<< endl
;
460 return !(missing_names
.size() || incompatible
.size());
465 create_symbols(const char* file
)
471 // Organize file data into container of symbol objects, and a
472 // container of mangled names without versioning information.
473 symbol_names
& names
= s
.first
;
474 symbol_objects
& objects
= s
.second
;
477 while (getline(ifs
, line
).good())
481 objects
[tmp
.name
] = tmp
;
482 names
.push_back(tmp
.name
);
489 os
<< "create_symbols failed for file " << file
;
490 __throw_runtime_error(os
.str().c_str());
497 demangle(const std::string
& mangled
)
500 if (mangled
[0] != '_' || mangled
[1] != 'Z')
502 // This is not a mangled symbol, thus has "C" linkage.
503 name
= mangled
.c_str();
507 // Use __cxa_demangle to demangle.
509 name
= abi::__cxa_demangle(mangled
.c_str(), 0, 0, &status
);
515 name
= "error code = 0: success";
518 name
= "error code = -1: memory allocation failure";
521 name
= "error code = -2: invalid mangled name";
524 name
= "error code = -3: invalid arguments";
527 name
= "error code unknown - who knows what happened";