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