OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [binutils-2.20.1/] [gold/] [errors.cc] - Blame information for rev 363

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.