|
|
Message-ID: <20261118182224.GW5716@brightrain.aerifal.cx>
Date: Wed, 18 Nov 2026 13:22:24 -0500
From: Rich Felker <dalias@...c.org>
To: illiliti <ilt@...s.net>
Cc: musl@...ts.openwall.com
Subject: Re: [PATCH v1 10/18] fts: drop aligned statp alloc support
On Wed, Nov 18, 2026 at 08:58:46PM +0300, illiliti wrote:
> On 11/18/26 5:34 PM, Rich Felker wrote:
> > On Wed, Nov 18, 2026 at 03:49:52PM +0300, illiliti wrote:
> >> ---
> >> src/misc/fts.c | 34 +---------------------------------
> >> 1 file changed, 1 insertion(+), 33 deletions(-)
> >>
> >> diff --git a/src/misc/fts.c b/src/misc/fts.c
> >> index bae0f8a9..498ef576 100644
> >> --- a/src/misc/fts.c
> >> +++ b/src/misc/fts.c
> >> @@ -53,12 +53,6 @@ static unsigned short fts_stat(FTS *, FTSENT *, int);
> >> static int fts_safe_changedir(const FTS *, const FTSENT *, int,
> >> const char *);
> >>
> >> -#if defined(ALIGNBYTES) && defined(ALIGN)
> >> -#define FTS_ALLOC_ALIGNED 1
> >> -#else
> >> -#undef FTS_ALLOC_ALIGNED
> >> -#endif
> >> -
> >> #ifndef ftsent_namelen_truncate
> >> #define ftsent_namelen_truncate(a) \
> >> ((a) > UINT_MAX ? UINT_MAX : (unsigned int)(a))
> >> @@ -989,29 +983,7 @@ static FTSENT *
> >> fts_alloc(FTS *sp, const char *name, size_t namelen)
> >> {
> >> FTSENT *p;
> >> -#if defined(FTS_ALLOC_ALIGNED)
> >> - size_t len;
> >> -#endif
> >> -
> >> -#if defined(FTS_ALLOC_ALIGNED)
> >> - /*
> >> - * The file name is a variable length array and no stat structure is
> >> - * necessary if the user has set the nostat bit. Allocate the FTSENT
> >> - * structure, the file name and the stat structure in one chunk, but
> >> - * be careful that the stat structure is reasonably aligned. Since the
> >> - * fts_name field is declared to be of size 1, the fts_name pointer is
> >> - * namelen + 2 before the first possible address of the stat structure.
> >> - */
> >
> > I've skimmed through this quickly to give some initial feedback, and
> > this is the first thing that really stuck out at me. The thing of
> > using a size-1 array as if it were a flexible array member produces
> > undefined behavior in the caller and is not acceptable in a public
> > interface or internal to musl. Hopefully this isn't something callers
> > can depend on and it can just be fixed to use a real FAM.
>
> This code has been dropped as you may see and you are right it is bad.
> It does some stupid micro optimization that reduces two mallocs to one.
> I don't see much point in retaining it as it exchanges correctness for no
> meaningful gain.
I don't see where the fts_name[1] is fixed. It needs to be fts_name[]
with the size logic potentially fixed.
> > - A squashed patch, and explanations of the motivations for individual
> > changes like the one I'm replying to here for the broken-down
> > changes. It's a lot more work to evaluate potentially-unacceptable
> > parts of the patch when it's not apparent without reading all of the
> > other patches whether those things will be removed by the end.
>
> Okay, I can squash the patchset.
Thanks! Having both handy on-list will make it easier to review.
> > - Some research on what programs that use fts are doing now. Are they
> > shipping their own drop-ins, or using a library? I don't think
> > libbsd has it but I might be misremembering.
>
> Some are vendoring fts code, some use musl-fts hack. Neither is good
> approach.
>
> I can research every possible program that uses fts if that's
> necessary to convince you, but I'd rather not. I hope the existence of the
> musl-fts hack and the substantial number of packages that use fts will be
> convincing enough for you.
I think Leah's response has it covered. So it looks like this is a
place where distros really are shimming it, and like this does make
sense to pursue. I hope my initial hesitance was not too off-putting.
> > - Is the fts public interface actually common between implementations?
> > Just now looking up the fts_name thing, it looks like glibc has
> > fts_name as a pointer rather than an array. Generally musl is
> > hesitant to take on interfaces that have multiple incompatible
> > historical versions by the same name, since doing so prevents
> > dropping in one to match what the caller expects and might conflict
> > with future standardization, putting us in a bad position with
> > regards to ABI.
>
> glibc implemention is based on 4.4 BSD. There are a few changes though,
> mostly internal, but they don't seem to cause any problem, at least on
> the application side.
>
> The fts_name is a char array on the latest(2.44) glibc:
> https://elixir.bootlin.com/glibc/glibc-2.44/source/include/fts.h#L53
> https://elixir.bootlin.com/glibc/glibc-2.44/source/io/fts.h#L300
> (or whatever the hell header file they are using)
Oh, then the man page is wrong. Lovely. The man page says it's char *
but indeed glibc has the same fts_name[1] faux-FAM. At least this
shoots down the concern that there are conflicting APIs.
> > Also, for future reference, it's nicer if you can send patch series as
> > multiple MIME attachments rather than a git-send-email style thread.
> > Less inbox clutter to list subscribers, and it would make it possible
> > to reply to multiple parts of the series in a single reply rather than
> > having replies attached just to one branch of the thread.
>
> Sorry I genuinely didn't know. There is no CONTRIBUTING or HACKING file as
> far as I'm aware, so I had to resort to the linux kernel style. Didn't realize
> a different style is preferred here.
That's okay. Yes, we need to have things like this documented on the
website/wiki.
Rich
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.