opcodes/
[binutils.git] / gold / errors.cc
blob3aa3ece89729bd2db535ac1a4fbbd41225dbb70b
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.
23 #include "gold.h"
25 #include <cstdarg>
26 #include <cstdio>
28 #include "gold-threads.h"
29 #include "parameters.h"
30 #include "object.h"
31 #include "symtab.h"
32 #include "errors.h"
34 namespace gold
37 // Class Errors.
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),
43 undefined_symbols_()
47 // Report a fatal error.
49 void
50 Errors::fatal(const char* format, va_list args)
52 fprintf(stderr, "%s: ", this->program_name_);
53 vfprintf(stderr, format, args);
54 fputc('\n', stderr);
55 gold_exit(false);
58 // Report an error.
60 void
61 Errors::error(const char* format, va_list args)
63 fprintf(stderr, "%s: ", this->program_name_);
64 vfprintf(stderr, format, args);
65 fputc('\n', stderr);
67 Hold_lock h(this->lock_);
68 ++this->error_count_;
72 // Report a warning.
74 void
75 Errors::warning(const char* format, va_list args)
77 fprintf(stderr, _("%s: warning: "), this->program_name_);
78 vfprintf(stderr, format, args);
79 fputc('\n', stderr);
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>
89 void
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);
97 fputc('\n', stderr);
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>
107 void
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);
115 fputc('\n', stderr);
117 Hold_lock h(this->lock_);
118 ++this->warning_count_;
122 // Issue an undefined symbol error.
124 template<int size, bool big_endian>
125 void
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)
133 return;
134 ++this->error_count_;
136 fprintf(stderr, _("%s: %s: undefined reference to '%s'\n"),
137 this->program_name_, relinfo->location(relnum, reloffset).c_str(),
138 sym->name());
142 // The functions which the rest of the code actually calls.
144 // Report a fatal error.
146 void
147 gold_fatal(const char* format, ...)
149 va_list args;
150 va_start(args, format);
151 parameters->errors()->fatal(format, args);
152 va_end(args);
155 // Report an error.
157 void
158 gold_error(const char* format, ...)
160 va_list args;
161 va_start(args, format);
162 parameters->errors()->error(format, args);
163 va_end(args);
166 // Report a warning.
168 void
169 gold_warning(const char* format, ...)
171 va_list args;
172 va_start(args, format);
173 parameters->errors()->warning(format, args);
174 va_end(args);
177 // Report an error at a location.
179 template<int size, bool big_endian>
180 void
181 gold_error_at_location(const Relocate_info<size, big_endian>* relinfo,
182 size_t relnum, off_t reloffset,
183 const char* format, ...)
185 va_list args;
186 va_start(args, format);
187 parameters->errors()->error_at_location(relinfo, relnum, reloffset,
188 format, args);
189 va_end(args);
192 // Report a warning at a location.
194 template<int size, bool big_endian>
195 void
196 gold_warning_at_location(const Relocate_info<size, big_endian>* relinfo,
197 size_t relnum, off_t reloffset,
198 const char* format, ...)
200 va_list args;
201 va_start(args, format);
202 parameters->errors()->warning_at_location(relinfo, relnum, reloffset,
203 format, args);
204 va_end(args);
207 // Report an undefined symbol.
209 template<int size, bool big_endian>
210 void
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
219 template
220 void
221 gold_error_at_location<32, false>(const Relocate_info<32, false>* relinfo,
222 size_t relnum, off_t reloffset,
223 const char* format, ...);
224 #endif
226 #ifdef HAVE_TARGET_32_BIG
227 template
228 void
229 gold_error_at_location<32, true>(const Relocate_info<32, true>* relinfo,
230 size_t relnum, off_t reloffset,
231 const char* format, ...);
232 #endif
234 #ifdef HAVE_TARGET_64_LITTLE
235 template
236 void
237 gold_error_at_location<64, false>(const Relocate_info<64, false>* relinfo,
238 size_t relnum, off_t reloffset,
239 const char* format, ...);
240 #endif
242 #ifdef HAVE_TARGET_64_BIG
243 template
244 void
245 gold_error_at_location<64, true>(const Relocate_info<64, true>* relinfo,
246 size_t relnum, off_t reloffset,
247 const char* format, ...);
248 #endif
250 #ifdef HAVE_TARGET_32_LITTLE
251 template
252 void
253 gold_warning_at_location<32, false>(const Relocate_info<32, false>* relinfo,
254 size_t relnum, off_t reloffset,
255 const char* format, ...);
256 #endif
258 #ifdef HAVE_TARGET_32_BIG
259 template
260 void
261 gold_warning_at_location<32, true>(const Relocate_info<32, true>* relinfo,
262 size_t relnum, off_t reloffset,
263 const char* format, ...);
264 #endif
266 #ifdef HAVE_TARGET_64_LITTLE
267 template
268 void
269 gold_warning_at_location<64, false>(const Relocate_info<64, false>* relinfo,
270 size_t relnum, off_t reloffset,
271 const char* format, ...);
272 #endif
274 #ifdef HAVE_TARGET_64_BIG
275 template
276 void
277 gold_warning_at_location<64, true>(const Relocate_info<64, true>* relinfo,
278 size_t relnum, off_t reloffset,
279 const char* format, ...);
280 #endif
282 #ifdef HAVE_TARGET_32_LITTLE
283 template
284 void
285 gold_undefined_symbol<32, false>(const Symbol* sym,
286 const Relocate_info<32, false>* relinfo,
287 size_t relnum, off_t reloffset);
288 #endif
290 #ifdef HAVE_TARGET_32_BIG
291 template
292 void
293 gold_undefined_symbol<32, true>(const Symbol* sym,
294 const Relocate_info<32, true>* relinfo,
295 size_t relnum, off_t reloffset);
296 #endif
298 #ifdef HAVE_TARGET_64_LITTLE
299 template
300 void
301 gold_undefined_symbol<64, false>(const Symbol* sym,
302 const Relocate_info<64, false>* relinfo,
303 size_t relnum, off_t reloffset);
304 #endif
306 #ifdef HAVE_TARGET_64_BIG
307 template
308 void
309 gold_undefined_symbol<64, true>(const Symbol* sym,
310 const Relocate_info<64, true>* relinfo,
311 size_t relnum, off_t reloffset);
312 #endif
314 } // End namespace gold.