* errors.cc (Errors::undefined_symbol): Mention symbol version if
[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{
83 fprintf(stderr, "%s: ", this->program_name_);
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{
94 fprintf(stderr, "%s: ", this->program_name_);
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
113// Report an error at a reloc location.
114
115template<int size, bool big_endian>
116void
117Errors::error_at_location(const Relocate_info<size, big_endian>* relinfo,
118 size_t relnum, off_t reloffset,
119 const char* format, va_list args)
120{
121 fprintf(stderr, "%s: %s: ", this->program_name_,
122 relinfo->location(relnum, reloffset).c_str());
123 vfprintf(stderr, format, args);
124 fputc('\n', stderr);
c7912668 125
2dd3e587 126 this->increment_counter(&this->error_count_);
75f2446e
ILT
127}
128
129// Report a warning at a reloc location.
130
131template<int size, bool big_endian>
132void
133Errors::warning_at_location(const Relocate_info<size, big_endian>* relinfo,
134 size_t relnum, off_t reloffset,
135 const char* format, va_list args)
136{
137 fprintf(stderr, _("%s: %s: warning: "), this->program_name_,
138 relinfo->location(relnum, reloffset).c_str());
139 vfprintf(stderr, format, args);
140 fputc('\n', stderr);
c7912668 141
2dd3e587 142 this->increment_counter(&this->warning_count_);
75f2446e
ILT
143}
144
145// Issue an undefined symbol error.
146
147template<int size, bool big_endian>
148void
149Errors::undefined_symbol(const Symbol* sym,
150 const Relocate_info<size, big_endian>* relinfo,
151 size_t relnum, off_t reloffset)
152{
2dd3e587
ILT
153 bool initialized = this->initialize_lock();
154 gold_assert(initialized);
75f2446e 155 {
c7912668 156 Hold_lock h(*this->lock_);
75f2446e
ILT
157 if (++this->undefined_symbols_[sym] >= max_undefined_error_report)
158 return;
159 ++this->error_count_;
160 }
789aa6de
ILT
161 const char* const version = sym->version();
162 if (version == NULL)
163 fprintf(stderr, _("%s: %s: undefined reference to '%s'\n"),
164 this->program_name_, relinfo->location(relnum, reloffset).c_str(),
165 sym->demangled_name().c_str());
166 else
167 fprintf(stderr, _("%s: %s: undefined reference to '%s', version '%s'\n"),
168 this->program_name_, relinfo->location(relnum, reloffset).c_str(),
169 sym->demangled_name().c_str(), version);
75f2446e
ILT
170}
171
c7912668
ILT
172// Issue a debugging message.
173
174void
175Errors::debug(const char* format, ...)
176{
177 fprintf(stderr, _("%s: "), this->program_name_);
178
179 va_list args;
180 va_start(args, format);
181 vfprintf(stderr, format, args);
182 va_end(args);
183
184 fputc('\n', stderr);
185}
75f2446e
ILT
186
187// The functions which the rest of the code actually calls.
188
189// Report a fatal error.
190
191void
192gold_fatal(const char* format, ...)
193{
194 va_list args;
195 va_start(args, format);
196 parameters->errors()->fatal(format, args);
197 va_end(args);
198}
199
200// Report an error.
201
202void
203gold_error(const char* format, ...)
204{
205 va_list args;
206 va_start(args, format);
207 parameters->errors()->error(format, args);
208 va_end(args);
209}
210
211// Report a warning.
212
213void
214gold_warning(const char* format, ...)
215{
216 va_list args;
217 va_start(args, format);
218 parameters->errors()->warning(format, args);
219 va_end(args);
220}
221
222// Report an error at a location.
223
224template<int size, bool big_endian>
225void
226gold_error_at_location(const Relocate_info<size, big_endian>* relinfo,
227 size_t relnum, off_t reloffset,
228 const char* format, ...)
229{
230 va_list args;
231 va_start(args, format);
232 parameters->errors()->error_at_location(relinfo, relnum, reloffset,
233 format, args);
234 va_end(args);
235}
236
237// Report a warning at a location.
238
239template<int size, bool big_endian>
240void
241gold_warning_at_location(const Relocate_info<size, big_endian>* relinfo,
242 size_t relnum, off_t reloffset,
243 const char* format, ...)
244{
245 va_list args;
246 va_start(args, format);
247 parameters->errors()->warning_at_location(relinfo, relnum, reloffset,
248 format, args);
249 va_end(args);
250}
251
252// Report an undefined symbol.
253
254template<int size, bool big_endian>
255void
256gold_undefined_symbol(const Symbol* sym,
257 const Relocate_info<size, big_endian>* relinfo,
258 size_t relnum, off_t reloffset)
259{
260 parameters->errors()->undefined_symbol(sym, relinfo, relnum, reloffset);
261}
262
263#ifdef HAVE_TARGET_32_LITTLE
264template
265void
266gold_error_at_location<32, false>(const Relocate_info<32, false>* relinfo,
267 size_t relnum, off_t reloffset,
268 const char* format, ...);
269#endif
270
271#ifdef HAVE_TARGET_32_BIG
272template
273void
274gold_error_at_location<32, true>(const Relocate_info<32, true>* relinfo,
275 size_t relnum, off_t reloffset,
276 const char* format, ...);
277#endif
278
279#ifdef HAVE_TARGET_64_LITTLE
280template
281void
282gold_error_at_location<64, false>(const Relocate_info<64, false>* relinfo,
283 size_t relnum, off_t reloffset,
284 const char* format, ...);
285#endif
286
287#ifdef HAVE_TARGET_64_BIG
288template
289void
290gold_error_at_location<64, true>(const Relocate_info<64, true>* relinfo,
291 size_t relnum, off_t reloffset,
292 const char* format, ...);
293#endif
294
295#ifdef HAVE_TARGET_32_LITTLE
296template
297void
298gold_warning_at_location<32, false>(const Relocate_info<32, false>* relinfo,
299 size_t relnum, off_t reloffset,
300 const char* format, ...);
301#endif
302
303#ifdef HAVE_TARGET_32_BIG
304template
305void
306gold_warning_at_location<32, true>(const Relocate_info<32, true>* relinfo,
307 size_t relnum, off_t reloffset,
308 const char* format, ...);
309#endif
310
311#ifdef HAVE_TARGET_64_LITTLE
312template
313void
314gold_warning_at_location<64, false>(const Relocate_info<64, false>* relinfo,
315 size_t relnum, off_t reloffset,
316 const char* format, ...);
317#endif
318
319#ifdef HAVE_TARGET_64_BIG
320template
321void
322gold_warning_at_location<64, true>(const Relocate_info<64, true>* relinfo,
323 size_t relnum, off_t reloffset,
324 const char* format, ...);
325#endif
326
327#ifdef HAVE_TARGET_32_LITTLE
328template
329void
330gold_undefined_symbol<32, false>(const Symbol* sym,
331 const Relocate_info<32, false>* relinfo,
332 size_t relnum, off_t reloffset);
333#endif
334
335#ifdef HAVE_TARGET_32_BIG
336template
337void
338gold_undefined_symbol<32, true>(const Symbol* sym,
339 const Relocate_info<32, true>* relinfo,
340 size_t relnum, off_t reloffset);
341#endif
342
343#ifdef HAVE_TARGET_64_LITTLE
344template
345void
346gold_undefined_symbol<64, false>(const Symbol* sym,
347 const Relocate_info<64, false>* relinfo,
348 size_t relnum, off_t reloffset);
349#endif
350
351#ifdef HAVE_TARGET_64_BIG
352template
353void
354gold_undefined_symbol<64, true>(const Symbol* sym,
355 const Relocate_info<64, true>* relinfo,
356 size_t relnum, off_t reloffset);
357#endif
358
359} // End namespace gold.
This page took 0.055154 seconds and 4 git commands to generate.