1 // errors.cc -- handle errors for gold
3 // Copyright 2006, 2007 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_(), error_count_(0), warning_count_(0),
47 // Report a fatal error.
50 Errors::fatal(const char* format, va_list args)
52 fprintf(stderr, "%s: ", this->program_name_);
53 vfprintf(stderr, format, args);
61 Errors::error(const char* format, va_list args)
63 fprintf(stderr, "%s: ", this->program_name_);
64 vfprintf(stderr, format, args);
67 Hold_lock h(this->lock_);
75 Errors::warning(const char* format, va_list args)
77 fprintf(stderr, _("%s: warning: "), this->program_name_);
78 vfprintf(stderr, format, args);
81 Hold_lock h(this->lock_);
82 ++this->warning_count_;
86 // Report an error at a reloc location.
88 template<int size, bool big_endian>
90 Errors::error_at_location(const Relocate_info<size, big_endian>* relinfo,
91 size_t relnum, off_t reloffset,
92 const char* format, va_list args)
94 fprintf(stderr, "%s: %s: ", this->program_name_,
95 relinfo->location(relnum, reloffset).c_str());
96 vfprintf(stderr, format, args);
99 Hold_lock h(this->lock_);
100 ++this->error_count_;
104 // Report a warning at a reloc location.
106 template<int size, bool big_endian>
108 Errors::warning_at_location(const Relocate_info<size, big_endian>* relinfo,
109 size_t relnum, off_t reloffset,
110 const char* format, va_list args)
112 fprintf(stderr, _("%s: %s: warning: "), this->program_name_,
113 relinfo->location(relnum, reloffset).c_str());
114 vfprintf(stderr, format, args);
117 Hold_lock h(this->lock_);
118 ++this->warning_count_;
122 // Issue an undefined symbol error.
124 template<int size, bool big_endian>
126 Errors::undefined_symbol(const Symbol* sym,
127 const Relocate_info<size, big_endian>* relinfo,
128 size_t relnum, off_t reloffset)
131 Hold_lock h(this->lock_);
132 if (++this->undefined_symbols_[sym] >= max_undefined_error_report)
134 ++this->error_count_;
136 fprintf(stderr, _("%s: %s: undefined reference to '%s'\n"),
137 this->program_name_, relinfo->location(relnum, reloffset).c_str(),
142 // The functions which the rest of the code actually calls.
144 // Report a fatal error.
147 gold_fatal(const char* format, ...)
150 va_start(args, format);
151 parameters->errors()->fatal(format, args);
158 gold_error(const char* format, ...)
161 va_start(args, format);
162 parameters->errors()->error(format, args);
169 gold_warning(const char* format, ...)
172 va_start(args, format);
173 parameters->errors()->warning(format, args);
177 // Report an error at a location.
179 template<int size, bool big_endian>
181 gold_error_at_location(const Relocate_info<size, big_endian>* relinfo,
182 size_t relnum, off_t reloffset,
183 const char* format, ...)
186 va_start(args, format);
187 parameters->errors()->error_at_location(relinfo, relnum, reloffset,
192 // Report a warning at a location.
194 template<int size, bool big_endian>
196 gold_warning_at_location(const Relocate_info<size, big_endian>* relinfo,
197 size_t relnum, off_t reloffset,
198 const char* format, ...)
201 va_start(args, format);
202 parameters->errors()->warning_at_location(relinfo, relnum, reloffset,
207 // Report an undefined symbol.
209 template<int size, bool big_endian>
211 gold_undefined_symbol(const Symbol* sym,
212 const Relocate_info<size, big_endian>* relinfo,
213 size_t relnum, off_t reloffset)
215 parameters->errors()->undefined_symbol(sym, relinfo, relnum, reloffset);
218 #ifdef HAVE_TARGET_32_LITTLE
221 gold_error_at_location<32, false>(const Relocate_info<32, false>* relinfo,
222 size_t relnum, off_t reloffset,
223 const char* format, ...);
226 #ifdef HAVE_TARGET_32_BIG
229 gold_error_at_location<32, true>(const Relocate_info<32, true>* relinfo,
230 size_t relnum, off_t reloffset,
231 const char* format, ...);
234 #ifdef HAVE_TARGET_64_LITTLE
237 gold_error_at_location<64, false>(const Relocate_info<64, false>* relinfo,
238 size_t relnum, off_t reloffset,
239 const char* format, ...);
242 #ifdef HAVE_TARGET_64_BIG
245 gold_error_at_location<64, true>(const Relocate_info<64, true>* relinfo,
246 size_t relnum, off_t reloffset,
247 const char* format, ...);
250 #ifdef HAVE_TARGET_32_LITTLE
253 gold_warning_at_location<32, false>(const Relocate_info<32, false>* relinfo,
254 size_t relnum, off_t reloffset,
255 const char* format, ...);
258 #ifdef HAVE_TARGET_32_BIG
261 gold_warning_at_location<32, true>(const Relocate_info<32, true>* relinfo,
262 size_t relnum, off_t reloffset,
263 const char* format, ...);
266 #ifdef HAVE_TARGET_64_LITTLE
269 gold_warning_at_location<64, false>(const Relocate_info<64, false>* relinfo,
270 size_t relnum, off_t reloffset,
271 const char* format, ...);
274 #ifdef HAVE_TARGET_64_BIG
277 gold_warning_at_location<64, true>(const Relocate_info<64, true>* relinfo,
278 size_t relnum, off_t reloffset,
279 const char* format, ...);
282 #ifdef HAVE_TARGET_32_LITTLE
285 gold_undefined_symbol<32, false>(const Symbol* sym,
286 const Relocate_info<32, false>* relinfo,
287 size_t relnum, off_t reloffset);
290 #ifdef HAVE_TARGET_32_BIG
293 gold_undefined_symbol<32, true>(const Symbol* sym,
294 const Relocate_info<32, true>* relinfo,
295 size_t relnum, off_t reloffset);
298 #ifdef HAVE_TARGET_64_LITTLE
301 gold_undefined_symbol<64, false>(const Symbol* sym,
302 const Relocate_info<64, false>* relinfo,
303 size_t relnum, off_t reloffset);
306 #ifdef HAVE_TARGET_64_BIG
309 gold_undefined_symbol<64, true>(const Symbol* sym,
310 const Relocate_info<64, true>* relinfo,
311 size_t relnum, off_t reloffset);
314 } // End namespace gold.