From patchwork Fri Aug 5 17:54:27 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Ellcey X-Patchwork-Id: 108705 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id BFA6FB6F65 for ; Sat, 6 Aug 2011 03:54:46 +1000 (EST) Received: (qmail 18173 invoked by alias); 5 Aug 2011 17:54:45 -0000 Received: (qmail 18165 invoked by uid 22791); 5 Aug 2011 17:54:43 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from g1t0028.austin.hp.com (HELO g1t0028.austin.hp.com) (15.216.28.35) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 05 Aug 2011 17:54:29 +0000 Received: from g1t0039.austin.hp.com (g1t0039.austin.hp.com [16.236.32.45]) by g1t0028.austin.hp.com (Postfix) with ESMTP id C7FDF1C3A5; Fri, 5 Aug 2011 17:54:28 +0000 (UTC) Received: from catbert.cup.hp.com (catbert.cup.hp.com [15.244.97.27]) by g1t0039.austin.hp.com (Postfix) with ESMTP id 5963734006; Fri, 5 Aug 2011 17:54:28 +0000 (UTC) Received: (from sje@localhost) by catbert.cup.hp.com (8.11.1 (PHNE_35951)/8.11.1) id p75HsR004415; Fri, 5 Aug 2011 10:54:27 -0700 (PDT) Date: Fri, 5 Aug 2011 10:54:27 -0700 (PDT) From: Steve Ellcey Message-Id: <201108051754.p75HsR004415@catbert.cup.hp.com> To: gcc-patches@gcc.gnu.org Subject: [patch, ia64] Fix unaligned accesses on IA64 from dwarf2out.c Cc: jakub@redhat.com Reply-to: sje@cup.hp.com Mime-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Some recent changes in dwarf2out.c have caused GCC to generate unaligned data traps on IA64 Linux. In looking a this I tracked it down to md5_read_ctx in libiberty, which is called by md5_finish_ctx, which in turn is called by various routines in dwarf2out.c. md5_read_ctx has a comment that the buffer must be 32 bit aligned but there is nothing in dwarf2out.c to enforce this alignment to the checksum buffer passed in to md5_finish_ctx. I looked at calls to md5_finish_ctx in fold-const.c to see why these didn't seem to have a problem and noticed that the buffers used were always declared after the md5_ctx structure and I think that 'accidentaly' got everything aligned correctly. If I do the same thing on the three buffer declarations in dwarf2out.c the misaligned messages go away and things work fine. Obviously this isn't a perfect fix, it is relying on how GCC is laying out local variables which isn't gauranteed, but it fixes the problem and I thought I would see if I could get approval for this simple fix or if people think we need a more complete fix. If we need a better fix, what should I do? It doesn't look like we use the alignment attribute in the GCC code anywhere. I could change the type of the checksum buffer from an array of unsigned char to something that has a stronger alignment requirement, but that would probably require a number of casts be added where the checksum variable is used. So, can I get someone to approve this simple, if imperfect, patch? Tested on IA64 Linux. Steve Ellcey sje@cup.hp.com 2011-08-05 Steve Ellcey * dwarf2out.c (generate_type_signature): Change decl order to force alignment. (compute_section_prefix): (optimize_macinfo_range): Ditto. Index: dwarf2out.c =================================================================== --- dwarf2out.c (revision 177422) +++ 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; + unsigned char checksum[16]; dw_die_ref decl; name = get_AT_string (die, DW_AT_name); @@ -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; + unsigned char checksum[16]; /* Compute the checksum of the DIE, then append part of it as hex digits to the name filename of the unit. */ @@ -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; + unsigned char checksum[16]; char *grp_name, *tail; const char *base; unsigned int i, count, encoded_filename_len, linebuf_len;