daily update
[deliverable/binutils-gdb.git] / gold / archive.cc
index a64109aef1227422ddda5fbfa48fe8424be914d1..d0854036a6728b895b38dea3a640f7813b9e7476 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "elfcpp.h"
 #include "fileread.h"
+#include "readsyms.h"
 #include "symtab.h"
 #include "object.h"
 #include "archive.h"
@@ -47,14 +48,6 @@ const char Archive::armag[sarmag] =
 
 const char Archive::arfmag[2] = { '`', '\n' };
 
-// Get a view into the underlying file.
-
-const unsigned char*
-Archive::get_view(off_t start, off_t size)
-{
-  return this->input_file_->file().get_view(start, size);
-}
-
 // Set up the archive: read the symbol map and the extended name
 // table.
 
@@ -77,7 +70,7 @@ Archive::setup()
 
   // Numbers in the armap are always big-endian.
   const elfcpp::Elf_Word* pword = reinterpret_cast<const elfcpp::Elf_Word*>(p);
-  unsigned int nsyms = elfcpp::read_elf_word<true>(pword);
+  unsigned int nsyms = elfcpp::Swap<32, true>::readval(pword);
   ++pword;
 
   // Note that the addition is in units of sizeof(elfcpp::Elf_Word).
@@ -88,7 +81,7 @@ Archive::setup()
   for (unsigned int i = 0; i < nsyms; ++i)
     {
       this->armap_[i].name = pnames;
-      this->armap_[i].offset = elfcpp::read_elf_word<true>(pword);
+      this->armap_[i].offset = elfcpp::Swap<32, true>::readval(pword);
       pnames += strlen(pnames) + 1;
       ++pword;
     }
@@ -113,6 +106,10 @@ Archive::setup()
       this->extended_names_.assign(px, extended_size);
     }
 
+  // This array keeps track of which symbols are for archive elements
+  // which we have already included in the link.
+  this->seen_.resize(nsyms);
+
   // Opening the file locked it.  Unlock it now.
   this->input_file_->file().unlock();
 }
@@ -218,13 +215,10 @@ Archive::read_header(off_t off, std::string* pname)
 // may be satisfied by other objects in the archive.
 
 void
-Archive::add_symbols(Symbol_table* symtab, Layout* layout,
-                    Input_objects* input_objects)
+Archive::add_symbols(const General_options& options, Symbol_table* symtab,
+                    Layout* layout, Input_objects* input_objects)
 {
-  size_t armap_size = this->armap_.size();
-  std::vector<bool> seen;
-  seen.resize(this->armap_.size());
-  seen.clear();
+  const size_t armap_size = this->armap_.size();
 
   bool added_new_object;
   do
@@ -233,20 +227,20 @@ Archive::add_symbols(Symbol_table* symtab, Layout* layout,
       off_t last = -1;
       for (size_t i = 0; i < armap_size; ++i)
        {
-         if (seen[i])
+         if (this->seen_[i])
            continue;
          if (this->armap_[i].offset == last)
            {
-             seen[i] = true;
+             this->seen_[i] = true;
              continue;
            }
 
          Symbol* sym = symtab->lookup(this->armap_[i].name);
          if (sym == NULL)
            continue;
-         else if (sym->shnum() != elfcpp::SHN_UNDEF)
+         else if (!sym->is_undefined())
            {
-             seen[i] = true;
+             this->seen_[i] = true;
              continue;
            }
          else if (sym->binding() == elfcpp::STB_WEAK)
@@ -254,7 +248,8 @@ Archive::add_symbols(Symbol_table* symtab, Layout* layout,
 
          // We want to include this object in the link.
          last = this->armap_[i].offset;
-         this->include_member(symtab, layout, input_objects, last);
+         this->include_member(options, symtab, layout, input_objects, last);
+         this->seen_[i] = true;
          added_new_object = true;
        }
     }
@@ -265,8 +260,9 @@ Archive::add_symbols(Symbol_table* symtab, Layout* layout,
 // the member header.
 
 void
-Archive::include_member(Symbol_table* symtab, Layout* layout,
-                       Input_objects* input_objects, off_t off)
+Archive::include_member(const General_options& options, Symbol_table* symtab,
+                       Layout* layout, Input_objects* input_objects,
+                       off_t off)
 {
   std::string n;
   this->read_header(off, &n);
@@ -308,7 +304,7 @@ Archive::include_member(Symbol_table* symtab, Layout* layout,
 
   Read_symbols_data sd;
   obj->read_symbols(&sd);
-  obj->layout(layout, &sd);
+  obj->layout(options, symtab, layout, &sd);
   obj->add_symbols(symtab, &sd);
 }
 
@@ -337,13 +333,13 @@ class Add_archive_symbols::Add_archive_symbols_locker : public Task_locker
 {
  public:
   Add_archive_symbols_locker(Task_token& token, Workqueue* workqueue,
-                            Archive* archive)
-    : blocker_(token, workqueue), archlock_(*archive)
+                            File_read& file)
+    : blocker_(token, workqueue), filelock_(file)
   { }
 
  private:
   Task_locker_block blocker_;
-  Task_locker_obj<Archive> archlock_;                       
+  Task_locker_obj<File_read> filelock_;                             
 };
 
 Task_locker*
@@ -351,14 +347,22 @@ Add_archive_symbols::locks(Workqueue* workqueue)
 {
   return new Add_archive_symbols_locker(*this->next_blocker_,
                                        workqueue,
-                                       this->archive_);
+                                       this->archive_->file());
 }
 
 void
 Add_archive_symbols::run(Workqueue*)
 {
-  this->archive_->add_symbols(this->symtab_, this->layout_,
+  this->archive_->add_symbols(this->options_, this->symtab_, this->layout_,
                              this->input_objects_);
+
+  if (this->input_group_ != NULL)
+    this->input_group_->add_archive(this->archive_);
+  else
+    {
+      // We no longer need to know about this archive.
+      delete this->archive_;
+    }
 }
 
 } // End namespace gold.
This page took 0.024673 seconds and 4 git commands to generate.