This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Fwd: [libiberty] problem with unaligned pointers when using md5_process_bytes
- From: <piervit at pvittet dot com>
- To: <gcc-help at gcc dot gnu dot org>, <sje at cup dot hp dot com>
- Cc: <basile at starynkevitch dot net>
- Date: Thu, 15 Sep 2011 14:03:33 +0200
- Subject: Fwd: [libiberty] problem with unaligned pointers when using md5_process_bytes
Hello,
I request your help on the following problem:
Recently, I used the libiberty md5_process_bytes function (for some
MELT code) and got a problem with it:
I don't know why but on some systems (debian i686) I got some
unaligned pointers (only when using MELT, I could not reproduce
elsewhere, so that might come from me or from MELT). Normally, even
with unaligned pointers, this should works as the function
md5_process_bytes handles this case:
#if !_STRING_ARCH_unaligned
/* To check alignment gcc has an appropriate operator. Other
compilers don't. */
# if __GNUC__ >= 2
# define UNALIGNED_P(p) (((md5_uintptr) p) % __alignof__ (md5_uint32)
!= 0)
# else
# define UNALIGNED_P(p) (((md5_uintptr) p) % sizeof (md5_uint32) !=
0)
# endif
len --;
if (UNALIGNED_P (buffer))
while (len > 64)
{
memcpy (ctx->buffer, buffer, 64);
md5_process_block (ctx->buffer, 64, ctx);
buffer = (const char *) buffer + 64;
len -= 64;
}
else
#endif
md5_process_block (buffer, len & ~63, ctx);
buffer = (const void *) ((const char *) buffer + (len & ~63));
len &= 63;
}
However the handling looks quite strange to me, if UNALIGNED_P
(buffer) (as this is the case for me) is true, we normally travel the
while, but then, we execute a new time the line "buffer = (const void
*) ((const char *) buffer + (len & ~63));", which appear to shift the
buffer a new time (for more detail, you can have a look at my given gdb
trace).
I was able to fully compile GCC MELT branch by only adding a pair of
braces as you can see on the given diff file. I guess this is a bug in
libiberty (even if I can't understand why my pointer is not aligned).
So can you confirm (or no) that there is a bug in this function (I can
post to gcc-patches if you think it is a bug), and give me informations
about how to explain the fact that I get unaligned pointers.
Thanks a lot for your help!
Pierre Vittet
Attachment:
md5_process_bytes-gdb_trace.log
Description: Text document
Attachment:
md5_process_bytes_works_with_unaligned_ptr-178851.diff
Description: Text document