Remove get_view_and_size.
authorIan Lance Taylor <iant@google.com>
Tue, 25 Sep 2007 05:16:35 +0000 (05:16 +0000)
committerIan Lance Taylor <iant@google.com>
Tue, 25 Sep 2007 05:16:35 +0000 (05:16 +0000)
gold/archive.cc
gold/archive.h
gold/fileread.cc
gold/fileread.h
gold/readsyms.cc

index f7194f8fea0b30b3fa9c8da25c95029fcd479b1b..5ab3696c7c86cb5f8ba90644348fdb61fd97dd07 100644 (file)
@@ -328,10 +328,11 @@ Archive::include_all_members(Symbol_table* symtab, Layout* layout,
   off_t off = sarmag;
   while (true)
     {
+      unsigned char hdr_buf[sizeof(Archive_header)];
       off_t bytes;
-      const unsigned char* p = this->get_view_and_size(off,
-                                                      sizeof(Archive_header),
-                                                      &bytes);
+      this->input_file_->file().read_up_to(off, sizeof(Archive_header),
+                                          hdr_buf, &bytes);
+
       if (bytes < sizeof(Archive_header))
         {
           if (bytes != 0)
@@ -345,7 +346,8 @@ Archive::include_all_members(Symbol_table* symtab, Layout* layout,
           break;
         }
 
-      const Archive_header* hdr = reinterpret_cast<const Archive_header*>(p);
+      const Archive_header* hdr =
+       reinterpret_cast<const Archive_header*>(hdr_buf);
       std::string name;
       off_t size = this->interpret_header(hdr, off, &name);
       if (name.empty())
@@ -379,9 +381,9 @@ Archive::include_member(Symbol_table* symtab, Layout* layout,
 
   // Read enough of the file to pick up the entire ELF header.
   int ehdr_size = elfcpp::Elf_sizes<64>::ehdr_size;
+  unsigned char ehdr_buf[ehdr_size];
   off_t bytes;
-  const unsigned char* p =
-    this->input_file_->file().get_view_and_size(memoff, ehdr_size, &bytes);
+  this->input_file_->file().read_up_to(memoff, ehdr_size, ehdr_buf, &bytes);
   if (bytes < 4)
     {
       fprintf(stderr, _("%s: %s: member at %ld is not an ELF object"),
@@ -395,7 +397,7 @@ Archive::include_member(Symbol_table* symtab, Layout* layout,
       elfcpp::ELFMAG0, elfcpp::ELFMAG1,
       elfcpp::ELFMAG2, elfcpp::ELFMAG3
     };
-  if (memcmp(p, elfmagic, 4) != 0)
+  if (memcmp(ehdr_buf, elfmagic, 4) != 0)
     {
       fprintf(stderr, _("%s: %s: member at %ld is not an ELF object"),
              program_name, this->name().c_str(),
@@ -405,7 +407,7 @@ Archive::include_member(Symbol_table* symtab, Layout* layout,
 
   Object* obj = make_elf_object((std::string(this->input_file_->filename())
                                 + "(" + n + ")"),
-                               this->input_file_, memoff, p, bytes);
+                               this->input_file_, memoff, ehdr_buf, bytes);
 
   input_objects->add_object(obj);
 
index 7fa1d11ae80115550ad3e6df053e1befff6bb77e..7ebdf47e6890a84d7d9cc2b33bedf1200feec82e 100644 (file)
@@ -101,10 +101,6 @@ class Archive
   get_view(off_t start, off_t size)
   { return this->input_file_->file().get_view(start, size); }
 
-  const unsigned char*
-  get_view_and_size(off_t start, off_t size, off_t* pbytes)
-  { return this->input_file_->file().get_view_and_size(start, size, pbytes); }
-
   // Read the archive symbol map.
   void
   read_armap(off_t start, off_t size);
index a39d530ab8753ed65b567a3405e0e9b32eb5da63..ee2ae73f61b8477038863637047b72f6a7978e6d 100644 (file)
@@ -239,7 +239,7 @@ File_read::read_up_to(off_t start, off_t size, void* p, off_t* pbytes)
 // Find an existing view or make a new one.
 
 File_read::View*
-File_read::find_or_make_view(off_t start, off_t size, off_t* pbytes)
+File_read::find_or_make_view(off_t start, off_t size)
 {
   gold_assert(this->lock_count_ > 0);
 
@@ -254,11 +254,7 @@ File_read::find_or_make_view(off_t start, off_t size, off_t* pbytes)
       // There was an existing view at this offset.
       File_read::View* v = ins.first->second;
       if (v->size() - (start - v->start()) >= size)
-       {
-         if (pbytes != NULL)
-           *pbytes = size;
-         return v;
-       }
+       return v;
 
       // This view is not large enough.
       this->saved_views_.push_back(v);
@@ -277,17 +273,7 @@ File_read::find_or_make_view(off_t start, off_t size, off_t* pbytes)
   ins.first->second = v;
 
   if (bytes - (start - poff) >= size)
-    {
-      if (pbytes != NULL)
-       *pbytes = size;
-      return v;
-    }
-
-  if (pbytes != NULL)
-    {
-      *pbytes = bytes - (start - poff);
-      return v;
-    }
+    return v;
 
   fprintf(stderr,
          _("%s: %s: file too short: read only %lld of %lld bytes at %lld\n"),
@@ -306,15 +292,7 @@ const unsigned char*
 File_read::get_view(off_t start, off_t size)
 {
   gold_assert(this->lock_count_ > 0);
-  File_read::View* pv = this->find_or_make_view(start, size, NULL);
-  return pv->data() + (start - pv->start());
-}
-
-const unsigned char*
-File_read::get_view_and_size(off_t start, off_t size, off_t* pbytes)
-{
-  gold_assert(this->lock_count_ > 0);
-  File_read::View* pv = this->find_or_make_view(start, size, pbytes);
+  File_read::View* pv = this->find_or_make_view(start, size);
   return pv->data() + (start - pv->start());
 }
 
@@ -322,7 +300,7 @@ File_view*
 File_read::get_lasting_view(off_t start, off_t size)
 {
   gold_assert(this->lock_count_ > 0);
-  File_read::View* pv = this->find_or_make_view(start, size, NULL);
+  File_read::View* pv = this->find_or_make_view(start, size);
   pv->lock();
   return new File_view(*this, pv, pv->data() + (start - pv->start()));
 }
index a77721d47bb87e63e33023acbf6739b7eae2bca7..781031aef55cf51643c310399565729f7ea5d3e7 100644 (file)
@@ -87,13 +87,6 @@ class File_read
   const unsigned char*
   get_view(off_t start, off_t size);
 
-  // Return a view into the file starting at file offset START, for up
-  // to SIZE bytes.  Set *PBYTES to the number of bytes read.  This
-  // may be less than SIZE.  The pointer will remain valid until the
-  // File_read is unlocked.
-  const unsigned char*
-  get_view_and_size(off_t start, off_t size, off_t* pbytes);
-
   // Read data from the file into the buffer P starting at file offset
   // START for SIZE bytes.
   void
@@ -170,7 +163,7 @@ class File_read
 
   // Find or make a view into the file.
   View*
-  find_or_make_view(off_t start, off_t size, off_t* pbytes);
+  find_or_make_view(off_t start, off_t size);
 
   // Clear the file views.
   void
index 58e3385131b2f3bc2caf647a9fd45aa2b47ab80e..5c5594daabe84f88e9308244e085faa8a9b7c3fd 100644 (file)
@@ -86,10 +86,11 @@ Read_symbols::run(Workqueue* workqueue)
 
   // Read enough of the file to pick up the entire ELF header.
 
-  int ehdr_size = elfcpp::Elf_sizes<64>::ehdr_size;
+  const int ehdr_size = elfcpp::Elf_sizes<64>::ehdr_size;
+  unsigned char ehdr_buf[ehdr_size];
   off_t bytes;
-  const unsigned char* p = input_file->file().get_view_and_size(0, ehdr_size,
-                                                               &bytes);
+  input_file->file().read_up_to(0, ehdr_size, ehdr_buf, &bytes);
+
   if (bytes >= 4)
     {
       static unsigned char elfmagic[4] =
@@ -97,12 +98,12 @@ Read_symbols::run(Workqueue* workqueue)
          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, bytes);
 
          // 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
@@ -133,7 +134,7 @@ Read_symbols::run(Workqueue* workqueue)
 
   if (bytes >= 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(),
@@ -161,7 +162,8 @@ Read_symbols::run(Workqueue* workqueue)
   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, bytes, this->this_blocker_,
+                       this->next_blocker_))
     return;
 
   // Here we have to handle any other input file types we need.