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]

gold patch committed: Simplify system directory handling


When gold warns about undefined symbols in shared libraries, it avoids
issuing a warning if the shared library is in a system directory.  This
is to avoid warning about symbols which are defined in the dynamic
linker and referenced by -ldl.  Currently gold decides whether a library
is in a system directory based on whether it is in the directory in
which gold finds libc.so.  This is a somewhat shaky heuristic.

gold already has a different heuristic for a system directory, which it
uses to decide whether to put a directory into the sysroot if there is
one.  I committed this patch to make gold use the latter heuristic to
pick a system directory.  This permitted some minor code
simplifications.  I think this heuristic is slightly better.

Ian


2009-02-27  Ian Lance Taylor  <iant@google.com>

	PR 6811
	* options.h (class Search_directory): Add is_system_directory.
	(class General_options): Declare is_in_system_directory.
	* options.cc (get_relative_sysroot): Make static.
	(get_default_sysroot): Make static.
	(General_optoins::is_in_system_directory): New function.
	* fileread.cc (Input_file::is_in_system_directory): New function.
	* fileread.h (class Input_file): Declare is_in_system_directory.
	* object.h (class Object): Add is_in_system_directory.
	(class Input_objects): Remove system_library_directory_ field.
	* object.cc (Input_objects::add_object): Don't set
	system_library_directory_.
	(input_objects::found_in_system_library_directory): Remove.
	* symtab.cc (Symbol_table::write_globals): Remove input_objects
	parameter.  Change all callers.
	(Symbol_table::sized_write_globals): Likewise.
	(Symbol_table::warn_about_undefined_dynobj_symbol): Likewise.
	Call Object::is_in_system_directory.
	* symtab.h (class Symbol_table): Update declarations.


Index: fileread.cc
===================================================================
RCS file: /cvs/src/src/gold/fileread.cc,v
retrieving revision 1.47
diff -p -u -r1.47 fileread.cc
--- fileread.cc	15 Jan 2009 01:29:25 -0000	1.47
+++ fileread.cc	28 Feb 2009 04:35:24 -0000
@@ -738,6 +738,16 @@ Input_file::name() const
   return this->input_argument_->name();
 }
 
+// Return whether this file is in a system directory.
+
+bool
+Input_file::is_in_system_directory() const
+{
+  if (this->is_in_sysroot())
+    return true;
+  return parameters->options().is_in_system_directory(this->filename());
+}
+
 // Return whether we are only reading symbols.
 
 bool
Index: fileread.h
===================================================================
RCS file: /cvs/src/src/gold/fileread.h,v
retrieving revision 1.32
diff -p -u -r1.32 fileread.h
--- fileread.h	15 Jan 2009 01:29:25 -0000	1.32
+++ fileread.h	28 Feb 2009 04:35:24 -0000
@@ -471,6 +471,10 @@ class Input_file
   is_in_sysroot() const
   { return this->is_in_sysroot_; }
 
+  // Whether this file is in a system directory.
+  bool
+  is_in_system_directory() const;
+
   // Return whether this file is to be read only for its symbols.
   bool
   just_symbols() const;
Index: layout.cc
===================================================================
RCS file: /cvs/src/src/gold/layout.cc,v
retrieving revision 1.117
diff -p -u -r1.117 layout.cc
--- layout.cc	25 Feb 2009 19:05:20 -0000	1.117
+++ layout.cc	28 Feb 2009 04:35:24 -0000
@@ -3317,8 +3317,8 @@ Write_symbols_task::locks(Task_locker* t
 void
 Write_symbols_task::run(Workqueue*)
 {
-  this->symtab_->write_globals(this->input_objects_, this->sympool_,
-			       this->dynpool_, this->layout_->symtab_xindex(),
+  this->symtab_->write_globals(this->sympool_, this->dynpool_,
+			       this->layout_->symtab_xindex(),
 			       this->layout_->dynsym_xindex(), this->of_);
 }
 
Index: object.cc
===================================================================
RCS file: /cvs/src/src/gold/object.cc,v
retrieving revision 1.85
diff -p -u -r1.85 object.cc
--- object.cc	28 Feb 2009 00:12:26 -0000	1.85
+++ object.cc	28 Feb 2009 04:35:25 -0000
@@ -1941,19 +1941,6 @@ Input_objects::add_object(Object* obj)
 	}
 
       this->dynobj_list_.push_back(dynobj);
-
-      // If this is -lc, remember the directory in which we found it.
-      // We use this when issuing warnings about undefined symbols: as
-      // a heuristic, we don't warn about system libraries found in
-      // the same directory as -lc.
-      if (strncmp(soname, "libc.so", 7) == 0)
-	{
-	  const char* object_name = dynobj->name().c_str();
-	  const char* base = lbasename(object_name);
-	  if (base != object_name)
-	    this->system_library_directory_.assign(object_name,
-						   base - 1 - object_name);
-	}
     }
 
   // Add this object to the cross-referencer if requested.
@@ -1967,17 +1954,6 @@ Input_objects::add_object(Object* obj)
   return true;
 }
 
-// Return whether an object was found in the system library directory.
-
-bool
-Input_objects::found_in_system_library_directory(const Object* object) const
-{
-  return (!this->system_library_directory_.empty()
-	  && object->name().compare(0,
-				    this->system_library_directory_.size(),
-				    this->system_library_directory_) == 0);
-}
-
 // For each dynamic object, record whether we've seen all of its
 // explicit dependencies.
 
Index: object.h
===================================================================
RCS file: /cvs/src/src/gold/object.h,v
retrieving revision 1.69
diff -p -u -r1.69 object.h
--- object.h	13 Feb 2009 19:04:45 -0000	1.69
+++ object.h	28 Feb 2009 04:35:25 -0000
@@ -444,6 +444,11 @@ class Object
   set_target(Target* target)
   { this->target_ = target; }
 
+  // Return whether this object was found in a system directory.
+  bool
+  is_in_system_directory() const
+  { return this->input_file()->is_in_system_directory(); }
+
  protected:
   // Returns NULL for Objects that are not plugin objects.  This method
   // is overridden in the Pluginobj class.
@@ -1832,8 +1837,7 @@ class Input_objects
 {
  public:
   Input_objects()
-    : relobj_list_(), dynobj_list_(), sonames_(), system_library_directory_(),
-      cref_(NULL)
+    : relobj_list_(), dynobj_list_(), sonames_(), cref_(NULL)
   { }
 
   // The type of the list of input relocateable objects.
@@ -1911,8 +1915,6 @@ class Input_objects
   Dynobj_list dynobj_list_;
   // SONAMEs that we have seen.
   Unordered_set<std::string> sonames_;
-  // The directory in which we find the libc.so.
-  std::string system_library_directory_;
   // Manage cross-references if requested.
   Cref* cref_;
 };
Index: options.cc
===================================================================
RCS file: /cvs/src/src/gold/options.cc,v
retrieving revision 1.82
diff -p -u -r1.82 options.cc
--- options.cc	6 Feb 2009 23:49:43 -0000	1.82
+++ options.cc	28 Feb 2009 04:35:25 -0000
@@ -1,6 +1,6 @@
 // options.c -- handle command line options for gold
 
-// Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 // Written by Ian Lance Taylor <iant@google.com>.
 
 // This file is part of gold.
@@ -451,7 +451,7 @@ string_to_object_format(const char* arg)
 // If the default sysroot is relocatable, try relocating it based on
 // the prefix FROM.
 
-char*
+static char*
 get_relative_sysroot(const char* from)
 {
   char* path = make_relative_prefix(gold::program_name, from,
@@ -472,7 +472,7 @@ get_relative_sysroot(const char* from)
 // get_relative_sysroot, which is a small memory leak, but is
 // necessary since we store this pointer directly in General_options.
 
-const char*
+static const char*
 get_default_sysroot()
 {
   const char* sysroot = TARGET_SYSTEM_ROOT;
@@ -684,6 +684,26 @@ General_options::add_sysroot()
   free(canonical_sysroot);
 }
 
+// Return whether FILENAME is in a system directory.
+
+bool
+General_options::is_in_system_directory(const std::string& filename) const
+{
+  for (Dir_list::const_iterator p = this->library_path_.value.begin();
+       p != this->library_path_.value.end();
+       ++p)
+    {
+      // We use a straight string comparison rather than calling
+      // FILENAME_CMP because we are only interested in the cases
+      // where we found the file in a system directory, which means
+      // that we used the directory name as a prefix for a -L search.
+      if (p->is_system_directory()
+	  && filename.compare(0, p->name().size(), p->name()) == 0)
+	return true;
+    }
+  return false;
+}
+
 // Add a plugin to the list of plugins.
 
 void
Index: options.h
===================================================================
RCS file: /cvs/src/src/gold/options.h,v
retrieving revision 1.94
diff -p -u -r1.94 options.h
--- options.h	6 Feb 2009 23:49:43 -0000	1.94
+++ options.h	28 Feb 2009 04:35:25 -0000
@@ -534,9 +534,22 @@ class Search_directory
   is_in_sysroot() const
   { return this->is_in_sysroot_; }
 
+  // Return whether this is considered a system directory.
+  bool
+  is_system_directory() const
+  { return this->put_in_sysroot_ || this->is_in_sysroot_; }
+
  private:
+  // The directory name.
   std::string name_;
+  // True if the sysroot should be added as a prefix for this
+  // directory (if there is a sysroot).  This is true for system
+  // directories that we search by default.
   bool put_in_sysroot_;
+  // True if this directory is in the sysroot (if there is a sysroot).
+  // This is true if there is a sysroot and either 1) put_in_sysroot_
+  // is true, or 2) the directory happens to be in the sysroot based
+  // on a pathname comparison.
   bool is_in_sysroot_;
 };
 
@@ -962,6 +975,10 @@ class General_options
   Object_format format_enum() const;
   Object_format oformat_enum() const;
 
+  // Return whether FILENAME is in a system directory.
+  bool
+  is_in_system_directory(const std::string& name) const;
+
   // These are the best way to get access to the execstack state,
   // not execstack() and noexecstack() which are hard to use properly.
   bool
Index: symtab.cc
===================================================================
RCS file: /cvs/src/src/gold/symtab.cc,v
retrieving revision 1.115
diff -p -u -r1.115 symtab.cc
--- symtab.cc	27 Feb 2009 19:57:46 -0000	1.115
+++ symtab.cc	28 Feb 2009 04:35:26 -0000
@@ -2373,8 +2373,7 @@ Symbol_table::sized_finalize_symbol(Symb
 // Write out the global symbols.
 
 void
-Symbol_table::write_globals(const Input_objects* input_objects,
-			    const Stringpool* sympool,
+Symbol_table::write_globals(const Stringpool* sympool,
 			    const Stringpool* dynpool,
 			    Output_symtab_xindex* symtab_xindex,
 			    Output_symtab_xindex* dynsym_xindex,
@@ -2384,29 +2383,25 @@ Symbol_table::write_globals(const Input_
     {
 #ifdef HAVE_TARGET_32_LITTLE
     case Parameters::TARGET_32_LITTLE:
-      this->sized_write_globals<32, false>(input_objects, sympool,
-                                           dynpool, symtab_xindex,
+      this->sized_write_globals<32, false>(sympool, dynpool, symtab_xindex,
 					   dynsym_xindex, of);
       break;
 #endif
 #ifdef HAVE_TARGET_32_BIG
     case Parameters::TARGET_32_BIG:
-      this->sized_write_globals<32, true>(input_objects, sympool,
-                                          dynpool, symtab_xindex,
+      this->sized_write_globals<32, true>(sympool, dynpool, symtab_xindex,
 					  dynsym_xindex, of);
       break;
 #endif
 #ifdef HAVE_TARGET_64_LITTLE
     case Parameters::TARGET_64_LITTLE:
-      this->sized_write_globals<64, false>(input_objects, sympool,
-                                           dynpool, symtab_xindex,
+      this->sized_write_globals<64, false>(sympool, dynpool, symtab_xindex,
 					   dynsym_xindex, of);
       break;
 #endif
 #ifdef HAVE_TARGET_64_BIG
     case Parameters::TARGET_64_BIG:
-      this->sized_write_globals<64, true>(input_objects, sympool,
-                                          dynpool, symtab_xindex,
+      this->sized_write_globals<64, true>(sympool, dynpool, symtab_xindex,
 					  dynsym_xindex, of);
       break;
 #endif
@@ -2419,8 +2414,7 @@ Symbol_table::write_globals(const Input_
 
 template<int size, bool big_endian>
 void
-Symbol_table::sized_write_globals(const Input_objects* input_objects,
-				  const Stringpool* sympool,
+Symbol_table::sized_write_globals(const Stringpool* sympool,
 				  const Stringpool* dynpool,
 				  Output_symtab_xindex* symtab_xindex,
 				  Output_symtab_xindex* dynsym_xindex,
@@ -2456,7 +2450,7 @@ Symbol_table::sized_write_globals(const 
       Sized_symbol<size>* sym = static_cast<Sized_symbol<size>*>(p->second);
 
       // Possibly warn about unresolved symbols in shared libraries.
-      this->warn_about_undefined_dynobj_symbol(input_objects, sym);
+      this->warn_about_undefined_dynobj_symbol(sym);
 
       unsigned int sym_index = sym->symtab_index();
       unsigned int dynsym_index;
@@ -2621,16 +2615,13 @@ Symbol_table::sized_write_symbol(
 // entry, we aren't going to be able to reliably report whether the
 // symbol is undefined.
 
-// We also don't warn about libraries found in the system library
-// directory (the directory were we find libc.so); we assume that
-// those libraries are OK.  This heuristic avoids problems in
-// GNU/Linux, in which -ldl can have undefined references satisfied by
-// ld-linux.so.
+// We also don't warn about libraries found in a system library
+// directory (e.g., /lib or /usr/lib); we assume that those libraries
+// are OK.  This heuristic avoids problems on GNU/Linux, in which -ldl
+// can have undefined references satisfied by ld-linux.so.
 
 inline void
-Symbol_table::warn_about_undefined_dynobj_symbol(
-    const Input_objects* input_objects,
-    Symbol* sym) const
+Symbol_table::warn_about_undefined_dynobj_symbol(Symbol* sym) const
 {
   bool dummy;
   if (sym->source() == Symbol::FROM_OBJECT
@@ -2639,7 +2630,7 @@ Symbol_table::warn_about_undefined_dynob
       && sym->binding() != elfcpp::STB_WEAK
       && !parameters->options().allow_shlib_undefined()
       && !parameters->target().is_defined_by_abi(sym)
-      && !input_objects->found_in_system_library_directory(sym->object()))
+      && !sym->object()->is_in_system_directory())
     {
       // A very ugly cast.
       Dynobj* dynobj = static_cast<Dynobj*>(sym->object());
Index: symtab.h
===================================================================
RCS file: /cvs/src/src/gold/symtab.h,v
retrieving revision 1.85
diff -p -u -r1.85 symtab.h
--- symtab.h	27 Feb 2009 19:57:46 -0000	1.85
+++ symtab.h	28 Feb 2009 04:35:26 -0000
@@ -1342,7 +1342,7 @@ class Symbol_table
 
   // Write out the global symbols.
   void
-  write_globals(const Input_objects*, const Stringpool*, const Stringpool*,
+  write_globals(const Stringpool*, const Stringpool*,
 		Output_symtab_xindex*, Output_symtab_xindex*,
 		Output_file*) const;
 
@@ -1509,9 +1509,9 @@ class Symbol_table
   // Write globals specialized for size and endianness.
   template<int size, bool big_endian>
   void
-  sized_write_globals(const Input_objects*, const Stringpool*,
-		      const Stringpool*, Output_symtab_xindex*,
-		      Output_symtab_xindex*, Output_file*) const;
+  sized_write_globals(const Stringpool*, const Stringpool*,
+		      Output_symtab_xindex*, Output_symtab_xindex*,
+		      Output_file*) const;
 
   // Write out a symbol to P.
   template<int size, bool big_endian>
@@ -1523,7 +1523,7 @@ class Symbol_table
 
   // Possibly warn about an undefined symbol from a dynamic object.
   void
-  warn_about_undefined_dynobj_symbol(const Input_objects*, Symbol*) const;
+  warn_about_undefined_dynobj_symbol(Symbol*) const;
 
   // Write out a section symbol, specialized for size and endianness.
   template<int size, bool big_endian>

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