* elflink.c (set_symbol_value): Add isymbuf and locsymcount
[deliverable/binutils-gdb.git] / gold / readsyms.cc
index 2b200ba54849764e8143bce102391520253e6f6a..bbeb425f98189e3cbd98018ee81ecce402280c01 100644 (file)
@@ -1,5 +1,25 @@
 // readsyms.cc -- read input file symbols for gold
 
+// Copyright 2006, 2007 Free Software Foundation, Inc.
+// Written by Ian Lance Taylor <iant@google.com>.
+
+// This file is part of gold.
+
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+// MA 02110-1301, USA.
+
 #include "gold.h"
 
 #include <cstring>
@@ -61,27 +81,41 @@ Read_symbols::run(Workqueue* workqueue)
       return;
     }
 
-  Input_file* input_file = new Input_file(this->input_argument_->file());
+  Input_file* input_file = new Input_file(&this->input_argument_->file());
   input_file->open(this->options_, this->dirpath_);
 
   // Read enough of the file to pick up the entire ELF header.
 
-  int ehdr_size = elfcpp::Elf_sizes<64>::ehdr_size;
-  off_t bytes;
-  const unsigned char* p = input_file->file().get_view(0, ehdr_size, &bytes);
-  if (bytes >= 4)
+  off_t filesize = input_file->file().filesize();
+
+  if (filesize == 0)
+    {
+      fprintf(stderr, _("%s: %s: file is empty\n"),
+             program_name, input_file->file().filename().c_str());
+      gold_exit(false);
+    }
+
+  unsigned char ehdr_buf[elfcpp::Elf_sizes<64>::ehdr_size];
+
+  int read_size = elfcpp::Elf_sizes<64>::ehdr_size;
+  if (filesize < read_size)
+    read_size = filesize;
+
+  input_file->file().read(0, read_size, ehdr_buf);
+
+  if (read_size >= 4)
     {
       static unsigned char elfmagic[4] =
        {
          elfcpp::ELFMAG0, elfcpp::ELFMAG1,
          elfcpp::ELFMAG2, elfcpp::ELFMAG3
        };
-      if (memcmp(p, elfmagic, 4) == 0)
+      if (memcmp(ehdr_buf, elfmagic, 4) == 0)
        {
          // This is an ELF object.
 
          Object* obj = make_elf_object(input_file->filename(),
-                                       input_file, 0, p, bytes);
+                                       input_file, 0, ehdr_buf, read_size);
 
          // We don't have a way to record a non-archive in an input
          // group.  If this is an ordinary object file, we can't
@@ -97,8 +131,7 @@ Read_symbols::run(Workqueue* workqueue)
 
          Read_symbols_data* sd = new Read_symbols_data;
          obj->read_symbols(sd);
-         workqueue->queue_front(new Add_symbols(this->options_,
-                                                this->input_objects_,
+         workqueue->queue_front(new Add_symbols(this->input_objects_,
                                                 this->symtab_, this->layout_,
                                                 obj, sd,
                                                 this->this_blocker_,
@@ -111,16 +144,15 @@ Read_symbols::run(Workqueue* workqueue)
        }
     }
 
-  if (bytes >= Archive::sarmag)
+  if (read_size >= Archive::sarmag)
     {
-      if (memcmp(p, Archive::armag, Archive::sarmag) == 0)
+      if (memcmp(ehdr_buf, Archive::armag, Archive::sarmag) == 0)
        {
          // This is an archive.
          Archive* arch = new Archive(this->input_argument_->file().name(),
                                      input_file);
          arch->setup();
-         workqueue->queue(new Add_archive_symbols(this->options_,
-                                                  this->symtab_,
+         workqueue->queue(new Add_archive_symbols(this->symtab_,
                                                   this->layout_,
                                                   this->input_objects_,
                                                   arch,
@@ -131,18 +163,12 @@ Read_symbols::run(Workqueue* workqueue)
        }
     }
 
-  if (bytes == 0)
-    {
-      fprintf(stderr, _("%s: %s: file is empty\n"),
-             program_name, input_file->file().filename().c_str());
-      gold_exit(false);
-    }
-
   // Try to parse this file as a script.
   if (read_input_script(workqueue, this->options_, this->symtab_,
                        this->layout_, this->dirpath_, this->input_objects_,
                        this->input_group_, this->input_argument_, input_file,
-                       p, bytes, this->this_blocker_, this->next_blocker_))
+                       ehdr_buf, read_size, this->this_blocker_,
+                       this->next_blocker_))
     return;
 
   // Here we have to handle any other input file types we need.
@@ -182,8 +208,7 @@ Read_symbols::do_group(Workqueue* workqueue)
     }
 
   const int saw_undefined = this->symtab_->saw_undefined();
-  workqueue->queue(new Finish_group(this->options_,
-                                   this->input_objects_,
+  workqueue->queue(new Finish_group(this->input_objects_,
                                    this->symtab_,
                                    this->layout_,
                                    input_group,
@@ -240,10 +265,16 @@ Add_symbols::locks(Workqueue* workqueue)
 void
 Add_symbols::run(Workqueue*)
 {
-  this->input_objects_->add_object(this->object_);
-  this->object_->layout(this->options_, this->symtab_, this->layout_,
-                       this->sd_);
-  this->object_->add_symbols(this->symtab_, this->sd_);
+  if (!this->input_objects_->add_object(this->object_))
+    {
+      // FIXME: We need to close the descriptor here.
+      delete this->object_;
+    }
+  else
+    {
+      this->object_->layout(this->symtab_, this->layout_, this->sd_);
+      this->object_->add_symbols(this->symtab_, this->sd_);
+    }
   delete this->sd_;
   this->sd_ = NULL;
 }
@@ -290,7 +321,7 @@ Finish_group::run(Workqueue*)
        {
          Task_lock_obj<Archive> tl(**p);
 
-         (*p)->add_symbols(this->options_, this->symtab_, this->layout_,
+         (*p)->add_symbols(this->symtab_, this->layout_,
                            this->input_objects_);
        }
     }
This page took 0.03786 seconds and 4 git commands to generate.