From patchwork Sat Jul 1 01:14:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 21379 Received: (qmail 60793 invoked by alias); 1 Jul 2017 01:14:41 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 60218 invoked by uid 89); 1 Jul 2017 01:14:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-pf0-f170.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=zfgrD7LLGbkjVt5M7EIiE7O8YFBrVfEDx03H0M/ne+A=; b=J+ieVIQge1P16R5zmm8y6Gx1rZsI6SDrnslmQKcFDB+J7iN5Tj2ckSPD4jljZuuBfd fd43FQoML6CmGMnLgOt9Jabk2rcImWqqmJAUJaDhz+dhbGuJ6rGl+DjnOUcdEaf9Pf1V cLCedkjTX93C8OdYwpvv367fUJPEBKYYQch9IGwBPKhN/ildL4fI0j7O6f55LmAdwBJJ Viz68i54JlRRMnbjk11a+uaAz91iSbduzi8HFhxIxf5PvsMPUzaddu5TctDLstUQ7mGp NcMN+OyiNBElm6kpTDDCsaZvD7Gg0wTOTH/mOrluLnn55ciDOgynHWihFdXOUHVTKwft pcVg== X-Gm-Message-State: AKS2vOxlHg8l+mKYg712NvS/TRrrvzhDR35l8pxH3U0TY9WniYJVCTOp NTSb+knTh+tjwvOE X-Received: by 10.98.89.13 with SMTP id n13mr25737624pfb.184.1498871677094; Fri, 30 Jun 2017 18:14:37 -0700 (PDT) Date: Fri, 30 Jun 2017 18:14:35 -0700 From: "H.J. Lu" To: GNU C Library Subject: [PATCH] Properly check __cpu_mask size [BZ #21696] Message-ID: <20170701011435.GA24085@gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.8.0 (2017-02-23) 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 . (__sched_cpucount): Check CPU_MASK_SIZE instead of LONG_BIT. Replace the ul suffix with the ull suffix for 64-bit cpu_mask. --- posix/Makefile | 2 ++ posix/cpu_mask.sym | 5 +++++ posix/sched_cpucount.c | 15 ++++++++------- 3 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 posix/cpu_mask.sym diff --git a/posix/Makefile b/posix/Makefile index 1c328b8..963cba8 100644 --- a/posix/Makefile +++ b/posix/Makefile @@ -144,6 +144,8 @@ tests-special += $(objpfx)bug-regex2-mem.out $(objpfx)bug-regex14-mem.out \ xtests-special += $(objpfx)bug-ga2-mem.out endif +gen-as-const-headers = cpu_mask.sym + include ../Rules ifeq ($(run-built-tests),yes) diff --git a/posix/cpu_mask.sym b/posix/cpu_mask.sym new file mode 100644 index 0000000..33519e6 --- /dev/null +++ b/posix/cpu_mask.sym @@ -0,0 +1,5 @@ +#include +#include + +-- +CPU_MASK_SIZE sizeof (__cpu_mask) diff --git a/posix/sched_cpucount.c b/posix/sched_cpucount.c index eaddf61..e3622b8 100644 --- a/posix/sched_cpucount.c +++ b/posix/sched_cpucount.c @@ -17,6 +17,7 @@ #include #include +#include int @@ -36,13 +37,13 @@ __sched_cpucount (size_t setsize, const cpu_set_t *setp) if (l == 0) continue; -# if LONG_BIT > 32 - l = (l & 0x5555555555555555ul) + ((l >> 1) & 0x5555555555555555ul); - l = (l & 0x3333333333333333ul) + ((l >> 2) & 0x3333333333333333ul); - l = (l & 0x0f0f0f0f0f0f0f0ful) + ((l >> 4) & 0x0f0f0f0f0f0f0f0ful); - l = (l & 0x00ff00ff00ff00fful) + ((l >> 8) & 0x00ff00ff00ff00fful); - l = (l & 0x0000ffff0000fffful) + ((l >> 16) & 0x0000ffff0000fffful); - l = (l & 0x00000000fffffffful) + ((l >> 32) & 0x00000000fffffffful); +# if CPU_MASK_SIZE > 4 + l = (l & 0x5555555555555555ull) + ((l >> 1) & 0x5555555555555555ull); + l = (l & 0x3333333333333333ull) + ((l >> 2) & 0x3333333333333333ull); + l = (l & 0x0f0f0f0f0f0f0f0full) + ((l >> 4) & 0x0f0f0f0f0f0f0f0full); + l = (l & 0x00ff00ff00ff00ffull) + ((l >> 8) & 0x00ff00ff00ff00ffull); + l = (l & 0x0000ffff0000ffffull) + ((l >> 16) & 0x0000ffff0000ffffull); + l = (l & 0x00000000ffffffffull) + ((l >> 32) & 0x00000000ffffffffull); # else l = (l & 0x55555555ul) + ((l >> 1) & 0x55555555ul); l = (l & 0x33333333ul) + ((l >> 2) & 0x33333333ul);