gold: fix race in FileRead::~View.
authorRalf Wildenhues <Ralf.Wildenhues@gmx.de>
Tue, 14 Dec 2010 21:33:26 +0000 (21:33 +0000)
committerRalf Wildenhues <Ralf.Wildenhues@gmx.de>
Tue, 14 Dec 2010 21:33:26 +0000 (21:33 +0000)
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.

gold/ChangeLog
gold/fileread.cc

index 7e1f6137deefd14d3e78a244e1cdf920df771c96..526fb78ae7bbd377830876ee891ad37465be38cf 100644 (file)
@@ -1,3 +1,11 @@
+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.
index a16738a0d593531271af644f6ce4439fb032faed..14a02b2f52f9ae29274d97342d461bd5d81a8afe 100644 (file)
@@ -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());