This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: Linux getdents.c is not aliasing safe
- From: Daniel Jacobowitz <dan at debian dot org>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: Wolfram Gloger <Wolfram dot Gloger at dent dot med dot uni-muenchen dot de>,geoffk at geoffk dot org, libc-alpha at sources dot redhat dot com,debian-glibc at lists dot debian dot org
- Date: Sat, 2 Nov 2002 18:36:32 -0500
- Subject: Re: Linux getdents.c is not aliasing safe
- References: <20021029215802.GA9479@nevyn.them.org> <je3cqo27ua.fsf@sykes.suse.de> <20021030010405.GA16098@nevyn.them.org> <jmd6pspw1g.fsf@desire.geoffk.org> <200210300952.KAA77812@max.zk-i.med.uni-muenchen.de> <20021030120312.V3451@sunsite.ms.mff.cuni.cz>
On Wed, Oct 30, 2002 at 12:03:12PM +0100, Jakub Jelinek wrote:
> On Wed, Oct 30, 2002 at 10:52:30AM +0100, Wolfram Gloger wrote:
> > > > [That is: two pointers to a buffer, of different types; walk through
> > > > the buffer, reading one object of the first type and writing out an
> > > > object of the second lesser-or-equal sized type.]
> > >
> > > No, there's no standard C way to do that. An object can only have one
> > > type at a time. You have to use another buffer as an intermediate.
> >
> > AFAICS, the code already has intermediate buffers:
> >
> > dp = (DIRENT_TYPE *)buf;
> > kdp = (struct kernel_dirent64 *) kbuf;
> >
> > uint64_t d_ino = kdp->d_ino;
> > int64_t d_off = kdp->d_off;
> > unsigned char d_type = kdp->d_type;
> >
> > DIRENT_SET_DP_INO (dp, d_ino);
> > dp->d_off = d_off;
> >
> > So, why not just use a char* ptr to write out the data using memcpy(),
> > do away with dp and e.g. change the last line into:
> >
> > memcpy(buf + offsetof(DIRENT_TYPE, d_off), &d_off, sizeof d_off);
> >
> > (the DIRENT_SET_DP_INO line of course needs to be handled a little
> > differently). Since char* can alias anything, that would remain
> > portable C.
>
> But that intermediate buffer is in registers (on sane arches), while using
> memcpy would mean at least with current compilers memory.
> glibc requires gcc (even 3.2+) to compile anyway, so IMHO just using the
> union as drow posted seems best to me.
If my patch is OK, could someone commit it, please?
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer