This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Properly check __cpu_mask size [BZ #21696]


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]