gold: Avoid sharing Plugin_list::iterator

class Plugin_manager has

  // A pointer to the current plugin.  Used while loading plugins.
  Plugin_list::iterator current_;

The same iterator is shared by all threads. It is OK to use it to load
plugins since only one thread loads plugins.  Avoid sharing Plugin_list
iterator in all other cases.

	PR gold/26200
	* plugin.cc (Plugin_manager::claim_file): Don't share Plugin_list
	iterator.
	(Plugin_manager::all_symbols_read): Likewise.
	(Plugin_manager::cleanup): Likewise.
This commit is contained in:
H.J. Lu 2020-11-08 04:10:01 -08:00
parent a907d563de
commit d4820dac5e
2 changed files with 25 additions and 17 deletions

View File

@ -1,3 +1,11 @@
2020-11-08 H.J. Lu <hongjiu.lu@intel.com>
PR gold/26200
* plugin.cc (Plugin_manager::claim_file): Don't share Plugin_list
iterator.
(Plugin_manager::all_symbols_read): Likewise.
(Plugin_manager::cleanup): Likewise.
2020-11-03 Alan Modra <amodra@gmail.com> 2020-11-03 Alan Modra <amodra@gmail.com>
* powerpc.cc (Target_powerpc::tocsave_loc): Return a pointer. * powerpc.cc (Target_powerpc::tocsave_loc): Return a pointer.

View File

@ -755,15 +755,15 @@ Plugin_manager::claim_file(Input_file* input_file, off_t offset,
this->objects_.push_back(elf_object); this->objects_.push_back(elf_object);
this->in_claim_file_handler_ = true; this->in_claim_file_handler_ = true;
for (this->current_ = this->plugins_.begin(); for (Plugin_list::iterator p = this->plugins_.begin();
this->current_ != this->plugins_.end(); p != this->plugins_.end();
++this->current_) ++p)
{ {
// If we aren't yet in replacement phase, allow plugins to claim input // If we aren't yet in replacement phase, allow plugins to claim input
// files, otherwise notify the plugin of the new input file, if needed. // files, otherwise notify the plugin of the new input file, if needed.
if (!this->in_replacement_phase_) if (!this->in_replacement_phase_)
{ {
if ((*this->current_)->claim_file(&this->plugin_input_file_)) if ((*p)->claim_file(&this->plugin_input_file_))
{ {
this->any_claimed_ = true; this->any_claimed_ = true;
this->in_claim_file_handler_ = false; this->in_claim_file_handler_ = false;
@ -775,7 +775,7 @@ Plugin_manager::claim_file(Input_file* input_file, off_t offset,
: elf_object->name()); : elf_object->name());
this->recorder_->claimed_file(objname, this->recorder_->claimed_file(objname,
offset, filesize, offset, filesize,
(*this->current_)->filename()); (*p)->filename());
} }
if (this->objects_.size() > handle if (this->objects_.size() > handle
@ -790,7 +790,7 @@ Plugin_manager::claim_file(Input_file* input_file, off_t offset,
} }
else else
{ {
(*this->current_)->new_input(&this->plugin_input_file_); (*p)->new_input(&this->plugin_input_file_);
} }
} }
@ -850,10 +850,10 @@ Plugin_manager::all_symbols_read(Workqueue* workqueue, Task* task,
layout->script_options()->set_defsym_uses_in_real_elf(symtab); layout->script_options()->set_defsym_uses_in_real_elf(symtab);
layout->script_options()->find_defsym_defs(this->defsym_defines_set_); layout->script_options()->find_defsym_defs(this->defsym_defines_set_);
for (this->current_ = this->plugins_.begin(); for (Plugin_list::iterator p = this->plugins_.begin();
this->current_ != this->plugins_.end(); p != this->plugins_.end();
++this->current_) ++p)
(*this->current_)->all_symbols_read(); (*p)->all_symbols_read();
if (this->any_added_) if (this->any_added_)
{ {
@ -1028,10 +1028,10 @@ Plugin_manager::cleanup()
close_all_descriptors(); close_all_descriptors();
} }
for (this->current_ = this->plugins_.begin(); for (Plugin_list::iterator p = this->plugins_.begin();
this->current_ != this->plugins_.end(); p != this->plugins_.end();
++this->current_) ++p)
(*this->current_)->cleanup(); (*p)->cleanup();
} }
// Make a new Pluginobj object. This is called when the plugin calls // Make a new Pluginobj object. This is called when the plugin calls