[RFC][PATCH] fix Read_symbols datarace
Evgeniy Dushistov
dushistov@mail.ru
Wed Nov 5 20:02:00 GMT 2014
After update to gcc 4.9.2, link of my project failed,
because of ld.gold crash.
I reproduce this problem:
https://sourceware.org/bugzilla/show_bug.cgi?id=17538
Today I dig into this, and see that problem in
that multiply threads run
Read_symbols::do_read_symbols
which call
Plugin_manager::claim_file
which call
this->objects_.push_back
without any sync, and so std::vector was modified
in many threads without any locks, which of course
cause crashes.
Attached patch fix problem for me.
Comments?
--
/Evgeniy
-------------- next part --------------
diff --git a/gold/plugin.cc b/gold/plugin.cc
index 0339d42..4b0f3cf 100644
--- a/gold/plugin.cc
+++ b/gold/plugin.cc
@@ -427,6 +427,7 @@ Plugin_manager::~Plugin_manager()
++obj)
delete *obj;
this->objects_.clear();
+ delete this->lock_;
}
// Load all plugin libraries.
@@ -447,6 +448,10 @@ Pluginobj*
Plugin_manager::claim_file(Input_file* input_file, off_t offset,
off_t filesize, Object* elf_object)
{
+ bool lock_initialized = this->initialize_lock_.initialize();
+
+ gold_assert(lock_initialized);
+ Hold_lock hl(*this->lock_);
if (this->in_replacement_phase_)
return NULL;
diff --git a/gold/plugin.h b/gold/plugin.h
index 9ef2812..174e81d 100644
--- a/gold/plugin.h
+++ b/gold/plugin.h
@@ -134,7 +134,7 @@ class Plugin_manager
in_claim_file_handler_(false),
options_(options), workqueue_(NULL), task_(NULL), input_objects_(NULL),
symtab_(NULL), layout_(NULL), dirpath_(NULL), mapfile_(NULL),
- this_blocker_(NULL), extra_search_path_()
+ this_blocker_(NULL), extra_search_path_(), lock_(NULL), initialize_lock_(&lock_)
{ this->current_ = plugins_.end(); }
~Plugin_manager();
@@ -376,6 +376,8 @@ class Plugin_manager
// An extra directory to seach for the libraries passed by
// add_input_library.
std::string extra_search_path_;
+ Lock *lock_;
+ Initialize_lock initialize_lock_;
};
More information about the Binutils
mailing list