Add -Wshadow to the gcc command line options used when compiling the binutils.
[deliverable/binutils-gdb.git] / gold / errors.cc
index c979463dfc25014bcf0138706d7c6682f7e7deac..a7c3ad20e8e6fcf8d05069674323bd98a2bc6d87 100644 (file)
@@ -1,6 +1,6 @@
 // errors.cc -- handle errors for gold
 
-// Copyright 2006, 2007 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 // Written by Ian Lance Taylor <iant@google.com>.
 
 // This file is part of gold.
@@ -38,19 +38,39 @@ namespace gold
 
 const int Errors::max_undefined_error_report;
 
-Errors::Errors(const char* program_name)
-  : program_name_(program_name), lock_(NULL), error_count_(0),
-    warning_count_(0), undefined_symbols_()
+Errors::Errors(const char* prog_name)
+  : program_name_(prog_name), lock_(NULL), initialize_lock_(&this->lock_),
+    error_count_(0), warning_count_(0), undefined_symbols_()
 {
 }
 
-// Initialize the lock_ field.
+// Initialize the lock_ field.  If we have not yet processed the
+// parameters, then we can't initialize, since we don't yet know
+// whether we are using threads.  That is OK, since if we haven't
+// processed the parameters, we haven't created any threads, and we
+// don't need a lock.  Return true if the lock is now initialized.
 
-void
+bool
 Errors::initialize_lock()
 {
-  if (this->lock_ == NULL)
-    this->lock_ = new Lock;
+  return this->initialize_lock_.initialize();
+}
+
+// Increment a counter, holding the lock if available.
+
+void
+Errors::increment_counter(int *counter)
+{
+  if (!this->initialize_lock())
+    {
+      // The lock does not exist, which means that we don't need it.
+      ++*counter;
+    }
+  else
+    {
+      Hold_lock h(*this->lock_);
+      ++*counter;
+    }
 }
 
 // Report a fatal error.
@@ -58,7 +78,7 @@ Errors::initialize_lock()
 void
 Errors::fatal(const char* format, va_list args)
 {
-  fprintf(stderr, "%s: ", this->program_name_);
+  fprintf(stderr, _("%s: fatal error: "), this->program_name_);
   vfprintf(stderr, format, args);
   fputc('\n', stderr);
   gold_exit(false);
@@ -69,15 +89,11 @@ Errors::fatal(const char* format, va_list args)
 void
 Errors::error(const char* format, va_list args)
 {
-  fprintf(stderr, "%s: ", this->program_name_);
+  fprintf(stderr, _("%s: error: "), this->program_name_);
   vfprintf(stderr, format, args);
   fputc('\n', stderr);
 
-  this->initialize_lock();
-  {
-    Hold_lock h(*this->lock_);
-    ++this->error_count_;
-  }
+  this->increment_counter(&this->error_count_);
 }
 
 // Report a warning.
@@ -89,11 +105,16 @@ Errors::warning(const char* format, va_list args)
   vfprintf(stderr, format, args);
   fputc('\n', stderr);
 
-  this->initialize_lock();
-  {
-    Hold_lock h(*this->lock_);
-    ++this->warning_count_;
-  }
+  this->increment_counter(&this->warning_count_);
+}
+
+// Print an informational message.
+
+void
+Errors::info(const char* format, va_list args)
+{
+  vfprintf(stderr, format, args);
+  fputc('\n', stderr);
 }
 
 // Report an error at a reloc location.
@@ -104,16 +125,12 @@ Errors::error_at_location(const Relocate_info<size, big_endian>* relinfo,
                          size_t relnum, off_t reloffset,
                          const char* format, va_list args)
 {
-  fprintf(stderr, "%s: %s: ", this->program_name_,
+  fprintf(stderr, _("%s: %s: error: "), this->program_name_,
          relinfo->location(relnum, reloffset).c_str());
   vfprintf(stderr, format, args);
   fputc('\n', stderr);
 
-  this->initialize_lock();
-  {
-    Hold_lock h(*this->lock_);
-    ++this->error_count_;
-  }
+  this->increment_counter(&this->error_count_);
 }
 
 // Report a warning at a reloc location.
@@ -129,31 +146,32 @@ Errors::warning_at_location(const Relocate_info<size, big_endian>* relinfo,
   vfprintf(stderr, format, args);
   fputc('\n', stderr);
 
-  this->initialize_lock();
-  {
-    Hold_lock h(*this->lock_);
-    ++this->warning_count_;
-  }
+  this->increment_counter(&this->warning_count_);
 }
 
-// Issue an undefined symbol error.
+// Issue an undefined symbol error with a caller-supplied location string.
 
-template<int size, bool big_endian>
 void
-Errors::undefined_symbol(const Symbol* sym,
-                        const Relocate_info<size, big_endian>* relinfo,
-                        size_t relnum, off_t reloffset)
+Errors::undefined_symbol(const Symbol* sym, const std::string& location)
 {
-  this->initialize_lock();
+  bool initialized = this->initialize_lock();
+  gold_assert(initialized);
   {
     Hold_lock h(*this->lock_);
     if (++this->undefined_symbols_[sym] >= max_undefined_error_report)
       return;
     ++this->error_count_;
   }
-  fprintf(stderr, _("%s: %s: undefined reference to '%s'\n"),
-         this->program_name_, relinfo->location(relnum, reloffset).c_str(),
-         sym->demangled_name().c_str());
+  const char* const version = sym->version();
+  if (version == NULL)
+    fprintf(stderr, _("%s: %s: error: undefined reference to '%s'\n"),
+           this->program_name_, location.c_str(),
+           sym->demangled_name().c_str());
+  else
+    fprintf(stderr,
+            _("%s: %s: error: undefined reference to '%s', version '%s'\n"),
+           this->program_name_, location.c_str(),
+           sym->demangled_name().c_str(), version);
 }
 
 // Issue a debugging message.
@@ -206,6 +224,17 @@ gold_warning(const char* format, ...)
   va_end(args);
 }
 
+// Print an informational message.
+
+void
+gold_info(const char* format, ...)
+{
+  va_list args;
+  va_start(args, format);
+  parameters->errors()->info(format, args);
+  va_end(args);
+}
+
 // Report an error at a location.
 
 template<int size, bool big_endian>
@@ -238,13 +267,22 @@ gold_warning_at_location(const Relocate_info<size, big_endian>* relinfo,
 
 // Report an undefined symbol.
 
+void
+gold_undefined_symbol(const Symbol* sym)
+{
+  parameters->errors()->undefined_symbol(sym, sym->object()->name().c_str());
+}
+
+// Report an undefined symbol at a reloc location
+
 template<int size, bool big_endian>
 void
-gold_undefined_symbol(const Symbol* sym,
+gold_undefined_symbol_at_location(const Symbol* sym,
                      const Relocate_info<size, big_endian>* relinfo,
                      size_t relnum, off_t reloffset)
 {
-  parameters->errors()->undefined_symbol(sym, relinfo, relnum, reloffset);
+  parameters->errors()->undefined_symbol(sym,
+                                         relinfo->location(relnum, reloffset));
 }
 
 #ifdef HAVE_TARGET_32_LITTLE
@@ -314,33 +352,37 @@ gold_warning_at_location<64, true>(const Relocate_info<64, true>* relinfo,
 #ifdef HAVE_TARGET_32_LITTLE
 template
 void
-gold_undefined_symbol<32, false>(const Symbol* sym,
-                                const Relocate_info<32, false>* relinfo,
-                                size_t relnum, off_t reloffset);
+gold_undefined_symbol_at_location<32, false>(
+    const Symbol* sym,
+    const Relocate_info<32, false>* relinfo,
+    size_t relnum, off_t reloffset);
 #endif
 
 #ifdef HAVE_TARGET_32_BIG
 template
 void
-gold_undefined_symbol<32, true>(const Symbol* sym,
-                               const Relocate_info<32, true>* relinfo,
-                               size_t relnum, off_t reloffset);
+gold_undefined_symbol_at_location<32, true>(
+    const Symbol* sym,
+    const Relocate_info<32, true>* relinfo,
+    size_t relnum, off_t reloffset);
 #endif
 
 #ifdef HAVE_TARGET_64_LITTLE
 template
 void
-gold_undefined_symbol<64, false>(const Symbol* sym,
-                                const Relocate_info<64, false>* relinfo,
-                                size_t relnum, off_t reloffset);
+gold_undefined_symbol_at_location<64, false>(
+    const Symbol* sym,
+    const Relocate_info<64, false>* relinfo,
+    size_t relnum, off_t reloffset);
 #endif
 
 #ifdef HAVE_TARGET_64_BIG
 template
 void
-gold_undefined_symbol<64, true>(const Symbol* sym,
-                               const Relocate_info<64, true>* relinfo,
-                               size_t relnum, off_t reloffset);
+gold_undefined_symbol_at_location<64, true>(
+    const Symbol* sym,
+    const Relocate_info<64, true>* relinfo,
+    size_t relnum, off_t reloffset);
 #endif
 
 } // End namespace gold.
This page took 0.028952 seconds and 4 git commands to generate.