diff options
author | Ralf Wildenhues <Ralf.Wildenhues@gmx.de> | 2010-12-14 21:33:26 +0000 |
---|---|---|
committer | Ralf Wildenhues <Ralf.Wildenhues@gmx.de> | 2010-12-14 21:33:26 +0000 |
commit | fedb228d125f9f510c29371a038cd70a9f9c5c61 (patch) | |
tree | 28c92c0766d08b11199afff27a3bb3914201ecee | |
parent | a8852dc55e66b770e87e3028189ed2be09e86b81 (diff) | |
download | fsf-binutils-gdb-fedb228d125f9f510c29371a038cd70a9f9c5c61.zip fsf-binutils-gdb-fedb228d125f9f510c29371a038cd70a9f9c5c61.tar.gz fsf-binutils-gdb-fedb228d125f9f510c29371a038cd70a9f9c5c61.tar.bz2 |
gold: fix race in FileRead::~View.
gold/:
* fileread.cc (file_counts_lock, file_counts_initialize_lock)
(total_mapped_bytes, current_mapped_bytes, maximum_mapped_bytes):
Move definition before File_read::View member definitions.
(File_read::View::~View): Initialize and hold lock before
updating current_mapped_bytes.
-rw-r--r-- | gold/ChangeLog | 8 | ||||
-rw-r--r-- | gold/fileread.cc | 27 |
2 files changed, 25 insertions, 10 deletions
diff --git a/gold/ChangeLog b/gold/ChangeLog index 7e1f613..526fb78 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,5 +1,13 @@ 2010-12-14 Ralf Wildenhues <Ralf.Wildenhues@gmx.de> + * fileread.cc (file_counts_lock, file_counts_initialize_lock) + (total_mapped_bytes, current_mapped_bytes, maximum_mapped_bytes): + Move definition before File_read::View member definitions. + (File_read::View::~View): Initialize and hold lock before + updating current_mapped_bytes. + +2010-12-14 Ralf Wildenhues <Ralf.Wildenhues@gmx.de> + * dwarf_reader.cc: Remove outdated comment. * gold-threads.cc: Fix typo in error message. * archive.cc: Fix typos in comments. diff --git a/gold/fileread.cc b/gold/fileread.cc index a16738a..14a02b2 100644 --- a/gold/fileread.cc +++ b/gold/fileread.cc @@ -57,6 +57,17 @@ readv(int, const iovec*, int) namespace gold { +// Class File_read. + +// A lock for the File_read static variables. +static Lock* file_counts_lock = NULL; +static Initialize_lock file_counts_initialize_lock(&file_counts_lock); + +// The File_read static variables. +unsigned long long File_read::total_mapped_bytes; +unsigned long long File_read::current_mapped_bytes; +unsigned long long File_read::maximum_mapped_bytes; + // Class File_read::View. File_read::View::~View() @@ -70,7 +81,12 @@ File_read::View::~View() case DATA_MMAPPED: if (::munmap(const_cast<unsigned char*>(this->data_), this->size_) != 0) gold_warning(_("munmap failed: %s"), strerror(errno)); - File_read::current_mapped_bytes -= this->size_; + if (!parameters->options_valid() || parameters->options().stats()) + { + file_counts_initialize_lock.initialize(); + Hold_optional_lock hl(file_counts_lock); + File_read::current_mapped_bytes -= this->size_; + } break; case DATA_NOT_OWNED: break; @@ -100,15 +116,6 @@ File_read::View::is_locked() // Class File_read. -// A lock for the File_read static variables. -static Lock* file_counts_lock = NULL; -static Initialize_lock file_counts_initialize_lock(&file_counts_lock); - -// The File_read static variables. -unsigned long long File_read::total_mapped_bytes; -unsigned long long File_read::current_mapped_bytes; -unsigned long long File_read::maximum_mapped_bytes; - File_read::~File_read() { gold_assert(this->token_.is_writable()); |