testsuite_abi_check.cc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. // Blame subsequent hacks on Loren J. Rittle <ljrittle@acm.org>, Phil
  16. // Edwards <pme@gcc.gnu.org>, and a cast of dozens at libstdc++@gcc.gnu.org.
  17. #include "testsuite_abi.h"
  18. #include <iostream>
  19. #include <cstdlib>
  20. #include <unistd.h> // for access(2)
  21. int
  22. main(int argc, char** argv)
  23. {
  24. using namespace std;
  25. // Get arguments. (Heading towards getopt_long, I can feel it.)
  26. string argv1 = argc > 1 ? argv[1] : "";
  27. if (argv1 == "--help" || argc < 4)
  28. {
  29. cerr << "usage: abi_check --check current baseline\n"
  30. " --check-verbose current baseline\n"
  31. " --examine symbol current\n"
  32. " --help\n"
  33. "\n"
  34. "All arguments are string literals.\n"
  35. "CURRENT is a file generated byextract_symvers.\n"
  36. "BASELINE is a file from config/abi.\n"
  37. "SYMBOL is a mangled name.\n"
  38. << endl;
  39. exit(1);
  40. }
  41. if (argv1.find("--check") != string::npos)
  42. {
  43. bool verbose = false;
  44. if (argv1 == "--check-verbose")
  45. verbose = true;
  46. // Quick sanity/setup check for arguments.
  47. const char* test_file = argv[2];
  48. const char* baseline_file = argv[3];
  49. if (access(test_file, R_OK) != 0)
  50. {
  51. cerr << "Cannot read symbols file " << test_file
  52. << ", did you forget to build first?" << endl;
  53. exit(1);
  54. }
  55. if (access(baseline_file, R_OK) != 0)
  56. {
  57. cerr << "Cannot read baseline file " << baseline_file << endl;
  58. exit(1);
  59. }
  60. if (!compare_symbols(baseline_file, test_file, verbose))
  61. exit (1);
  62. }
  63. if (argv1 == "--examine")
  64. {
  65. const char* file = argv[3];
  66. if (access(file, R_OK) != 0)
  67. {
  68. cerr << "Cannot read symbol file " << file << endl;
  69. exit(1);
  70. }
  71. examine_symbol(argv[2], file);
  72. }
  73. return 0;
  74. }