This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: How do disable generation of LDRD in ARM
- From: Andrew Haley <aph at redhat dot com>
- To: Roger Cruz <roger_r_cruz at yahoo dot com>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Wed, 26 Dec 2012 13:00:42 +0000
- Subject: Re: How do disable generation of LDRD in ARM
- References: <1356378834.81396.YahooMailNeo@web110302.mail.gq1.yahoo.com>
On 12/24/2012 07:53 PM, Roger Cruz wrote:
>
>
> I am compiling this piece of code from an open source project that I
> wish not to have to change. The problem is that when compiled for
> ARM, it generates an LDRD instruction, which when executed, causes a
> bus error since the address in ptr is not doubleword aligned.
Well, that's going to be tough. Your code isn't legal C, and a
compiler is not obligated to generate anything sensible for it. You
can't just convert an arbitrary byte pointer to a UINT64* and expect
working code. If you lie to the compiler it will bite you.
> I know I can change the code but I prefer to leave it intact as
> there may be many more instances of this and I don't wish to
> maintain the code.
There's no point talking about "maintenance" because the code is
already broken.
> 248 static DWORD64 dwarf2_get_u8(const unsigned char* ptr)
> 249 {
> 250 return *(const UINT64*)ptr;
> 251 }
This is the right way to do it:
static DWORD64 dwarf2_get_u8(const unsigned char* ptr)
{
UINT64 poo;
memcpy(&poo, ptr, sizeof poo);
return poo;
}
If GCC can detect that ptr is correctly aligned, it will generate an
LDRD or LDM instruction, as appropriate.
> Happy Holidays,
You too! :-)
Andrew.