From 2dd3e587bdab39d73086c35be60399e096d48b46 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 7 Jan 2008 05:19:02 +0000 Subject: Report linker script errors with line numbers. Ignore OUTPUT_FORMAT with three arguments, and ignore OUTPUT_ARCH. --- gold/errors.cc | 55 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 24 deletions(-) (limited to 'gold/errors.cc') diff --git a/gold/errors.cc b/gold/errors.cc index c979463..85c5512 100644 --- a/gold/errors.cc +++ b/gold/errors.cc @@ -44,13 +44,35 @@ Errors::Errors(const char* program_name) { } -// 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) + 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. @@ -73,11 +95,7 @@ Errors::error(const char* format, va_list args) 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 +107,7 @@ 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_); } // Report an error at a reloc location. @@ -109,11 +123,7 @@ Errors::error_at_location(const Relocate_info* relinfo, 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,11 +139,7 @@ Errors::warning_at_location(const Relocate_info* 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. @@ -144,7 +150,8 @@ Errors::undefined_symbol(const Symbol* sym, const Relocate_info* relinfo, size_t relnum, off_t reloffset) { - 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) -- cgit v1.1