1 // errors.cc -- handle errors for gold
3 // Copyright (C) 2006-2014 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
28 #include "gold-threads.h"
29 #include "parameters.h"
39 const int Errors::max_undefined_error_report;
41 Errors::Errors(const char* program_name)
42 : program_name_(program_name), lock_(NULL), initialize_lock_(&this->lock_),
43 error_count_(0), warning_count_(0), undefined_symbols_()
47 // Initialize the lock_ field. If we have not yet processed the
48 // parameters, then we can't initialize, since we don't yet know
49 // whether we are using threads. That is OK, since if we haven't
50 // processed the parameters, we haven't created any threads, and we
51 // don't need a lock. Return true if the lock is now initialized.
54 Errors::initialize_lock()
56 return this->initialize_lock_.initialize();
59 // Increment a counter, holding the lock if available.
62 Errors::increment_counter(int *counter)
64 if (!this->initialize_lock())
66 // The lock does not exist, which means that we don't need it.
71 Hold_lock h(*this->lock_);
76 // Report a fatal error.
79 Errors::fatal(const char* format, va_list args)
81 fprintf(stderr, _("%s: fatal error: "), this->program_name_);
82 vfprintf(stderr, format, args);
87 // Report a fallback error.
90 Errors::fallback(const char* format, va_list args)
92 fprintf(stderr, _("%s: fatal error: "), this->program_name_);
93 vfprintf(stderr, format, args);
95 gold_exit(GOLD_FALLBACK);
101 Errors::error(const char* format, va_list args)
103 fprintf(stderr, _("%s: error: "), this->program_name_);
104 vfprintf(stderr, format, args);
107 this->increment_counter(&this->error_count_);
113 Errors::warning(const char* format, va_list args)
115 fprintf(stderr, _("%s: warning: "), this->program_name_);
116 vfprintf(stderr, format, args);
119 this->increment_counter(&this->warning_count_);
122 // Print an informational message.
125 Errors::info(const char* format, va_list args)
127 vfprintf(stderr, format, args);
131 // Report an error at a reloc location.
133 template<int size, bool big_endian>
135 Errors::error_at_location(const Relocate_info<size, big_endian>* relinfo,
136 size_t relnum, off_t reloffset,
137 const char* format, va_list args)
139 fprintf(stderr, _("%s: error: "),
140 relinfo->location(relnum, reloffset).c_str());
141 vfprintf(stderr, format, args);
144 this->increment_counter(&this->error_count_);
147 // Report a warning at a reloc location.
149 template<int size, bool big_endian>
151 Errors::warning_at_location(const Relocate_info<size, big_endian>* relinfo,
152 size_t relnum, off_t reloffset,
153 const char* format, va_list args)
155 fprintf(stderr, _("%s: warning: "),
156 relinfo->location(relnum, reloffset).c_str());
157 vfprintf(stderr, format, args);
160 this->increment_counter(&this->warning_count_);
163 // Issue an undefined symbol error with a caller-supplied location string.
166 Errors::undefined_symbol(const Symbol* sym, const std::string& location)
168 bool initialized = this->initialize_lock();
169 gold_assert(initialized);
173 Hold_lock h(*this->lock_);
174 if (++this->undefined_symbols_[sym] >= max_undefined_error_report)
176 if (parameters->options().warn_unresolved_symbols())
178 ++this->warning_count_;
183 ++this->error_count_;
188 const char* const version = sym->version();
190 fprintf(stderr, _("%s: %s: undefined reference to '%s'\n"),
191 location.c_str(), zmsg, sym->demangled_name().c_str());
194 _("%s: %s: undefined reference to '%s', version '%s'\n"),
195 location.c_str(), zmsg, sym->demangled_name().c_str(), version);
197 if (sym->is_cxx_vtable())
198 gold_info(_("%s: the vtable symbol may be undefined because "
199 "the class is missing its key function"),
203 // Issue a debugging message.
206 Errors::debug(const char* format, ...)
208 fprintf(stderr, _("%s: "), this->program_name_);
211 va_start(args, format);
212 vfprintf(stderr, format, args);
218 // The functions which the rest of the code actually calls.
220 // Report a fatal error.
223 gold_fatal(const char* format, ...)
226 va_start(args, format);
227 parameters->errors()->fatal(format, args);
231 // Report a fallback error.
234 gold_fallback(const char* format, ...)
237 va_start(args, format);
238 parameters->errors()->fallback(format, args);
245 gold_error(const char* format, ...)
248 va_start(args, format);
249 parameters->errors()->error(format, args);
256 gold_warning(const char* format, ...)
259 va_start(args, format);
260 parameters->errors()->warning(format, args);
264 // Print an informational message.
267 gold_info(const char* format, ...)
270 va_start(args, format);
271 parameters->errors()->info(format, args);
275 // Report an error at a location.
277 template<int size, bool big_endian>
279 gold_error_at_location(const Relocate_info<size, big_endian>* relinfo,
280 size_t relnum, off_t reloffset,
281 const char* format, ...)
284 va_start(args, format);
285 parameters->errors()->error_at_location(relinfo, relnum, reloffset,
290 // Report a warning at a location.
292 template<int size, bool big_endian>
294 gold_warning_at_location(const Relocate_info<size, big_endian>* relinfo,
295 size_t relnum, off_t reloffset,
296 const char* format, ...)
299 va_start(args, format);
300 parameters->errors()->warning_at_location(relinfo, relnum, reloffset,
305 // Report an undefined symbol.
308 gold_undefined_symbol(const Symbol* sym)
310 parameters->errors()->undefined_symbol(sym, sym->object()->name().c_str());
313 // Report an undefined symbol at a reloc location
315 template<int size, bool big_endian>
317 gold_undefined_symbol_at_location(const Symbol* sym,
318 const Relocate_info<size, big_endian>* relinfo,
319 size_t relnum, off_t reloffset)
321 parameters->errors()->undefined_symbol(sym,
322 relinfo->location(relnum, reloffset));
325 #ifdef HAVE_TARGET_32_LITTLE
328 gold_error_at_location<32, false>(const Relocate_info<32, false>* relinfo,
329 size_t relnum, off_t reloffset,
330 const char* format, ...);
333 #ifdef HAVE_TARGET_32_BIG
336 gold_error_at_location<32, true>(const Relocate_info<32, true>* relinfo,
337 size_t relnum, off_t reloffset,
338 const char* format, ...);
341 #ifdef HAVE_TARGET_64_LITTLE
344 gold_error_at_location<64, false>(const Relocate_info<64, false>* relinfo,
345 size_t relnum, off_t reloffset,
346 const char* format, ...);
349 #ifdef HAVE_TARGET_64_BIG
352 gold_error_at_location<64, true>(const Relocate_info<64, true>* relinfo,
353 size_t relnum, off_t reloffset,
354 const char* format, ...);
357 #ifdef HAVE_TARGET_32_LITTLE
360 gold_warning_at_location<32, false>(const Relocate_info<32, false>* relinfo,
361 size_t relnum, off_t reloffset,
362 const char* format, ...);
365 #ifdef HAVE_TARGET_32_BIG
368 gold_warning_at_location<32, true>(const Relocate_info<32, true>* relinfo,
369 size_t relnum, off_t reloffset,
370 const char* format, ...);
373 #ifdef HAVE_TARGET_64_LITTLE
376 gold_warning_at_location<64, false>(const Relocate_info<64, false>* relinfo,
377 size_t relnum, off_t reloffset,
378 const char* format, ...);
381 #ifdef HAVE_TARGET_64_BIG
384 gold_warning_at_location<64, true>(const Relocate_info<64, true>* relinfo,
385 size_t relnum, off_t reloffset,
386 const char* format, ...);
389 #ifdef HAVE_TARGET_32_LITTLE
392 gold_undefined_symbol_at_location<32, false>(
394 const Relocate_info<32, false>* relinfo,
395 size_t relnum, off_t reloffset);
398 #ifdef HAVE_TARGET_32_BIG
401 gold_undefined_symbol_at_location<32, true>(
403 const Relocate_info<32, true>* relinfo,
404 size_t relnum, off_t reloffset);
407 #ifdef HAVE_TARGET_64_LITTLE
410 gold_undefined_symbol_at_location<64, false>(
412 const Relocate_info<64, false>* relinfo,
413 size_t relnum, off_t reloffset);
416 #ifdef HAVE_TARGET_64_BIG
419 gold_undefined_symbol_at_location<64, true>(
421 const Relocate_info<64, true>* relinfo,
422 size_t relnum, off_t reloffset);
425 } // End namespace gold.