[PATCH] linux: mips: Fix getdents64 fallback on mips64-n32
Adhemerval Zanella
adhemerval.zanella@linaro.org
Tue Nov 17 17:37:21 GMT 2020
On 17/11/2020 10:38, Andreas Schwab wrote:
> On Nov 17 2020, Adhemerval Zanella wrote:
>
>> diff --git a/sysdeps/unix/sysv/linux/mips/mips64/getdents64.c b/sysdeps/unix/sysv/linux/mips/mips64/getdents64.c
>> index d18a5297dc..368128244e 100644
>> --- a/sysdeps/unix/sysv/linux/mips/mips64/getdents64.c
>> +++ b/sysdeps/unix/sysv/linux/mips/mips64/getdents64.c
>> @@ -90,17 +90,14 @@ __getdents64 (int fd, void *buf, size_t nbytes)
>>
>> while ((char *) kdp < (char *) skdp + r)
>> {
>> - /* This macro is used to avoid aliasing violation. */
>> -#define KDP_MEMBER(src, member) \
>> - (__typeof__((struct kernel_dirent){0}.member) *) \
>> - memcpy (&((__typeof__((struct kernel_dirent){0}.member)){0}), \
>> - ((char *)(src) + offsetof (struct kernel_dirent, member)),\
>> - sizeof ((struct kernel_dirent){0}.member))
>> -
>> /* This is a conservative approximation, since some of size_diff might
>> fit into the existing padding for alignment. */
>> - unsigned short int k_reclen = *KDP_MEMBER (kdp, d_reclen);
>> - unsigned short int new_reclen = ALIGN_UP (k_reclen + size_diff,
>> +
>> + /* Obtain the d_ino, d_off, and d_reclen from kernel filled buffer. */
>> + struct kernel_dirent kdirent;
>> + memcpy (&kdirent, kdp, sizeof (struct kernel_dirent));
>
> How good is the compiler at eliding the memcpy? What would change if
> kdp would just be void *?
Not that good, I see a large stack usage (1456 vs 1152 from my initial
version) and some more memory load/store memory instructions. The
kdp type change does not change the code generation.
I don't have a strong preference here, in any case this should be
used only as fallback on older kernels.
More information about the Libc-alpha
mailing list