This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [gold][patch] Clean up library names search


David Meyer <pdox@google.com> writes:

> I am working on an architecture which has more than two library
> suffixes (.a, .so, and .pso).
>
> This patch increases the flexibility of library name searching, by
> using a list instead of hard-coding two possibilities.


Approved and applied with some formatting changes and the following
ChangeLog entry.  I also changed from std::list to std::vector--gold
mostly uses vectors.

Thanks.

Ian


2011-05-24  David Meyer  <pdox@google.com>

	* dirsearch.cc (Dirsearch::find): Replace n1 and n2 parameters
	with name parameter.  Add found_name parameter.
	* fileread.cc (Input_file::find_file): Adjust code accordingly.
	* dirsearch.h (class Dirsearch): Update declaration.


Index: dirsearch.cc
===================================================================
RCS file: /cvs/src/src/gold/dirsearch.cc,v
retrieving revision 1.12
diff -u -r1.12 dirsearch.cc
--- dirsearch.cc	11 Feb 2010 07:42:17 -0000	1.12
+++ dirsearch.cc	25 May 2011 06:12:45 -0000
@@ -1,6 +1,6 @@
 // dirsearch.cc -- directory searching for gold
 
-// Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
 // Written by Ian Lance Taylor <iant@google.com>.
 
 // This file is part of gold.
@@ -241,8 +241,9 @@
 // File_read::open.
 
 std::string
-Dirsearch::find(const std::string& n1, const std::string& n2,
-		bool* is_in_sysroot, int* pindex) const
+Dirsearch::find(const std::vector<std::string>& names,
+		bool* is_in_sysroot, int* pindex,
+		std::string *found_name) const
 {
   gold_assert(!this->token_.is_blocked());
   gold_assert(*pindex >= 0);
@@ -254,27 +255,20 @@
       const Search_directory* p = &this->directories_->at(i);
       Dir_cache* pdc = caches->lookup(p->name().c_str());
       gold_assert(pdc != NULL);
-      if (pdc->find(n1))
+      for (std::vector<std::string>::const_iterator n = names.begin();
+	   n != names.end();
+	   ++n)
 	{
-	  *is_in_sysroot = p->is_in_sysroot();
-	  *pindex = i;
-	  return p->name() + '/' + n1;
-	}
-      else
-        gold_debug(DEBUG_FILES, "Attempt to open %s/%s failed",
-                   p->name().c_str(), n1.c_str());
-
-      if (!n2.empty())
-        {
-          if (pdc->find(n2))
-            {
-              *is_in_sysroot = p->is_in_sysroot();
+	  if (pdc->find(*n))
+	    {
+	      *is_in_sysroot = p->is_in_sysroot();
 	      *pindex = i;
-              return p->name() + '/' + n2;
-            }
-          else
-            gold_debug(DEBUG_FILES, "Attempt to open %s/%s failed",
-                       p->name().c_str(), n2.c_str());
+	      *found_name = *n;
+	      return p->name() + '/' + *n;
+	    }
+	  else
+	    gold_debug(DEBUG_FILES, "Attempt to open %s/%s failed",
+		       p->name().c_str(), (*n).c_str());
 	}
     }
 
Index: dirsearch.h
===================================================================
RCS file: /cvs/src/src/gold/dirsearch.h,v
retrieving revision 1.8
diff -u -r1.8 dirsearch.h
--- dirsearch.h	25 Aug 2010 08:36:54 -0000	1.8
+++ dirsearch.h	25 May 2011 06:12:45 -0000
@@ -1,6 +1,6 @@
 // dirsearch.h -- directory searching for gold  -*- C++ -*-
 
-// Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
 // Written by Ian Lance Taylor <iant@google.com>.
 
 // This file is part of gold.
@@ -59,8 +59,8 @@
   // and that value plus one may be used to find the next file with
   // the same name(s).
   std::string
-  find(const std::string&, const std::string& n2, bool* is_in_sysroot,
-       int* pindex) const;
+  find(const std::vector<std::string>& names, bool* is_in_sysroot,
+       int* pindex, std::string *found_name) const;
 
   // Return the blocker token which controls access.
   Task_token*
Index: fileread.cc
===================================================================
RCS file: /cvs/src/src/gold/fileread.cc,v
retrieving revision 1.73
diff -u -r1.73 fileread.cc
--- fileread.cc	12 Apr 2011 18:06:16 -0000	1.73
+++ fileread.cc	25 May 2011 06:12:45 -0000
@@ -986,45 +986,40 @@
   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 +1029,21 @@
       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;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]