Re: Header symbols that shouldn't be visible to ports?

From: Alan Somers <asomers_at_freebsd.org>
Date: Mon, 05 Sep 2022 15:07:49 UTC
On Mon, Sep 5, 2022 at 8:53 AM Mark Johnston <markj@freebsd.org> wrote:
>
> On Mon, Sep 05, 2022 at 08:41:58AM -0600, Alan Somers wrote:
> > On Sat, Sep 3, 2022 at 11:10 PM Konstantin Belousov <kostikbel@gmail.com> wrote:
> > >
> > > On Sat, Sep 03, 2022 at 10:19:12AM -0600, Alan Somers wrote:
> > > > Our /usr/include headers define a lot of symbols that are used by
> > > > critical utilities in the base system like ps and ifconfig, but aren't
> > > > stable across major releases.  Since they aren't stable, utilities
> > > > built for older releases won't run correctly on newer ones.  Would it
> > > > make sense to guard these symbols so they can't be used by programs in
> > > > the ports tree?  There is some precedent for that, for example
> > > > _WANT_SOCKET and _WANT_MNTOPTNAMES.
> > > _WANT_SOCKET is clearly about exposing parts of the kernel definitions
> > > for userspace code that wants to dig into kernel structures.  Similarly
> > > for _WANT_MNTOPTNAMES, but in fact this thing is quite stable.  The
> > > definitions are guarded by additional defines not due to their instability,
> > > but because using them in userspace requires (much) more preparation from
> > > userspace environment, which is either not trivial (_WANT_SOCKET) or
> > > contradicts to standartized use of the header (_WANT_MNTOPTNAMES +
> > > sys/mount.h).
> > >
> > > >
> > > > I'm particular, I'm thinking about symbols like the following:
> > > > MINCORE_SUPER
> > > Why this symbol should be hidden?  It is implementation-defined and
> > > intended to be exposed to userspace.  All MINCORE_* not only MINCORE_SUPER
> > > are under BSD_VISIBLE braces, because POSIX does not define the symbols.
> >
> > Because it isn't stable.  It changed for example in rev 847ab36bf22
> > for 13.0.  Programs using the older value (including virtually every
> > Rust program) won't work on 13.0 and later.
>
> Why won't they work?  Code that tests (vec[i] & MINCORE_SUPER) using the
> old value will still give the same result when running on a newer
> kernel, since MINCORE_PSIND(1) is 0x20, the old MINCORE_SUPER value.
> This isn't to say that the change was perfectly backwards compatible,
> but I haven't seen an example of code which was broken by the change.

Well, from mincore(2):

In particular, applications compiled using the old value of
MINCORE_SUPER will not identify large pages with size index 2 as being
large pages.