elf32-hppa shared lib support part 4

Alan Modra alan@linuxcare.com.au
Tue Sep 19 21:17:00 GMT 2000


On 19 Sep 2000, Ian Lance Taylor wrote:

> I think that routines in BFD should not call exit.  They should return
> an indication of failure.  The caller should decide what to do on
> failure.

OK.  Doing it properly, I caught a few more cases where a NULL might be
returned.

bfd/ChangeLog
	* section.c (bfd_get_unique_section_name): Return NULL if
	bfd_malloc fails.

ld/ChangeLog
	* emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Handle
	out of memory failure.

	* ldwrite.c (ldwrite): Remove unnecessary einfo arg.
	(clone_section): Handle out of memory failures.  Rename var to
	avoid c++ reserved word.

Alan Modra
-- 
Linuxcare.  Support for the Revolution.

Index: bfd/section.c
===================================================================
RCS file: /cvs/src/src/bfd/section.c,v
retrieving revision 1.22
diff -u -p -r1.22 section.c
--- section.c	2000/09/08 02:11:34	1.22
+++ section.c	2000/09/20 03:13:56
@@ -672,6 +672,8 @@ bfd_get_unique_section_name (abfd, templ
 
   len = strlen (templat);
   sname = bfd_malloc (len + 8);
+  if (sname == NULL)
+    return NULL;
   strcpy (sname, templat);
   num = 1;
   if (count != NULL)
Index: ld/ldwrite.c
===================================================================
RCS file: /cvs/src/src/ld/ldwrite.c,v
retrieving revision 1.3
diff -u -p -r1.3 ldwrite.c
--- ldwrite.c	2000/09/05 03:05:19	1.3
+++ ldwrite.c	2000/09/20 03:16:05
@@ -306,23 +306,22 @@ clone_section (abfd, s, name, count)
      const char *name;
      int *count;
 {
-  char template[6];
+  char templ[6];
   char *sname;
   asection *n;
   struct bfd_link_hash_entry *h;
 
   /* Invent a section name from the first five chars of the base
      section name and a digit suffix.  */
-  strncpy (template, name, sizeof (template) - 1);
-  template[sizeof (template) - 1] = '\0';
-  sname = bfd_get_unique_section_name (abfd, template, count);
+  strncpy (templ, name, sizeof (templ) - 1);
+  templ[sizeof (templ) - 1] = '\0';
+  if ((sname = bfd_get_unique_section_name (abfd, templ, count)) == NULL
+      || (n = bfd_make_section_anyway (abfd, sname)) == NULL
+      || (h = bfd_link_hash_lookup (link_info.hash,
+				    sname, true, true, false)) == NULL)
+    einfo (_("%F%P: clone section failed: %E\n"));
 
-  n = bfd_make_section_anyway (abfd, sname);
-
-  /* Create a symbol of the same name.  */
-
-  h = bfd_link_hash_lookup (link_info.hash,
-			    sname, true, true, false);
+  /* Set up section symbol.  */
   h->type = bfd_link_hash_defined;
   h->u.def.value = 0;
   h->u.def.section = n;
@@ -536,7 +535,7 @@ ldwrite ()
 	 out.  */
 
       if (bfd_get_error () != bfd_error_no_error)
-	einfo (_("%F%P: final link failed: %E\n"), output_bfd);
+	einfo (_("%F%P: final link failed: %E\n"));
       else
 	xexit(1);
     }
Index: ld/emultempl/elf32.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/elf32.em,v
retrieving revision 1.35
diff -u -p -r1.35 elf32.em
--- elf32.em	2000/09/07 09:09:19	1.35
+++ elf32.em	2000/09/20 03:16:21
@@ -1092,9 +1092,13 @@ gld${EMULATION_NAME}_place_orphan (file,
      loadable or allocateable characteristics.  */
   outsecname = secname;
   if (bfd_get_section_by_name (output_bfd, outsecname) != NULL)
-    outsecname = bfd_get_unique_section_name (output_bfd,
-					      outsecname,
-					      &count);
+    {
+      outsecname = bfd_get_unique_section_name (output_bfd,
+						outsecname,
+						&count);
+      if (outsecname == NULL)
+	einfo ("%F%P: place_orphan failed: %E\n");
+    }
 
   /* Start building a list of statements for this section.
      First save the current statement pointer.  */



More information about the Binutils mailing list