This is the mail archive of the
mailing list for the binutils project.
Re: [patch][gold] Avoid invalid unaligned write
- From: Rafael EspÃndola <rafael dot espindola at gmail dot com>
- To: Cary Coutant <ccoutant at gmail dot com>
- Cc: Binutils <binutils at sourceware dot org>
- Date: Thu, 11 Jun 2015 17:29:30 -0400
- Subject: Re: [patch][gold] Avoid invalid unaligned write
- Authentication-results: sourceware.org; auth=none
- References: <CAG3jReLrv-31r3M-LseE9HMo1AN9jJOcZH1HSZhuQAsSsiUjrA at mail dot gmail dot com> <CAJimCsHuUD2k_MJF+dbdPp9R8F2F-2sXV1+A1Z-9AKGhnzJXZw at mail dot gmail dot com>
> 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
> 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?