PR 6048
[binutils-gdb.git] / gold / errors.cc
index 2da1a2569edd9e6943b42a522becdf82c893ad1a..01ce97f5eb93b65249e94a1b6bb0c66429e0f0da 100644 (file)
@@ -1,6 +1,6 @@
 // errors.cc -- handle errors for gold
 
-// Copyright 2006, 2007 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
 // Written by Ian Lance Taylor <iant@google.com>.
 
 // This file is part of gold.
@@ -39,11 +39,42 @@ namespace gold
 const int Errors::max_undefined_error_report;
 
 Errors::Errors(const char* program_name)
-  : program_name_(program_name), lock_(), error_count_(0), warning_count_(0),
-    undefined_symbols_()
+  : program_name_(program_name), lock_(NULL), error_count_(0),
+    warning_count_(0), undefined_symbols_()
 {
 }
 
+// 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.
+
+bool
+Errors::initialize_lock()
+{
+  if (this->lock_ == NULL && parameters->options_valid())
+    this->lock_ = new Lock;
+  return this->lock_ != NULL;
+}
+
+// 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.
 
 void
@@ -63,10 +94,8 @@ Errors::error(const char* format, va_list args)
   fprintf(stderr, "%s: ", this->program_name_);
   vfprintf(stderr, format, args);
   fputc('\n', stderr);
-  {
-    Hold_lock h(this->lock_);
-    ++this->error_count_;
-  }
+
+  this->increment_counter(&this->error_count_);
 }
 
 // Report a warning.
@@ -77,10 +106,17 @@ Errors::warning(const char* format, va_list args)
   fprintf(stderr, _("%s: warning: "), this->program_name_);
   vfprintf(stderr, format, args);
   fputc('\n', stderr);
-  {
-    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.
@@ -95,10 +131,8 @@ Errors::error_at_location(const Relocate_info<size, big_endian>* relinfo,
          relinfo->location(relnum, reloffset).c_str());
   vfprintf(stderr, format, args);
   fputc('\n', stderr);
-  {
-    Hold_lock h(this->lock_);
-    ++this->error_count_;
-  }
+
+  this->increment_counter(&this->error_count_);
 }
 
 // Report a warning at a reloc location.
@@ -113,10 +147,8 @@ Errors::warning_at_location(const Relocate_info<size, big_endian>* relinfo,
          relinfo->location(relnum, reloffset).c_str());
   vfprintf(stderr, format, args);
   fputc('\n', stderr);
-  {
-    Hold_lock h(this->lock_);
-    ++this->warning_count_;
-  }
+
+  this->increment_counter(&this->warning_count_);
 }
 
 // Issue an undefined symbol error.
@@ -127,17 +159,39 @@ Errors::undefined_symbol(const Symbol* sym,
                         const Relocate_info<size, big_endian>* relinfo,
                         size_t relnum, off_t reloffset)
 {
+  bool initialized = this->initialize_lock();
+  gold_assert(initialized);
   {
-    Hold_lock h(this->lock_);
+    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: undefined reference to '%s'\n"),
+           this->program_name_, relinfo->location(relnum, reloffset).c_str(),
+           sym->demangled_name().c_str());
+  else
+    fprintf(stderr, _("%s: %s: undefined reference to '%s', version '%s'\n"),
+           this->program_name_, relinfo->location(relnum, reloffset).c_str(),
+           sym->demangled_name().c_str(), version);
 }
 
+// Issue a debugging message.
+
+void
+Errors::debug(const char* format, ...)
+{
+  fprintf(stderr, _("%s: "), this->program_name_);
+
+  va_list args;
+  va_start(args, format);
+  vfprintf(stderr, format, args);
+  va_end(args);
+
+  fputc('\n', stderr);
+}
 
 // The functions which the rest of the code actually calls.
 
@@ -174,6 +228,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>