+// Class Lib_group static variables.
+unsigned int Lib_group::total_lib_groups;
+unsigned int Lib_group::total_members;
+unsigned int Lib_group::total_members_loaded;
+
+Lib_group::Lib_group(const Input_file_lib* lib, Task* task)
+ : Library_base(task), members_()
+{
+ this->members_.resize(lib->size());
+}
+
+const std::string&
+Lib_group::do_filename() const
+{
+ std::string *filename = new std::string("/group/");
+ return *filename;
+}
+
+// Select members from the lib group and add them to the link. We walk
+// through the members, and check if each one up should be included.
+// If the object says it should be included, we do so. We have to do
+// this in a loop, since including one member may create new undefined
+// symbols which may be satisfied by other members.
+
+void
+Lib_group::add_symbols(Symbol_table* symtab, Layout* layout,
+ Input_objects* input_objects)
+{
+ ++Lib_group::total_lib_groups;
+
+ Lib_group::total_members += this->members_.size();
+
+ bool added_new_object;
+ do
+ {
+ added_new_object = false;
+ unsigned int i = 0;
+ while (i < this->members_.size())
+ {
+ const Archive_member& member = this->members_[i];
+ Object* obj = member.obj_;
+ std::string why;
+
+ // Skip files with no symbols. Plugin objects have
+ // member.sd_ == NULL.
+ if (obj != NULL
+ && (member.sd_ == NULL || member.sd_->symbol_names != NULL))
+ {
+ Archive::Should_include t = obj->should_include_member(symtab,
+ layout,
+ member.sd_,
+ &why);
+
+ if (t != Archive::SHOULD_INCLUDE_YES)
+ {
+ ++i;
+ continue;
+ }
+
+ this->include_member(symtab, layout, input_objects, member);
+
+ added_new_object = true;
+ }
+ else
+ {
+ if (member.sd_ != NULL)
+ {
+ // The file must be locked in order to destroy the views
+ // associated with it.
+ gold_assert(obj != NULL);
+ obj->lock(this->task_);
+ delete member.sd_;
+ obj->unlock(this->task_);
+ }
+ }
+
+ this->members_[i] = this->members_.back();
+ this->members_.pop_back();
+ }
+ }
+ while (added_new_object);
+}
+
+// Include a lib group member in the link.
+
+void
+Lib_group::include_member(Symbol_table* symtab, Layout* layout,
+ Input_objects* input_objects,
+ const Archive_member& member)
+{
+ ++Lib_group::total_members_loaded;
+
+ Object* obj = member.obj_;
+ gold_assert(obj != NULL);
+
+ Pluginobj* pluginobj = obj->pluginobj();
+ if (pluginobj != NULL)
+ {
+ pluginobj->add_symbols(symtab, NULL, layout);
+ return;
+ }
+
+ Read_symbols_data* sd = member.sd_;
+ gold_assert(sd != NULL);
+ obj->lock(this->task_);
+ if (input_objects->add_object(obj))
+ {
+ if (layout->incremental_inputs() != NULL)
+ layout->incremental_inputs()->report_object(obj, member.arg_serial_,
+ this, NULL);
+ obj->layout(symtab, layout, sd);
+ obj->add_symbols(symtab, sd, layout);
+ }
+ delete sd;
+ // Unlock the file for the next task.
+ obj->unlock(this->task_);
+}
+
+// Iterate over all unused symbols, and call the visitor class V for each.
+
+void
+Lib_group::do_for_all_unused_symbols(Symbol_visitor_base* v) const
+{
+ // Files are removed from the members list when used, so all the
+ // files remaining on the list are unused.
+ for (std::vector<Archive_member>::const_iterator p = this->members_.begin();
+ p != this->members_.end();
+ ++p)
+ {
+ Object* obj = p->obj_;
+ obj->for_all_global_symbols(p->sd_, v);
+ }
+}
+
+// Print statistical information to stderr. This is used for --stats.
+
+void
+Lib_group::print_stats()
+{
+ fprintf(stderr, _("%s: lib groups: %u\n"),
+ program_name, Lib_group::total_lib_groups);
+ fprintf(stderr, _("%s: total lib groups members: %u\n"),
+ program_name, Lib_group::total_members);
+ fprintf(stderr, _("%s: loaded lib groups members: %u\n"),
+ program_name, Lib_group::total_members_loaded);
+}
+
+Task_token*
+Add_lib_group_symbols::is_runnable()
+{
+ if (this->readsyms_blocker_ != NULL && this->readsyms_blocker_->is_blocked())
+ return this->readsyms_blocker_;
+ if (this->this_blocker_ != NULL && this->this_blocker_->is_blocked())
+ return this->this_blocker_;
+ return NULL;
+}
+
+void
+Add_lib_group_symbols::locks(Task_locker* tl)
+{
+ tl->add(this, this->next_blocker_);
+}
+
+void
+Add_lib_group_symbols::run(Workqueue*)
+{
+ // For an incremental link, begin recording layout information.
+ Incremental_inputs* incremental_inputs = this->layout_->incremental_inputs();
+ if (incremental_inputs != NULL)
+ incremental_inputs->report_archive_begin(this->lib_, 0, NULL);
+
+ this->lib_->add_symbols(this->symtab_, this->layout_, this->input_objects_);
+
+ if (incremental_inputs != NULL)
+ incremental_inputs->report_archive_end(this->lib_);
+}
+
+Add_lib_group_symbols::~Add_lib_group_symbols()
+{
+ if (this->this_blocker_ != NULL)
+ delete this->this_blocker_;
+ // next_blocker_ is deleted by the task associated with the next
+ // input file.
+}
+