errors.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // errors.h -- handle errors for gold -*- C++ -*-
  2. // Copyright (C) 2006-2022 Free Software Foundation, Inc.
  3. // Written by Ian Lance Taylor <iant@google.com>.
  4. // This file is part of gold.
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 3 of the License, or
  8. // (at your option) any later version.
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. // MA 02110-1301, USA.
  17. #ifndef GOLD_ERRORS_H
  18. #define GOLD_ERRORS_H
  19. #include <cstdarg>
  20. #include <string>
  21. #include "gold-threads.h"
  22. namespace gold
  23. {
  24. class Symbol;
  25. template<int size, bool big_endian>
  26. struct Relocate_info;
  27. // This class handles errors for gold. There is a single instance
  28. // which is used by all threads. If and when we make the gold code
  29. // more amenable to being used in a library, we will make this an
  30. // abstract interface class, and expect the caller to provide their
  31. // own instantiation.
  32. class Errors
  33. {
  34. public:
  35. Errors(const char* program_name);
  36. // Report a fatal error. After printing the error, this must exit.
  37. void
  38. fatal(const char* format, va_list) ATTRIBUTE_NORETURN;
  39. // Report a fallback error. After printing the error, this must exit
  40. // with a special status code indicating that fallback to
  41. // --incremental-full is required.
  42. void
  43. fallback(const char* format, va_list) ATTRIBUTE_NORETURN;
  44. // Report an error and continue.
  45. void
  46. error(const char* format, va_list);
  47. // Report a warning and continue.
  48. void
  49. warning(const char* format, va_list);
  50. // Print an informational message and continue.
  51. void
  52. info(const char* format, va_list);
  53. // Print a trace message and continue.
  54. void
  55. trace(const char* format, va_list);
  56. // Report an error at a reloc location.
  57. template<int size, bool big_endian>
  58. void
  59. error_at_location(const Relocate_info<size, big_endian>* relinfo,
  60. size_t relnum, off_t reloffset,
  61. const char* format, va_list);
  62. // Report a warning at a reloc location.
  63. template<int size, bool big_endian>
  64. void
  65. warning_at_location(const Relocate_info<size, big_endian>* relinfo,
  66. size_t relnum, off_t reloffset,
  67. const char* format, va_list);
  68. // Issue an undefined symbol error. LOCATION is the location of
  69. // the error (typically an object file name or relocation info).
  70. void
  71. undefined_symbol(const Symbol* sym, const std::string& location);
  72. // Report a debugging message.
  73. void
  74. debug(const char* format, ...) ATTRIBUTE_PRINTF_2;
  75. // Return the number of errors.
  76. int
  77. error_count() const
  78. { return this->error_count_; }
  79. // Return the number of warnings.
  80. int
  81. warning_count() const
  82. { return this->warning_count_; }
  83. private:
  84. Errors(const Errors&);
  85. Errors& operator=(const Errors&);
  86. // Initialize the lock. We don't do this in the constructor because
  87. // lock initialization wants to know whether we are using threads or
  88. // not. This returns true if the lock is now initialized.
  89. bool
  90. initialize_lock();
  91. // Increment a counter, holding the lock.
  92. void
  93. increment_counter(int*);
  94. // The number of times we report an undefined symbol.
  95. static const int max_undefined_error_report = 5;
  96. // The name of the program.
  97. const char* program_name_;
  98. // This class can be accessed from multiple threads. This lock is
  99. // used to control access to the data structures.
  100. Lock* lock_;
  101. // Used to initialize the lock_ field exactly once.
  102. Initialize_lock initialize_lock_;
  103. // Numbers of errors reported.
  104. int error_count_;
  105. // Number of warnings reported.
  106. int warning_count_;
  107. // A map counting the numbers of times we have seen an undefined
  108. // symbol.
  109. Unordered_map<const Symbol*, int> undefined_symbols_;
  110. };
  111. } // End namespace gold.
  112. #endif // !defined(GOLD_ERRORS_H)