diff mbox

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

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

Commit Message

Steve Ellcey Aug. 10, 2011, 4:52 p.m. UTC
On Wed, 2011-08-10 at 11:19 +0200, Richard Guenther wrote:
> On Wed, Aug 10, 2011 at 10:48 AM, Pedro Alves <pedro@codesourcery.com> wrote:
> >
> > which makes me wonder if the right fix isn't to change
> > libiberty internally to not rely on the alignment.
> 
> I think that would be the best fix.  It hardly can be a performance
> critical part - libiberty could use a local aligned buffer for
> compute and do a copy on return.
> 
> Richard.

I like this idea.  How about this patch.  I am still testing it but it
should work.

Steve Ellcey
sje@cup.hp.com


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

        * md5.c (md5_read_ctx): Handle mis-aligned resbuf pointer.

Comments

Richard Henderson Aug. 10, 2011, 4:56 p.m. UTC | #1
On 08/10/2011 09:52 AM, Steve Ellcey wrote:
>         * md5.c (md5_read_ctx): Handle mis-aligned resbuf pointer.

Ok.


r~
diff mbox

Patch

Index: md5.c
===================================================================
--- md5.c	(revision 177411)
+++ md5.c	(working copy)
@@ -76,15 +76,19 @@  md5_init_ctx (struct md5_ctx *ctx)
 /* Put result from CTX in first 16 bytes following RESBUF.  The result
    must be in little endian byte order.
 
-   IMPORTANT: On some systems it is required that RESBUF is correctly
-   aligned for a 32 bits value.  */
+   IMPORTANT: RESBUF may not be aligned as strongly as MD5_UNIT32 so we
+   put things in a local (aligned) buffer first, then memcpy into RESBUF.  */
 void *
 md5_read_ctx (const struct md5_ctx *ctx, void *resbuf)
 {
-  ((md5_uint32 *) resbuf)[0] = SWAP (ctx->A);
-  ((md5_uint32 *) resbuf)[1] = SWAP (ctx->B);
-  ((md5_uint32 *) resbuf)[2] = SWAP (ctx->C);
-  ((md5_uint32 *) resbuf)[3] = SWAP (ctx->D);
+  md5_unit32 buffer[4];
+
+  buffer[0] = SWAP (ctx->A);
+  buffer[1] = SWAP (ctx->B);
+  buffer[2] = SWAP (ctx->C);
+  buffer[3] = SWAP (ctx->D);
+
+  memcpy (resbuf, buffer, 16);
 
   return resbuf;
 }