From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 130765 invoked by alias); 11 Jun 2015 17:07:11 -0000 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org Received: (qmail 130755 invoked by uid 89); 11 Jun 2015 17:07:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-yh0-f67.google.com Received: from mail-yh0-f67.google.com (HELO mail-yh0-f67.google.com) (209.85.213.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 11 Jun 2015 17:07:09 +0000 Received: by yhl29 with SMTP id 29so1757965yhl.0 for ; Thu, 11 Jun 2015 10:07:07 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.13.193.198 with SMTP id c189mr12905519ywd.122.1434042427722; Thu, 11 Jun 2015 10:07:07 -0700 (PDT) Received: by 10.129.119.9 with HTTP; Thu, 11 Jun 2015 10:07:07 -0700 (PDT) In-Reply-To: References: Date: Thu, 11 Jun 2015 17:07:00 -0000 Message-ID: Subject: Re: [patch][gold] Avoid invalid unaligned write From: Cary Coutant To: =?UTF-8?Q?Rafael_Esp=C3=ADndola?= Cc: Binutils Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2015-06/txt/msg00122.txt.bz2 > 2015-06-07 Rafael =C3=81vila de Esp=C3=ADndola > > * elfcpp_swap.h (Swap::writeval): Avoid unaligned access. We already have Swap and Swap_unaligned templates. Rather than pessimize the Swap template, we should be using Swap_unaligned wherever the target of the relocation might be unaligned. The arm, powerpc, and sparc targets already do this. The i386 and x86_64 targets don't, but we haven't got into trouble only because (presumably) no one has ever tried to build a cross-linker for those targets on a platform where aligned accesses are required. I'd prefer to see _unaligned variants of all necessary functions in Relocate_functions, and have i386 and x86_64 targets use those. The mips target may also need this. Before doing that, however, the non-byte-swapping versions of the Swap_unaligned class templates need to be rewritten to use memcpy so that we don't generate horrible code when hosted on a platform that supports unaligned access. I'm not sure yet whether the byte-swapping versions should remain as written (byte-at-a-time, taking care of unaligned loads and byte swapping together), or whether they should use memcpy and Convert::convert_host. (The latter would be far simpler.) As you've pointed out, unaligned accesses on x86 aren't hurting us, so I don't see this as a high priority. It's just something to take care of before someone tries to build a cross linker for x86 hosted on a platform that doesn't tolerate unaligned access. -cary