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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [gnu/] [binutils/] [gold/] [errors.cc] - Blame information for rev 127

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

Line No. Rev Author Line
1 27 khays
// errors.cc -- handle errors for gold
2
 
3
// Copyright 2006, 2007, 2008, 2009, 2010, 2011 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: error: "),
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: warning: "),
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
  const char* zmsg;
161
  {
162
    Hold_lock h(*this->lock_);
163
    if (++this->undefined_symbols_[sym] >= max_undefined_error_report)
164
      return;
165
    if (parameters->options().warn_unresolved_symbols())
166
      {
167
        ++this->warning_count_;
168
        zmsg = _("warning");
169
      }
170
    else
171
      {
172
        ++this->error_count_;
173
        zmsg = _("error");
174
      }
175
  }
176
 
177
  const char* const version = sym->version();
178
  if (version == NULL)
179
    fprintf(stderr, _("%s: %s: undefined reference to '%s'\n"),
180
            location.c_str(), zmsg, sym->demangled_name().c_str());
181
  else
182
    fprintf(stderr,
183
            _("%s: %s: undefined reference to '%s', version '%s'\n"),
184
            location.c_str(), zmsg, sym->demangled_name().c_str(), version);
185
}
186
 
187
// Issue a debugging message.
188
 
189
void
190
Errors::debug(const char* format, ...)
191
{
192
  fprintf(stderr, _("%s: "), this->program_name_);
193
 
194
  va_list args;
195
  va_start(args, format);
196
  vfprintf(stderr, format, args);
197
  va_end(args);
198
 
199
  fputc('\n', stderr);
200
}
201
 
202
// The functions which the rest of the code actually calls.
203
 
204
// Report a fatal error.
205
 
206
void
207
gold_fatal(const char* format, ...)
208
{
209
  va_list args;
210
  va_start(args, format);
211
  parameters->errors()->fatal(format, args);
212
  va_end(args);
213
}
214
 
215
// Report an error.
216
 
217
void
218
gold_error(const char* format, ...)
219
{
220
  va_list args;
221
  va_start(args, format);
222
  parameters->errors()->error(format, args);
223
  va_end(args);
224
}
225
 
226
// Report a warning.
227
 
228
void
229
gold_warning(const char* format, ...)
230
{
231
  va_list args;
232
  va_start(args, format);
233
  parameters->errors()->warning(format, args);
234
  va_end(args);
235
}
236
 
237
// Print an informational message.
238
 
239
void
240
gold_info(const char* format, ...)
241
{
242
  va_list args;
243
  va_start(args, format);
244
  parameters->errors()->info(format, args);
245
  va_end(args);
246
}
247
 
248
// Report an error at a location.
249
 
250
template<int size, bool big_endian>
251
void
252
gold_error_at_location(const Relocate_info<size, big_endian>* relinfo,
253
                       size_t relnum, off_t reloffset,
254
                       const char* format, ...)
255
{
256
  va_list args;
257
  va_start(args, format);
258
  parameters->errors()->error_at_location(relinfo, relnum, reloffset,
259
                                          format, args);
260
  va_end(args);
261
}
262
 
263
// Report a warning at a location.
264
 
265
template<int size, bool big_endian>
266
void
267
gold_warning_at_location(const Relocate_info<size, big_endian>* relinfo,
268
                         size_t relnum, off_t reloffset,
269
                         const char* format, ...)
270
{
271
  va_list args;
272
  va_start(args, format);
273
  parameters->errors()->warning_at_location(relinfo, relnum, reloffset,
274
                                            format, args);
275
  va_end(args);
276
}
277
 
278
// Report an undefined symbol.
279
 
280
void
281
gold_undefined_symbol(const Symbol* sym)
282
{
283
  parameters->errors()->undefined_symbol(sym, sym->object()->name().c_str());
284
}
285
 
286
// Report an undefined symbol at a reloc location
287
 
288
template<int size, bool big_endian>
289
void
290
gold_undefined_symbol_at_location(const Symbol* sym,
291
                      const Relocate_info<size, big_endian>* relinfo,
292
                      size_t relnum, off_t reloffset)
293
{
294
  parameters->errors()->undefined_symbol(sym,
295
                                         relinfo->location(relnum, reloffset));
296
}
297
 
298
#ifdef HAVE_TARGET_32_LITTLE
299
template
300
void
301
gold_error_at_location<32, false>(const Relocate_info<32, false>* relinfo,
302
                                  size_t relnum, off_t reloffset,
303
                                  const char* format, ...);
304
#endif
305
 
306
#ifdef HAVE_TARGET_32_BIG
307
template
308
void
309
gold_error_at_location<32, true>(const Relocate_info<32, true>* relinfo,
310
                                 size_t relnum, off_t reloffset,
311
                                 const char* format, ...);
312
#endif
313
 
314
#ifdef HAVE_TARGET_64_LITTLE
315
template
316
void
317
gold_error_at_location<64, false>(const Relocate_info<64, false>* relinfo,
318
                                  size_t relnum, off_t reloffset,
319
                                  const char* format, ...);
320
#endif
321
 
322
#ifdef HAVE_TARGET_64_BIG
323
template
324
void
325
gold_error_at_location<64, true>(const Relocate_info<64, true>* relinfo,
326
                                 size_t relnum, off_t reloffset,
327
                                 const char* format, ...);
328
#endif
329
 
330
#ifdef HAVE_TARGET_32_LITTLE
331
template
332
void
333
gold_warning_at_location<32, false>(const Relocate_info<32, false>* relinfo,
334
                                    size_t relnum, off_t reloffset,
335
                                    const char* format, ...);
336
#endif
337
 
338
#ifdef HAVE_TARGET_32_BIG
339
template
340
void
341
gold_warning_at_location<32, true>(const Relocate_info<32, true>* relinfo,
342
                                   size_t relnum, off_t reloffset,
343
                                   const char* format, ...);
344
#endif
345
 
346
#ifdef HAVE_TARGET_64_LITTLE
347
template
348
void
349
gold_warning_at_location<64, false>(const Relocate_info<64, false>* relinfo,
350
                                    size_t relnum, off_t reloffset,
351
                                    const char* format, ...);
352
#endif
353
 
354
#ifdef HAVE_TARGET_64_BIG
355
template
356
void
357
gold_warning_at_location<64, true>(const Relocate_info<64, true>* relinfo,
358
                                   size_t relnum, off_t reloffset,
359
                                   const char* format, ...);
360
#endif
361
 
362
#ifdef HAVE_TARGET_32_LITTLE
363
template
364
void
365
gold_undefined_symbol_at_location<32, false>(
366
    const Symbol* sym,
367
    const Relocate_info<32, false>* relinfo,
368
    size_t relnum, off_t reloffset);
369
#endif
370
 
371
#ifdef HAVE_TARGET_32_BIG
372
template
373
void
374
gold_undefined_symbol_at_location<32, true>(
375
    const Symbol* sym,
376
    const Relocate_info<32, true>* relinfo,
377
    size_t relnum, off_t reloffset);
378
#endif
379
 
380
#ifdef HAVE_TARGET_64_LITTLE
381
template
382
void
383
gold_undefined_symbol_at_location<64, false>(
384
    const Symbol* sym,
385
    const Relocate_info<64, false>* relinfo,
386
    size_t relnum, off_t reloffset);
387
#endif
388
 
389
#ifdef HAVE_TARGET_64_BIG
390
template
391
void
392
gold_undefined_symbol_at_location<64, true>(
393
    const Symbol* sym,
394
    const Relocate_info<64, true>* relinfo,
395
    size_t relnum, off_t reloffset);
396
#endif
397
 
398
} // End namespace gold.

powered by: WebSVN 2.1.0

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