This is the mail archive of the binutils@sources.redhat.com 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: PATCH: Add "-z muldefs" (Re: question of ld)


On Wed, May 22, 2002 at 02:08:40PM +0930, Alan Modra wrote:
> On Tue, May 21, 2002 at 08:09:03PM -0700, H . J . Lu wrote:
> > 2002-05-21  H.J. Lu  (hjl@gnu.org)
> > 
> > 	* linker.c (_bfd_generic_link_add_one_symbol): Allow multiple
> > 	definition.
> > 
> > 2002-05-21  H.J. Lu  (hjl@gnu.org)
> > 
> > 	* bfdlink.h (bfd_link_info): Add allow_multiple_definition.
> > 
> > 2002-05-21  H.J. Lu  (hjl@gnu.org)
> > 
> > 	* emultempl/elf32.em (gld${EMULATION_NAME}_parse_args): Handle
> > 	"-z muldefs".
> > 	(gld${EMULATION_NAME}_list_options): Add "-z muldefs".
> > 
> > 	* ldmain.c (main): Initialize the allow_multiple_definition
> > 	field to false.
> > 
> > 	* lexsup.c (OPTION_ALLOW_MULTIPLE_DEFINITION): New.
> > 	(ld_options): Add --allow-multiple-definition.
> > 	(parse_args): Support OPTION_ALLOW_MULTIPLE_DEFINITION.
> 
> OK.  Please fix the formatting when applying your linker.c patch.
> 

I am going to check in this with updated documentation.


H.J.
---
2002-05-21  H.J. Lu  (hjl@gnu.org)

	* linker.c (_bfd_generic_link_add_one_symbol): Allow multiple
	definition.

2002-05-21  H.J. Lu  (hjl@gnu.org)

	* bfdlink.h (bfd_link_info): Add allow_multiple_definition.

2002-05-21  H.J. Lu  (hjl@gnu.org)

	* emultempl/elf32.em (gld${EMULATION_NAME}_parse_args): Handle
	"-z muldefs".
	(gld${EMULATION_NAME}_list_options): Add "-z muldefs".

	* ld.texinfo: Updated for --allow-multiple-definition and
	"-z muldefs".

	* ldmain.c (main): Initialize the allow_multiple_definition
	field to false.

	* lexsup.c (OPTION_ALLOW_MULTIPLE_DEFINITION): New.
	(ld_options): Add --allow-multiple-definition.
	(parse_args): Support OPTION_ALLOW_MULTIPLE_DEFINITION.

--- binutils/bfd/linker.c.muldefs	Mon May 20 11:03:04 2002
+++ binutils/bfd/linker.c	Tue May 21 21:45:40 2002
@@ -1813,37 +1813,38 @@ _bfd_generic_link_add_one_symbol (info, 
 	  /* Fall through.  */
 	case MDEF:
 	  /* Handle a multiple definition.  */
-	  {
-	    asection *msec = NULL;
-	    bfd_vma mval = 0;
+	  if (!info->allow_multiple_definition)
+	    {
+	      asection *msec = NULL;
+	      bfd_vma mval = 0;
 
-	    switch (h->type)
-	      {
-	      case bfd_link_hash_defined:
-		msec = h->u.def.section;
-		mval = h->u.def.value;
-		break;
-	      case bfd_link_hash_indirect:
-		msec = bfd_ind_section_ptr;
-		mval = 0;
-		break;
-	      default:
-		abort ();
-	      }
+	      switch (h->type)
+		{
+		case bfd_link_hash_defined:
+		  msec = h->u.def.section;
+		  mval = h->u.def.value;
+		  break;
+	        case bfd_link_hash_indirect:
+		  msec = bfd_ind_section_ptr;
+		  mval = 0;
+		  break;
+		default:
+		  abort ();
+		}
 
-	    /* Ignore a redefinition of an absolute symbol to the same
-               value; it's harmless.  */
-	    if (h->type == bfd_link_hash_defined
-		&& bfd_is_abs_section (msec)
-		&& bfd_is_abs_section (section)
-		&& value == mval)
-	      break;
+	      /* Ignore a redefinition of an absolute symbol to the
+		 same value; it's harmless.  */
+	      if (h->type == bfd_link_hash_defined
+		  && bfd_is_abs_section (msec)
+		  && bfd_is_abs_section (section)
+		  && value == mval)
+		break;
 
-	    if (! ((*info->callbacks->multiple_definition)
-		   (info, h->root.string, msec->owner, msec, mval, abfd,
-		    section, value)))
-	      return false;
-	  }
+	      if (! ((*info->callbacks->multiple_definition)
+		     (info, h->root.string, msec->owner, msec, mval,
+		      abfd, section, value)))
+		return false;
+	    }
 	  break;
 
 	case CIND:
--- binutils/include/bfdlink.h.muldefs	Fri Mar  8 09:48:28 2002
+++ binutils/include/bfdlink.h	Tue May 21 19:39:48 2002
@@ -231,6 +231,8 @@ struct bfd_link_info
      select an appropriate memset function.  Apparently it is also
      normal for HPPA shared libraries to have undefined symbols.  */
   boolean allow_shlib_undefined;
+  /* True if ok to have multiple definition.  */
+  boolean allow_multiple_definition;
   /* Which symbols to strip.  */
   enum bfd_link_strip strip;
   /* Which local symbols to discard.  */
--- binutils/ld/emultempl/elf32.em.muldefs	Tue Apr 23 15:18:44 2002
+++ binutils/ld/emultempl/elf32.em	Tue May 21 19:53:45 2002
@@ -1541,6 +1541,8 @@ cat >>e${EMULATION_NAME}.c <<EOF
 	}
       else if (strcmp (optarg, "defs") == 0)
 	link_info.no_undefined = true;
+      else if (strcmp (optarg, "muldefs") == 0)
+	link_info.allow_multiple_definition = true;
       else if (strcmp (optarg, "combreloc") == 0)
 	link_info.combreloc = true;
       else if (strcmp (optarg, "nocombreloc") == 0)
@@ -1589,6 +1591,7 @@ cat >>e${EMULATION_NAME}.c <<EOF
   fprintf (file, _("  -z initfirst\t\tMark DSO to be initialized first at runtime\n"));
   fprintf (file, _("  -z interpose\t\tMark object to interpose all DSOs but executable\n"));
   fprintf (file, _("  -z loadfltr\t\tMark object requiring immediate process\n"));
+  fprintf (file, _("  -z muldefs\t\tAllow multiple definitions\n"));
   fprintf (file, _("  -z nocombreloc\tDon't merge dynamic relocs into one section\n"));
   fprintf (file, _("  -z nocopyreloc\tDon't create copy relocs\n"));
   fprintf (file, _("  -z nodefaultlib\tMark object not to use default search paths\n"));
--- binutils/ld/ld.texinfo.muldefs	Tue Apr 23 15:18:43 2002
+++ binutils/ld/ld.texinfo	Tue May 21 21:32:24 2002
@@ -859,6 +859,7 @@ of this object will ignore any default l
 @code{now} marks the object with the non-lazy runtime binding.
 @code{origin} marks the object may contain $ORIGIN.
 @code{defs} disallows undefined symbols.
+@code{muldefs} allows multiple definitions.
 @code{combreloc} combines multiple reloc sections and sorts them
 to make dynamic symbol lookup caching possible.
 @code{nocombreloc} disables multiple reloc sections combining.
@@ -1080,6 +1081,14 @@ Normally when creating a non-symbolic sh
 are allowed and left to be resolved by the runtime loader.  These options
 disallows such undefined symbols.
 
+@kindex --allow-multiple-definition
+@kindex -z muldefs
+@item --allow-multiple-definition
+@itemx -z muldefs
+Normally when a symbol is defined multiple times, the linker will
+report a fatal error. These options allow multiple definitions and the
+first definition will be used.
+
 @kindex --allow-shlib-undefined
 @item --allow-shlib-undefined
 Allow undefined symbols in shared objects even  when --no-undefined is
--- binutils/ld/ldmain.c.muldefs	Mon May 20 11:03:50 2002
+++ binutils/ld/ldmain.c	Tue May 21 19:39:14 2002
@@ -239,6 +239,7 @@ main (argc, argv)
   link_info.optimize = false;
   link_info.no_undefined = false;
   link_info.allow_shlib_undefined = false;
+  link_info.allow_multiple_definition = false;
   link_info.strip = strip_none;
   link_info.discard = discard_sec_merge;
   link_info.keep_memory = true;
--- binutils/ld/lexsup.c.muldefs	Mon May 20 11:03:50 2002
+++ binutils/ld/lexsup.c	Tue May 21 19:54:17 2002
@@ -126,7 +126,8 @@ int parsing_defsym = 0;
 #define OPTION_UNIQUE			(OPTION_SECTION_START + 1)
 #define OPTION_TARGET_HELP              (OPTION_UNIQUE + 1)
 #define OPTION_ALLOW_SHLIB_UNDEFINED	(OPTION_TARGET_HELP + 1)
-#define OPTION_DISCARD_NONE		(OPTION_ALLOW_SHLIB_UNDEFINED + 1)
+#define OPTION_ALLOW_MULTIPLE_DEFINITION (OPTION_ALLOW_SHLIB_UNDEFINED + 1)
+#define OPTION_DISCARD_NONE		(OPTION_ALLOW_MULTIPLE_DEFINITION + 1)
 #define OPTION_SPARE_DYNAMIC_TAGS	(OPTION_DISCARD_NONE + 1)
 #define OPTION_NO_DEFINE_COMMON		(OPTION_SPARE_DYNAMIC_TAGS + 1)
 #define OPTION_NOSTDLIB			(OPTION_NO_DEFINE_COMMON + 1)
@@ -319,6 +320,8 @@ static const struct ld_option ld_options
      '\0', NULL, N_("Allow no undefined symbols"), TWO_DASHES },
   { {"allow-shlib-undefined", no_argument, NULL, OPTION_ALLOW_SHLIB_UNDEFINED},
      '\0', NULL, N_("Allow undefined symbols in shared objects"), TWO_DASHES },
+  { {"allow-multiple-definition", no_argument, NULL, OPTION_ALLOW_MULTIPLE_DEFINITION},
+     '\0', NULL, N_("Allow multiple definitions"), TWO_DASHES },
   { {"no-warn-mismatch", no_argument, NULL, OPTION_NO_WARN_MISMATCH},
       '\0', NULL, N_("Don't warn about mismatched input files"), TWO_DASHES},
   { {"no-whole-archive", no_argument, NULL, OPTION_NO_WHOLE_ARCHIVE},
@@ -761,6 +764,9 @@ parse_args (argc, argv)
 	case OPTION_ALLOW_SHLIB_UNDEFINED:
 	  link_info.allow_shlib_undefined = true;
 	  break;
+	case OPTION_ALLOW_MULTIPLE_DEFINITION:
+	  link_info.allow_multiple_definition = true;
+	  break;
 	case OPTION_NO_WARN_MISMATCH:
 	  command_line.warn_mismatch = false;
 	  break;


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