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_(NULL
), error_count_(0),
43 warning_count_(0), undefined_symbols_()
47 // Initialize the lock_ field.
50 Errors::initialize_lock()
52 if (this->lock_
== NULL
)
53 this->lock_
= new Lock
;
56 // Report a fatal error.
59 Errors::fatal(const char* format
, va_list args
)
61 fprintf(stderr
, "%s: ", this->program_name_
);
62 vfprintf(stderr
, format
, args
);
70 Errors::error(const char* format
, va_list args
)
72 fprintf(stderr
, "%s: ", this->program_name_
);
73 vfprintf(stderr
, format
, args
);
76 this->initialize_lock();
78 Hold_lock
h(*this->lock_
);
86 Errors::warning(const char* format
, va_list args
)
88 fprintf(stderr
, _("%s: warning: "), this->program_name_
);
89 vfprintf(stderr
, format
, args
);
92 this->initialize_lock();
94 Hold_lock
h(*this->lock_
);
95 ++this->warning_count_
;
99 // Report an error at a reloc location.
101 template<int size
, bool big_endian
>
103 Errors::error_at_location(const Relocate_info
<size
, big_endian
>* relinfo
,
104 size_t relnum
, off_t reloffset
,
105 const char* format
, va_list args
)
107 fprintf(stderr
, "%s: %s: ", this->program_name_
,
108 relinfo
->location(relnum
, reloffset
).c_str());
109 vfprintf(stderr
, format
, args
);
112 this->initialize_lock();
114 Hold_lock
h(*this->lock_
);
115 ++this->error_count_
;
119 // Report a warning at a reloc location.
121 template<int size
, bool big_endian
>
123 Errors::warning_at_location(const Relocate_info
<size
, big_endian
>* relinfo
,
124 size_t relnum
, off_t reloffset
,
125 const char* format
, va_list args
)
127 fprintf(stderr
, _("%s: %s: warning: "), this->program_name_
,
128 relinfo
->location(relnum
, reloffset
).c_str());
129 vfprintf(stderr
, format
, args
);
132 this->initialize_lock();
134 Hold_lock
h(*this->lock_
);
135 ++this->warning_count_
;
139 // Issue an undefined symbol error.
141 template<int size
, bool big_endian
>
143 Errors::undefined_symbol(const Symbol
* sym
,
144 const Relocate_info
<size
, big_endian
>* relinfo
,
145 size_t relnum
, off_t reloffset
)
147 this->initialize_lock();
149 Hold_lock
h(*this->lock_
);
150 if (++this->undefined_symbols_
[sym
] >= max_undefined_error_report
)
152 ++this->error_count_
;
154 fprintf(stderr
, _("%s: %s: undefined reference to '%s'\n"),
155 this->program_name_
, relinfo
->location(relnum
, reloffset
).c_str(),
156 sym
->demangled_name().c_str());
159 // Issue a debugging message.
162 Errors::debug(const char* format
, ...)
164 fprintf(stderr
, _("%s: "), this->program_name_
);
167 va_start(args
, format
);
168 vfprintf(stderr
, format
, args
);
174 // The functions which the rest of the code actually calls.
176 // Report a fatal error.
179 gold_fatal(const char* format
, ...)
182 va_start(args
, format
);
183 parameters
->errors()->fatal(format
, args
);
190 gold_error(const char* format
, ...)
193 va_start(args
, format
);
194 parameters
->errors()->error(format
, args
);
201 gold_warning(const char* format
, ...)
204 va_start(args
, format
);
205 parameters
->errors()->warning(format
, args
);
209 // Report an error at a location.
211 template<int size
, bool big_endian
>
213 gold_error_at_location(const Relocate_info
<size
, big_endian
>* relinfo
,
214 size_t relnum
, off_t reloffset
,
215 const char* format
, ...)
218 va_start(args
, format
);
219 parameters
->errors()->error_at_location(relinfo
, relnum
, reloffset
,
224 // Report a warning at a location.
226 template<int size
, bool big_endian
>
228 gold_warning_at_location(const Relocate_info
<size
, big_endian
>* relinfo
,
229 size_t relnum
, off_t reloffset
,
230 const char* format
, ...)
233 va_start(args
, format
);
234 parameters
->errors()->warning_at_location(relinfo
, relnum
, reloffset
,
239 // Report an undefined symbol.
241 template<int size
, bool big_endian
>
243 gold_undefined_symbol(const Symbol
* sym
,
244 const Relocate_info
<size
, big_endian
>* relinfo
,
245 size_t relnum
, off_t reloffset
)
247 parameters
->errors()->undefined_symbol(sym
, relinfo
, relnum
, reloffset
);
250 #ifdef HAVE_TARGET_32_LITTLE
253 gold_error_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_error_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_error_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_error_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_warning_at_location
<32, false>(const Relocate_info
<32, false>* relinfo
,
286 size_t relnum
, off_t reloffset
,
287 const char* format
, ...);
290 #ifdef HAVE_TARGET_32_BIG
293 gold_warning_at_location
<32, true>(const Relocate_info
<32, true>* relinfo
,
294 size_t relnum
, off_t reloffset
,
295 const char* format
, ...);
298 #ifdef HAVE_TARGET_64_LITTLE
301 gold_warning_at_location
<64, false>(const Relocate_info
<64, false>* relinfo
,
302 size_t relnum
, off_t reloffset
,
303 const char* format
, ...);
306 #ifdef HAVE_TARGET_64_BIG
309 gold_warning_at_location
<64, true>(const Relocate_info
<64, true>* relinfo
,
310 size_t relnum
, off_t reloffset
,
311 const char* format
, ...);
314 #ifdef HAVE_TARGET_32_LITTLE
317 gold_undefined_symbol
<32, false>(const Symbol
* sym
,
318 const Relocate_info
<32, false>* relinfo
,
319 size_t relnum
, off_t reloffset
);
322 #ifdef HAVE_TARGET_32_BIG
325 gold_undefined_symbol
<32, true>(const Symbol
* sym
,
326 const Relocate_info
<32, true>* relinfo
,
327 size_t relnum
, off_t reloffset
);
330 #ifdef HAVE_TARGET_64_LITTLE
333 gold_undefined_symbol
<64, false>(const Symbol
* sym
,
334 const Relocate_info
<64, false>* relinfo
,
335 size_t relnum
, off_t reloffset
);
338 #ifdef HAVE_TARGET_64_BIG
341 gold_undefined_symbol
<64, true>(const Symbol
* sym
,
342 const Relocate_info
<64, true>* relinfo
,
343 size_t relnum
, off_t reloffset
);
346 } // End namespace gold.