1 // errors.cc -- handle errors for gold
3 // Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
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), error_count_(0),
43 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 if (this->lock_ == NULL && parameters->options_valid())
57 this->lock_ = new Lock;
58 return this->lock_ != NULL;
61 // Increment a counter, holding the lock if available.
64 Errors::increment_counter(int *counter)
66 if (!this->initialize_lock())
68 // The lock does not exist, which means that we don't need it.
73 Hold_lock h(*this->lock_);
78 // Report a fatal error.
81 Errors::fatal(const char* format, va_list args)
83 fprintf(stderr, "%s: ", this->program_name_);
84 vfprintf(stderr, format, args);
92 Errors::error(const char* format, va_list args)
94 fprintf(stderr, "%s: ", this->program_name_);
95 vfprintf(stderr, format, args);
98 this->increment_counter(&this->error_count_);
104 Errors::warning(const char* format, va_list args)
106 fprintf(stderr, _("%s: warning: "), this->program_name_);
107 vfprintf(stderr, format, args);
110 this->increment_counter(&this->warning_count_);
113 // Print an informational message.
116 Errors::info(const char* format, va_list args)
118 vfprintf(stderr, format, args);
122 // Report an error at a reloc location.
124 template<int size, bool big_endian>
126 Errors::error_at_location(const Relocate_info<size, big_endian>* relinfo,
127 size_t relnum, off_t reloffset,
128 const char* format, va_list args)
130 fprintf(stderr, "%s: %s: ", this->program_name_,
131 relinfo->location(relnum, reloffset).c_str());
132 vfprintf(stderr, format, args);
135 this->increment_counter(&this->error_count_);
138 // Report a warning at a reloc location.
140 template<int size, bool big_endian>
142 Errors::warning_at_location(const Relocate_info<size, big_endian>* relinfo,
143 size_t relnum, off_t reloffset,
144 const char* format, va_list args)
146 fprintf(stderr, _("%s: %s: warning: "), this->program_name_,
147 relinfo->location(relnum, reloffset).c_str());
148 vfprintf(stderr, format, args);
151 this->increment_counter(&this->warning_count_);
154 // Issue an undefined symbol error.
156 template<int size, bool big_endian>
158 Errors::undefined_symbol(const Symbol* sym,
159 const Relocate_info<size, big_endian>* relinfo,
160 size_t relnum, off_t reloffset)
162 bool initialized = this->initialize_lock();
163 gold_assert(initialized);
165 Hold_lock h(*this->lock_);
166 if (++this->undefined_symbols_[sym] >= max_undefined_error_report)
168 ++this->error_count_;
170 const char* const version = sym->version();
172 fprintf(stderr, _("%s: %s: undefined reference to '%s'\n"),
173 this->program_name_, relinfo->location(relnum, reloffset).c_str(),
174 sym->demangled_name().c_str());
176 fprintf(stderr, _("%s: %s: undefined reference to '%s', version '%s'\n"),
177 this->program_name_, relinfo->location(relnum, reloffset).c_str(),
178 sym->demangled_name().c_str(), version);
181 // Issue a debugging message.
184 Errors::debug(const char* format, ...)
186 fprintf(stderr, _("%s: "), this->program_name_);
189 va_start(args, format);
190 vfprintf(stderr, format, args);
196 // The functions which the rest of the code actually calls.
198 // Report a fatal error.
201 gold_fatal(const char* format, ...)
204 va_start(args, format);
205 parameters->errors()->fatal(format, args);
212 gold_error(const char* format, ...)
215 va_start(args, format);
216 parameters->errors()->error(format, args);
223 gold_warning(const char* format, ...)
226 va_start(args, format);
227 parameters->errors()->warning(format, args);
231 // Print an informational message.
234 gold_info(const char* format, ...)
237 va_start(args, format);
238 parameters->errors()->info(format, args);
242 // Report an error at a location.
244 template<int size, bool big_endian>
246 gold_error_at_location(const Relocate_info<size, big_endian>* relinfo,
247 size_t relnum, off_t reloffset,
248 const char* format, ...)
251 va_start(args, format);
252 parameters->errors()->error_at_location(relinfo, relnum, reloffset,
257 // Report a warning at a location.
259 template<int size, bool big_endian>
261 gold_warning_at_location(const Relocate_info<size, big_endian>* relinfo,
262 size_t relnum, off_t reloffset,
263 const char* format, ...)
266 va_start(args, format);
267 parameters->errors()->warning_at_location(relinfo, relnum, reloffset,
272 // Report an undefined symbol.
274 template<int size, bool big_endian>
276 gold_undefined_symbol(const Symbol* sym,
277 const Relocate_info<size, big_endian>* relinfo,
278 size_t relnum, off_t reloffset)
280 parameters->errors()->undefined_symbol(sym, relinfo, relnum, reloffset);
283 #ifdef HAVE_TARGET_32_LITTLE
286 gold_error_at_location<32, false>(const Relocate_info<32, false>* relinfo,
287 size_t relnum, off_t reloffset,
288 const char* format, ...);
291 #ifdef HAVE_TARGET_32_BIG
294 gold_error_at_location<32, true>(const Relocate_info<32, true>* relinfo,
295 size_t relnum, off_t reloffset,
296 const char* format, ...);
299 #ifdef HAVE_TARGET_64_LITTLE
302 gold_error_at_location<64, false>(const Relocate_info<64, false>* relinfo,
303 size_t relnum, off_t reloffset,
304 const char* format, ...);
307 #ifdef HAVE_TARGET_64_BIG
310 gold_error_at_location<64, true>(const Relocate_info<64, true>* relinfo,
311 size_t relnum, off_t reloffset,
312 const char* format, ...);
315 #ifdef HAVE_TARGET_32_LITTLE
318 gold_warning_at_location<32, false>(const Relocate_info<32, false>* relinfo,
319 size_t relnum, off_t reloffset,
320 const char* format, ...);
323 #ifdef HAVE_TARGET_32_BIG
326 gold_warning_at_location<32, true>(const Relocate_info<32, true>* relinfo,
327 size_t relnum, off_t reloffset,
328 const char* format, ...);
331 #ifdef HAVE_TARGET_64_LITTLE
334 gold_warning_at_location<64, false>(const Relocate_info<64, false>* relinfo,
335 size_t relnum, off_t reloffset,
336 const char* format, ...);
339 #ifdef HAVE_TARGET_64_BIG
342 gold_warning_at_location<64, true>(const Relocate_info<64, true>* relinfo,
343 size_t relnum, off_t reloffset,
344 const char* format, ...);
347 #ifdef HAVE_TARGET_32_LITTLE
350 gold_undefined_symbol<32, false>(const Symbol* sym,
351 const Relocate_info<32, false>* relinfo,
352 size_t relnum, off_t reloffset);
355 #ifdef HAVE_TARGET_32_BIG
358 gold_undefined_symbol<32, true>(const Symbol* sym,
359 const Relocate_info<32, true>* relinfo,
360 size_t relnum, off_t reloffset);
363 #ifdef HAVE_TARGET_64_LITTLE
366 gold_undefined_symbol<64, false>(const Symbol* sym,
367 const Relocate_info<64, false>* relinfo,
368 size_t relnum, off_t reloffset);
371 #ifdef HAVE_TARGET_64_BIG
374 gold_undefined_symbol<64, true>(const Symbol* sym,
375 const Relocate_info<64, true>* relinfo,
376 size_t relnum, off_t reloffset);
379 } // End namespace gold.