This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] powerpc: Use aligned stores in memset
- From: Steven Munroe <munroesj at linux dot vnet dot ibm dot com>
- To: Zack Weinberg <zackw at panix dot com>
- Cc: Florian Weimer <fweimer at redhat dot com>, Rajalakshmi Srinivasaraghavan <raji at linux dot vnet dot ibm dot com>, GNU C Library <libc-alpha at sourceware dot org>
- Date: Tue, 12 Sep 2017 08:57:27 -0500
- Subject: Re: [PATCH] powerpc: Use aligned stores in memset
- Authentication-results: sourceware.org; auth=none
- References: <1503033107-20047-1-git-send-email-raji@linux.vnet.ibm.com> <b8fd7e0c-8108-a808-a9a2-0c2df8961275@redhat.com> <e04fa334-d4e1-0660-ec26-024e97024761@linux.vnet.ibm.com> <e7daca03-3e86-8cdf-9d42-4e7effb02c63@redhat.com> <d7115391-1e52-5ecb-dce6-57895aaed268@redhat.com> <CAKCAbMhj5TE4sy7nqKEYAR8yWfY7Dv5HyzTZHPQQH3RKDozeZg@mail.gmail.com>
- Reply-to: munroesj at linux dot vnet dot ibm dot com
On Tue, 2017-09-12 at 08:18 -0400, Zack Weinberg wrote:
> On Tue, Sep 12, 2017 at 6:30 AM, Florian Weimer <fweimer@redhat.com> wrote:
> >
> > I could not find the manual which has the requirement that the mem*
> > functions do not use unaligned accesses. Unless they are worded in a
> > very peculiar way, right now, the GCC/glibc combination does not comply
> > with a requirement that memset & Co. can be used for device memory access.
>
> mem* are required to behave as-if they access memory as an array of
> unsigned char. Therefore it is valid to give them arbitrarily
> (un)aligned pointers. The C abstract machine doesn't specifically
> contemplate the possibility of a CPU that can do unaligned word reads
> but maybe not to all memory addresses, but I would argue that if there
> is such a CPU, then mem* are obliged to cope with it.
>
> > ...the current glibc
> > implementation accesses locations which are outside the specified object
> > boundaries.
>
> I think that's technically a defect. Nothing in the C standard
> licenses it to do that; we just get away with it because, on the
> implementations to date, it's not observable (unless you go past the
> end of a page, which you'll note there are a bunch of tests to ensure
> we don't do). If an over-read by a single byte is observable, then
> mem* is not allowed to do that.
>
Also a bit of over reaction.
As long a the library routine does no cause a visible artifact (segfault
or alignment check) aligned access before or after the requested start
address and length is an optimization.
For example accessing the source at offset 3 and length 10 with an
aligned quadword load is Ok as long I clear the leading and trailing
bytes.
But attempting to store 7 bytes within a quadword by merging bytes in a
register and storing the whole quadword would violate single copy
atomicity and is not allowed.
> zw
>