Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Sep 2025 07:19:28 +0200
From:      =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= <des@FreeBSD.org>
To:        Konstantin Belousov <kostikbel@gmail.com>
Cc:        src-committers@freebsd.org,  dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org
Subject:   Re: git: d58339f39874 - main - tzcode: Drop libc namespace
Message-ID:  <86zfadal9b.fsf@ltc.des.dev>
In-Reply-To: <aNnZ1yPIMwzlyxCt@kib.kiev.ua> (Konstantin Belousov's message of "Mon, 29 Sep 2025 03:59:03 %2B0300")
References:  <202509271707.58RH7ajb090983@gitrepo.freebsd.org> <aNhIKDCDJKWZbTqt@kib.kiev.ua> <86frc6bzcm.fsf@ltc.des.dev> <aNnZ1yPIMwzlyxCt@kib.kiev.ua>

next in thread | previous in thread | raw e-mail | index | archive | help
Konstantin Belousov <kostikbel@gmail.com> writes:
> Dag-Erling Sm=C3=B8rgrav <des@FreeBSD.org> writes:
> > If we really want to do what you suggest, there are better
> > ways (like what macOS does).
> I have no idea about MacOS/what is used by Mach-O.  Can you provide some
> hints or links, please?

They use macros in the header that contains the prototype to rename
functions when there are multiple variants.  In our case it would look
like this:

(in sys/sys/cdefs.h)

    #ifdef __LIBC
    #define __LIBC_SYM(sym) __asm("_" #sym)
    #else
    #define __LIBC_SYM(sym)
    #endif __LIBC

(in include/fcntl.h)

    int     open(const char *, int, ...) __LIBC_SYM(open);

(in lib/lib{c,sys,thr}/Makefile)

    CFLAGS+=3D-D__LIBC

This allows code in libc to use open() instead of _open() and not have
to worry about needing to include "namespace.h" and "un-namespace.h" in
the right places.  It also means simply adding __LIBC to any prototype
(and a __weak_reference in the correct place) automatically protects
every call to that function in lib{c,sys,thr} without having to chase
them all down.

DES
--=20
Dag-Erling Sm=C3=B8rgrav - des@FreeBSD.org



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86zfadal9b.fsf>