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]

[PATCH] windres: align resource data to 64 bits in coff


(Disclaimer: I already fired a bug in bugzilla [1] but got zero feedback
so trying to ping here. Is this mailing list preferred way?)


The patch changes alignment of resource data in coff output from 32 bits
to 64 bits. It should guarantee that the pointers as returned by
LoadResource()/LockResource() point to 64-bit alined block of memory in
run time.

Note the patch does that unconditionally for 32-bit and 64-bit targets,
because 64-bit processes still can also occasionally access some 32-bit
DLLs for their resources, and the padding bloat is IMO very small in
comparison with the resources themselves.

According to my inspection, Microsoft's RC (as of MSVC2010 Express) aligns
the resources to 64 bits too.


[1] https://sourceware.org/bugzilla/show_bug.cgi?id=16065

Regards,
Martin Mitas


======================

--- binutils/binutils/rescoff.c	2012-05-01 18:07:36 +0200
+++ binutils-patch/binutils/rescoff.c	2013-10-19 19:13:49 +0200
@@ -501,22 +501,22 @@
      know the various offsets we will need.  */
   coff_bin_sizes (resources, &cwi);

-  /* Force the directory strings to be 32 bit aligned.  Every other
-     structure is 32 bit aligned anyhow.  */
-  cwi.dirstrsize = (cwi.dirstrsize + 3) &~ 3;
+  /* Force the directory strings to be 64 bit aligned.  Every other
+     structure is 64 bit aligned anyhow.  */
+  cwi.dirstrsize = (cwi.dirstrsize + 7) &~ 7;

   /* Actually convert the resources to binary.  */
   coff_to_bin (resources, &cwi);

-  /* Add another 2 bytes to the directory strings if needed for
+  /* Add another few bytes to the directory strings if needed for
      alignment.  */
-  if ((cwi.dirstrs.length & 3) != 0)
+  if ((cwi.dirstrs.length & 7) != 0)
     {
+      rc_uint_type pad = 8 - (cwi.dirstrs.length & 7);
       bfd_byte *ex;

-      ex = coff_alloc (&cwi.dirstrs, 2);
-      ex[0] = 0;
-      ex[1] = 0;
+      ex = coff_alloc (&cwi.dirstrs, pad);
+      memset (ex, 0, pad);
     }

   /* Make sure that the data we built came out to the same size as we
@@ -741,10 +741,10 @@
     cwi->resources.last->next = d;

   cwi->resources.last = d;
-  cwi->resources.length += (d->length + 3) & ~3;
+  cwi->resources.length += (d->length + 7) & ~7;

   windres_put_32 (cwi->wrbfd, erd->size, d->length);

-  /* Force the next resource to have 32 bit alignment.  */
-  d->length = (d->length + 3) & ~3;
+  /* Force the next resource to have 64 bit alignment.  */
+  d->length = (d->length + 7) & ~7;
 }


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