gold/
[binutils-gdb.git] / gold / fileread.cc
index 232473470a9c5fd4adeb77d735f255881f5b05b9..c5dc320c34e8efb8952bfc05f3be021509a46197 100644 (file)
@@ -329,6 +329,10 @@ inline File_read::View*
 File_read::find_view(off_t start, section_size_type size,
                     unsigned int byteshift, File_read::View** vshifted) const
 {
+  gold_assert(start <= this->size_
+             && (static_cast<unsigned long long>(size)
+                 <= static_cast<unsigned long long>(this->size_ - start)));
+
   if (vshifted != NULL)
     *vshifted = NULL;
 
@@ -456,16 +460,9 @@ File_read::make_view(off_t start, section_size_type size,
                     unsigned int byteshift, bool cache)
 {
   gold_assert(size > 0);
-
-  // Check that start and end of the view are within the file.
-  if (start > this->size_
-      || (static_cast<unsigned long long>(size)
-          > static_cast<unsigned long long>(this->size_ - start)))
-    gold_fatal(_("%s: attempt to map %lld bytes at offset %lld exceeds "
-                 "size of file; the file may be corrupt"),
-                  this->filename().c_str(),
-                  static_cast<long long>(size),
-                  static_cast<long long>(start));
+  gold_assert(start <= this->size_
+             && (static_cast<unsigned long long>(size)
+                 <= static_cast<unsigned long long>(this->size_ - start)));
 
   off_t poff = File_read::page_offset(start);
 
@@ -523,6 +520,16 @@ File_read::View*
 File_read::find_or_make_view(off_t offset, off_t start,
                             section_size_type size, bool aligned, bool cache)
 {
+  // Check that start and end of the view are within the file.
+  if (start > this->size_
+      || (static_cast<unsigned long long>(size)
+          > static_cast<unsigned long long>(this->size_ - start)))
+    gold_fatal(_("%s: attempt to map %lld bytes at offset %lld exceeds "
+                 "size of file; the file may be corrupt"),
+                  this->filename().c_str(),
+                  static_cast<long long>(size),
+                  static_cast<long long>(start));
+
   unsigned int byteshift;
   if (offset == 0)
     byteshift = 0;
@@ -986,45 +993,40 @@ Input_file::find_file(const Dirsearch& dirpath, int* pindex,
   else if (input_argument->is_lib()
           || input_argument->is_searched_file())
     {
-      std::string n1, n2;
+      std::vector<std::string> names;
+      names.reserve(2);
       if (input_argument->is_lib())
        {
-         n1 = "lib";
-         n1 += input_argument->name();
+         std::string prefix = "lib";
+         prefix += input_argument->name();
          if (parameters->options().is_static()
              || !input_argument->options().Bdynamic())
-           n1 += ".a";
+           names.push_back(prefix + ".a");
          else
            {
-             n2 = n1 + ".a";
-             n1 += ".so";
+             names.push_back(prefix + ".so");
+             names.push_back(prefix + ".a");
            }
        }
       else
-       n1 = input_argument->name();
+       names.push_back(input_argument->name());
 
-      if (Input_file::try_extra_search_path(pindex, input_argument, n1,
-                                           found_name, namep))
-        return true;
-
-      if (!n2.empty() && Input_file::try_extra_search_path(pindex,
-                                                          input_argument, n2,
-                                                          found_name, namep))
-        return true;
+      for (std::vector<std::string>::const_iterator n = names.begin();
+          n != names.end();
+          ++n)
+       if (Input_file::try_extra_search_path(pindex, input_argument, *n,
+                                             found_name, namep))
+         return true;
 
       // It is not in the extra_search_path.
-      name = dirpath.find(n1, n2, is_in_sysroot, pindex);
+      name = dirpath.find(names, is_in_sysroot, pindex, found_name);
       if (name.empty())
        {
          gold_error(_("cannot find %s%s"),
-                    input_argument->is_lib() ? "-l" : "",
+                    input_argument->is_lib() ? "-l" : "",
                     input_argument->name());
          return false;
        }
-      if (n2.empty() || name[name.length() - 1] == 'o')
-       *found_name = n1;
-      else
-       *found_name = n2;
       *namep = name;
       return true;
     }
@@ -1034,22 +1036,21 @@ Input_file::find_file(const Dirsearch& dirpath, int* pindex,
       gold_assert(input_argument->extra_search_path() != NULL);
 
       if (try_extra_search_path(pindex, input_argument, input_argument->name(),
-                                found_name, namep))
-        return true;
+                               found_name, namep))
+       return true;
 
       // extra_search_path failed, so check the normal search-path.
       int index = *pindex;
       if (index > 0)
-        --index;
-      name = dirpath.find(input_argument->name(), "",
-                          is_in_sysroot, &index);
+       --index;
+      name = dirpath.find(std::vector<std::string>(1, input_argument->name()),
+                         is_in_sysroot, &index, found_name);
       if (name.empty())
-        {
-          gold_error(_("cannot find %s"),
-                     input_argument->name());
-          return false;
-        }
-      *found_name = input_argument->name();
+       {
+         gold_error(_("cannot find %s"),
+                    input_argument->name());
+         return false;
+       }
       *namep = name;
       *pindex = index + 1;
       return true;