1 // archive.cc -- archive support for gold
3 // Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
29 #include "libiberty.h"
30 #include "filenames.h"
46 // The header of an entry in the archive. This is all readable text,
47 // padded with spaces where necesary. If the contents of an archive
48 // are all text file, the entire archive is readable.
50 struct Archive::Archive_header
54 // The file modification time.
56 // The user's UID in decimal.
58 // The user's GID in decimal.
60 // The file mode in octal.
62 // The file size in decimal.
64 // The final magic code.
68 // Class Archive static variables.
69 unsigned int Archive::total_archives;
70 unsigned int Archive::total_members;
71 unsigned int Archive::total_members_loaded;
75 const char Archive::armag[sarmag] =
77 '!', '<', 'a', 'r', 'c', 'h', '>', '\n'
80 const char Archive::armagt[sarmag] =
82 '!', '<', 't', 'h', 'i', 'n', '>', '\n'
85 const char Archive::arfmag[2] = { '`', '\n' };
87 Archive::Archive(const std::string& name, Input_file* input_file,
88 bool is_thin_archive, Dirsearch* dirpath, Task* task)
89 : name_(name), input_file_(input_file), armap_(), armap_names_(),
90 extended_names_(), armap_checked_(), seen_offsets_(), members_(),
91 is_thin_archive_(is_thin_archive), included_member_(false),
92 nested_archives_(), dirpath_(dirpath), task_(task), num_members_(0)
95 parameters->options().check_excluded_libs(input_file->found_name());
98 // Set up the archive: read the symbol map and the extended name
104 // We need to ignore empty archives.
105 if (this->input_file_->file().filesize() == sarmag)
108 // The first member of the archive should be the symbol table.
109 std::string armap_name;
110 section_size_type armap_size =
111 convert_to_section_size_type(this->read_header(sarmag, false,
114 if (armap_name.empty())
116 this->read_armap(sarmag + sizeof(Archive_header), armap_size);
117 off = sarmag + sizeof(Archive_header) + armap_size;
119 else if (!this->input_file_->options().whole_archive())
120 gold_error(_("%s: no archive symbol table (run ranlib)"),
121 this->name().c_str());
123 // See if there is an extended name table. We cache these views
124 // because it is likely that we will want to read the following
125 // header in the add_symbols routine.
129 section_size_type extended_size =
130 convert_to_section_size_type(this->read_header(off, true, &xname, NULL));
133 const unsigned char* p = this->get_view(off + sizeof(Archive_header),
134 extended_size, false, true);
135 const char* px = reinterpret_cast<const char*>(p);
136 this->extended_names_.assign(px, extended_size);
138 bool preread_syms = (parameters->options().threads()
139 && parameters->options().preread_archive_symbols());
140 #ifndef ENABLE_THREADS
141 preread_syms = false;
143 if (parameters->options().has_plugins())
144 preread_syms = false;
147 this->read_all_symbols();
150 // Unlock any nested archives.
153 Archive::unlock_nested_archives()
155 for (Nested_archive_table::iterator p = this->nested_archives_.begin();
156 p != this->nested_archives_.end();
159 p->second->unlock(this->task_);
163 // Read the archive symbol map.
166 Archive::read_armap(off_t start, section_size_type size)
168 // To count the total number of archive members, we'll just count
169 // the number of times the file offset changes. Since most archives
170 // group the symbols in the armap by object, this ought to give us
171 // an accurate count.
172 off_t last_seen_offset = -1;
174 // Read in the entire armap.
175 const unsigned char* p = this->get_view(start, size, true, false);
177 // Numbers in the armap are always big-endian.
178 const elfcpp::Elf_Word* pword = reinterpret_cast<const elfcpp::Elf_Word*>(p);
179 unsigned int nsyms = elfcpp::Swap<32, true>::readval(pword);
182 // Note that the addition is in units of sizeof(elfcpp::Elf_Word).
183 const char* pnames = reinterpret_cast<const char*>(pword + nsyms);
184 section_size_type names_size =
185 reinterpret_cast<const char*>(p) + size - pnames;
186 this->armap_names_.assign(pnames, names_size);
188 this->armap_.resize(nsyms);
190 section_offset_type name_offset = 0;
191 for (unsigned int i = 0; i < nsyms; ++i)
193 this->armap_[i].name_offset = name_offset;
194 this->armap_[i].file_offset = elfcpp::Swap<32, true>::readval(pword);
195 name_offset += strlen(pnames + name_offset) + 1;
197 if (this->armap_[i].file_offset != last_seen_offset)
199 last_seen_offset = this->armap_[i].file_offset;
200 ++this->num_members_;
204 if (static_cast<section_size_type>(name_offset) > names_size)
205 gold_error(_("%s: bad archive symbol table names"),
206 this->name().c_str());
208 // This array keeps track of which symbols are for archive elements
209 // which we have already included in the link.
210 this->armap_checked_.resize(nsyms);
213 // Read the header of an archive member at OFF. Fail if something
214 // goes wrong. Return the size of the member. Set *PNAME to the name
218 Archive::read_header(off_t off, bool cache, std::string* pname,
221 const unsigned char* p = this->get_view(off, sizeof(Archive_header), true,
223 const Archive_header* hdr = reinterpret_cast<const Archive_header*>(p);
224 return this->interpret_header(hdr, off, pname, nested_off);
227 // Interpret the header of HDR, the header of the archive member at
228 // file offset OFF. Fail if something goes wrong. Return the size of
229 // the member. Set *PNAME to the name of the member.
232 Archive::interpret_header(const Archive_header* hdr, off_t off,
233 std::string* pname, off_t* nested_off) const
235 if (memcmp(hdr->ar_fmag, arfmag, sizeof arfmag) != 0)
237 gold_error(_("%s: malformed archive header at %zu"),
238 this->name().c_str(), static_cast<size_t>(off));
239 return this->input_file_->file().filesize() - off;
242 const int size_string_size = sizeof hdr->ar_size;
243 char size_string[size_string_size + 1];
244 memcpy(size_string, hdr->ar_size, size_string_size);
245 char* ps = size_string + size_string_size;
246 while (ps[-1] == ' ')
252 off_t member_size = strtol(size_string, &end, 10);
255 || (member_size == LONG_MAX && errno == ERANGE))
257 gold_error(_("%s: malformed archive header size at %zu"),
258 this->name().c_str(), static_cast<size_t>(off));
259 return this->input_file_->file().filesize() - off;
262 if (hdr->ar_name[0] != '/')
264 const char* name_end = strchr(hdr->ar_name, '/');
266 || name_end - hdr->ar_name >= static_cast<int>(sizeof hdr->ar_name))
268 gold_error(_("%s: malformed archive header name at %zu"),
269 this->name().c_str(), static_cast<size_t>(off));
270 return this->input_file_->file().filesize() - off;
272 pname->assign(hdr->ar_name, name_end - hdr->ar_name);
273 if (nested_off != NULL)
276 else if (hdr->ar_name[1] == ' ')
278 // This is the symbol table.
282 else if (hdr->ar_name[1] == '/')
284 // This is the extended name table.
285 pname->assign(1, '/');
290 long x = strtol(hdr->ar_name + 1, &end, 10);
293 y = strtol(end + 1, &end, 10);
296 || (x == LONG_MAX && errno == ERANGE)
297 || static_cast<size_t>(x) >= this->extended_names_.size())
299 gold_error(_("%s: bad extended name index at %zu"),
300 this->name().c_str(), static_cast<size_t>(off));
301 return this->input_file_->file().filesize() - off;
304 const char* name = this->extended_names_.data() + x;
305 const char* name_end = strchr(name, '\n');
306 if (static_cast<size_t>(name_end - name) > this->extended_names_.size()
307 || name_end[-1] != '/')
309 gold_error(_("%s: bad extended name entry at header %zu"),
310 this->name().c_str(), static_cast<size_t>(off));
311 return this->input_file_->file().filesize() - off;
313 pname->assign(name, name_end - 1 - name);
314 if (nested_off != NULL)
321 // An archive member iterator.
323 class Archive::const_iterator
326 // The header of an archive member. This is what this iterator
330 // The name of the member.
332 // The file offset of the member.
334 // The file offset of a nested archive member.
336 // The size of the member.
340 const_iterator(Archive* archive, off_t off)
341 : archive_(archive), off_(off)
342 { this->read_next_header(); }
346 { return this->header_; }
350 { return &this->header_; }
355 if (this->off_ == this->archive_->file().filesize())
357 this->off_ += sizeof(Archive_header);
358 if (!this->archive_->is_thin_archive())
359 this->off_ += this->header_.size;
360 if ((this->off_ & 1) != 0)
362 this->read_next_header();
369 const_iterator ret = *this;
375 operator==(const const_iterator p) const
376 { return this->off_ == p->off; }
379 operator!=(const const_iterator p) const
380 { return this->off_ != p->off; }
386 // The underlying archive.
388 // The current offset in the file.
390 // The current archive header.
394 // Read the next archive header.
397 Archive::const_iterator::read_next_header()
399 off_t filesize = this->archive_->file().filesize();
402 if (filesize - this->off_ < static_cast<off_t>(sizeof(Archive_header)))
404 if (filesize != this->off_)
406 gold_error(_("%s: short archive header at %zu"),
407 this->archive_->filename().c_str(),
408 static_cast<size_t>(this->off_));
409 this->off_ = filesize;
411 this->header_.off = filesize;
415 unsigned char buf[sizeof(Archive_header)];
416 this->archive_->file().read(this->off_, sizeof(Archive_header), buf);
418 const Archive_header* hdr = reinterpret_cast<const Archive_header*>(buf);
420 this->archive_->interpret_header(hdr, this->off_, &this->header_.name,
421 &this->header_.nested_off);
422 this->header_.off = this->off_;
424 // Skip special members.
425 if (!this->header_.name.empty() && this->header_.name != "/")
428 this->off_ += sizeof(Archive_header) + this->header_.size;
429 if ((this->off_ & 1) != 0)
436 Archive::const_iterator
439 return Archive::const_iterator(this, sarmag);
444 Archive::const_iterator
447 return Archive::const_iterator(this, this->input_file_->file().filesize());
450 // Get the file and offset for an archive member, which may be an
451 // external member of a thin archive. Set *INPUT_FILE to the
452 // file containing the actual member, *MEMOFF to the offset
453 // within that file (0 if not a nested archive), and *MEMBER_NAME
454 // to the name of the archive member. Return TRUE on success.
457 Archive::get_file_and_offset(off_t off, Input_file** input_file, off_t* memoff,
458 off_t* memsize, std::string* member_name)
462 *memsize = this->read_header(off, false, member_name, &nested_off);
464 *input_file = this->input_file_;
465 *memoff = off + static_cast<off_t>(sizeof(Archive_header));
467 if (!this->is_thin_archive_)
470 // Adjust a relative pathname so that it is relative
471 // to the directory containing the archive.
472 if (!IS_ABSOLUTE_PATH(member_name->c_str()))
474 const char* arch_path = this->filename().c_str();
475 const char* basename = lbasename(arch_path);
476 if (basename > arch_path)
477 member_name->replace(0, 0,
478 this->filename().substr(0, basename - arch_path));
483 // This is a member of a nested archive. Open the containing
484 // archive if we don't already have it open, then do a recursive
485 // call to include the member from that archive.
487 Nested_archive_table::const_iterator p =
488 this->nested_archives_.find(*member_name);
489 if (p != this->nested_archives_.end())
493 Input_file_argument* input_file_arg =
494 new Input_file_argument(member_name->c_str(),
495 Input_file_argument::INPUT_FILE_TYPE_FILE,
496 "", false, parameters->options());
497 *input_file = new Input_file(input_file_arg);
499 if (!(*input_file)->open(*this->dirpath_, this->task_, &dummy))
501 arch = new Archive(*member_name, *input_file, false, this->dirpath_,
504 std::pair<Nested_archive_table::iterator, bool> ins =
505 this->nested_archives_.insert(std::make_pair(*member_name, arch));
506 gold_assert(ins.second);
508 return arch->get_file_and_offset(nested_off, input_file, memoff,
509 memsize, member_name);
512 // This is an external member of a thin archive. Open the
513 // file as a regular relocatable object file.
514 Input_file_argument* input_file_arg =
515 new Input_file_argument(member_name->c_str(),
516 Input_file_argument::INPUT_FILE_TYPE_FILE,
517 "", false, this->input_file_->options());
518 *input_file = new Input_file(input_file_arg);
520 if (!(*input_file)->open(*this->dirpath_, this->task_, &dummy))
524 *memsize = (*input_file)->file().filesize();
528 // Return an ELF object for the member at offset OFF. If the ELF
529 // object has an unsupported target type, set *PUNCONFIGURED to true
533 Archive::get_elf_object_for_member(off_t off, bool* punconfigured)
535 *punconfigured = false;
537 Input_file* input_file;
540 std::string member_name;
541 if (!this->get_file_and_offset(off, &input_file, &memoff, &memsize,
545 if (parameters->options().has_plugins())
547 Object* obj = parameters->options().plugins()->claim_file(input_file,
552 // The input file was claimed by a plugin, and its symbols
553 // have been provided by the plugin.
558 const unsigned char* ehdr;
560 if (!is_elf_object(input_file, memoff, &ehdr, &read_size))
562 gold_error(_("%s: member at %zu is not an ELF object"),
563 this->name().c_str(), static_cast<size_t>(off));
567 Object *obj = make_elf_object((std::string(this->input_file_->filename())
568 + "(" + member_name + ")"),
569 input_file, memoff, ehdr, read_size,
573 obj->set_no_export(this->no_export());
577 // Read the symbols from all the archive members in the link.
580 Archive::read_all_symbols()
582 for (Archive::const_iterator p = this->begin();
585 this->read_symbols(p->off);
588 // Read the symbols from an archive member in the link. OFF is the file
589 // offset of the member header.
592 Archive::read_symbols(off_t off)
595 Object* obj = this->get_elf_object_for_member(off, &dummy);
600 Read_symbols_data* sd = new Read_symbols_data;
601 obj->read_symbols(sd);
602 Archive_member member(obj, sd);
603 this->members_[off] = member;
606 Archive::Should_include
607 Archive::should_include_member(Symbol_table* symtab, Layout* layout,
608 const char* sym_name, Symbol** symp,
609 std::string* why, char** tmpbufp,
612 // In an object file, and therefore in an archive map, an
613 // '@' in the name separates the symbol name from the
614 // version name. If there are two '@' characters, this is
615 // the default version.
616 char* tmpbuf = *tmpbufp;
617 const char* ver = strchr(sym_name, '@');
621 size_t symlen = ver - sym_name;
622 if (symlen + 1 > *tmpbuflen)
624 tmpbuf = static_cast<char*>(xrealloc(tmpbuf, symlen + 1));
626 *tmpbuflen = symlen + 1;
628 memcpy(tmpbuf, sym_name, symlen);
629 tmpbuf[symlen] = '\0';
640 Symbol* sym = symtab->lookup(sym_name, ver);
644 || !sym->is_undefined()
645 || sym->binding() == elfcpp::STB_WEAK))
646 sym = symtab->lookup(sym_name, NULL);
652 // Check whether the symbol was named in a -u option.
653 if (parameters->options().is_undefined(sym_name))
658 else if (layout->script_options()->is_referenced(sym_name))
660 size_t alc = 100 + strlen(sym_name);
661 char* buf = new char[alc];
662 snprintf(buf, alc, _("script or expression reference to %s"),
668 return Archive::SHOULD_INCLUDE_UNKNOWN;
670 else if (!sym->is_undefined())
671 return Archive::SHOULD_INCLUDE_NO;
672 else if (sym->binding() == elfcpp::STB_WEAK)
673 return Archive::SHOULD_INCLUDE_UNKNOWN;
675 return Archive::SHOULD_INCLUDE_YES;
678 // Select members from the archive and add them to the link. We walk
679 // through the elements in the archive map, and look each one up in
680 // the symbol table. If it exists as a strong undefined symbol, we
681 // pull in the corresponding element. We have to do this in a loop,
682 // since pulling in one element may create new undefined symbols which
683 // may be satisfied by other objects in the archive. Return true in
684 // the normal case, false if the first member we tried to add from
685 // this archive had an incompatible target.
688 Archive::add_symbols(Symbol_table* symtab, Layout* layout,
689 Input_objects* input_objects, Mapfile* mapfile)
691 ++Archive::total_archives;
693 if (this->input_file_->options().whole_archive())
694 return this->include_all_members(symtab, layout, input_objects,
697 Archive::total_members += this->num_members_;
699 input_objects->archive_start(this);
701 const size_t armap_size = this->armap_.size();
703 // This is a quick optimization, since we usually see many symbols
704 // in a row with the same offset. last_seen_offset holds the last
705 // offset we saw that was present in the seen_offsets_ set.
706 off_t last_seen_offset = -1;
708 // Track which symbols in the symbol table we've already found to be
712 size_t tmpbuflen = 0;
713 bool added_new_object;
716 added_new_object = false;
717 for (size_t i = 0; i < armap_size; ++i)
719 if (this->armap_checked_[i])
721 if (this->armap_[i].file_offset == last_seen_offset)
723 this->armap_checked_[i] = true;
726 if (this->seen_offsets_.find(this->armap_[i].file_offset)
727 != this->seen_offsets_.end())
729 this->armap_checked_[i] = true;
730 last_seen_offset = this->armap_[i].file_offset;
734 const char* sym_name = (this->armap_names_.data()
735 + this->armap_[i].name_offset);
739 Archive::Should_include t =
740 Archive::should_include_member(symtab, layout, sym_name, &sym,
741 &why, &tmpbuf, &tmpbuflen);
743 if (t == Archive::SHOULD_INCLUDE_NO
744 || t == Archive::SHOULD_INCLUDE_YES)
745 this->armap_checked_[i] = true;
747 if (t != Archive::SHOULD_INCLUDE_YES)
750 // We want to include this object in the link.
751 last_seen_offset = this->armap_[i].file_offset;
752 this->seen_offsets_.insert(last_seen_offset);
754 if (!this->include_member(symtab, layout, input_objects,
755 last_seen_offset, mapfile, sym,
763 added_new_object = true;
766 while (added_new_object);
771 input_objects->archive_stop(this);
776 // Include all the archive members in the link. This is for --whole-archive.
779 Archive::include_all_members(Symbol_table* symtab, Layout* layout,
780 Input_objects* input_objects, Mapfile* mapfile)
782 input_objects->archive_start(this);
784 if (this->members_.size() > 0)
786 std::map<off_t, Archive_member>::const_iterator p;
787 for (p = this->members_.begin();
788 p != this->members_.end();
791 if (!this->include_member(symtab, layout, input_objects, p->first,
792 mapfile, NULL, "--whole-archive"))
794 ++Archive::total_members;
799 for (Archive::const_iterator p = this->begin();
803 if (!this->include_member(symtab, layout, input_objects, p->off,
804 mapfile, NULL, "--whole-archive"))
806 ++Archive::total_members;
810 input_objects->archive_stop(this);
815 // Return the number of members in the archive. This is only used for
819 Archive::count_members()
822 for (Archive::const_iterator p = this->begin();
829 // Include an archive member in the link. OFF is the file offset of
830 // the member header. WHY is the reason we are including this member.
831 // Return true if we added the member or if we had an error, return
832 // false if this was the first member we tried to add from this
833 // archive and it had an incompatible format.
836 Archive::include_member(Symbol_table* symtab, Layout* layout,
837 Input_objects* input_objects, off_t off,
838 Mapfile* mapfile, Symbol* sym, const char* why)
840 ++Archive::total_members_loaded;
842 std::map<off_t, Archive_member>::const_iterator p = this->members_.find(off);
843 if (p != this->members_.end())
845 Object *obj = p->second.obj_;
847 Read_symbols_data *sd = p->second.sd_;
849 mapfile->report_include_archive_member(obj->name(), sym, why);
850 if (input_objects->add_object(obj))
852 obj->layout(symtab, layout, sd);
853 obj->add_symbols(symtab, sd, layout);
854 this->included_member_ = true;
861 Object* obj = this->get_elf_object_for_member(off, &unconfigured);
863 if (!this->included_member_
864 && this->searched_for()
873 mapfile->report_include_archive_member(obj->name(), sym, why);
875 Pluginobj* pluginobj = obj->pluginobj();
876 if (pluginobj != NULL)
878 pluginobj->add_symbols(symtab, NULL, layout);
879 this->included_member_ = true;
883 if (!input_objects->add_object(obj))
885 // If this is an external member of a thin archive, unlock the
887 if (obj->offset() == 0)
888 obj->unlock(this->task_);
894 Read_symbols_data sd;
895 obj->read_symbols(&sd);
896 obj->layout(symtab, layout, &sd);
897 obj->add_symbols(symtab, &sd, layout);
900 // If this is an external member of a thin archive, unlock the file
901 // for the next task.
902 if (obj->offset() == 0)
903 obj->unlock(this->task_);
905 this->included_member_ = true;
911 // Print statistical information to stderr. This is used for --stats.
914 Archive::print_stats()
916 fprintf(stderr, _("%s: archive libraries: %u\n"),
917 program_name, Archive::total_archives);
918 fprintf(stderr, _("%s: total archive members: %u\n"),
919 program_name, Archive::total_members);
920 fprintf(stderr, _("%s: loaded archive members: %u\n"),
921 program_name, Archive::total_members_loaded);
924 // Add_archive_symbols methods.
926 Add_archive_symbols::~Add_archive_symbols()
928 if (this->this_blocker_ != NULL)
929 delete this->this_blocker_;
930 // next_blocker_ is deleted by the task associated with the next
934 // Return whether we can add the archive symbols. We are blocked by
935 // this_blocker_. We block next_blocker_. We also lock the file.
938 Add_archive_symbols::is_runnable()
940 if (this->this_blocker_ != NULL && this->this_blocker_->is_blocked())
941 return this->this_blocker_;
946 Add_archive_symbols::locks(Task_locker* tl)
948 tl->add(this, this->next_blocker_);
949 tl->add(this, this->archive_->token());
953 Add_archive_symbols::run(Workqueue* workqueue)
955 bool added = this->archive_->add_symbols(this->symtab_, this->layout_,
956 this->input_objects_,
958 this->archive_->unlock_nested_archives();
960 this->archive_->release();
961 this->archive_->clear_uncached_views();
965 // This archive holds object files which are incompatible with
967 Read_symbols::incompatible_warning(this->input_argument_,
968 this->archive_->input_file());
969 Read_symbols::requeue(workqueue, this->input_objects_, this->symtab_,
970 this->layout_, this->dirpath_, this->dirindex_,
971 this->mapfile_, this->input_argument_,
972 this->input_group_, this->next_blocker_);
973 delete this->archive_;
977 if (this->input_group_ != NULL)
978 this->input_group_->add_archive(this->archive_);
981 // We no longer need to know about this archive.
982 delete this->archive_;
983 this->archive_ = NULL;
987 // Class Lib_group static variables.
988 unsigned int Lib_group::total_lib_groups;
989 unsigned int Lib_group::total_members;
990 unsigned int Lib_group::total_members_loaded;
992 Lib_group::Lib_group(const Input_file_lib* lib, Task* task)
993 : lib_(lib), task_(task), members_()
995 this->members_.resize(lib->size());
998 // Select members from the lib group and add them to the link. We walk
999 // through the the members, and check if each one up should be included.
1000 // If the object says it should be included, we do so. We have to do
1001 // this in a loop, since including one member may create new undefined
1002 // symbols which may be satisfied by other members.
1005 Lib_group::add_symbols(Symbol_table* symtab, Layout* layout,
1006 Input_objects* input_objects)
1008 ++Lib_group::total_lib_groups;
1010 Lib_group::total_members += this->members_.size();
1012 bool added_new_object;
1015 added_new_object = false;
1017 while (i < this->members_.size())
1019 const Archive_member& member = this->members_[i];
1020 Object *obj = member.obj_;
1023 // Skip files with no symbols. Plugin objects have
1024 // member.sd_ == NULL.
1026 && (member.sd_ == NULL || member.sd_->symbol_names != NULL))
1028 Archive::Should_include t = obj->should_include_member(symtab,
1033 if (t != Archive::SHOULD_INCLUDE_YES)
1039 this->include_member(symtab, layout, input_objects, member);
1041 added_new_object = true;
1045 if (member.sd_ != NULL)
1049 this->members_[i] = this->members_.back();
1050 this->members_.pop_back();
1053 while (added_new_object);
1056 // Include a lib group member in the link.
1059 Lib_group::include_member(Symbol_table* symtab, Layout* layout,
1060 Input_objects* input_objects,
1061 const Archive_member& member)
1063 ++Lib_group::total_members_loaded;
1065 Object* obj = member.obj_;
1066 gold_assert(obj != NULL);
1068 Pluginobj* pluginobj = obj->pluginobj();
1069 if (pluginobj != NULL)
1071 pluginobj->add_symbols(symtab, NULL, layout);
1075 Read_symbols_data* sd = member.sd_;
1076 gold_assert(sd != NULL);
1077 obj->lock(this->task_);
1078 if (input_objects->add_object(obj))
1080 obj->layout(symtab, layout, sd);
1081 obj->add_symbols(symtab, sd, layout);
1082 // Unlock the file for the next task.
1083 obj->unlock(this->task_);
1088 // Print statistical information to stderr. This is used for --stats.
1091 Lib_group::print_stats()
1093 fprintf(stderr, _("%s: lib groups: %u\n"),
1094 program_name, Lib_group::total_lib_groups);
1095 fprintf(stderr, _("%s: total lib groups members: %u\n"),
1096 program_name, Lib_group::total_members);
1097 fprintf(stderr, _("%s: loaded lib groups members: %u\n"),
1098 program_name, Lib_group::total_members_loaded);
1102 Add_lib_group_symbols::is_runnable()
1104 if (this->this_blocker_ != NULL && this->this_blocker_->is_blocked())
1105 return this->this_blocker_;
1110 Add_lib_group_symbols::locks(Task_locker* tl)
1112 tl->add(this, this->next_blocker_);
1116 Add_lib_group_symbols::run(Workqueue*)
1118 this->lib_->add_symbols(this->symtab_, this->layout_, this->input_objects_);
1121 Add_lib_group_symbols::~Add_lib_group_symbols()
1123 if (this->this_blocker_ != NULL)
1124 delete this->this_blocker_;
1125 // next_blocker_ is deleted by the task associated with the next
1129 } // End namespace gold.