diff mbox

[ia64] Fix unaligned accesses on IA64 from dwarf2out.c

Message ID 1312838651.2680.114.camel@hpsje.cup.hp.com
State New
Headers show

Commit Message

Steve Ellcey Aug. 8, 2011, 9:24 p.m. UTC
On Fri, 2011-08-05 at 11:45 -0700, Richard Henderson wrote:
> On 08/05/2011 10:54 AM, Steve Ellcey wrote:
> > -  unsigned char checksum[16];
> >    struct md5_ctx ctx;
> > +  unsigned char checksum[16];
> 
> How about
> 
>   struct md5_data
>   {
>     struct md5_ctx ctx;
>     unsigned char checksum[16];
>   };
> 
>   struct md5_data md5;
> 
> with the structure definition somewhere interesting?
> If no where else, just dwarf2out.c file scope.
> 
> 
> r~

Do you mean a union, as Andreas suggested?  What do you think of this
patch?  I used a union of the unsigned char array that we need and a
dummy variable of type md5_uint32 since md5_read_ctx is treating the
pointer as a pointer to an array of type md5_uint32 and so that is the
alignment that we need.

If this is considered the right approach, we can make a similar change
to fold-const.c which is why I put the definition of md5_resbuf in md5.h
instead of in dwarf2out.c.

Steve Ellcey
sje@cup.hp.com


2011-08-08  Steve Ellcey  <sje@cup.hp.com>

        * md5.h (md5_resbuf): New union type.


gcc/ChangeLog


2011-08-08  Steve Ellcey  <sje@cup.hp.com>

        * dwarf2out.c (generate_type_signature): Change type of checksum to
        union and change usages to access resbuf field.
        (compute_section_prefix): Ditto.
        (optimize_macinfo_range): Ditto.

Comments

Richard Henderson Aug. 8, 2011, 9:48 p.m. UTC | #1
On 08/08/2011 02:24 PM, Steve Ellcey wrote:
> Do you mean a union, as Andreas suggested?

No, I mean struct.  The union is wrong, because both data elements
are live at the same time.


r~
diff mbox

Patch

Index: include/md5.h
===================================================================
--- include/md5.h	(revision 177411)
+++ include/md5.h	(working copy)
@@ -89,6 +89,15 @@  struct md5_ctx
   char buffer[128] ATTRIBUTE_ALIGNED_ALIGNOF(md5_uint32);
 };
 
+/* Union for buffer data that must be aligned when accessed by
+   md5_read_ctx (usually called from md5_finish_ctx).  */
+
+union md5_resbuf
+{
+  md5_uint32 dummy;
+  unsigned char resbuf[16];
+};
+
 /*
  * The following three functions are build up the low level used in
  * the functions `md5_stream' and `md5_buffer'.
Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c	(revision 177411)
+++ gcc/dwarf2out.c	(working copy)
@@ -6369,8 +6369,8 @@  generate_type_signature (dw_die_ref die,
 {
   int mark;
   const char *name;
-  unsigned char checksum[16];
   struct md5_ctx ctx;
+  union md5_resbuf checksum;
   dw_die_ref decl;
 
   name = get_AT_string (die, DW_AT_name);
@@ -6390,9 +6390,9 @@  generate_type_signature (dw_die_ref die,
 
       md5_process_bytes (&die->die_tag, sizeof (die->die_tag), &ctx);
       md5_process_bytes (name, strlen (name) + 1, &ctx);
-      md5_finish_ctx (&ctx, checksum);
+      md5_finish_ctx (&ctx, checksum.resbuf);
 
-      add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
+      add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum.resbuf[8]);
     }
 
   /* Next, compute the complete type signature.  */
@@ -6408,11 +6408,11 @@  generate_type_signature (dw_die_ref die,
   /* Checksum the DIE and its children.  */
   die_checksum_ordered (die, &ctx, &mark);
   unmark_all_dies (die);
-  md5_finish_ctx (&ctx, checksum);
+  md5_finish_ctx (&ctx, checksum.resbuf);
 
   /* Store the signature in the type node and link the type DIE and the
      type node together.  */
-  memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
+  memcpy (type_node->signature, &checksum.resbuf[16 - DWARF_TYPE_SIGNATURE_SIZE],
           DWARF_TYPE_SIGNATURE_SIZE);
   die->die_id.die_type_node = type_node;
   type_node->type_die = die;
@@ -6602,8 +6602,8 @@  compute_section_prefix (dw_die_ref unit_
   char *name = XALLOCAVEC (char, strlen (base) + 64);
   char *p;
   int i, mark;
-  unsigned char checksum[16];
   struct md5_ctx ctx;
+  union md5_resbuf checksum;
 
   /* Compute the checksum of the DIE, then append part of it as hex digits to
      the name filename of the unit.  */
@@ -6612,7 +6612,7 @@  compute_section_prefix (dw_die_ref unit_
   mark = 0;
   die_checksum (unit_die, &ctx, &mark);
   unmark_all_dies (unit_die);
-  md5_finish_ctx (&ctx, checksum);
+  md5_finish_ctx (&ctx, checksum.resbuf);
 
   sprintf (name, "%s.", base);
   clean_symbol_name (name);
@@ -6620,7 +6620,7 @@  compute_section_prefix (dw_die_ref unit_
   p = name + strlen (name);
   for (i = 0; i < 4; i++)
     {
-      sprintf (p, "%.2x", checksum[i]);
+      sprintf (p, "%.2x", checksum.resbuf[i]);
       p += 2;
     }
 
@@ -20662,8 +20662,8 @@  optimize_macinfo_range (unsigned int idx
 {
   macinfo_entry *first, *second, *cur, *inc;
   char linebuf[sizeof (HOST_WIDE_INT) * 3 + 1];
-  unsigned char checksum[16];
   struct md5_ctx ctx;
+  union md5_resbuf checksum;
   char *grp_name, *tail;
   const char *base;
   unsigned int i, count, encoded_filename_len, linebuf_len;
@@ -20702,7 +20702,7 @@  optimize_macinfo_range (unsigned int idx
 	checksum_uleb128 (cur->lineno, &ctx);
 	md5_process_bytes (cur->info, strlen (cur->info) + 1, &ctx);
       }
-  md5_finish_ctx (&ctx, checksum);
+  md5_finish_ctx (&ctx, checksum.resbuf);
   count = i - idx;
 
   /* From the containing include filename (if any) pick up just
@@ -20737,7 +20737,7 @@  optimize_macinfo_range (unsigned int idx
   tail += linebuf_len;
   *tail++ = '.';
   for (i = 0; i < 16; i++)
-    sprintf (tail + i * 2, "%02x", checksum[i] & 0xff);
+    sprintf (tail + i * 2, "%02x", checksum.resbuf[i] & 0xff);
 
   /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
      in the empty vector entry before the first define/undef.  */