Re: System headers with clang?

From: Arnaud Lacombe <lacombar_at_gmail.com>
Date: Tue, 11 Oct 2011 14:52:17 -0400
Hi,

On Tue, Oct 11, 2011 at 2:39 PM, Larry Rosenman <ler_at_lerctr.org> wrote:
> On 10/11/2011 1:36 PM, Arnaud Lacombe wrote:
>>
>> Hi,
>>
>> On Tue, Oct 11, 2011 at 8:00 AM, Dimitry Andric<dim_at_freebsd.org>  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.
>>>
>> #ifdef _KERNEL/#endif protected part of system headers shall NEVER be
>> accessed by userland. It is a fault to have them present in
>> /usr/include. Linux got it right there, all those part are removed
>> upon headers' installation.
>>
>>  - Arnaud
>
> Then lsof would NOT be compilable / usable at all, as it delves into
> /dev/kmem to get information.
>
AFAIK, Linux is capable of supporting lsof in a backward compatible
manner, without exposing its internal guts.

FWIW, KVM is a bad kernel/userland interface, as it does not guarantee
backward compatibility.

> And it **NEEDS** to know what the structures are.
>
No, not kernel-only structure. Now, if these structure are not meant
to be kernel only, move them out of _KERNEL area, but beware of
backward compatibility issue in the future.

> That is unless someone(tm) writes the Kernel interfaces to get the info.
>
Yes, this is the core of the problem and a classical chicken/eggs
problem solves the very wrongest way.

At some point, I thought to modify the build system to pass kernel's
headers through unifdef(1), but I quickly forgot about that:

% git grep 'define _KERNEL' * | grep -v '^sys' | wc -l
      27

 - Arnaud
Received on Tue Oct 11 2011 - 16:52:27 UTC

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