NetBSD Problem Report #53081

From martin@aprisoft.de  Thu Mar  8 09:29:06 2018
Return-Path: <martin@aprisoft.de>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 50EE27A0AD
	for <gnats-bugs@gnats.NetBSD.org>; Thu,  8 Mar 2018 09:29:06 +0000 (UTC)
Message-Id: <20180308092857.3B54A5CC770@emmas.aprisoft.de>
Date: Thu,  8 Mar 2018 10:28:57 +0100 (CET)
From: martin@NetBSD.org
Reply-To: martin@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: __BITMAP_* bitops macros broken with gcc 6.4
X-Send-Pr-Version: 3.95

>Number:         53081
>Category:       toolchain
>Synopsis:       __BITMAP_* bitops macros broken with gcc 6.4
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    toolchain-manager
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Mar 08 09:30:00 +0000 2018
>Closed-Date:    Sat Apr 21 12:29:35 +0000 2018
>Last-Modified:  Sat Apr 21 12:29:35 +0000 2018
>Originator:     Martin Husemann
>Release:        NetBSD 8.99.12
>Organization:
The NetBSD Foundation, Inc.
>Environment:
System: NetBSD whoever-brings-the-night.aprisoft.de 8.99.12 NetBSD 8.99.12 (WHOEVER) #212: Mon Mar 5 08:13:25 CET 2018 martin@seven-days-to-the-wolves.aprisoft.de:/work/src/sys/arch/sparc64/compile/WHOEVER sparc64
Architecture: sparc64
Machine: sparc64
>Description:

The example from bitmap(3) is broken when compiled with gcc 6.4. This
also breaks the ASID storage of the common pmap, and makes for example
the evbmips64-eb ERLITE unbootable.

>How-To-Repeat:

Test program:

#include <stdio.h>
#include <sys/types.h>
#include <sys/bitops.h>

int
main(void)
{
	__BITMAP_TYPE(,unsigned long, 256) bitmap;

	// clear the whole bitmap
	__BITMAP_ZERO(&bitmap);

	// set a single bit
	__BITMAP_SET(0, &bitmap);

	// show all bits that are set
	for (size_t i = 0; i < 256; i++) {
		if (!__BITMAP_ISSET(i, &bitmap))
			continue;
		printf("bit %zu is set\n", i);
	}

	// dump whole bitmap for examination
	for (size_t i = 0; i < __arraycount(bitmap._b); i++)
		printf("%zu: %016lx\n", i, bitmap._b[i]);

	return 0;
}

Compile with -Wall -O2 and run:

bit 0 is set
bit 32 is set
0: 0000000000000001
1: 0000000000000000
2: 0000000000000000
3: 0000000000000000

As you can see, the bitmap state itself is correct, but the __BITMAP_ISSET()
macros gives a false postive for bit 32.

This happens at least on mips64eb and sparc64.

>Fix:
n/a

>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->pending-pullups
State-Changed-By: mrg@NetBSD.org
State-Changed-When: Thu, 08 Mar 2018 10:07:46 +0000
State-Changed-Why:
i commited a fix for this.  we should consider pullups in case pepole
end up using GCC 6 with netbsd 8 and this, and maybe -7 too.


From: "matthew green" <mrg@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/53081 CVS commit: src/sys/sys
Date: Thu, 8 Mar 2018 10:06:18 +0000

 Module Name:	src
 Committed By:	mrg
 Date:		Thu Mar  8 10:06:18 UTC 2018

 Modified Files:
 	src/sys/sys: bitops.h

 Log Message:
 use 1ul for a left shift that may be greater than int sized.
 noticed by martin.

 fixes PR#53081.


 To generate a diff of this commit:
 cvs rdiff -u -r1.12 -r1.13 src/sys/sys/bitops.h

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@NetBSD.org, toolchain-manager@netbsd.org, 
	gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Cc: 
Subject: Re: toolchain/53081: __BITMAP_* bitops macros broken with gcc 6.4
Date: Thu, 8 Mar 2018 15:31:55 -0500

 On Mar 8,  9:30am, martin@NetBSD.org (martin@NetBSD.org) wrote:
 -- Subject: toolchain/53081: __BITMAP_* bitops macros broken with gcc 6.4

 The fix to change the 1 to 1ul is incomplete:

 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/bitops.h>

 int
 main(void)
 {
         __BITMAP_TYPE(,unsigned long long, 256) bitmap;

         // clear the whole bitmap
         __BITMAP_ZERO(&bitmap);

         // set a single bit
         __BITMAP_SET(0, &bitmap);
         __BITMAP_SET(63, &bitmap);

         // show all bits that are set
         for (size_t i = 0; i < 256; i++) {
                 if (!__BITMAP_ISSET(i, &bitmap))
                         continue;
                 printf("bit %zu is set\n", i);
         }

         // dump whole bitmap for examination
         for (size_t i = 0; i < __arraycount(bitmap._b); i++)
                 printf("%zu: %016llx\n", i, bitmap._b[i]);

         return 0;
 }

 [3:02pm] 1536>cc -m32 bm.c
 [3:02pm] 1537>./a.out 
 bit 0 is set
 bit 32 is set
 0: 0000000000000001
 1: 0000000000000000
 2: 0000000000000000
 3: 0000000000000000

 christos

From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/53081 CVS commit: src/sys/sys
Date: Thu, 8 Mar 2018 15:32:33 -0500

 Module Name:	src
 Committed By:	christos
 Date:		Thu Mar  8 20:32:33 UTC 2018

 Modified Files:
 	src/sys/sys: bitops.h

 Log Message:
 PR/53081: Fix size of the shift to depend on the type of the bitmap so that
 we get the correct width.


 To generate a diff of this commit:
 cvs rdiff -u -r1.13 -r1.14 src/sys/sys/bitops.h

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/53081 CVS commit: [netbsd-8] src/sys/sys
Date: Tue, 13 Mar 2018 11:42:59 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Tue Mar 13 11:42:59 UTC 2018

 Modified Files:
 	src/sys/sys [netbsd-8]: bitops.h

 Log Message:
 Pull up following revision(s) (requested by mrg in ticket #621):
 	sys/sys/bitops.h: revision 1.13
 	sys/sys/bitops.h: revision 1.14
 use 1ul for a left shift that may be greater than int sized.
 noticed by martin.
 fixes PR#53081.

 PR/53081: Fix size of the shift to depend on the type of the bitmap so that
 we get the correct width.


 To generate a diff of this commit:
 cvs rdiff -u -r1.12 -r1.12.8.1 src/sys/sys/bitops.h

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/53081 CVS commit: [netbsd-7] src/sys/sys
Date: Wed, 21 Mar 2018 11:08:05 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Wed Mar 21 11:08:05 UTC 2018

 Modified Files:
 	src/sys/sys [netbsd-7]: bitops.h

 Log Message:
 Pull up following revision(s) (requested by mrg in ticket #1582):
 	sys/sys/bitops.h: revision 1.12
 	sys/sys/bitops.h: revision 1.13
 	sys/sys/bitops.h: revision 1.14
 fix sign issues

 use 1ul for a left shift that may be greater than int sized.
 noticed by martin.
 fixes PR#53081.

 PR/53081: Fix size of the shift to depend on the type of the bitmap so that
 we get the correct width.


 To generate a diff of this commit:
 cvs rdiff -u -r1.11 -r1.11.12.1 src/sys/sys/bitops.h

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/53081 CVS commit: [netbsd-7-1] src/sys/sys
Date: Wed, 21 Mar 2018 11:09:27 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Wed Mar 21 11:09:27 UTC 2018

 Modified Files:
 	src/sys/sys [netbsd-7-1]: bitops.h

 Log Message:
 Pull up following revision(s) (requested by mrg in ticket #1582):
 	sys/sys/bitops.h: revision 1.12
 	sys/sys/bitops.h: revision 1.13
 	sys/sys/bitops.h: revision 1.14
 fix sign issues

 use 1ul for a left shift that may be greater than int sized.
 noticed by martin.
 fixes PR#53081.

 PR/53081: Fix size of the shift to depend on the type of the bitmap so that
 we get the correct width.


 To generate a diff of this commit:
 cvs rdiff -u -r1.11 -r1.11.22.1 src/sys/sys/bitops.h

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/53081 CVS commit: [netbsd-7-0] src/sys/sys
Date: Wed, 21 Mar 2018 11:10:57 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Wed Mar 21 11:10:57 UTC 2018

 Modified Files:
 	src/sys/sys [netbsd-7-0]: bitops.h

 Log Message:
 Pull up following revision(s) (requested by mrg in ticket #1582):
 	sys/sys/bitops.h: revision 1.12
 	sys/sys/bitops.h: revision 1.13
 	sys/sys/bitops.h: revision 1.14
 fix sign issues

 use 1ul for a left shift that may be greater than int sized.
 noticed by martin.
 fixes PR#53081.

 PR/53081: Fix size of the shift to depend on the type of the bitmap so that
 we get the correct width.


 To generate a diff of this commit:
 cvs rdiff -u -r1.11 -r1.11.16.1 src/sys/sys/bitops.h

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: pending-pullups->closed
State-Changed-By: martin@NetBSD.org
State-Changed-When: Sat, 21 Apr 2018 12:29:35 +0000
State-Changed-Why:
All pullups done


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.