* archive.cc (Archive::get_elf_object_for_member): Remove call
[deliverable/binutils-gdb.git] / gold / archive.cc
1 // archive.cc -- archive support for gold
2
3 // Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
5
6 // This file is part of gold.
7
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.
12
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.
17
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.
22
23 #include "gold.h"
24
25 #include <cerrno>
26 #include <cstring>
27 #include <climits>
28 #include <vector>
29 #include "libiberty.h"
30 #include "filenames.h"
31
32 #include "elfcpp.h"
33 #include "options.h"
34 #include "mapfile.h"
35 #include "fileread.h"
36 #include "readsyms.h"
37 #include "symtab.h"
38 #include "object.h"
39 #include "archive.h"
40 #include "plugin.h"
41
42 namespace gold
43 {
44
45 // The header of an entry in the archive. This is all readable text,
46 // padded with spaces where necesary. If the contents of an archive
47 // are all text file, the entire archive is readable.
48
49 struct Archive::Archive_header
50 {
51 // The entry name.
52 char ar_name[16];
53 // The file modification time.
54 char ar_date[12];
55 // The user's UID in decimal.
56 char ar_uid[6];
57 // The user's GID in decimal.
58 char ar_gid[6];
59 // The file mode in octal.
60 char ar_mode[8];
61 // The file size in decimal.
62 char ar_size[10];
63 // The final magic code.
64 char ar_fmag[2];
65 };
66
67 // Class Archive static variables.
68 unsigned int Archive::total_archives;
69 unsigned int Archive::total_members;
70 unsigned int Archive::total_members_loaded;
71
72 // Archive methods.
73
74 const char Archive::armag[sarmag] =
75 {
76 '!', '<', 'a', 'r', 'c', 'h', '>', '\n'
77 };
78
79 const char Archive::armagt[sarmag] =
80 {
81 '!', '<', 't', 'h', 'i', 'n', '>', '\n'
82 };
83
84 const char Archive::arfmag[2] = { '`', '\n' };
85
86 // Set up the archive: read the symbol map and the extended name
87 // table.
88
89 void
90 Archive::setup(Input_objects* input_objects)
91 {
92 // We need to ignore empty archives.
93 if (this->input_file_->file().filesize() == sarmag)
94 return;
95
96 // The first member of the archive should be the symbol table.
97 std::string armap_name;
98 section_size_type armap_size =
99 convert_to_section_size_type(this->read_header(sarmag, false,
100 &armap_name, NULL));
101 off_t off = sarmag;
102 if (armap_name.empty())
103 {
104 this->read_armap(sarmag + sizeof(Archive_header), armap_size);
105 off = sarmag + sizeof(Archive_header) + armap_size;
106 }
107 else if (!this->input_file_->options().whole_archive())
108 gold_error(_("%s: no archive symbol table (run ranlib)"),
109 this->name().c_str());
110
111 // See if there is an extended name table. We cache these views
112 // because it is likely that we will want to read the following
113 // header in the add_symbols routine.
114 if ((off & 1) != 0)
115 ++off;
116 std::string xname;
117 section_size_type extended_size =
118 convert_to_section_size_type(this->read_header(off, true, &xname, NULL));
119 if (xname == "/")
120 {
121 const unsigned char* p = this->get_view(off + sizeof(Archive_header),
122 extended_size, false, true);
123 const char* px = reinterpret_cast<const char*>(p);
124 this->extended_names_.assign(px, extended_size);
125 }
126 bool preread_syms = (parameters->options().threads()
127 && parameters->options().preread_archive_symbols());
128 #ifndef ENABLE_THREADS
129 preread_syms = false;
130 #else
131 if (parameters->options().has_plugins())
132 preread_syms = false;
133 #endif
134 if (preread_syms)
135 this->read_all_symbols(input_objects);
136 }
137
138 // Unlock any nested archives.
139
140 void
141 Archive::unlock_nested_archives()
142 {
143 for (Nested_archive_table::iterator p = this->nested_archives_.begin();
144 p != this->nested_archives_.end();
145 ++p)
146 {
147 p->second->unlock(this->task_);
148 }
149 }
150
151 // Read the archive symbol map.
152
153 void
154 Archive::read_armap(off_t start, section_size_type size)
155 {
156 // To count the total number of archive members, we'll just count
157 // the number of times the file offset changes. Since most archives
158 // group the symbols in the armap by object, this ought to give us
159 // an accurate count.
160 off_t last_seen_offset = -1;
161
162 // Read in the entire armap.
163 const unsigned char* p = this->get_view(start, size, true, false);
164
165 // Numbers in the armap are always big-endian.
166 const elfcpp::Elf_Word* pword = reinterpret_cast<const elfcpp::Elf_Word*>(p);
167 unsigned int nsyms = elfcpp::Swap<32, true>::readval(pword);
168 ++pword;
169
170 // Note that the addition is in units of sizeof(elfcpp::Elf_Word).
171 const char* pnames = reinterpret_cast<const char*>(pword + nsyms);
172 section_size_type names_size =
173 reinterpret_cast<const char*>(p) + size - pnames;
174 this->armap_names_.assign(pnames, names_size);
175
176 this->armap_.resize(nsyms);
177
178 section_offset_type name_offset = 0;
179 for (unsigned int i = 0; i < nsyms; ++i)
180 {
181 this->armap_[i].name_offset = name_offset;
182 this->armap_[i].file_offset = elfcpp::Swap<32, true>::readval(pword);
183 name_offset += strlen(pnames + name_offset) + 1;
184 ++pword;
185 if (this->armap_[i].file_offset != last_seen_offset)
186 {
187 last_seen_offset = this->armap_[i].file_offset;
188 ++this->num_members_;
189 }
190 }
191
192 if (static_cast<section_size_type>(name_offset) > names_size)
193 gold_error(_("%s: bad archive symbol table names"),
194 this->name().c_str());
195
196 // This array keeps track of which symbols are for archive elements
197 // which we have already included in the link.
198 this->armap_checked_.resize(nsyms);
199 }
200
201 // Read the header of an archive member at OFF. Fail if something
202 // goes wrong. Return the size of the member. Set *PNAME to the name
203 // of the member.
204
205 off_t
206 Archive::read_header(off_t off, bool cache, std::string* pname,
207 off_t* nested_off)
208 {
209 const unsigned char* p = this->get_view(off, sizeof(Archive_header), true,
210 cache);
211 const Archive_header* hdr = reinterpret_cast<const Archive_header*>(p);
212 return this->interpret_header(hdr, off, pname, nested_off);
213 }
214
215 // Interpret the header of HDR, the header of the archive member at
216 // file offset OFF. Fail if something goes wrong. Return the size of
217 // the member. Set *PNAME to the name of the member.
218
219 off_t
220 Archive::interpret_header(const Archive_header* hdr, off_t off,
221 std::string* pname, off_t* nested_off) const
222 {
223 if (memcmp(hdr->ar_fmag, arfmag, sizeof arfmag) != 0)
224 {
225 gold_error(_("%s: malformed archive header at %zu"),
226 this->name().c_str(), static_cast<size_t>(off));
227 return this->input_file_->file().filesize() - off;
228 }
229
230 const int size_string_size = sizeof hdr->ar_size;
231 char size_string[size_string_size + 1];
232 memcpy(size_string, hdr->ar_size, size_string_size);
233 char* ps = size_string + size_string_size;
234 while (ps[-1] == ' ')
235 --ps;
236 *ps = '\0';
237
238 errno = 0;
239 char* end;
240 off_t member_size = strtol(size_string, &end, 10);
241 if (*end != '\0'
242 || member_size < 0
243 || (member_size == LONG_MAX && errno == ERANGE))
244 {
245 gold_error(_("%s: malformed archive header size at %zu"),
246 this->name().c_str(), static_cast<size_t>(off));
247 return this->input_file_->file().filesize() - off;
248 }
249
250 if (hdr->ar_name[0] != '/')
251 {
252 const char* name_end = strchr(hdr->ar_name, '/');
253 if (name_end == NULL
254 || name_end - hdr->ar_name >= static_cast<int>(sizeof hdr->ar_name))
255 {
256 gold_error(_("%s: malformed archive header name at %zu"),
257 this->name().c_str(), static_cast<size_t>(off));
258 return this->input_file_->file().filesize() - off;
259 }
260 pname->assign(hdr->ar_name, name_end - hdr->ar_name);
261 if (nested_off != NULL)
262 *nested_off = 0;
263 }
264 else if (hdr->ar_name[1] == ' ')
265 {
266 // This is the symbol table.
267 pname->clear();
268 }
269 else if (hdr->ar_name[1] == '/')
270 {
271 // This is the extended name table.
272 pname->assign(1, '/');
273 }
274 else
275 {
276 errno = 0;
277 long x = strtol(hdr->ar_name + 1, &end, 10);
278 long y = 0;
279 if (*end == ':')
280 y = strtol(end + 1, &end, 10);
281 if (*end != ' '
282 || x < 0
283 || (x == LONG_MAX && errno == ERANGE)
284 || static_cast<size_t>(x) >= this->extended_names_.size())
285 {
286 gold_error(_("%s: bad extended name index at %zu"),
287 this->name().c_str(), static_cast<size_t>(off));
288 return this->input_file_->file().filesize() - off;
289 }
290
291 const char* name = this->extended_names_.data() + x;
292 const char* name_end = strchr(name, '\n');
293 if (static_cast<size_t>(name_end - name) > this->extended_names_.size()
294 || name_end[-1] != '/')
295 {
296 gold_error(_("%s: bad extended name entry at header %zu"),
297 this->name().c_str(), static_cast<size_t>(off));
298 return this->input_file_->file().filesize() - off;
299 }
300 pname->assign(name, name_end - 1 - name);
301 if (nested_off != NULL)
302 *nested_off = y;
303 }
304
305 return member_size;
306 }
307
308 // An archive member iterator.
309
310 class Archive::const_iterator
311 {
312 public:
313 // The header of an archive member. This is what this iterator
314 // points to.
315 struct Header
316 {
317 // The name of the member.
318 std::string name;
319 // The file offset of the member.
320 off_t off;
321 // The file offset of a nested archive member.
322 off_t nested_off;
323 // The size of the member.
324 off_t size;
325 };
326
327 const_iterator(Archive* archive, off_t off)
328 : archive_(archive), off_(off)
329 { this->read_next_header(); }
330
331 const Header&
332 operator*() const
333 { return this->header_; }
334
335 const Header*
336 operator->() const
337 { return &this->header_; }
338
339 const_iterator&
340 operator++()
341 {
342 if (this->off_ == this->archive_->file().filesize())
343 return *this;
344 this->off_ += sizeof(Archive_header);
345 if (!this->archive_->is_thin_archive())
346 this->off_ += this->header_.size;
347 if ((this->off_ & 1) != 0)
348 ++this->off_;
349 this->read_next_header();
350 return *this;
351 }
352
353 const_iterator
354 operator++(int)
355 {
356 const_iterator ret = *this;
357 ++*this;
358 return ret;
359 }
360
361 bool
362 operator==(const const_iterator p) const
363 { return this->off_ == p->off; }
364
365 bool
366 operator!=(const const_iterator p) const
367 { return this->off_ != p->off; }
368
369 private:
370 void
371 read_next_header();
372
373 // The underlying archive.
374 Archive* archive_;
375 // The current offset in the file.
376 off_t off_;
377 // The current archive header.
378 Header header_;
379 };
380
381 // Read the next archive header.
382
383 void
384 Archive::const_iterator::read_next_header()
385 {
386 off_t filesize = this->archive_->file().filesize();
387 while (true)
388 {
389 if (filesize - this->off_ < static_cast<off_t>(sizeof(Archive_header)))
390 {
391 if (filesize != this->off_)
392 {
393 gold_error(_("%s: short archive header at %zu"),
394 this->archive_->filename().c_str(),
395 static_cast<size_t>(this->off_));
396 this->off_ = filesize;
397 }
398 this->header_.off = filesize;
399 return;
400 }
401
402 unsigned char buf[sizeof(Archive_header)];
403 this->archive_->file().read(this->off_, sizeof(Archive_header), buf);
404
405 const Archive_header* hdr = reinterpret_cast<const Archive_header*>(buf);
406 this->header_.size =
407 this->archive_->interpret_header(hdr, this->off_, &this->header_.name,
408 &this->header_.nested_off);
409 this->header_.off = this->off_;
410
411 // Skip special members.
412 if (!this->header_.name.empty() && this->header_.name != "/")
413 return;
414
415 this->off_ += sizeof(Archive_header) + this->header_.size;
416 if ((this->off_ & 1) != 0)
417 ++this->off_;
418 }
419 }
420
421 // Initial iterator.
422
423 Archive::const_iterator
424 Archive::begin()
425 {
426 return Archive::const_iterator(this, sarmag);
427 }
428
429 // Final iterator.
430
431 Archive::const_iterator
432 Archive::end()
433 {
434 return Archive::const_iterator(this, this->input_file_->file().filesize());
435 }
436
437 // Get the file and offset for an archive member, which may be an
438 // external member of a thin archive. Set *INPUT_FILE to the
439 // file containing the actual member, *MEMOFF to the offset
440 // within that file (0 if not a nested archive), and *MEMBER_NAME
441 // to the name of the archive member. Return TRUE on success.
442
443 bool
444 Archive::get_file_and_offset(off_t off, Input_objects* input_objects,
445 Input_file** input_file, off_t* memoff,
446 off_t* memsize, std::string* member_name)
447 {
448 off_t nested_off;
449
450 *memsize = this->read_header(off, false, member_name, &nested_off);
451
452 *input_file = this->input_file_;
453 *memoff = off + static_cast<off_t>(sizeof(Archive_header));
454
455 if (!this->is_thin_archive_)
456 return true;
457
458 // Adjust a relative pathname so that it is relative
459 // to the directory containing the archive.
460 if (!IS_ABSOLUTE_PATH(member_name->c_str()))
461 {
462 const char* arch_path = this->filename().c_str();
463 const char* basename = lbasename(arch_path);
464 if (basename > arch_path)
465 member_name->replace(0, 0,
466 this->filename().substr(0, basename - arch_path));
467 }
468
469 if (nested_off > 0)
470 {
471 // This is a member of a nested archive. Open the containing
472 // archive if we don't already have it open, then do a recursive
473 // call to include the member from that archive.
474 Archive* arch;
475 Nested_archive_table::const_iterator p =
476 this->nested_archives_.find(*member_name);
477 if (p != this->nested_archives_.end())
478 arch = p->second;
479 else
480 {
481 Input_file_argument* input_file_arg =
482 new Input_file_argument(member_name->c_str(), false, "", false,
483 parameters->options());
484 *input_file = new Input_file(input_file_arg);
485 if (!(*input_file)->open(parameters->options(), *this->dirpath_,
486 this->task_))
487 return false;
488 arch = new Archive(*member_name, *input_file, false, this->dirpath_,
489 this->task_);
490 arch->setup(input_objects);
491 std::pair<Nested_archive_table::iterator, bool> ins =
492 this->nested_archives_.insert(std::make_pair(*member_name, arch));
493 gold_assert(ins.second);
494 }
495 return arch->get_file_and_offset(nested_off, input_objects, input_file,
496 memoff, memsize, member_name);
497 }
498
499 // This is an external member of a thin archive. Open the
500 // file as a regular relocatable object file.
501 Input_file_argument* input_file_arg =
502 new Input_file_argument(member_name->c_str(), false, "", false,
503 this->input_file_->options());
504 *input_file = new Input_file(input_file_arg);
505 if (!(*input_file)->open(parameters->options(), *this->dirpath_,
506 this->task_))
507 return false;
508
509 *memoff = 0;
510 *memsize = (*input_file)->file().filesize();
511 return true;
512 }
513
514 // Return an ELF object for the member at offset OFF. Set *MEMBER_NAME to
515 // the name of the member.
516
517 Object*
518 Archive::get_elf_object_for_member(off_t off, Input_objects* input_objects)
519 {
520 std::string member_name;
521 Input_file* input_file;
522 off_t memoff;
523 off_t memsize;
524
525 if (!this->get_file_and_offset(off, input_objects, &input_file, &memoff,
526 &memsize, &member_name))
527 return NULL;
528
529 if (parameters->options().has_plugins())
530 {
531 Object* obj = parameters->options().plugins()->claim_file(input_file,
532 memoff,
533 memsize);
534 if (obj != NULL)
535 {
536 // The input file was claimed by a plugin, and its symbols
537 // have been provided by the plugin.
538 return obj;
539 }
540 }
541
542 off_t filesize = input_file->file().filesize();
543 int read_size = elfcpp::Elf_sizes<64>::ehdr_size;
544 if (filesize - memoff < read_size)
545 read_size = filesize - memoff;
546
547 if (read_size < 4)
548 {
549 gold_error(_("%s: member at %zu is not an ELF object"),
550 this->name().c_str(), static_cast<size_t>(off));
551 return NULL;
552 }
553
554 const unsigned char* ehdr = input_file->file().get_view(memoff, 0, read_size,
555 true, false);
556
557 static unsigned char elfmagic[4] =
558 {
559 elfcpp::ELFMAG0, elfcpp::ELFMAG1,
560 elfcpp::ELFMAG2, elfcpp::ELFMAG3
561 };
562 if (memcmp(ehdr, elfmagic, 4) != 0)
563 {
564 gold_error(_("%s: member at %zu is not an ELF object"),
565 this->name().c_str(), static_cast<size_t>(off));
566 return NULL;
567 }
568
569 return make_elf_object((std::string(this->input_file_->filename())
570 + "(" + member_name + ")"),
571 input_file, memoff, ehdr, read_size);
572 }
573
574 // Read the symbols from all the archive members in the link.
575
576 void
577 Archive::read_all_symbols(Input_objects* input_objects)
578 {
579 for (Archive::const_iterator p = this->begin();
580 p != this->end();
581 ++p)
582 this->read_symbols(input_objects, p->off);
583 }
584
585 // Read the symbols from an archive member in the link. OFF is the file
586 // offset of the member header.
587
588 void
589 Archive::read_symbols(Input_objects* input_objects, off_t off)
590 {
591 Object* obj = this->get_elf_object_for_member(off, input_objects);
592
593 if (obj == NULL)
594 return;
595
596 Read_symbols_data* sd = new Read_symbols_data;
597 obj->read_symbols(sd);
598 Archive_member member(obj, sd);
599 this->members_[off] = member;
600 }
601
602 // Select members from the archive and add them to the link. We walk
603 // through the elements in the archive map, and look each one up in
604 // the symbol table. If it exists as a strong undefined symbol, we
605 // pull in the corresponding element. We have to do this in a loop,
606 // since pulling in one element may create new undefined symbols which
607 // may be satisfied by other objects in the archive.
608
609 void
610 Archive::add_symbols(Symbol_table* symtab, Layout* layout,
611 Input_objects* input_objects, Mapfile* mapfile)
612 {
613 ++Archive::total_archives;
614
615 if (this->input_file_->options().whole_archive())
616 return this->include_all_members(symtab, layout, input_objects,
617 mapfile);
618
619 Archive::total_members += this->num_members_;
620
621 input_objects->archive_start(this);
622
623 const size_t armap_size = this->armap_.size();
624
625 // This is a quick optimization, since we usually see many symbols
626 // in a row with the same offset. last_seen_offset holds the last
627 // offset we saw that was present in the seen_offsets_ set.
628 off_t last_seen_offset = -1;
629
630 // Track which symbols in the symbol table we've already found to be
631 // defined.
632
633 bool added_new_object;
634 do
635 {
636 added_new_object = false;
637 for (size_t i = 0; i < armap_size; ++i)
638 {
639 if (this->armap_checked_[i])
640 continue;
641 if (this->armap_[i].file_offset == last_seen_offset)
642 {
643 this->armap_checked_[i] = true;
644 continue;
645 }
646 if (this->seen_offsets_.find(this->armap_[i].file_offset)
647 != this->seen_offsets_.end())
648 {
649 this->armap_checked_[i] = true;
650 last_seen_offset = this->armap_[i].file_offset;
651 continue;
652 }
653
654 const char* sym_name = (this->armap_names_.data()
655 + this->armap_[i].name_offset);
656 Symbol* sym = symtab->lookup(sym_name);
657 if (sym == NULL)
658 {
659 // Check whether the symbol was named in a -u option.
660 if (!parameters->options().is_undefined(sym_name))
661 continue;
662 }
663 else if (!sym->is_undefined())
664 {
665 this->armap_checked_[i] = true;
666 continue;
667 }
668 else if (sym->binding() == elfcpp::STB_WEAK)
669 continue;
670
671 // We want to include this object in the link.
672 last_seen_offset = this->armap_[i].file_offset;
673 this->seen_offsets_.insert(last_seen_offset);
674 this->armap_checked_[i] = true;
675
676 std::string why;
677 if (sym == NULL)
678 {
679 why = "-u ";
680 why += sym_name;
681 }
682 this->include_member(symtab, layout, input_objects,
683 last_seen_offset, mapfile, sym, why.c_str());
684
685 added_new_object = true;
686 }
687 }
688 while (added_new_object);
689
690 input_objects->archive_stop(this);
691 }
692
693 // Include all the archive members in the link. This is for --whole-archive.
694
695 void
696 Archive::include_all_members(Symbol_table* symtab, Layout* layout,
697 Input_objects* input_objects, Mapfile* mapfile)
698 {
699 input_objects->archive_start(this);
700
701 if (this->members_.size() > 0)
702 {
703 std::map<off_t, Archive_member>::const_iterator p;
704 for (p = this->members_.begin();
705 p != this->members_.end();
706 ++p)
707 {
708 this->include_member(symtab, layout, input_objects, p->first,
709 mapfile, NULL, "--whole-archive");
710 ++Archive::total_members;
711 }
712 }
713 else
714 {
715 for (Archive::const_iterator p = this->begin();
716 p != this->end();
717 ++p)
718 {
719 this->include_member(symtab, layout, input_objects, p->off,
720 mapfile, NULL, "--whole-archive");
721 ++Archive::total_members;
722 }
723 }
724
725 input_objects->archive_stop(this);
726 }
727
728 // Return the number of members in the archive. This is only used for
729 // reports.
730
731 size_t
732 Archive::count_members()
733 {
734 size_t ret = 0;
735 for (Archive::const_iterator p = this->begin();
736 p != this->end();
737 ++p)
738 ++ret;
739 return ret;
740 }
741
742 // Include an archive member in the link. OFF is the file offset of
743 // the member header. WHY is the reason we are including this member.
744
745 void
746 Archive::include_member(Symbol_table* symtab, Layout* layout,
747 Input_objects* input_objects, off_t off,
748 Mapfile* mapfile, Symbol* sym, const char* why)
749 {
750 ++Archive::total_members_loaded;
751
752 std::map<off_t, Archive_member>::const_iterator p = this->members_.find(off);
753 if (p != this->members_.end())
754 {
755 Object *obj = p->second.obj_;
756 Read_symbols_data *sd = p->second.sd_;
757 if (mapfile != NULL)
758 mapfile->report_include_archive_member(obj->name(), sym, why);
759 if (input_objects->add_object(obj))
760 {
761 obj->layout(symtab, layout, sd);
762 obj->add_symbols(symtab, sd);
763 }
764 delete sd;
765 return;
766 }
767
768 Object* obj = this->get_elf_object_for_member(off, input_objects);
769 if (obj == NULL)
770 return;
771
772 if (mapfile != NULL)
773 mapfile->report_include_archive_member(obj->name(), sym, why);
774
775 Pluginobj* pluginobj = obj->pluginobj();
776 if (pluginobj != NULL)
777 {
778 pluginobj->add_symbols(symtab, layout);
779 return;
780 }
781
782 if (input_objects->add_object(obj))
783 {
784 Read_symbols_data sd;
785 obj->read_symbols(&sd);
786 obj->layout(symtab, layout, &sd);
787 obj->add_symbols(symtab, &sd);
788
789 // If this is an external member of a thin archive, unlock the file
790 // for the next task.
791 if (obj->offset() == 0)
792 obj->unlock(this->task_);
793 }
794 else
795 {
796 // FIXME: We need to close the descriptor here.
797 delete obj;
798 }
799 }
800
801 // Print statistical information to stderr. This is used for --stats.
802
803 void
804 Archive::print_stats()
805 {
806 fprintf(stderr, _("%s: archive libraries: %u\n"),
807 program_name, Archive::total_archives);
808 fprintf(stderr, _("%s: total archive members: %u\n"),
809 program_name, Archive::total_members);
810 fprintf(stderr, _("%s: loaded archive members: %u\n"),
811 program_name, Archive::total_members_loaded);
812 }
813
814 // Add_archive_symbols methods.
815
816 Add_archive_symbols::~Add_archive_symbols()
817 {
818 if (this->this_blocker_ != NULL)
819 delete this->this_blocker_;
820 // next_blocker_ is deleted by the task associated with the next
821 // input file.
822 }
823
824 // Return whether we can add the archive symbols. We are blocked by
825 // this_blocker_. We block next_blocker_. We also lock the file.
826
827 Task_token*
828 Add_archive_symbols::is_runnable()
829 {
830 if (this->this_blocker_ != NULL && this->this_blocker_->is_blocked())
831 return this->this_blocker_;
832 return NULL;
833 }
834
835 void
836 Add_archive_symbols::locks(Task_locker* tl)
837 {
838 tl->add(this, this->next_blocker_);
839 tl->add(this, this->archive_->token());
840 }
841
842 void
843 Add_archive_symbols::run(Workqueue*)
844 {
845 this->archive_->add_symbols(this->symtab_, this->layout_,
846 this->input_objects_, this->mapfile_);
847
848 this->archive_->unlock_nested_archives();
849
850 this->archive_->release();
851 this->archive_->clear_uncached_views();
852
853 if (this->input_group_ != NULL)
854 this->input_group_->add_archive(this->archive_);
855 else
856 {
857 // We no longer need to know about this archive.
858 delete this->archive_;
859 this->archive_ = NULL;
860 }
861 }
862
863 } // End namespace gold.
This page took 0.046445 seconds and 5 git commands to generate.