This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: memcpy to an unaligned address
- From: Carl Whitwell <carl dot whitwell at gmail dot com>
- To: Shaun Jackman <sjackman at gmail dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Fri, 5 Aug 2005 09:40:56 +0100
- Subject: Re: memcpy to an unaligned address
- References: <345be691050804025955c0b4ab@mail.gmail.com> <7f45d93905080408053411888b@mail.gmail.com>
- Reply-to: Carl Whitwell <carl dot whitwell at gmail dot com>
On 8/4/05, Shaun Jackman <sjackman@gmail.com> wrote:
> Are you using an x86 host and an arm target?
>
Actually no, my major concern at the time was the large quantity of
legacy code with packed structures that we have on an embedded linux
x86 system. I was just testing that we didn't have an issue there with
the structure access.
> Did it produce an open code memcpy, and was it correct?
>
I couldn't see any problems with the generated code - with no
optimisation memcpy was called as a normal function, under
optimisation the memcpy was replaced with the same code as the s->b =
n line produced.
> Interesting. Can you post an assembler snippet of this?
>
I created an executable and made it report the alignment -
I used your test case and declared a variable of the packed structure then did
printf("Address of a = %p\n", &test.a);
printf("Address of b = %p\n", &test.b);
with interesting differences between gcc 3 and 4.
On further consideration i'd also add
printf("Address of test = %p\n", &test);
just to see if it showed up anything interesting.
If I had more time I'd investigate where gcc 4 is putting this
variable in memory, I have a small concern that it may be leaving
padding bytes on the stack to align the structure, I'm not sure it's a
big issue though (it definitely isn't to me anyway since we're using
2.95.3 and the unmentionable 2.96 ;o) ).
Not sure any of this helps with the memcpy alignment issue though.