errors.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // errors.h -- handle errors for gold -*- C++ -*-
  2. // Copyright (C) 2006-2015 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 "gold-threads.h"
  21. namespace gold
  22. {
  23. class Symbol;
  24. template<int size, bool big_endian>
  25. struct Relocate_info;
  26. // This class handles errors for gold. There is a single instance
  27. // which is used by all threads. If and when we make the gold code
  28. // more amenable to being used in a library, we will make this an
  29. // abstract interface class, and expect the caller to provide their
  30. // own instantiation.
  31. class Errors
  32. {
  33. public:
  34. Errors(const char* program_name);
  35. // Report a fatal error. After printing the error, this must exit.
  36. void
  37. fatal(const char* format, va_list) ATTRIBUTE_NORETURN;
  38. // Report a fallback error. After printing the error, this must exit
  39. // with a special status code indicating that fallback to
  40. // --incremental-full is required.
  41. void
  42. fallback(const char* format, va_list) ATTRIBUTE_NORETURN;
  43. // Report an error and continue.
  44. void
  45. error(const char* format, va_list);
  46. // Report a warning and continue.
  47. void
  48. warning(const char* format, va_list);
  49. // Print an informational message and continue.
  50. void
  51. info(const char* format, va_list);
  52. // Report an error at a reloc location.
  53. template<int size, bool big_endian>
  54. void
  55. error_at_location(const Relocate_info<size, big_endian>* relinfo,
  56. size_t relnum, off_t reloffset,
  57. const char* format, va_list);
  58. // Report a warning at a reloc location.
  59. template<int size, bool big_endian>
  60. void
  61. warning_at_location(const Relocate_info<size, big_endian>* relinfo,
  62. size_t relnum, off_t reloffset,
  63. const char* format, va_list);
  64. // Issue an undefined symbol error. LOCATION is the location of
  65. // the error (typically an object file name or relocation info).
  66. void
  67. undefined_symbol(const Symbol* sym, const std::string& location);
  68. // Report a debugging message.
  69. void
  70. debug(const char* format, ...) ATTRIBUTE_PRINTF_2;
  71. // Return the number of errors.
  72. int
  73. error_count() const
  74. { return this->error_count_; }
  75. // Return the number of warnings.
  76. int
  77. warning_count() const
  78. { return this->warning_count_; }
  79. private:
  80. Errors(const Errors&);
  81. Errors& operator=(const Errors&);
  82. // Initialize the lock. We don't do this in the constructor because
  83. // lock initialization wants to know whether we are using threads or
  84. // not. This returns true if the lock is now initialized.
  85. bool
  86. initialize_lock();
  87. // Increment a counter, holding the lock.
  88. void
  89. increment_counter(int*);
  90. // The number of times we report an undefined symbol.
  91. static const int max_undefined_error_report = 5;
  92. // The name of the program.
  93. const char* program_name_;
  94. // This class can be accessed from multiple threads. This lock is
  95. // used to control access to the data structures.
  96. Lock* lock_;
  97. // Used to initialize the lock_ field exactly once.
  98. Initialize_lock initialize_lock_;
  99. // Numbers of errors reported.
  100. int error_count_;
  101. // Number of warnings reported.
  102. int warning_count_;
  103. // A map counting the numbers of times we have seen an undefined
  104. // symbol.
  105. Unordered_map<const Symbol*, int> undefined_symbols_;
  106. };
  107. } // End namespace gold.
  108. #endif // !defined(GOLD_ERRORS_H)