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 to 2.20 branch: --no-add-needed


One way to make sure that a program links with both GNU ld and gold is
to use the --no-add-needed option.  That will make GNU ld avoid
looking in indirectly referenced shared libraries, as gold always
does.  However, binutils 2.20 has the annoyance that gold does not
support the --no-add-needed option.  I copied this patch from mainline
to 2.20  branch to avoid that annoyance.

Ian


2010-01-13  Ian Lance Taylor  <iant@google.com>

	Bring over from mainline:
	2010-01-04  Ian Lance Taylor  <iant@google.com>

	PR 10980
	* options.h (class General_options): Add --add-needed and
	--copy-dt-needed-entries.  Tweak --as-needed help entry.
	* object.cc (Input_objects::check_dynamic_dependencies): Give an
	error if --copy-dt-needed-entries aka --add-needed is used and
	would cause a change in behaviour.


Index: object.cc
===================================================================
RCS file: /cvs/src/src/gold/object.cc,v
retrieving revision 1.98.2.1
diff -p -u -r1.98.2.1 object.cc
--- object.cc	16 Oct 2009 05:51:17 -0000	1.98.2.1
+++ object.cc	13 Jan 2010 16:16:44 -0000
@@ -1,6 +1,6 @@
 // object.cc -- support for an object file for linking in gold
 
-// Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 // Written by Ian Lance Taylor <iant@google.com>.
 
 // This file is part of gold.
@@ -2134,15 +2134,15 @@ Input_objects::add_object(Object* obj)
 void
 Input_objects::check_dynamic_dependencies() const
 {
+  bool issued_copy_dt_needed_error = false;
   for (Dynobj_list::const_iterator p = this->dynobj_list_.begin();
        p != this->dynobj_list_.end();
        ++p)
     {
       const Dynobj::Needed& needed((*p)->needed());
       bool found_all = true;
-      for (Dynobj::Needed::const_iterator pneeded = needed.begin();
-	   pneeded != needed.end();
-	   ++pneeded)
+      Dynobj::Needed::const_iterator pneeded;
+      for (pneeded = needed.begin(); pneeded != needed.end(); ++pneeded)
 	{
 	  if (this->sonames_.find(*pneeded) == this->sonames_.end())
 	    {
@@ -2151,6 +2151,25 @@ Input_objects::check_dynamic_dependencie
 	    }
 	}
       (*p)->set_has_unknown_needed_entries(!found_all);
+
+      // --copy-dt-needed-entries aka --add-needed is a GNU ld option
+      // --that gold does not support.  However, they cause no trouble
+      // --unless there is a DT_NEEDED entry that we don't know about;
+      // --warn only in that case.
+      if (!found_all
+	  && !issued_copy_dt_needed_error
+	  && (parameters->options().copy_dt_needed_entries()
+	      || parameters->options().add_needed()))
+	{
+	  const char* optname;
+	  if (parameters->options().copy_dt_needed_entries())
+	    optname = "--copy-dt-needed-entries";
+	  else
+	    optname = "--add-needed";
+	  gold_error(_("%s is not supported but is required for %s in %s"),
+		     optname, (*pneeded).c_str(), (*p)->name().c_str());
+	  issued_copy_dt_needed_error = true;
+	}
     }
 }
 
Index: options.h
===================================================================
RCS file: /cvs/src/src/gold/options.h,v
retrieving revision 1.106.2.2
diff -p -u -r1.106.2.2 options.h
--- options.h	4 Nov 2009 01:28:30 -0000	1.106.2.2
+++ options.h	13 Jan 2010 16:16:44 -0000
@@ -1,6 +1,6 @@
 // options.h -- handle command line options for gold  -*- C++ -*-
 
-// Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 // Written by Ian Lance Taylor <iant@google.com>.
 
 // This file is part of gold.
@@ -580,13 +580,17 @@ class General_options
   // alphabetical order).  For both, lowercase sorts before uppercase.
   // The -z options come last.
 
+  DEFINE_bool(add_needed, options::TWO_DASHES, '\0', false,
+	      N_("Not supported"),
+	      N_("Do not copy DT_NEEDED tags from shared libraries"));
+
   DEFINE_bool(allow_shlib_undefined, options::TWO_DASHES, '\0', false,
               N_("Allow unresolved references in shared libraries"),
               N_("Do not allow unresolved references in shared libraries"));
 
   DEFINE_bool(as_needed, options::TWO_DASHES, '\0', false,
-              N_("Only set DT_NEEDED for dynamic libs if used"),
-              N_("Always DT_NEEDED for dynamic libs"));
+              N_("Only set DT_NEEDED for shared libraries if used"),
+              N_("Always DT_NEEDED for shared libraries"));
 
   // This should really be an "enum", but it's too easy for folks to
   // forget to update the list as they add new targets.  So we just
@@ -627,6 +631,10 @@ class General_options
               {"none"});
 #endif
 
+  DEFINE_bool(copy_dt_needed_entries, options::TWO_DASHES, '\0', false,
+	      N_("Not supported"),
+	      N_("Do not copy DT_NEEDED tags from shared libraries"));
+
   DEFINE_bool(define_common, options::TWO_DASHES, 'd', false,
               N_("Define common symbols"),
               N_("Do not define common symbols"));

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