Re: System headers with clang?

From: Larry Rosenman <ler_at_lerctr.org>
Date: Tue, 11 Oct 2011 08:31:18 -0500 (CDT)
On Tue, 11 Oct 2011, Dimitry Andric wrote:

> On 2011-10-09 19:32, Larry Rosenman wrote:
>> I had gotten a PR about sysutils/lsof not compiling with clang.  I had
>> Vic Abell check it out, and the problem is NOT with lsof per se, but
>> with the system headers.
>> 
>> Is there a project afoot to update the system headers to make them clang
>> compilable?
>
> The problem isn't that clang can't compile the system headers, but
> normally these don't get included from userspace.  And they certainly
> won't work as expected when you define _KERNEL in userspace, as the lsof
> port foolishly does.  It probably can't be avoided in such a tool, though.
>
>
> ...
>> In file included from ckkv.c:43:
>> In file included from ./../lsof.h:195:
>> In file included from ./../dlsof.h:190:
>> In file included from /usr/src/sys/ufs/ufs/ufsmount.h:36:
>> /usr/src/sys/sys/buf.h:388:2: warning: implicit declaration of function 
>> 'KASSERT' is invalid in C99
>> [-Wimplicit-function-declaration]
>>           KASSERT(bp->b_bufobj != NULL, ("bwrite: no bufobj bp=%p", bp));
>>           ^
>> /usr/src/sys/sys/buf.h:388:33: warning: expression result unused 
>> [-Wunused-value]
>>           KASSERT(bp->b_bufobj != NULL, ("bwrite: no bufobj bp=%p", bp));
>>                                          ^~~~~~~~~~~~~~~~~~~~~~~~~
>
> These are more or less harmless warnings, as long as nobody calls a
> function that uses KASSERT.  They occur because lsof's headers don't
> include <sys/param.h> and <sys/systm.h> before <sys/ufs/ufs/ufsmount.h>.
>
> ...
>> In file included from ckkv.c:43:
>> In file included from ./../lsof.h:195:
>> In file included from ./../dlsof.h:432:
>> In file included from /usr/include/string.h:45:
>> /usr/include/strings.h:47:6: error: conflicting types for '__builtin_ffs'
>> int      ffs(int) __pure2;
>>            ^
>> /usr/include/machine/cpufunc.h:140:24: note: expanded from:
>> #define        ffs(x)  __builtin_ffs(x)
>>                          ^
>> /usr/include/strings.h:47:6: note: '__builtin_ffs' is a builtin with type 
>> 'int (unsigned int)'
>
> This is because the amd64 system headers redefine ffs to __builtin_ffs,
> after which it conflicts with the declaration in /usr/include/strings.h.
> On i386, ffs is not redefined, but I have no idea why.
>
> In any case, gcc does not complain about the incompatible redeclaration,
> which may be a bug, or just stupid luck, depending on your POV. :)
>
> I've attached a fix for the lsof port, which also makes it build on
> 10.0-CURRENT (this was easy to fix here, as lsof uses its own
> hand-rolled configuration script).  Let me know if it works for you.
>
Unless the headers are fixed, Vic Abell (lsof Author) will NOT support it.

We need to get clang/system headers to allow warning free compilation
just like GCC does.

I will NOT accept the change.


-- 
Larry Rosenman                     http://www.lerctr.org/~ler
Phone: +1 512-248-2683                 E-Mail: ler_at_lerctr.org
US Mail: 430 Valona Loop, Round Rock, TX 78681-3893
Received on Tue Oct 11 2011 - 11:31:26 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:19 UTC