This is the mail archive of the
mailing list for the binutils project.
Re: [patch][gold] Avoid invalid unaligned write
- From: Cary Coutant <ccoutant at gmail dot com>
- To: Rafael EspÃndola <rafael dot espindola at gmail dot com>
- Cc: Binutils <binutils at sourceware dot org>
- Date: Thu, 11 Jun 2015 10:07:07 -0700
- Subject: Re: [patch][gold] Avoid invalid unaligned write
- Authentication-results: sourceware.org; auth=none
- References: <CAG3jReLrv-31r3M-LseE9HMo1AN9jJOcZH1HSZhuQAsSsiUjrA at mail dot gmail dot com>
> 2015-06-07 Rafael Ãvila de EspÃndola <email@example.com>
> * 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
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.