3 // Copyright (C) 2004-2025 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 3, 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 COPYING3. If not see
17 // <http://www.gnu.org/licenses/>.
20 // Benjamin Kosnik <bkoz@redhat.com>
22 #include "testsuite_abi.h"
33 symbol::init(string
& data
)
35 const char delim
= ':';
36 const char version_delim
= '@';
37 const string::size_type npos
= string::npos
;
38 string::size_type n
= 0;
41 if (data
.find("FUNC") == 0)
42 type
= symbol::function
;
43 else if (data
.find("OBJECT") == 0)
44 type
= symbol::object
;
45 else if (data
.find("TLS") == 0)
48 n
= data
.find_first_of(delim
);
50 data
.erase(data
.begin(), data
.begin() + n
+ 1);
52 // Iff object or TLS, get size info.
53 if (type
== symbol::object
|| type
== symbol::tls
)
55 n
= data
.find_first_of(delim
);
58 string
objectsize(data
.begin(), data
.begin() + n
);
59 istringstream
iss(objectsize
);
64 data
.erase(data
.begin(), data
.begin() + n
+ 1);
68 // Set the name and raw_name.
69 raw_name
= string(data
.begin(), data
.end());
70 n
= data
.find_first_of(version_delim
);
73 // Found version string.
74 name
= string(data
.begin(), data
.begin() + n
);
75 n
= data
.find_last_of(version_delim
);
76 data
.erase(data
.begin(), data
.begin() + n
+ 1);
83 // No versioning info.
84 name
= string(data
.begin(), data
.end());
85 version_status
= symbol::none
;
88 // Set the demangled name.
89 demangled_name
= demangle(name
);
95 const char tab
= '\t';
98 if (demangled_name
!= name
)
99 cout
<< demangled_name
<< endl
;
102 switch (version_status
)
111 vers
= "incompatible";
114 vers
= "unversioned";
119 cout
<< "version status: " << vers
<< endl
;
121 if (version_name
.size()
122 && (version_status
== compatible
|| version_status
== incompatible
))
123 cout
<< version_name
<< endl
;
129 type_string
= "function";
132 type_string
= "object";
138 type_string
= "uncategorized";
141 type_string
= "<default>";
143 cout
<< "type: " << type_string
<< endl
;
145 if (type
== object
|| type
== tls
)
146 cout
<< "type size: " << size
<< endl
;
148 string status_string
;
152 status_string
= "added";
155 status_string
= "subtracted";
158 status_string
= "undesignated";
161 status_string
= "<default>";
163 cout
<< "status: " << status_string
<< endl
;
170 check_version(symbol
& test
, bool added
)
172 // Construct list of compatible versions.
173 typedef std::vector
<std::string
> compat_list
;
174 static compat_list known_versions
;
175 if (known_versions
.empty())
177 // NB: First version here must be the default version for this
178 // version of DT_SONAME.
179 known_versions
.push_back("GLIBCXX_3.4");
180 known_versions
.push_back("GLIBCXX_LDBL_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_LDBL_3.4.7");
189 known_versions
.push_back("GLIBCXX_3.4.8");
190 known_versions
.push_back("GLIBCXX_3.4.9");
191 known_versions
.push_back("GLIBCXX_3.4.10");
192 known_versions
.push_back("GLIBCXX_LDBL_3.4.10");
193 known_versions
.push_back("GLIBCXX_3.4.11");
194 known_versions
.push_back("GLIBCXX_3.4.12");
195 known_versions
.push_back("GLIBCXX_3.4.13");
196 known_versions
.push_back("GLIBCXX_3.4.14");
197 known_versions
.push_back("GLIBCXX_3.4.15");
198 known_versions
.push_back("GLIBCXX_3.4.16");
199 known_versions
.push_back("GLIBCXX_3.4.17");
200 known_versions
.push_back("GLIBCXX_3.4.18");
201 known_versions
.push_back("GLIBCXX_3.4.19");
202 known_versions
.push_back("GLIBCXX_3.4.20");
203 known_versions
.push_back("GLIBCXX_3.4.21");
204 known_versions
.push_back("GLIBCXX_LDBL_3.4.21");
205 known_versions
.push_back("GLIBCXX_3.4.22");
206 known_versions
.push_back("GLIBCXX_3.4.23");
207 known_versions
.push_back("GLIBCXX_3.4.24");
208 known_versions
.push_back("GLIBCXX_3.4.25");
209 known_versions
.push_back("GLIBCXX_3.4.26");
210 known_versions
.push_back("GLIBCXX_3.4.27");
211 known_versions
.push_back("GLIBCXX_3.4.28");
212 known_versions
.push_back("GLIBCXX_3.4.29");
213 known_versions
.push_back("GLIBCXX_LDBL_3.4.29");
214 known_versions
.push_back("GLIBCXX_3.4.30");
215 known_versions
.push_back("GLIBCXX_3.4.31");
216 known_versions
.push_back("GLIBCXX_3.4.32");
217 known_versions
.push_back("GLIBCXX_3.4.33");
218 known_versions
.push_back("GLIBCXX_3.4.34");
219 known_versions
.push_back("GLIBCXX_LDBL_3.4.31");
220 known_versions
.push_back("GLIBCXX_IEEE128_3.4.29");
221 known_versions
.push_back("GLIBCXX_IEEE128_3.4.30");
222 known_versions
.push_back("GLIBCXX_IEEE128_3.4.31");
223 known_versions
.push_back("CXXABI_1.3");
224 known_versions
.push_back("CXXABI_LDBL_1.3");
225 known_versions
.push_back("CXXABI_1.3.1");
226 known_versions
.push_back("CXXABI_1.3.2");
227 known_versions
.push_back("CXXABI_1.3.3");
228 known_versions
.push_back("CXXABI_1.3.4");
229 known_versions
.push_back("CXXABI_1.3.5");
230 known_versions
.push_back("CXXABI_1.3.6");
231 known_versions
.push_back("CXXABI_1.3.7");
232 known_versions
.push_back("CXXABI_1.3.8");
233 known_versions
.push_back("CXXABI_1.3.9");
234 known_versions
.push_back("CXXABI_1.3.10");
235 known_versions
.push_back("CXXABI_1.3.11");
236 known_versions
.push_back("CXXABI_1.3.12");
237 known_versions
.push_back("CXXABI_1.3.13");
238 known_versions
.push_back("CXXABI_1.3.14");
239 known_versions
.push_back("CXXABI_1.3.15");
240 known_versions
.push_back("CXXABI_IEEE128_1.3.13");
241 known_versions
.push_back("CXXABI_TM_1");
242 known_versions
.push_back("CXXABI_FLOAT128");
244 compat_list::iterator begin
= known_versions
.begin();
245 compat_list::iterator end
= known_versions
.end();
247 // Check for compatible version.
248 if (test
.version_name
.size())
250 compat_list::iterator it1
= find(begin
, end
, test
.version_name
);
251 compat_list::iterator it2
= find(begin
, end
, test
.name
);
253 test
.version_status
= symbol::compatible
;
255 test
.version_status
= symbol::incompatible
;
257 // Check that added symbols are added in the latest pre-release version.
258 bool latestp
= (test
.version_name
== "GLIBCXX_3.4.34"
259 || test
.version_name
== "CXXABI_1.3.16"
260 || test
.version_name
== "CXXABI_FLOAT128"
261 || test
.version_name
== "CXXABI_TM_1");
262 if (added
&& !latestp
)
263 test
.version_status
= symbol::incompatible
;
265 // Check that long double compatibility symbols demangled as
266 // __float128 and regular __float128 symbols are put into some _LDBL_
267 // or _FLOAT128 version name.
268 if (added
&& test
.demangled_name
.find("__float128") != std::string::npos
269 && test
.demangled_name
.find("std::__cxx11::") != 0)
271 if (test
.version_name
.find("_LDBL_") == std::string::npos
272 && test
.version_name
.find("_FLOAT128") == std::string::npos
273 && test
.version_name
.find("_IEEE128") == std::string::npos
)
274 test
.version_status
= symbol::incompatible
;
277 // Check that IEEE128 long double compatibility symbols demangled as
278 // __ieee128 are put into some _LDBL_IEEE version name.
279 // XXX is this right? might not want *everything* for __ieee128 in here.
280 if (added
&& test
.demangled_name
.find("__ieee128") != std::string::npos
)
282 if (test
.version_name
.find("_IEEE128") == std::string::npos
)
283 test
.version_status
= symbol::incompatible
;
286 // Check for weak label.
287 if (it1
== end
&& it2
== end
)
288 test
.version_status
= symbol::incompatible
;
293 // version as compatible
300 // New version labels are ok. The rest are not.
301 compat_list::iterator it2
= find(begin
, end
, test
.name
);
303 test
.version_status
= symbol::compatible
;
305 test
.version_status
= symbol::incompatible
;
308 return test
.version_status
== symbol::compatible
;
312 check_compatible(symbol
& lhs
, symbol
& rhs
, bool verbose
)
315 const char tab
= '\t';
317 // Check to see if symbol_objects are compatible.
318 if (lhs
.type
!= rhs
.type
)
322 cout
<< tab
<< "incompatible types" << endl
;
325 if (lhs
.name
!= rhs
.name
)
329 cout
<< tab
<< "incompatible names" << endl
;
332 if (lhs
.size
!= rhs
.size
)
337 cout
<< tab
<< "incompatible sizes" << endl
;
338 cout
<< tab
<< lhs
.size
<< endl
;
339 cout
<< tab
<< rhs
.size
<< endl
;
343 if (lhs
.version_name
!= rhs
.version_name
344 && !check_version(lhs
) && !check_version(rhs
))
349 cout
<< tab
<< "incompatible versions" << endl
;
350 cout
<< tab
<< lhs
.version_name
<< endl
;
351 cout
<< tab
<< rhs
.version_name
<< endl
;
363 has_symbol(const string
& name
, const symbols
& s
) throw()
364 { return s
.find(name
) != s
.end(); }
367 get_symbol(const string
& name
, const symbols
& s
)
369 symbols::const_iterator i
= s
.find(name
);
377 os
<< "get_symbol failed for symbol " << name
;
378 __throw_logic_error(os
.str().c_str());
383 examine_symbol(const char* name
, const char* file
)
385 symbols s
= create_symbols(file
);
386 const symbol
& sym
= get_symbol(name
, s
);
391 compare_symbols(const char* baseline_file
, const char* test_file
,
394 // Input both lists of symbols into container.
395 symbols baseline
= create_symbols(baseline_file
);
396 symbols test
= create_symbols(test_file
);
398 // Sanity check results.
399 if (!baseline
.size() || !test
.size())
401 cerr
<< "Problems parsing the list of exported symbols." << endl
;
405 // Check to see if any long double compatibility symbols are produced.
406 bool ld_version_found(false);
407 symbols::iterator
li(test
.begin());
408 while (!ld_version_found
&& li
!= test
.end())
410 if (li
->second
.version_name
.find("_LDBL_") != std::string::npos
)
411 ld_version_found
= true;
415 // Similarly for IEEE128 symbols.
416 bool ieee_version_found(false);
417 for (li
= test
.begin(); li
!= test
.end(); ++li
)
418 if (li
->second
.version_name
.find("_IEEE128_") != std::string::npos
)
420 ieee_version_found
= true;
425 // Assuming all baseline names and test names are both unique w/ no
428 // The names added to missing_names are baseline names not found in
430 // -> symbols that have been deleted.
432 // The names added to added_names are test names not in
434 // -> symbols that have been added.
435 typedef std::vector
<std::string
> symbol_names
;
436 symbol_names shared_names
;
437 symbol_names missing_names
;
438 symbol_names added_names
;
439 for (li
= test
.begin(); li
!= test
.end(); ++li
)
440 added_names
.push_back(li
->first
);
442 for (symbols::iterator i
= baseline
.begin(); i
!= baseline
.end(); ++i
)
444 string
name(i
->first
);
445 symbol_names::iterator end
= added_names
.end();
446 symbol_names::iterator it
= find(added_names
.begin(), end
, name
);
450 shared_names
.push_back(name
);
451 added_names
.erase(it
);
455 // Iff no test long double compatibility symbols at all and the symbol
456 // missing is a baseline long double compatibility symbol, skip.
457 string
version_name(i
->second
.version_name
.size()
458 ? i
->second
.version_name
: i
->first
);
459 bool base_ld(version_name
.find("_LDBL_") != std::string::npos
);
460 bool base_ieee(version_name
.find("_IEEE128_") != std::string::npos
);
461 if ((!base_ld
|| (base_ld
&& ld_version_found
))
462 && (!base_ieee
|| (base_ieee
&& ieee_version_found
)))
463 missing_names
.push_back(name
);
467 // Fill out list of incompatible symbols.
468 typedef pair
<symbol
, symbol
> symbol_pair
;
469 vector
<symbol_pair
> incompatible
;
471 // Fill out list of undesignated symbols.
472 vector
<symbol
> undesignated
;
474 // Check missing names for compatibility.
475 for (size_t j
= 0; j
< missing_names
.size(); ++j
)
477 symbol
& sbase
= baseline
[missing_names
[j
]];
478 sbase
.status
= symbol::subtracted
;
479 incompatible
.push_back(symbol_pair(sbase
, sbase
));
482 // Check shared names for compatibility.
483 const symbol_names::size_type shared_size
= shared_names
.size();
484 for (size_t k
= 0; k
< shared_size
; ++k
)
486 symbol
& sbase
= baseline
[shared_names
[k
]];
487 symbol
& stest
= test
[shared_names
[k
]];
488 stest
.status
= symbol::existing
;
489 if (!check_compatible(sbase
, stest
))
490 incompatible
.push_back(symbol_pair(sbase
, stest
));
493 // Check added names for compatibility.
494 const symbol_names::size_type added_size
= added_names
.size();
495 for (size_t l
= 0; l
< added_size
; ++l
)
497 symbol
& stest
= test
[added_names
[l
]];
499 // Mark TLS as undesignated, remove from added.
500 if (stest
.type
== symbol::tls
)
502 stest
.status
= symbol::undesignated
;
503 if (!check_version(stest
, false))
504 incompatible
.push_back(symbol_pair(stest
, stest
));
506 undesignated
.push_back(stest
);
508 // See PR libstdc++/103407 - abi_check FAILs on Solaris
509 else if (stest
.type
== symbol::function
510 && stest
.name
.compare(0, 23, "_ZSt10from_charsPKcS0_R") == 0
511 && stest
.name
.find_first_of("def", 23) == 23
512 && (stest
.version_name
== "GLIBCXX_3.4.29"
513 || stest
.version_name
== "GLIBCXX_3.4.30"))
515 stest
.status
= symbol::undesignated
;
516 if (!check_version(stest
, false))
517 incompatible
.push_back(symbol_pair(stest
, stest
));
519 undesignated
.push_back(stest
);
523 stest
.status
= symbol::added
;
524 if (!check_version(stest
, true))
525 incompatible
.push_back(symbol_pair(stest
, stest
));
529 // Normalize added names and undesignated names.
530 const size_t undesignated_size
= undesignated
.size();
531 for (size_t l
= 0; l
< undesignated_size
; ++l
)
533 symbol
& sundes
= undesignated
[l
];
534 symbol_names::iterator end
= added_names
.end();
535 symbol_names::iterator it
= find(added_names
.begin(), end
, sundes
.name
);
539 added_names
.erase(it
);
542 __throw_runtime_error(sundes
.name
.c_str());
547 if (verbose
&& added_names
.size())
549 cout
<< endl
<< added_names
.size() << " added symbols " << endl
;
550 for (size_t j
= 0; j
< added_names
.size() ; ++j
)
553 test
[added_names
[j
]].print();
557 if (verbose
&& missing_names
.size())
559 cout
<< endl
<< missing_names
.size() << " missing symbols " << endl
;
560 for (size_t j
= 0; j
< missing_names
.size() ; ++j
)
563 baseline
[missing_names
[j
]].print();
567 if (verbose
&& undesignated
.size())
569 cout
<< endl
<< undesignated
.size() << " undesignated symbols " << endl
;
570 for (size_t j
= 0; j
< undesignated
.size() ; ++j
)
572 // First, print index.
575 // Second, report name.
576 symbol
& s
= undesignated
[j
];
581 if (verbose
&& incompatible
.size())
583 cout
<< endl
<< incompatible
.size() << " incompatible symbols " << endl
;
584 for (size_t j
= 0; j
< incompatible
.size() ; ++j
)
586 // First, print index.
589 // Second, report name.
590 symbol
& sbase
= incompatible
[j
].first
;
591 symbol
& stest
= incompatible
[j
].second
;
594 // Third, report reason or reasons incompatible.
595 check_compatible(sbase
, stest
, true);
599 cout
<< "\n\t\t==== libstdc++-v3 check-abi Summary ====" << endl
;
601 cout
<< "# of added symbols:\t\t " << added_names
.size() << endl
;
602 cout
<< "# of missing symbols:\t\t " << missing_names
.size() << endl
;
603 cout
<< "# of undesignated symbols:\t " << undesignated
.size() << endl
;
604 cout
<< "# of incompatible symbols:\t " << incompatible
.size() << endl
;
606 cout
<< "using: " << baseline_file
<< endl
;
608 return !(missing_names
.size() || incompatible
.size());
613 create_symbols(const char* file
)
619 // Organize file data into an associated container (symbols) of symbol
620 // objects mapped to mangled names without versioning
624 while (getline(ifs
, line
).good())
635 os
<< "create_symbols failed for file " << file
;
636 __throw_runtime_error(os
.str().c_str());
643 demangle(const std::string
& mangled
)
646 if (mangled
[0] != '_' || mangled
[1] != 'Z')
648 // This is not a mangled symbol, thus has "C" linkage.
653 // Use __cxa_demangle to demangle.
655 char* ptr
= abi::__cxa_demangle(mangled
.c_str(), 0, 0, &status
);
666 name
= "error code = 0: success";
669 name
= "error code = -1: memory allocation failure";
672 name
= "error code = -2: invalid mangled name";
675 name
= "error code = -3: invalid arguments";
678 name
= "error code unknown - who knows what happened";