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: ld -shared -pie vs. unresolved symbols


On Tue, Jul 03, 2007 at 04:07:30PM +0200, Andreas Schwab wrote:
> "H.J. Lu" <hjl@lucon.org> writes:
> 
> > On Tue, Jul 03, 2007 at 03:30:36PM +0200, Andreas Schwab wrote:
> >> There is a problem with the ia64 linker that it crashes when seeing a
> >> R_IA64_PCREL21B relocation against an unresolved symbol, because no PLT
> >> has been allocated for it.  This can be fixed with the patch below, but
> >> I'm not sure whether that combination should be allowed in the first
> >> place.
> >> 
> >
> > Is this the same as
> >
> > http://sourceware.org/bugzilla/show_bug.cgi?id=4409
> >
> > Does the Linux binutils 2.17.50.0.17 crash?
> 
> It silently generates a shared library that crashes at runtime, so I'd
> rather ban the combination of -shared with -pie regardless of how the
> crash is resolved.
> 
> Andreas.
> 

I think this patch should work. If it is confirmed, I will add it to
my PR 4409 fix with a new testcae.


H.J.
----
--- ld/ldmain.c.unresolved	2007-07-03 06:50:23.000000000 -0700
+++ ld/ldmain.c	2007-07-03 08:05:39.000000000 -0700
@@ -103,6 +103,9 @@ bfd_boolean add_needed = TRUE;
 /* TRUE if we should demangle symbol names.  */
 bfd_boolean demangling;
 
+/* How to report unresolved symbols.  */
+enum report_method how_to_report_unresolved_symbols = RM_GENERATE_ERROR;
+
 args_type command_line;
 
 ld_config_type config;
@@ -388,6 +391,28 @@ main (int argc, char **argv)
   if (! link_info.shared || link_info.pie)
     link_info.executable = TRUE;
 
+  /* When creating a shared library, the default behaviour is to
+     ignore any unresolved references.  */
+  if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
+    {
+      if (link_info.shared && !link_info.pie)
+	link_info.unresolved_syms_in_objects = RM_IGNORE;
+      else
+	/* FIXME: Should we allow emulations a chance to set this ?  */
+	link_info.unresolved_syms_in_objects
+	  = how_to_report_unresolved_symbols;
+    }
+
+  if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
+    {
+      if (link_info.shared && !link_info.pie)
+	link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
+      else
+	/* FIXME: Should we allow emulations a chance to set this ?  */
+	link_info.unresolved_syms_in_shared_libs
+	  = how_to_report_unresolved_symbols;
+    }
+
   /* Treat ld -r -s as ld -r -S -x (i.e., strip all local symbols).  I
      don't see how else this can be handled, since in this case we
      must preserve all externally visible symbols.  */
--- ld/ldmain.h.unresolved	2005-05-12 00:32:03.000000000 -0700
+++ ld/ldmain.h	2007-07-03 07:57:38.000000000 -0700
@@ -35,6 +35,7 @@ extern bfd_boolean whole_archive;
 extern bfd_boolean as_needed;
 extern bfd_boolean add_needed;
 extern bfd_boolean demangling;
+extern enum report_method how_to_report_unresolved_symbols;
 extern int g_switch_value;
 extern const char *output_filename;
 extern struct bfd_link_info link_info;
--- ld/lexsup.c.unresolved	2007-05-03 14:07:32.000000000 -0700
+++ ld/lexsup.c	2007-07-03 08:01:28.000000000 -0700
@@ -567,7 +567,6 @@ parse_args (unsigned argc, char **argv)
   struct option *longopts;
   struct option *really_longopts;
   int last_optind;
-  enum report_method how_to_report_unresolved_symbols = RM_GENERATE_ERROR;
 
   shortopts = xmalloc (OPTION_COUNT * 3 + 2);
   longopts = xmalloc (sizeof (*longopts) * (OPTION_COUNT + 1));
@@ -1111,15 +1110,7 @@ parse_args (unsigned argc, char **argv)
 	  break;
 	case OPTION_SHARED:
 	  if (config.has_shared)
-	    {
-	      link_info.shared = TRUE;
-	      /* When creating a shared library, the default
-		 behaviour is to ignore any unresolved references.  */
-	      if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
-		link_info.unresolved_syms_in_objects = RM_IGNORE;
-	      if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
-		link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
-	    }
+	    link_info.shared = TRUE;
 	  else
 	    einfo (_("%P%F: -shared not supported\n"));
 	  break;
@@ -1444,14 +1435,6 @@ parse_args (unsigned argc, char **argv)
       set_default_dirlist (default_dirlist);
       free (default_dirlist);
     }
-
-  if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
-    /* FIXME: Should we allow emulations a chance to set this ?  */
-    link_info.unresolved_syms_in_objects = how_to_report_unresolved_symbols;
-
-  if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
-    /* FIXME: Should we allow emulations a chance to set this ?  */
-    link_info.unresolved_syms_in_shared_libs = how_to_report_unresolved_symbols;
 }
 
 /* Add the (colon-separated) elements of DIRLIST_PTR to the


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