NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: kern/46557: sys/syslog.h can't be compiled on its own with -D_KERNEL



The following reply was made to PR kern/46557; it has been noted by GNATS.

From: Richard Hansen <rhansen%bbn.com@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: 
Subject: Re: kern/46557: sys/syslog.h can't be compiled on its own with
 -D_KERNEL
Date: Tue, 8 Sep 2015 16:05:58 -0400

 Apologies for forgetting about this; comments below.
 
 On 2014-07-20 19:10, David Holland wrote:
 > On Wed, Jun 06, 2012 at 08:15:00PM +0000, rhansen%bbn.com@localhost wrote:
 >> (snapshot of netbsd-6 from 2012-03-28)
 >>=20
 >> With -D_KERNEL, <sys/syslog.h> fails to compile unless <sys/cdefs.h> a=
 nd <sys/ansi.h> are included before it.
 >> >How-To-Repeat:
 >> $ cd /usr/src/sys
 >> $ echo '#include <sys/syslog.h>' >test.c
 >> $ gcc -ffreestanding -nostdinc -D_KERNEL -I. -c test.c
 >=20
 > As per longstanding tradition, you need <sys/types.h> first in kernel
 > source files.
 
 That's not a very discoverable tradition for coders unfamiliar with the
 kernel codebase.
 
 It'd be good if there was a document saying that <sys/types.h> must be
 included first in all kernel .c files (and the reasons why).  There
 should be lots of pointers to that document to make the policy easy to
 discover.
 
 Even better would be to follow C best practices and make sure each
 header #includes the other headers it depends on.  The patch I provided
 does this for sys/syslog.h.
 
 >=20
 > If you aren't compiling kernel code, don't use -D_KERNEL.
 
 I was compiling kernel code.
 
 > What are you trying to do? You might be looking for -D_KMEMUSER.
 
 If I remember correctly, I had created a new .c file to add some new
 functionality to the kernel for a project I was working on.  I got that
 compiler error when I wasn't magically imbued with the knowledge that I
 needed to #include other stuff before sys/syslog.h.  :)
 
 >=20
 > When these constraints are honored, it works for me...
 
 It also works for me when I #include other headers first, but I
 shouldn't need to do that.  Is there any reason to not apply the patch I
 provided?
 
 If you don't want to apply the patch, perhaps it would be good to add a
 comment to the top of sys/syslog.h that says that <sys/types.h> must be
 #included first (along with the justification for not #including it from
 sys/syslog.h itself).
 
 Thanks,
 Richard
 


Home | Main Index | Thread Index | Old Index