This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v2 1/5] mips: Do not malloc on getdents64 fallback
- From: Florian Weimer <fweimer at redhat dot com>
- To: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- Cc: libc-alpha at sourceware dot org
- Date: Mon, 07 Oct 2019 20:29:37 +0200
- Subject: Re: [PATCH v2 1/5] mips: Do not malloc on getdents64 fallback
- References: <20190731183136.21545-1-adhemerval.zanella@linaro.org> <87k1av6kuh.fsf@oldenburg2.str.redhat.com> <49dc9440-d9a5-112f-9ec6-b62f4c0bcdf2@linaro.org> <87zhjmvoow.fsf@oldenburg2.str.redhat.com> <30395e41-d6c9-4fce-ca7a-933d55900fc7@linaro.org>
* Adhemerval Zanella:
> +#define copy_field(dst, src) \
> + ({ \
> + typeof (src) _src; \
> + memcpy (&_src, &(src), sizeof (src)); \
> + typeof (dst) _dst = _src; \
> + memcpy (&(dst), &_dst, sizeof (dst)); \
> + })
> +
> + copy_field (dp->d_ino, kdp->d_ino);
> + copy_field (dp->d_off, kdp->d_off);
> + copy_field (last_offset, kdp->d_off);
> + copy_field (dp->d_reclen, new_reclen);
> dp->d_type = *((char *) kdp + kdp->d_reclen - 1);
I believe this still asserts the dynamic type of *dp, which is not what
we want. The truly portable way probably involves using offsetof and
not -> dereferencing. 8-(
Considering that, I would probably drop copy_field, compile the file
with -fno-strict-aliasing, and add a comment to the (now plain
assignments) that this is okay due to -fno-strict-aliasing.
But this is really up to you, I do not want to discuss this patch to
death.
Thanks,
Florian