testsuite_abi.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // -*- C++ -*-
  2. // Copyright (C) 2004-2022 Free Software Foundation, Inc.
  3. // This library is free software; you can redistribute it and/or
  4. // modify it under the terms of the GNU General Public License as
  5. // published by the Free Software Foundation; either version 3, or (at
  6. // your option) any later version.
  7. // This library is distributed in the hope that it will be useful, but
  8. // WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. // General Public License for more details.
  11. // You should have received a copy of the GNU General Public License
  12. // along with this library; see the file COPYING3. If not see
  13. // <http://www.gnu.org/licenses/>.
  14. // Benjamin Kosnik <bkoz@redhat.com>
  15. #include <string>
  16. #include <stdexcept>
  17. #include <vector>
  18. #include <locale>
  19. #if __cplusplus >= 201103L
  20. # include <unordered_map>
  21. # ifdef _GLIBCXX_DEBUG
  22. namespace unord = std::_GLIBCXX_STD_C;
  23. # else
  24. namespace unord = std;
  25. # endif
  26. #else
  27. # include <tr1/unordered_map>
  28. namespace unord = std::tr1;
  29. #endif
  30. #include <cxxabi.h>
  31. // Encapsulates symbol characteristics.
  32. struct symbol
  33. {
  34. enum category { function, object, tls, uncategorized };
  35. enum designation { existing, added, subtracted, undesignated };
  36. enum version { none, compatible, incompatible, unversioned };
  37. enum compatibility
  38. {
  39. compat_type = 1,
  40. compat_name = 2,
  41. compat_size = 4,
  42. compat_version = 8
  43. };
  44. category type;
  45. std::string name;
  46. std::string raw_name; // Name with versioning info still attached.
  47. std::string demangled_name;
  48. int size;
  49. std::string version_name;
  50. version version_status;
  51. designation status;
  52. symbol()
  53. : type(uncategorized), size(0), version_status(unversioned),
  54. status(undesignated) { }
  55. symbol(const symbol& other)
  56. : type(other.type), name(other.name), demangled_name(other.demangled_name),
  57. size(other.size), version_name(other.version_name),
  58. version_status(other.version_status), status(other.status) { }
  59. void
  60. print() const;
  61. void
  62. init(std::string& data);
  63. };
  64. // Map type between symbol names and full symbol info.
  65. typedef unord::unordered_map<std::string, symbol> symbols;
  66. // Check.
  67. bool
  68. check_version(symbol& test, bool added = false);
  69. bool
  70. check_compatible(symbol& lhs, symbol& rhs, bool verbose = false);
  71. // Examine.
  72. bool
  73. has_symbol(const std::string& mangled, const symbols& list) throw();
  74. const symbol&
  75. get_symbol(const std::string& mangled, const symbols& list);
  76. extern "C" void
  77. examine_symbol(const char* name, const char* file);
  78. extern "C" int
  79. compare_symbols(const char* baseline_file, const char* test_file, bool verb);
  80. // Util.
  81. symbols
  82. create_symbols(const char* file);
  83. std::string
  84. demangle(const std::string& mangled);