*** empty log message ***
[deliverable/binutils-gdb.git] / gold / errors.cc
CommitLineData
75f2446e
ILT
1// errors.cc -- handle errors for gold
2
ebdbb458 3// Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
75f2446e
ILT
4// Written by Ian Lance Taylor <iant@google.com>.
5
6// This file is part of gold.
7
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.
12
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.
17
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.
22
23#include "gold.h"
24
25#include <cstdarg>
26#include <cstdio>
27
28#include "gold-threads.h"
29#include "parameters.h"
30#include "object.h"
31#include "symtab.h"
32#include "errors.h"
33
34namespace gold
35{
36
37// Class Errors.
38
39const int Errors::max_undefined_error_report;
40
41Errors::Errors(const char* program_name)
c7912668
ILT
42 : program_name_(program_name), lock_(NULL), error_count_(0),
43 warning_count_(0), undefined_symbols_()
75f2446e
ILT
44{
45}
46
2dd3e587
ILT
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.
c7912668 52
2dd3e587 53bool
c7912668
ILT
54Errors::initialize_lock()
55{
2dd3e587 56 if (this->lock_ == NULL && parameters->options_valid())
c7912668 57 this->lock_ = new Lock;
2dd3e587
ILT
58 return this->lock_ != NULL;
59}
60
61// Increment a counter, holding the lock if available.
62
63void
64Errors::increment_counter(int *counter)
65{
66 if (!this->initialize_lock())
67 {
68 // The lock does not exist, which means that we don't need it.
69 ++*counter;
70 }
71 else
72 {
73 Hold_lock h(*this->lock_);
74 ++*counter;
75 }
c7912668
ILT
76}
77
75f2446e
ILT
78// Report a fatal error.
79
80void
81Errors::fatal(const char* format, va_list args)
82{
f073bbf7 83 fprintf(stderr, _("%s: fatal error: "), this->program_name_);
75f2446e
ILT
84 vfprintf(stderr, format, args);
85 fputc('\n', stderr);
86 gold_exit(false);
87}
88
89// Report an error.
90
91void
92Errors::error(const char* format, va_list args)
93{
f073bbf7 94 fprintf(stderr, _("%s: error: "), this->program_name_);
75f2446e
ILT
95 vfprintf(stderr, format, args);
96 fputc('\n', stderr);
c7912668 97
2dd3e587 98 this->increment_counter(&this->error_count_);
75f2446e
ILT
99}
100
101// Report a warning.
102
103void
104Errors::warning(const char* format, va_list args)
105{
106 fprintf(stderr, _("%s: warning: "), this->program_name_);
107 vfprintf(stderr, format, args);
108 fputc('\n', stderr);
c7912668 109
2dd3e587 110 this->increment_counter(&this->warning_count_);
75f2446e
ILT
111}
112
c5818ff1
CC
113// Print an informational message.
114
115void
116Errors::info(const char* format, va_list args)
117{
118 vfprintf(stderr, format, args);
119 fputc('\n', stderr);
120}
121
75f2446e
ILT
122// Report an error at a reloc location.
123
124template<int size, bool big_endian>
125void
126Errors::error_at_location(const Relocate_info<size, big_endian>* relinfo,
127 size_t relnum, off_t reloffset,
128 const char* format, va_list args)
129{
f073bbf7 130 fprintf(stderr, _("%s: %s: error: "), this->program_name_,
75f2446e
ILT
131 relinfo->location(relnum, reloffset).c_str());
132 vfprintf(stderr, format, args);
133 fputc('\n', stderr);
c7912668 134
2dd3e587 135 this->increment_counter(&this->error_count_);
75f2446e
ILT
136}
137
138// Report a warning at a reloc location.
139
140template<int size, bool big_endian>
141void
142Errors::warning_at_location(const Relocate_info<size, big_endian>* relinfo,
143 size_t relnum, off_t reloffset,
144 const char* format, va_list args)
145{
146 fprintf(stderr, _("%s: %s: warning: "), this->program_name_,
147 relinfo->location(relnum, reloffset).c_str());
148 vfprintf(stderr, format, args);
149 fputc('\n', stderr);
c7912668 150
2dd3e587 151 this->increment_counter(&this->warning_count_);
75f2446e
ILT
152}
153
f073bbf7 154// Issue an undefined symbol error with a caller-supplied location string.
75f2446e 155
75f2446e 156void
f073bbf7 157Errors::undefined_symbol(const Symbol* sym, const std::string& location)
75f2446e 158{
2dd3e587
ILT
159 bool initialized = this->initialize_lock();
160 gold_assert(initialized);
75f2446e 161 {
c7912668 162 Hold_lock h(*this->lock_);
75f2446e
ILT
163 if (++this->undefined_symbols_[sym] >= max_undefined_error_report)
164 return;
165 ++this->error_count_;
166 }
789aa6de
ILT
167 const char* const version = sym->version();
168 if (version == NULL)
f073bbf7
CD
169 fprintf(stderr, _("%s: %s: error: undefined reference to '%s'\n"),
170 this->program_name_, location.c_str(),
789aa6de
ILT
171 sym->demangled_name().c_str());
172 else
f073bbf7
CD
173 fprintf(stderr,
174 _("%s: %s: error: undefined reference to '%s', version '%s'\n"),
175 this->program_name_, location.c_str(),
789aa6de 176 sym->demangled_name().c_str(), version);
75f2446e
ILT
177}
178
c7912668
ILT
179// Issue a debugging message.
180
181void
182Errors::debug(const char* format, ...)
183{
184 fprintf(stderr, _("%s: "), this->program_name_);
185
186 va_list args;
187 va_start(args, format);
188 vfprintf(stderr, format, args);
189 va_end(args);
190
191 fputc('\n', stderr);
192}
75f2446e
ILT
193
194// The functions which the rest of the code actually calls.
195
196// Report a fatal error.
197
198void
199gold_fatal(const char* format, ...)
200{
201 va_list args;
202 va_start(args, format);
203 parameters->errors()->fatal(format, args);
204 va_end(args);
205}
206
207// Report an error.
208
209void
210gold_error(const char* format, ...)
211{
212 va_list args;
213 va_start(args, format);
214 parameters->errors()->error(format, args);
215 va_end(args);
216}
217
218// Report a warning.
219
220void
221gold_warning(const char* format, ...)
222{
223 va_list args;
224 va_start(args, format);
225 parameters->errors()->warning(format, args);
226 va_end(args);
227}
228
c5818ff1
CC
229// Print an informational message.
230
231void
232gold_info(const char* format, ...)
233{
234 va_list args;
235 va_start(args, format);
236 parameters->errors()->info(format, args);
237 va_end(args);
238}
239
75f2446e
ILT
240// Report an error at a location.
241
242template<int size, bool big_endian>
243void
244gold_error_at_location(const Relocate_info<size, big_endian>* relinfo,
245 size_t relnum, off_t reloffset,
246 const char* format, ...)
247{
248 va_list args;
249 va_start(args, format);
250 parameters->errors()->error_at_location(relinfo, relnum, reloffset,
251 format, args);
252 va_end(args);
253}
254
255// Report a warning at a location.
256
257template<int size, bool big_endian>
258void
259gold_warning_at_location(const Relocate_info<size, big_endian>* relinfo,
260 size_t relnum, off_t reloffset,
261 const char* format, ...)
262{
263 va_list args;
264 va_start(args, format);
265 parameters->errors()->warning_at_location(relinfo, relnum, reloffset,
266 format, args);
267 va_end(args);
268}
269
270// Report an undefined symbol.
271
f073bbf7
CD
272void
273gold_undefined_symbol(const Symbol* sym)
274{
275 parameters->errors()->undefined_symbol(sym, sym->object()->name().c_str());
276}
277
278// Report an undefined symbol at a reloc location
279
75f2446e
ILT
280template<int size, bool big_endian>
281void
f073bbf7 282gold_undefined_symbol_at_location(const Symbol* sym,
75f2446e
ILT
283 const Relocate_info<size, big_endian>* relinfo,
284 size_t relnum, off_t reloffset)
285{
f073bbf7
CD
286 parameters->errors()->undefined_symbol(sym,
287 relinfo->location(relnum, reloffset));
75f2446e
ILT
288}
289
290#ifdef HAVE_TARGET_32_LITTLE
291template
292void
293gold_error_at_location<32, false>(const Relocate_info<32, false>* relinfo,
294 size_t relnum, off_t reloffset,
295 const char* format, ...);
296#endif
297
298#ifdef HAVE_TARGET_32_BIG
299template
300void
301gold_error_at_location<32, true>(const Relocate_info<32, true>* relinfo,
302 size_t relnum, off_t reloffset,
303 const char* format, ...);
304#endif
305
306#ifdef HAVE_TARGET_64_LITTLE
307template
308void
309gold_error_at_location<64, false>(const Relocate_info<64, false>* relinfo,
310 size_t relnum, off_t reloffset,
311 const char* format, ...);
312#endif
313
314#ifdef HAVE_TARGET_64_BIG
315template
316void
317gold_error_at_location<64, true>(const Relocate_info<64, true>* relinfo,
318 size_t relnum, off_t reloffset,
319 const char* format, ...);
320#endif
321
322#ifdef HAVE_TARGET_32_LITTLE
323template
324void
325gold_warning_at_location<32, false>(const Relocate_info<32, false>* relinfo,
326 size_t relnum, off_t reloffset,
327 const char* format, ...);
328#endif
329
330#ifdef HAVE_TARGET_32_BIG
331template
332void
333gold_warning_at_location<32, true>(const Relocate_info<32, true>* relinfo,
334 size_t relnum, off_t reloffset,
335 const char* format, ...);
336#endif
337
338#ifdef HAVE_TARGET_64_LITTLE
339template
340void
341gold_warning_at_location<64, false>(const Relocate_info<64, false>* relinfo,
342 size_t relnum, off_t reloffset,
343 const char* format, ...);
344#endif
345
346#ifdef HAVE_TARGET_64_BIG
347template
348void
349gold_warning_at_location<64, true>(const Relocate_info<64, true>* relinfo,
350 size_t relnum, off_t reloffset,
351 const char* format, ...);
352#endif
353
354#ifdef HAVE_TARGET_32_LITTLE
355template
356void
f073bbf7
CD
357gold_undefined_symbol_at_location<32, false>(
358 const Symbol* sym,
359 const Relocate_info<32, false>* relinfo,
360 size_t relnum, off_t reloffset);
75f2446e
ILT
361#endif
362
363#ifdef HAVE_TARGET_32_BIG
364template
365void
f073bbf7
CD
366gold_undefined_symbol_at_location<32, true>(
367 const Symbol* sym,
368 const Relocate_info<32, true>* relinfo,
369 size_t relnum, off_t reloffset);
75f2446e
ILT
370#endif
371
372#ifdef HAVE_TARGET_64_LITTLE
373template
374void
f073bbf7
CD
375gold_undefined_symbol_at_location<64, false>(
376 const Symbol* sym,
377 const Relocate_info<64, false>* relinfo,
378 size_t relnum, off_t reloffset);
75f2446e
ILT
379#endif
380
381#ifdef HAVE_TARGET_64_BIG
382template
383void
f073bbf7
CD
384gold_undefined_symbol_at_location<64, true>(
385 const Symbol* sym,
386 const Relocate_info<64, true>* relinfo,
387 size_t relnum, off_t reloffset);
75f2446e
ILT
388#endif
389
390} // End namespace gold.
This page took 0.085534 seconds and 4 git commands to generate.