From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 95254 invoked by alias); 11 Jun 2015 21:29:34 -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 95230 invoked by uid 89); 11 Jun 2015 21:29:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-oi0-f44.google.com Received: from mail-oi0-f44.google.com (HELO mail-oi0-f44.google.com) (209.85.218.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 11 Jun 2015 21:29:32 +0000 Received: by oigz2 with SMTP id z2so10766693oig.1 for ; Thu, 11 Jun 2015 14:29:30 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.202.178.70 with SMTP id b67mr8736885oif.0.1434058170897; Thu, 11 Jun 2015 14:29:30 -0700 (PDT) Received: by 10.202.200.139 with HTTP; Thu, 11 Jun 2015 14:29:30 -0700 (PDT) In-Reply-To: References: Date: Thu, 11 Jun 2015 21:29:00 -0000 Message-ID: Subject: Re: [patch][gold] Avoid invalid unaligned write From: =?UTF-8?Q?Rafael_Esp=C3=ADndola?= To: Cary Coutant Cc: Binutils Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2015-06/txt/msg00126.txt.bz2 > 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. Yes, I started this just to get the alignment sanitizer working to test my other patch (unaligned access on X86), so this would probably be a bit to much work for that. BTW, is there an architecture where it is known that the malloc+memcpy+aligned access is faster than doing unaligned accesses? I tested X86 and power8le and both got faster with unaligned. I can try on ARM when I get back home on Monday. If all current architectures are faster with unaligned accesses, maybe we could just drop the malloc case? Cheers, Rafael