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