From: Alejandro Colomar <alx@kernel.org>
To: Rich Felker <dalias@libc.org>
Cc: Leah Neukirchen <leah@vuxu.org>,
musl@lists.openwall.com, libc-alpha@sourceware.org,
Richard Russon <rich@flatcap.org>
Subject: Re: [musl] gcvt(3) should be MT-Safe, AS-Safe, AC-Safe
Date: Thu, 2 May 2024 02:01:42 +0200 [thread overview]
Message-ID: <ZjLX5wPi9UIOlLi3@debian> (raw)
In-Reply-To: <ZjLUHRQqEPo1Urb_@debian>
[-- Attachment #1: Type: text/plain, Size: 3112 bytes --]
On Thu, May 02, 2024 at 01:45:27AM +0200, Alejandro Colomar wrote:
> [CC += libc-alpha (glibc), Richard]
>
> Hi Rich Felker,
>
> On Wed, May 01, 2024 at 07:04:38PM -0400, Rich Felker wrote:
> > On Wed, May 01, 2024 at 09:55:10PM +0200, Alejandro Colomar wrote:
> > > On Wed, May 01, 2024 at 01:21:39PM -0400, Rich Felker wrote:
> > > > It doesn't matter either way because musl's s[n]printf is AS-safe.
> > >
> > > Hmm; interesting. Thanks!
> >
> > Yes, it's a pure function (aside from fenv, errno for %m, and possibly
> > LC_NUMERIC in the future) and has no reason to do anything AS-unsafe
> > unless you implement it with dynamic allocation, in which case you
> > have unforced failure cases which are very low QoI.
> >
> > musl's printf core also has very low stack usage suitable for AS use,
> > at least in principle. LLVM and possibly modern GCC like to
> > inline-and-lift the slightly-large (IIRC something like 6-8k on
> > ld80/IEEE-quad archs, 2k on ld64 archs) floating point workspace to be
> > allocated unconditionally, but if you can suppress that, it should
> > only need a few hundred bytes of stack.
> >
> > dprintf is also AS-safe (as intended by its creator; this was
> > discussed on the glibc list a few years back)
I've been digging into the archives, and found it:
<https://inbox.sourceware.org/libc-alpha/20130925180327.0351F2C097@topped-with-meat.com/>
But then it seems that, at least in 2013, it wasn't AS-safe:
<https://inbox.sourceware.org/libc-alpha/20130925212954.GQ20515@brightrain.aerifal.cx/>
It would be interesting to know the status as of today (if I have to
guess, I'd bet it's unsafe), and also if there could be any guarantees
that at least a subset of dprintf(3) was guaranteed to be AS-safe (e.g.,
ignoring '$', wide-char, ...).
> I realize that dprintf(3) is not documented in the ATTRIBUTES section of
> its manual page. POSIX doesn't seem to document AS safety of it (or of
> most functions FWIW). glibc's manual doesn't seem to document
> dprintf(3) at all. I guess I should fix that.
>
> The BSDs don't seem to document it as being AS-safe either. NetBSD
> mentions the existence of snprintf_ss(3), but nothing about dprintf(3).
> FreeBSD is silent. OpenBSD is silent too.
>
> I've CCed glibc so that they confirm that this is MT-safe + AS-safe on
> glibc. I guess if the original design was to have it AS-safe, we can
> report bugs to the BSDs so that they document their AS safety status,
> and that they make the function AS-safe if it isn't already.
>
> Also, having dprintf(3) documented as AS-safe by design would be a great
> standard solution for my original interest, which was finding a libc
> portable AS-safe replacement for printf(3). I could just
>
> dprintf(STDOUT_FILENO, ...)
>
> and avoid any hand-written wrappers around write(1).
>
> > and even fprintf is
> > under the condition that you're not interrupting code accessing the
> > same FILE you pass to it.
> >
> > Rich
>
> Have a lovely night!
> Alex
--
<https://www.alejandro-colomar.es/>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2024-05-02 0:02 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-01 15:09 Alejandro Colomar
2024-05-01 15:19 ` Leah Neukirchen
2024-05-01 15:38 ` Alejandro Colomar
2024-05-01 17:21 ` Rich Felker
2024-05-01 19:55 ` Alejandro Colomar
2024-05-01 23:04 ` Rich Felker
2024-05-01 23:45 ` Alejandro Colomar
2024-05-01 23:57 ` Thorsten Glaser
2024-05-02 0:01 ` Alejandro Colomar [this message]
2024-05-02 20:34 ` Joseph Myers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZjLX5wPi9UIOlLi3@debian \
--to=alx@kernel.org \
--cc=dalias@libc.org \
--cc=leah@vuxu.org \
--cc=libc-alpha@sourceware.org \
--cc=musl@lists.openwall.com \
--cc=rich@flatcap.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).