3 // Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc.
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
8 // published by the Free Software Foundation; either version 3, or (at
9 // your option) any later version.
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.
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
21 // Benjamin Kosnik <bkoz@redhat.com>
23 #include "testsuite_abi.h"
34 symbol::init(string
& data
)
36 const char delim
= ':';
37 const char version_delim
= '@';
38 const string::size_type npos
= string::npos
;
39 string::size_type n
= 0;
42 if (data
.find("FUNC") == 0)
43 type
= symbol::function
;
44 else if (data
.find("OBJECT") == 0)
45 type
= symbol::object
;
46 else if (data
.find("TLS") == 0)
49 n
= data
.find_first_of(delim
);
51 data
.erase(data
.begin(), data
.begin() + n
+ 1);
53 // Iff object or TLS, get size info.
54 if (type
== symbol::object
|| type
== symbol::tls
)
56 n
= data
.find_first_of(delim
);
59 string
objectsize(data
.begin(), data
.begin() + n
);
60 istringstream
iss(objectsize
);
65 data
.erase(data
.begin(), data
.begin() + n
+ 1);
69 // Set the name and raw_name.
70 raw_name
= string(data
.begin(), data
.end());
71 n
= data
.find_first_of(version_delim
);
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);
84 // No versioning info.
85 name
= string(data
.begin(), data
.end());
86 version_status
= symbol::none
;
89 // Set the demangled name.
90 demangled_name
= demangle(name
);
96 const char tab
= '\t';
99 if (demangled_name
!= name
)
100 cout
<< demangled_name
<< endl
;
103 switch (version_status
)
112 vers
= "incompatible";
115 vers
= "unversioned";
120 cout
<< "version status: " << vers
<< endl
;
122 if (version_name
.size()
123 && (version_status
== compatible
|| version_status
== incompatible
))
124 cout
<< version_name
<< endl
;
130 type_string
= "function";
133 type_string
= "object";
139 type_string
= "uncategorized";
142 type_string
= "<default>";
144 cout
<< "type: " << type_string
<< endl
;
146 if (type
== object
|| type
== tls
)
147 cout
<< "type size: " << size
<< endl
;
149 string status_string
;
153 status_string
= "added";
156 status_string
= "subtracted";
159 status_string
= "undesignated";
162 status_string
= "<default>";
164 cout
<< "status: " << status_string
<< endl
;
171 check_version(symbol
& test
, bool added
)
173 // Construct list of compatible versions.
174 typedef std::vector
<std::string
> compat_list
;
175 static compat_list known_versions
;
176 if (known_versions
.empty())
178 // NB: First version here must be the default version for this
179 // version of DT_SONAME.
180 known_versions
.push_back("GLIBCXX_3.4");
181 known_versions
.push_back("GLIBCXX_3.4.1");
182 known_versions
.push_back("GLIBCXX_3.4.2");
183 known_versions
.push_back("GLIBCXX_3.4.3");
184 known_versions
.push_back("GLIBCXX_3.4.4");
185 known_versions
.push_back("GLIBCXX_3.4.5");
186 known_versions
.push_back("GLIBCXX_3.4.6");
187 known_versions
.push_back("GLIBCXX_3.4.7");
188 known_versions
.push_back("GLIBCXX_3.4.8");
189 known_versions
.push_back("GLIBCXX_3.4.9");
190 known_versions
.push_back("GLIBCXX_3.4.10");
191 known_versions
.push_back("GLIBCXX_3.4.11");
192 known_versions
.push_back("GLIBCXX_3.4.12");
193 known_versions
.push_back("GLIBCXX_3.4.13");
194 known_versions
.push_back("GLIBCXX_3.4.14");
195 known_versions
.push_back("GLIBCXX_3.4.15");
196 known_versions
.push_back("GLIBCXX_3.4.16");
197 known_versions
.push_back("GLIBCXX_3.4.17");
198 known_versions
.push_back("GLIBCXX_3.4.18");
199 known_versions
.push_back("GLIBCXX_LDBL_3.4");
200 known_versions
.push_back("GLIBCXX_LDBL_3.4.7");
201 known_versions
.push_back("GLIBCXX_LDBL_3.4.10");
202 known_versions
.push_back("CXXABI_1.3");
203 known_versions
.push_back("CXXABI_1.3.1");
204 known_versions
.push_back("CXXABI_1.3.2");
205 known_versions
.push_back("CXXABI_1.3.3");
206 known_versions
.push_back("CXXABI_1.3.4");
207 known_versions
.push_back("CXXABI_1.3.5");
208 known_versions
.push_back("CXXABI_1.3.6");
209 known_versions
.push_back("CXXABI_LDBL_1.3");
210 known_versions
.push_back("CXXABI_TM_1");
212 compat_list::iterator begin
= known_versions
.begin();
213 compat_list::iterator end
= known_versions
.end();
215 // Check for compatible version.
216 if (test
.version_name
.size())
218 compat_list::iterator it1
= find(begin
, end
, test
.version_name
);
219 compat_list::iterator it2
= find(begin
, end
, test
.name
);
221 test
.version_status
= symbol::compatible
;
223 test
.version_status
= symbol::incompatible
;
225 // Check that added symbols are added in the latest pre-release version.
226 bool latestp
= (test
.version_name
== "GLIBCXX_3.4.18"
227 || test
.version_name
== "CXXABI_1.3.6"
228 || test
.version_name
== "CXXABI_TM_1");
229 if (added
&& !latestp
)
230 test
.version_status
= symbol::incompatible
;
232 // Check that long double compatibility symbols demangled as
233 // __float128 are put into some _LDBL_ version name.
234 if (added
&& test
.demangled_name
.find("__float128") != std::string::npos
)
236 // Has to be in _LDBL_ version name.
237 if (test
.version_name
.find("_LDBL_") == std::string::npos
)
238 test
.version_status
= symbol::incompatible
;
241 // Check for weak label.
242 if (it1
== end
&& it2
== end
)
243 test
.version_status
= symbol::incompatible
;
248 // version as compatible
255 // New version labels are ok. The rest are not.
256 compat_list::iterator it2
= find(begin
, end
, test
.name
);
258 test
.version_status
= symbol::compatible
;
260 test
.version_status
= symbol::incompatible
;
263 return test
.version_status
== symbol::compatible
;
267 check_compatible(symbol
& lhs
, symbol
& rhs
, bool verbose
)
270 const char tab
= '\t';
272 // Check to see if symbol_objects are compatible.
273 if (lhs
.type
!= rhs
.type
)
277 cout
<< tab
<< "incompatible types" << endl
;
280 if (lhs
.name
!= rhs
.name
)
284 cout
<< tab
<< "incompatible names" << endl
;
287 if (lhs
.size
!= rhs
.size
)
292 cout
<< tab
<< "incompatible sizes" << endl
;
293 cout
<< tab
<< lhs
.size
<< endl
;
294 cout
<< tab
<< rhs
.size
<< endl
;
298 if (lhs
.version_name
!= rhs
.version_name
299 && !check_version(lhs
) && !check_version(rhs
))
304 cout
<< tab
<< "incompatible versions" << endl
;
305 cout
<< tab
<< lhs
.version_name
<< endl
;
306 cout
<< tab
<< rhs
.version_name
<< endl
;
318 has_symbol(const string
& name
, const symbols
& s
) throw()
319 { return s
.find(name
) != s
.end(); }
322 get_symbol(const string
& name
, const symbols
& s
)
324 symbols::const_iterator i
= s
.find(name
);
332 os
<< "get_symbol failed for symbol " << name
;
333 __throw_logic_error(os
.str().c_str());
338 examine_symbol(const char* name
, const char* file
)
342 symbols s
= create_symbols(file
);
343 const symbol
& sym
= get_symbol(name
, s
);
347 { __throw_exception_again
; }
351 compare_symbols(const char* baseline_file
, const char* test_file
,
354 // Input both lists of symbols into container.
355 symbols baseline
= create_symbols(baseline_file
);
356 symbols test
= create_symbols(test_file
);
358 // Sanity check results.
359 if (!baseline
.size() || !test
.size())
361 cerr
<< "Problems parsing the list of exported symbols." << endl
;
365 // Check to see if any long double compatibility symbols are produced.
366 bool ld_version_found(false);
367 symbols::iterator
li(test
.begin());
368 while (!ld_version_found
&& li
!= test
.end())
370 if (li
->second
.version_name
.find("_LDBL_") != std::string::npos
)
371 ld_version_found
= true;
376 // Assuming all baseline names and test names are both unique w/ no
379 // The names added to missing_names are baseline names not found in
381 // -> symbols that have been deleted.
383 // The names added to added_names are test names not in
385 // -> symbols that have been added.
386 typedef std::vector
<std::string
> symbol_names
;
387 symbol_names shared_names
;
388 symbol_names missing_names
;
389 symbol_names added_names
;
390 for (li
= test
.begin(); li
!= test
.end(); ++li
)
391 added_names
.push_back(li
->first
);
393 for (symbols::iterator i
= baseline
.begin(); i
!= baseline
.end(); ++i
)
395 string
name(i
->first
);
396 symbol_names::iterator end
= added_names
.end();
397 symbol_names::iterator it
= find(added_names
.begin(), end
, name
);
401 shared_names
.push_back(name
);
402 added_names
.erase(it
);
406 // Iff no test long double compatibility symbols at all and the symbol
407 // missing is a baseline long double compatibility symbol, skip.
408 string
version_name(i
->second
.version_name
);
409 bool base_ld(version_name
.find("_LDBL_") != std::string::npos
);
410 if (!base_ld
|| base_ld
&& ld_version_found
)
411 missing_names
.push_back(name
);
415 // Fill out list of incompatible symbols.
416 typedef pair
<symbol
, symbol
> symbol_pair
;
417 vector
<symbol_pair
> incompatible
;
419 // Fill out list of undesignated symbols.
420 vector
<symbol
> undesignated
;
422 // Check missing names for compatibility.
423 for (size_t j
= 0; j
< missing_names
.size(); ++j
)
425 symbol
& sbase
= baseline
[missing_names
[j
]];
426 sbase
.status
= symbol::subtracted
;
427 incompatible
.push_back(symbol_pair(sbase
, sbase
));
430 // Check shared names for compatibility.
431 const symbol_names::size_type shared_size
= shared_names
.size();
432 for (size_t k
= 0; k
< shared_size
; ++k
)
434 symbol
& sbase
= baseline
[shared_names
[k
]];
435 symbol
& stest
= test
[shared_names
[k
]];
436 stest
.status
= symbol::existing
;
437 if (!check_compatible(sbase
, stest
))
438 incompatible
.push_back(symbol_pair(sbase
, stest
));
441 // Check added names for compatibility.
442 const symbol_names::size_type added_size
= added_names
.size();
443 for (size_t l
= 0; l
< added_size
; ++l
)
445 symbol
& stest
= test
[added_names
[l
]];
447 // Mark TLS as undesignated, remove from added.
448 if (stest
.type
== symbol::tls
)
450 stest
.status
= symbol::undesignated
;
451 if (!check_version(stest
, false))
452 incompatible
.push_back(symbol_pair(stest
, stest
));
454 undesignated
.push_back(stest
);
458 stest
.status
= symbol::added
;
459 if (!check_version(stest
, true))
460 incompatible
.push_back(symbol_pair(stest
, stest
));
464 // Normalize added names and undesignated names.
465 const size_t undesignated_size
= undesignated
.size();
466 for (size_t l
= 0; l
< undesignated_size
; ++l
)
468 symbol
& sundes
= undesignated
[l
];
469 symbol_names::iterator end
= added_names
.end();
470 symbol_names::iterator it
= find(added_names
.begin(), end
, sundes
.name
);
474 added_names
.erase(it
);
477 __throw_runtime_error(sundes
.name
.c_str());
482 if (verbose
&& added_names
.size())
484 cout
<< endl
<< added_names
.size() << " added symbols " << endl
;
485 for (size_t j
= 0; j
< added_names
.size() ; ++j
)
488 test
[added_names
[j
]].print();
492 if (verbose
&& missing_names
.size())
494 cout
<< endl
<< missing_names
.size() << " missing symbols " << endl
;
495 for (size_t j
= 0; j
< missing_names
.size() ; ++j
)
498 baseline
[missing_names
[j
]].print();
502 if (verbose
&& undesignated
.size())
504 cout
<< endl
<< undesignated
.size() << " undesignated symbols " << endl
;
505 for (size_t j
= 0; j
< undesignated
.size() ; ++j
)
507 // First, print index.
510 // Second, report name.
511 symbol
& s
= undesignated
[j
];
516 if (verbose
&& incompatible
.size())
518 cout
<< endl
<< incompatible
.size() << " incompatible symbols " << endl
;
519 for (size_t j
= 0; j
< incompatible
.size() ; ++j
)
521 // First, print index.
524 // Second, report name.
525 symbol
& sbase
= incompatible
[j
].first
;
526 symbol
& stest
= incompatible
[j
].second
;
529 // Third, report reason or reasons incompatible.
530 check_compatible(sbase
, stest
, true);
534 cout
<< "\n\t\t==== libstdc++-v3 check-abi Summary ====" << endl
;
536 cout
<< "# of added symbols:\t\t " << added_names
.size() << endl
;
537 cout
<< "# of missing symbols:\t\t " << missing_names
.size() << endl
;
538 cout
<< "# of undesignated symbols:\t " << undesignated
.size() << endl
;
539 cout
<< "# of incompatible symbols:\t " << incompatible
.size() << endl
;
541 cout
<< "using: " << baseline_file
<< endl
;
543 return !(missing_names
.size() || incompatible
.size());
548 create_symbols(const char* file
)
554 // Organize file data into an associated container (symbols) of symbol
555 // objects mapped to mangled names without versioning
559 while (getline(ifs
, line
).good())
570 os
<< "create_symbols failed for file " << file
;
571 __throw_runtime_error(os
.str().c_str());
578 demangle(const std::string
& mangled
)
581 if (mangled
[0] != '_' || mangled
[1] != 'Z')
583 // This is not a mangled symbol, thus has "C" linkage.
584 name
= mangled
.c_str();
588 // Use __cxa_demangle to demangle.
590 name
= abi::__cxa_demangle(mangled
.c_str(), 0, 0, &status
);
596 name
= "error code = 0: success";
599 name
= "error code = -1: memory allocation failure";
602 name
= "error code = -2: invalid mangled name";
605 name
= "error code = -3: invalid arguments";
608 name
= "error code unknown - who knows what happened";