Re: [PATCH v1 2/6] tools lib api: Add io_dir an allocation free readdir alternative

From: Namhyung Kim
Date: Tue Dec 12 2023 - 20:34:04 EST


On Mon, Dec 11, 2023 at 3:54 PM Ian Rogers <irogers@xxxxxxxxxx> wrote:
>
> On Mon, Dec 11, 2023 at 3:25 PM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
> >
> > On Wed, Dec 6, 2023 at 9:04 PM Ian Rogers <irogers@xxxxxxxxxx> wrote:
> > >
> > > glibc's opendir allocates a minimum of 32kb, when called recursively
> > > for a directory tree the memory consumption can add up - nearly 300kb
> > > during perf start-up when processing modules. Add a stack allocated
> > > variant of readdir sized a little more than 1kb.
> > >
> > > As getdents64 may be missing from libc, add support using syscall.
> >
> > Unfortunately my alpine build has:
> >
> > In file included from util/machine.c:2:
> > /build/libapi/include/api/io_dir.h:17:23: error: conflicting types for
> > 'getdents'; have 'ssize_t(int, void *, size_t)' {aka 'long int(int,
> > void *, long unsigned int)'}
> > 17 | static inline ssize_t getdents64(int fd, void *dirp, size_t count)
> > | ^~~~~~~~~~
> > /usr/include/dirent.h:52:5: note: previous declaration of 'getdents'
> > with type 'int(int, struct dirent *, size_t)' {aka 'int(int, struct
> > dirent *, long unsigned int)'}
> > 52 | int getdents(int, struct dirent *, size_t);
> > | ^~~~~~~~
>
> Presumably there is a #define getdents64 getdents .. Could we stop
> caring about this version of Alpine linux?

Right, there's a #define:

https://git.musl-libc.org/cgit/musl/tree/include/dirent.h#n68

But I'm not sure ignoring Alpine linux is a good idea.
Maybe we can add a #undef right before?

Thanks,
Namhyung