This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Properly check __cpu_mask size [BZ #21696]
- From: Florian Weimer <fweimer at redhat dot com>
- To: "H.J. Lu" <hjl dot tools at gmail dot com>, GNU C Library <libc-alpha at sourceware dot org>
- Date: Sat, 1 Jul 2017 08:33:19 +0200
- Subject: Re: [PATCH] Properly check __cpu_mask size [BZ #21696]
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=fweimer at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7E092C19AE2A
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7E092C19AE2A
- References: <20170701011435.GA24085@gmail.com>
On 07/01/2017 03:14 AM, H.J. Lu wrote:
> posix/sched_cpucount.c assumes that size of __cpu_mask == size of long,
> which is incorrect for x32. This patch generates size of __cpu_mask and
> uses it in posix/sched_cpucount.c.
>
> Tested on i686, x86-64 and x32 with multi-arch disabled.
>
> OK for master?
>
> H.J.
> [BZ #21696]
> * posix/Makefile (gen-as-const-headers): New.
> * posix/cpu_mask.sym: New file.
> * posix/sched_cpucount.c: Include <cpu_mask.h>.
> (__sched_cpucount): Check CPU_MASK_SIZE instead of LONG_BIT.
> Replace the ul suffix with the ull suffix for 64-bit cpu_mask.
Does one of the existing test cases fail reliably due to this?
> +gen-as-const-headers = cpu_mask.sym
This is not needed if you use a regular #if and not a preprocessor
conditional.
_Static_assert (sizeof (l) == sizeof (unsigned int)
|| sizeof (l) == sizeof (unsigned long)
|| sizeof (l) == sizeof (unsigned long long),
"sizeof (__cpu_mask"));
if (sizeof (__cpu_mask) == sizeof (unsigned int))
s += __builtin_popcount (l);
else if (sizeof (__cpu_mask) == sizeof (unsigned long))
s += __builtin_popcountl (l);
else
s += __builtin_popcountll (l);
Untested, but __builtin_popcount… has fallback emulation GCC, so this
work. (And GCC 4.8 already has it.)
Thanks,
Florian