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] Sparc32 ELF TLS fixes


On Wed, Apr 13, 2005 at 06:27:48PM -0700, Richard Henderson wrote:
> On Thu, Apr 14, 2005 at 10:01:24AM +0930, Alan Modra wrote:
> > Um, after applying this I'm wondering whether we need to bfd_bwrite the
> > zero bytes?  I know lseek should put zeros in gaps, but I have a nagging
> > feeling that not all operating systems we support do this.  Anyone?
> 
> Windows.

Blech.  BeOS too, according to some old posts in the archives.

	* merge.c (sec_merge_emit): Tidy.  Check for bfd_zmalloc errors.
	Write trailing padding.

Index: bfd/merge.c
===================================================================
RCS file: /cvs/src/src/bfd/merge.c,v
retrieving revision 1.23
diff -u -p -r1.23 merge.c
--- bfd/merge.c	14 Apr 2005 00:27:20 -0000	1.23
+++ bfd/merge.c	14 Apr 2005 02:00:47 -0000
@@ -288,24 +288,27 @@ sec_merge_emit (bfd *abfd, struct sec_me
 {
   struct sec_merge_sec_info *secinfo = entry->secinfo;
   asection *sec = secinfo->sec;
-  char *pad = "";
+  char *pad = NULL;
   bfd_size_type off = 0;
   int alignment_power = sec->output_section->alignment_power;
 
   if (alignment_power)
-    pad = bfd_zmalloc ((bfd_size_type) 1 << alignment_power);
+    {
+      pad = bfd_zmalloc ((bfd_size_type) 1 << alignment_power);
+      if (pad == NULL)
+	return FALSE;
+    }
 
   for (; entry != NULL && entry->secinfo == secinfo; entry = entry->next)
     {
-      register const char *str;
-      register size_t len;
+      const char *str;
+      bfd_size_type len;
 
-      len = off & (entry->alignment - 1);
-      if (len)
+      len = -off & (entry->alignment - 1);
+      if (len != 0)
 	{
-	  len = entry->alignment - len;
 	  if (bfd_bwrite (pad, len, abfd) != len)
-	    break;
+	    goto err;
 	  off += len;
 	}
 
@@ -313,15 +316,25 @@ sec_merge_emit (bfd *abfd, struct sec_me
       len = entry->len;
 
       if (bfd_bwrite (str, len, abfd) != len)
-	break;
+	goto err;
 
       off += len;
     }
 
-  if (alignment_power)
+  /* Trailing alignment needed?  */
+  off = sec->size - off;
+  if (off != 0
+      && bfd_bwrite (pad, off, abfd) != off)
+    goto err;
+
+  if (pad != NULL)
     free (pad);
+  return TRUE;
 
-  return entry == NULL || entry->secinfo != secinfo;
+ err:
+  if (pad != NULL)
+    free (pad);
+  return FALSE;
 }
 
 /* Register a SEC_MERGE section as a candidate for merging.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


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