From Craig Silverstein: Minimal --script implementation.
[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)
42 : program_name_(program_name), lock_(), error_count_(0), warning_count_(0),
43 undefined_symbols_()
44{
45}
46
47// Report a fatal error.
48
49void
50Errors::fatal(const char* format, va_list args)
51{
52 fprintf(stderr, "%s: ", this->program_name_);
53 vfprintf(stderr, format, args);
54 fputc('\n', stderr);
55 gold_exit(false);
56}
57
58// Report an error.
59
60void
61Errors::error(const char* format, va_list args)
62{
63 fprintf(stderr, "%s: ", this->program_name_);
64 vfprintf(stderr, format, args);
65 fputc('\n', stderr);
66 {
67 Hold_lock h(this->lock_);
68 ++this->error_count_;
69 }
70}
71
72// Report a warning.
73
74void
75Errors::warning(const char* format, va_list args)
76{
77 fprintf(stderr, _("%s: warning: "), this->program_name_);
78 vfprintf(stderr, format, args);
79 fputc('\n', stderr);
80 {
81 Hold_lock h(this->lock_);
82 ++this->warning_count_;
83 }
84}
85
86// Report an error at a reloc location.
87
88template<int size, bool big_endian>
89void
90Errors::error_at_location(const Relocate_info<size, big_endian>* relinfo,
91 size_t relnum, off_t reloffset,
92 const char* format, va_list args)
93{
94 fprintf(stderr, "%s: %s: ", this->program_name_,
95 relinfo->location(relnum, reloffset).c_str());
96 vfprintf(stderr, format, args);
97 fputc('\n', stderr);
98 {
99 Hold_lock h(this->lock_);
100 ++this->error_count_;
101 }
102}
103
104// Report a warning at a reloc location.
105
106template<int size, bool big_endian>
107void
108Errors::warning_at_location(const Relocate_info<size, big_endian>* relinfo,
109 size_t relnum, off_t reloffset,
110 const char* format, va_list args)
111{
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);
116 {
117 Hold_lock h(this->lock_);
118 ++this->warning_count_;
119 }
120}
121
122// Issue an undefined symbol error.
123
124template<int size, bool big_endian>
125void
126Errors::undefined_symbol(const Symbol* sym,
127 const Relocate_info<size, big_endian>* relinfo,
128 size_t relnum, off_t reloffset)
129{
130 {
131 Hold_lock h(this->lock_);
132 if (++this->undefined_symbols_[sym] >= max_undefined_error_report)
133 return;
134 ++this->error_count_;
135 }
136 fprintf(stderr, _("%s: %s: undefined reference to '%s'\n"),
137 this->program_name_, relinfo->location(relnum, reloffset).c_str(),
138 sym->name());
139}
140
141
142// The functions which the rest of the code actually calls.
143
144// Report a fatal error.
145
146void
147gold_fatal(const char* format, ...)
148{
149 va_list args;
150 va_start(args, format);
151 parameters->errors()->fatal(format, args);
152 va_end(args);
153}
154
155// Report an error.
156
157void
158gold_error(const char* format, ...)
159{
160 va_list args;
161 va_start(args, format);
162 parameters->errors()->error(format, args);
163 va_end(args);
164}
165
166// Report a warning.
167
168void
169gold_warning(const char* format, ...)
170{
171 va_list args;
172 va_start(args, format);
173 parameters->errors()->warning(format, args);
174 va_end(args);
175}
176
177// Report an error at a location.
178
179template<int size, bool big_endian>
180void
181gold_error_at_location(const Relocate_info<size, big_endian>* relinfo,
182 size_t relnum, off_t reloffset,
183 const char* format, ...)
184{
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);
190}
191
192// Report a warning at a location.
193
194template<int size, bool big_endian>
195void
196gold_warning_at_location(const Relocate_info<size, big_endian>* relinfo,
197 size_t relnum, off_t reloffset,
198 const char* format, ...)
199{
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);
205}
206
207// Report an undefined symbol.
208
209template<int size, bool big_endian>
210void
211gold_undefined_symbol(const Symbol* sym,
212 const Relocate_info<size, big_endian>* relinfo,
213 size_t relnum, off_t reloffset)
214{
215 parameters->errors()->undefined_symbol(sym, relinfo, relnum, reloffset);
216}
217
218#ifdef HAVE_TARGET_32_LITTLE
219template
220void
221gold_error_at_location<32, false>(const Relocate_info<32, false>* relinfo,
222 size_t relnum, off_t reloffset,
223 const char* format, ...);
224#endif
225
226#ifdef HAVE_TARGET_32_BIG
227template
228void
229gold_error_at_location<32, true>(const Relocate_info<32, true>* relinfo,
230 size_t relnum, off_t reloffset,
231 const char* format, ...);
232#endif
233
234#ifdef HAVE_TARGET_64_LITTLE
235template
236void
237gold_error_at_location<64, false>(const Relocate_info<64, false>* relinfo,
238 size_t relnum, off_t reloffset,
239 const char* format, ...);
240#endif
241
242#ifdef HAVE_TARGET_64_BIG
243template
244void
245gold_error_at_location<64, true>(const Relocate_info<64, true>* relinfo,
246 size_t relnum, off_t reloffset,
247 const char* format, ...);
248#endif
249
250#ifdef HAVE_TARGET_32_LITTLE
251template
252void
253gold_warning_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_warning_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_warning_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_warning_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_undefined_symbol<32, false>(const Symbol* sym,
286 const Relocate_info<32, false>* relinfo,
287 size_t relnum, off_t reloffset);
288#endif
289
290#ifdef HAVE_TARGET_32_BIG
291template
292void
293gold_undefined_symbol<32, true>(const Symbol* sym,
294 const Relocate_info<32, true>* relinfo,
295 size_t relnum, off_t reloffset);
296#endif
297
298#ifdef HAVE_TARGET_64_LITTLE
299template
300void
301gold_undefined_symbol<64, false>(const Symbol* sym,
302 const Relocate_info<64, false>* relinfo,
303 size_t relnum, off_t reloffset);
304#endif
305
306#ifdef HAVE_TARGET_64_BIG
307template
308void
309gold_undefined_symbol<64, true>(const Symbol* sym,
310 const Relocate_info<64, true>* relinfo,
311 size_t relnum, off_t reloffset);
312#endif
313
314} // End namespace gold.
This page took 0.060166 seconds and 4 git commands to generate.