[PATCH-bfd] i386-mingw32-ld crash on x86_64 linux

Peter O'Gorman binutils@mlists.thewrittenword.com
Sun Apr 19 03:34:00 GMT 2009


On Sat, Apr 18, 2009 at 06:47:07PM +0100, Dave Korn wrote:
>   I'm not sure that bfd_make_section_anyway_with_flags copies the name.  I
> think it stashes the value of the pointer passed in (twice in fact, once in
> the asection itself and once in the root bfd_hash_entry to which the section
> is anchored), so we do need to allocate some memory after all.  So I'll try
> re-adding that and we'll see if it helps.
> 

Yes, that seems to be it! If I add a bfd_alloc and strcpy, it works.

Attached is what I used to test (your patch + alloc & copy).

Thank you!

Peter
-- 
Peter O'Gorman
pogma@thewrittenword.com
-------------- next part --------------
Index: bfd/peXXigen.c
===================================================================
--- bfd/peXXigen.c.orig	2009-04-18 15:32:06.773969268 +0000
+++ bfd/peXXigen.c	2009-04-19 03:17:19.246352672 +0000
@@ -129,6 +129,9 @@
      they will be handled somewhat correctly in the bfd code.  */
   if (in->n_sclass == C_SECTION)
     {
+      char namebuf[SYMNMLEN + 1];
+      const char *name = namebuf;
+
       in->n_value = 0x0;
 
       /* Create synthetic empty sections as needed.  DJ */
@@ -136,33 +139,25 @@
 	{
 	  asection *sec;
 
-	  for (sec = abfd->sections; sec; sec = sec->next)
-	    {
-	      if (strcmp (sec->name, in->n_name) == 0)
-		{
-		  in->n_scnum = sec->target_index;
-		  break;
-		}
-	    }
+	  name = _bfd_coff_internal_syment_name (abfd, in, namebuf);
+	  sec = bfd_get_section_by_name (abfd, name);
+	  if (sec != NULL)
+	    in->n_scnum = sec->target_index;
 	}
 
       if (in->n_scnum == 0)
 	{
 	  int unused_section_number = 0;
 	  asection *sec;
-	  char *name;
 	  flagword flags;
-
+	  char * namecpy = bfd_alloc (abfd, (bfd_size_type) strlen (name) + 1);
+	  strcpy(namecpy, name);
 	  for (sec = abfd->sections; sec; sec = sec->next)
 	    if (unused_section_number <= sec->target_index)
 	      unused_section_number = sec->target_index + 1;
 
-	  name = bfd_alloc (abfd, (bfd_size_type) strlen (in->n_name) + 10);
-	  if (name == NULL)
-	    return;
-	  strcpy (name, in->n_name);
 	  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_DATA | SEC_LOAD;
-	  sec = bfd_make_section_anyway_with_flags (abfd, name, flags);
+	  sec = bfd_make_section_anyway_with_flags (abfd, namecpy, flags);
 
 	  sec->vma = 0;
 	  sec->lma = 0;


More information about the Binutils mailing list