/tmp/foo.diff
[deliverable/binutils-gdb.git] / gold / errors.cc
CommitLineData
75f2446e
ILT
1// errors.cc -- handle errors for gold
2
3// Copyright 2006, 2007 Free Software Foundation, Inc.
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
c7912668
ILT
47// Initialize the lock_ field.
48
49void
50Errors::initialize_lock()
51{
52 if (this->lock_ == NULL)
53 this->lock_ = new Lock;
54}
55
75f2446e
ILT
56// Report a fatal error.
57
58void
59Errors::fatal(const char* format, va_list args)
60{
61 fprintf(stderr, "%s: ", this->program_name_);
62 vfprintf(stderr, format, args);
63 fputc('\n', stderr);
64 gold_exit(false);
65}
66
67// Report an error.
68
69void
70Errors::error(const char* format, va_list args)
71{
72 fprintf(stderr, "%s: ", this->program_name_);
73 vfprintf(stderr, format, args);
74 fputc('\n', stderr);
c7912668
ILT
75
76 this->initialize_lock();
75f2446e 77 {
c7912668 78 Hold_lock h(*this->lock_);
75f2446e
ILT
79 ++this->error_count_;
80 }
81}
82
83// Report a warning.
84
85void
86Errors::warning(const char* format, va_list args)
87{
88 fprintf(stderr, _("%s: warning: "), this->program_name_);
89 vfprintf(stderr, format, args);
90 fputc('\n', stderr);
c7912668
ILT
91
92 this->initialize_lock();
75f2446e 93 {
c7912668 94 Hold_lock h(*this->lock_);
75f2446e
ILT
95 ++this->warning_count_;
96 }
97}
98
99// Report an error at a reloc location.
100
101template<int size, bool big_endian>
102void
103Errors::error_at_location(const Relocate_info<size, big_endian>* relinfo,
104 size_t relnum, off_t reloffset,
105 const char* format, va_list args)
106{
107 fprintf(stderr, "%s: %s: ", this->program_name_,
108 relinfo->location(relnum, reloffset).c_str());
109 vfprintf(stderr, format, args);
110 fputc('\n', stderr);
c7912668
ILT
111
112 this->initialize_lock();
75f2446e 113 {
c7912668 114 Hold_lock h(*this->lock_);
75f2446e
ILT
115 ++this->error_count_;
116 }
117}
118
119// Report a warning at a reloc location.
120
121template<int size, bool big_endian>
122void
123Errors::warning_at_location(const Relocate_info<size, big_endian>* relinfo,
124 size_t relnum, off_t reloffset,
125 const char* format, va_list args)
126{
127 fprintf(stderr, _("%s: %s: warning: "), this->program_name_,
128 relinfo->location(relnum, reloffset).c_str());
129 vfprintf(stderr, format, args);
130 fputc('\n', stderr);
c7912668
ILT
131
132 this->initialize_lock();
75f2446e 133 {
c7912668 134 Hold_lock h(*this->lock_);
75f2446e
ILT
135 ++this->warning_count_;
136 }
137}
138
139// Issue an undefined symbol error.
140
141template<int size, bool big_endian>
142void
143Errors::undefined_symbol(const Symbol* sym,
144 const Relocate_info<size, big_endian>* relinfo,
145 size_t relnum, off_t reloffset)
146{
c7912668 147 this->initialize_lock();
75f2446e 148 {
c7912668 149 Hold_lock h(*this->lock_);
75f2446e
ILT
150 if (++this->undefined_symbols_[sym] >= max_undefined_error_report)
151 return;
152 ++this->error_count_;
153 }
154 fprintf(stderr, _("%s: %s: undefined reference to '%s'\n"),
155 this->program_name_, relinfo->location(relnum, reloffset).c_str(),
a2b1aa12 156 sym->demangled_name().c_str());
75f2446e
ILT
157}
158
c7912668
ILT
159// Issue a debugging message.
160
161void
162Errors::debug(const char* format, ...)
163{
164 fprintf(stderr, _("%s: "), this->program_name_);
165
166 va_list args;
167 va_start(args, format);
168 vfprintf(stderr, format, args);
169 va_end(args);
170
171 fputc('\n', stderr);
172}
75f2446e
ILT
173
174// The functions which the rest of the code actually calls.
175
176// Report a fatal error.
177
178void
179gold_fatal(const char* format, ...)
180{
181 va_list args;
182 va_start(args, format);
183 parameters->errors()->fatal(format, args);
184 va_end(args);
185}
186
187// Report an error.
188
189void
190gold_error(const char* format, ...)
191{
192 va_list args;
193 va_start(args, format);
194 parameters->errors()->error(format, args);
195 va_end(args);
196}
197
198// Report a warning.
199
200void
201gold_warning(const char* format, ...)
202{
203 va_list args;
204 va_start(args, format);
205 parameters->errors()->warning(format, args);
206 va_end(args);
207}
208
209// Report an error at a location.
210
211template<int size, bool big_endian>
212void
213gold_error_at_location(const Relocate_info<size, big_endian>* relinfo,
214 size_t relnum, off_t reloffset,
215 const char* format, ...)
216{
217 va_list args;
218 va_start(args, format);
219 parameters->errors()->error_at_location(relinfo, relnum, reloffset,
220 format, args);
221 va_end(args);
222}
223
224// Report a warning at a location.
225
226template<int size, bool big_endian>
227void
228gold_warning_at_location(const Relocate_info<size, big_endian>* relinfo,
229 size_t relnum, off_t reloffset,
230 const char* format, ...)
231{
232 va_list args;
233 va_start(args, format);
234 parameters->errors()->warning_at_location(relinfo, relnum, reloffset,
235 format, args);
236 va_end(args);
237}
238
239// Report an undefined symbol.
240
241template<int size, bool big_endian>
242void
243gold_undefined_symbol(const Symbol* sym,
244 const Relocate_info<size, big_endian>* relinfo,
245 size_t relnum, off_t reloffset)
246{
247 parameters->errors()->undefined_symbol(sym, relinfo, relnum, reloffset);
248}
249
250#ifdef HAVE_TARGET_32_LITTLE
251template
252void
253gold_error_at_location<32, false>(const Relocate_info<32, false>* relinfo,
254 size_t relnum, off_t reloffset,
255 const char* format, ...);
256#endif
257
258#ifdef HAVE_TARGET_32_BIG
259template
260void
261gold_error_at_location<32, true>(const Relocate_info<32, true>* relinfo,
262 size_t relnum, off_t reloffset,
263 const char* format, ...);
264#endif
265
266#ifdef HAVE_TARGET_64_LITTLE
267template
268void
269gold_error_at_location<64, false>(const Relocate_info<64, false>* relinfo,
270 size_t relnum, off_t reloffset,
271 const char* format, ...);
272#endif
273
274#ifdef HAVE_TARGET_64_BIG
275template
276void
277gold_error_at_location<64, true>(const Relocate_info<64, true>* relinfo,
278 size_t relnum, off_t reloffset,
279 const char* format, ...);
280#endif
281
282#ifdef HAVE_TARGET_32_LITTLE
283template
284void
285gold_warning_at_location<32, false>(const Relocate_info<32, false>* relinfo,
286 size_t relnum, off_t reloffset,
287 const char* format, ...);
288#endif
289
290#ifdef HAVE_TARGET_32_BIG
291template
292void
293gold_warning_at_location<32, true>(const Relocate_info<32, true>* relinfo,
294 size_t relnum, off_t reloffset,
295 const char* format, ...);
296#endif
297
298#ifdef HAVE_TARGET_64_LITTLE
299template
300void
301gold_warning_at_location<64, false>(const Relocate_info<64, false>* relinfo,
302 size_t relnum, off_t reloffset,
303 const char* format, ...);
304#endif
305
306#ifdef HAVE_TARGET_64_BIG
307template
308void
309gold_warning_at_location<64, true>(const Relocate_info<64, true>* relinfo,
310 size_t relnum, off_t reloffset,
311 const char* format, ...);
312#endif
313
314#ifdef HAVE_TARGET_32_LITTLE
315template
316void
317gold_undefined_symbol<32, false>(const Symbol* sym,
318 const Relocate_info<32, false>* relinfo,
319 size_t relnum, off_t reloffset);
320#endif
321
322#ifdef HAVE_TARGET_32_BIG
323template
324void
325gold_undefined_symbol<32, true>(const Symbol* sym,
326 const Relocate_info<32, true>* relinfo,
327 size_t relnum, off_t reloffset);
328#endif
329
330#ifdef HAVE_TARGET_64_LITTLE
331template
332void
333gold_undefined_symbol<64, false>(const Symbol* sym,
334 const Relocate_info<64, false>* relinfo,
335 size_t relnum, off_t reloffset);
336#endif
337
338#ifdef HAVE_TARGET_64_BIG
339template
340void
341gold_undefined_symbol<64, true>(const Symbol* sym,
342 const Relocate_info<64, true>* relinfo,
343 size_t relnum, off_t reloffset);
344#endif
345
346} // End namespace gold.
This page took 0.058098 seconds and 4 git commands to generate.