NetBSD Problem Report #49696

From dholland@macaran.localdomain  Thu Feb 26 03:51:05 2015
Return-Path: <dholland@macaran.localdomain>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id A9D39A5B2E
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 26 Feb 2015 03:51:05 +0000 (UTC)
Message-Id: <20150226035105.03AE06E262@macaran.localdomain>
Date: Wed, 25 Feb 2015 22:51:04 -0500 (EST)
From: dholland@eecs.harvard.edu
Reply-To: dholland@eecs.harvard.edu
To: gnats-bugs@NetBSD.org
Subject: circular includes in sys/
X-Send-Pr-Version: 3.95

>Number:         49696
>Category:       lib
>Synopsis:       circular includes in sys/
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Feb 26 03:55:00 +0000 2015
>Last-Modified:  Thu Feb 26 04:25:00 +0000 2015
>Originator:     David A. Holland
>Release:        NetBSD 7.99.4 (20150117)
>Organization:
>Environment:
System: NetBSD macaran 7.99.1 NetBSD 7.99.1 (MACARAN) #22: Fri Oct 24 18:32:54 EDT 2014 dholland@macaran:/usr/src/sys/arch/amd64/compile/MACARAN amd64
Architecture: x86_64
Machine: amd64
>Description:

The following include cycle exists:

sys/types.h -> machine/endian.h -> sys/endian.h -> 
   machine/bswap.h -> sys/bswap.h -> sys/types.h

(as well as a shorter one that doesn't involve bswap.h)

It all works, at the moment, but it's ugly and fragile.

>How-To-Repeat:

grep

>Fix:
torches and pitchforks

>Audit-Trail:
From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: lib/49696: circular includes in sys/
Date: Thu, 26 Feb 2015 04:16:36 +0000

 On Thu, Feb 26, 2015 at 03:55:00AM +0000, dholland@eecs.harvard.edu wrote:
  > The following include cycle exists:
  > 
  > sys/types.h -> machine/endian.h -> sys/endian.h -> 
  >    machine/bswap.h -> sys/bswap.h -> sys/types.h
  > 
  > (as well as a shorter one that doesn't involve bswap.h)
  > 
  > It all works, at the moment, but it's ugly and fragile.

 Actually, it doesn't:

 macaran% cat t.c
 #include <machine/bswap.h>
 macaran% gcc -c t.c
 In file included from /usr/include/amd64/bswap.h:13:0,
                  from t.c:1:
 /usr/include/sys/bswap.h:20:10: error: conflicting types for 'bswap16'
  uint16_t bswap16(uint16_t) __RENAME(__bswap16) __constfunc;
           ^
 In file included from /usr/include/amd64/endian.h:3:0,
                  from /usr/include/sys/types.h:98,
                  from /usr/include/amd64/byte_swap.h:42,
                  from /usr/include/amd64/bswap.h:10,
                  from t.c:1:
 /usr/include/sys/endian.h:203:1: note: previous implicit declaration of 'bswap16' was here
  __GEN_ENDIAN_ENC(16, be)
  ^
 In file included from /usr/include/amd64/bswap.h:13:0,
                  from t.c:1:
 /usr/include/sys/bswap.h:21:10: error: conflicting types for 'bswap32'
  uint32_t bswap32(uint32_t) __RENAME(__bswap32) __constfunc;
           ^
 In file included from /usr/include/amd64/endian.h:3:0,
                  from /usr/include/sys/types.h:98,
                  from /usr/include/amd64/byte_swap.h:42,
                  from /usr/include/amd64/bswap.h:10,
                  from t.c:1:
 /usr/include/sys/endian.h:204:1: note: previous implicit declaration of 'bswap32' was here
  __GEN_ENDIAN_ENC(32, be)
  ^
 In file included from /usr/include/amd64/bswap.h:13:0,
                  from t.c:1:
 /usr/include/sys/bswap.h:23:10: error: conflicting types for 'bswap64'
  uint64_t bswap64(uint64_t) __constfunc;
           ^
 In file included from /usr/include/amd64/endian.h:3:0,
                  from /usr/include/sys/types.h:98,
                  from /usr/include/amd64/byte_swap.h:42,
                  from /usr/include/amd64/bswap.h:10,
                  from t.c:1:
 /usr/include/sys/endian.h:205:1: note: previous implicit declaration of 'bswap64' was here
  __GEN_ENDIAN_ENC(64, be)
  ^
 Exit 1
 macaran% 

 -- 
 David A. Holland
 dholland@netbsd.org

From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: lib/49696: circular includes in sys/
Date: Thu, 26 Feb 2015 04:23:59 +0000

 On Thu, Feb 26, 2015 at 04:20:00AM +0000, David Holland wrote:
  > Actually, it doesn't:
  > [...]

 A workaround for this is to add #include <sys/types.h> *outside* the
 include guard in machine/bswap.h and sys/bswap.h. However, this if
 anything makes the circularity worse. This should be fixed properly...
 sometime... not sure it's entirely feasible without the big header
 reorg that needs rename support in version control.

 -- 
 David A. Holland
 dholland@netbsd.org

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.