[RFC PATCH] elf: Add opt-in per-object resolution notes

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Thu Nov 5 12:34:15 GMT 2026



On 30/10/26 12:44, Domen Kožar wrote:
> Hello,
> 
> Programs with long DT_RUNPATH lists can spend many failed file lookups
> resolving each library at startup. This patch lets glibc use
> per-object ELF notes containing precomputed library paths to avoid
> repeated directory searches.
> 
> Each note records ordered exact-file candidates and directories that
> still need to be searched at runtime. The loader consults it after
> LD_LIBRARY_PATH and before the normal DT_RUNPATH search. The feature
> defaults off and is enabled with glibc.rtld.resolution_cache=1.

Indeed this is know problem on some specific areas. I recall reading about
the stat storm in HPC area where workloads are usually deployed through
some network filesystem and during some workload startup thousands of
dynamic linked binaries would trigger a *lot* of network traffic.

They solved this by using a caching mechanism based on audit modules [1].
Guix, in the other hand, patched glibc to provide a per-application loader
cached (ld.so.cache) [2]. I think the Guix issue is similar to the Nix-like
layout.

There is also Shrinkwrap, which rewrites every transitive DT_NEEDED
dependency as an absolute path, which has the same effect as caching
the lookups and avoids the failed attempts on each RUNPATH entry [3].

This approach has some concerns, where a per-object ELF note is a new
on-disk ABI that glibc would have to support indefinitely, and every
record in it depends on filesystem state that the loader cannot check:

1.1 It is a permanent ABI.

The new note adds an ABI constraint that add extra maintenance: binaries
carrying the note exist for good, and every later glibc has to keep
parsing them, including any variant that appears before the format
settles. And it seems that we already have two: this RFC uses owner
"glibc" with type 1 and rejects the nixpkgs/patchelf predecessor,
whose identifiers differ. 

1.2 It records negative facts that the loader cannot verify.

The ld.so can check none of the list deployers must guarantee to make the
note notes consistent:

  - skipped files and directories never change, including those where
    no library was found when the note was written;
  - mutable directories stay in the note as runtime searches, in order;
  - the writer preserves hardware-capability selection;
  - access rights and filesystem namespaces match the writer's view;
  - any change to DT_RUNPATH, DT_NEEDED or a recorded path regenerates
    or removes the note.

The prelink support had similar constraints, with cached resolution
results, per-library timestamps and checksums in .gnu.liblist,
plus DT_GNU_PRELINKED and DT_CHECKSUM. It added a lot of extra code,
and it was bitrotten with ABI extensions.

1.3 It must stay in sync with data that other tools rewrite.

I would require to add patchelf and any other tool that manipulates 
DT_RUNPATH and DT_NEEDED support to read/parse/update this note.

1.4 It does not cover everything and add extra costs

This RFC states it only for direct startup dependencies in the
initial namespace, missing dlopen and its dependencies, dlmopen, preload
and audit modules, LD_LIBRARY_PATH and DT_RPATH. This add inconsistency
for the dynamic loading semantic.


The same problem can be fixed inside the loader at runtime, with no
format, no writer tool and nothing that can go stale, and that recovers
nearly all of the gain.

The loader already remembers missing directories (status[] in r_search_path_elem). 
What remains is one failed openat per pair of existing directory and library.
I have added a very WIP patch that implements it (caveat: I haven't tested
this extensively and there is no tests):

  - It lists each absolute search directory with getdents64 the first
    time a load operation uses it.  A load operation is process
    startup or one dlopen call, and its listings are dropped when it
    ends.

  - It keeps 32-bit hashes of the entry names (the GNU hash, computed
    once per search) and skips the open when the name is not in the
    set.  A hash hit still goes through open, so a collision costs one
    syscall and never changes the result.

  - A directory that is missing, or has no glibc-hwcaps entry, settles
    all of its glibc-hwcaps subdirectories without probing them.  As
    with today's probes, each directory status is decided once per
    process.

  - The listings and a 16 KiB scratch buffer share one 256 KiB
    anonymous mapping per operation, released when the operation ends.
    Only the pages that are touched use memory.  

  - With the tunable off, nothing is  mapped and only one static pointer
    is added.  No malloc is used, since interposed malloc may call
    dlopen.

The results seems promising, I have crated a benchmarks trying to mimic
how Guix/Niox folder setup and evaluate binaries with 10/50/100 runpaths.

The first value is your proposal:

$ ./repro.py /home/azanella/Projects/glibc/build/x86_64-linux-gnu-study
build: /home/azanella/Projects/glibc/build/x86_64-linux-gnu-study
  glibc.rtld.dircache: no, glibc.rtld.resolution_cache: yes
N=10
  variant     median us     min us  failed openat
  baseline        440.2      426.4             77
  note            367.0      364.6              2
  absolute        364.6      352.9              2
N=50
  variant     median us     min us  failed openat
  baseline       2206.1     2191.1           1377
  note           1082.4     1054.4              2
  absolute       1029.8     1021.7              2
N=100
  variant     median us     min us  failed openat
  baseline       6341.6     6317.0           5252
  note           2100.5     2093.3              2
  absolute       2009.0     2002.7              2

And the following is the proposed approach:

$ ./repro.py /home/azanella/Projects/glibc/build/x86_64-linux-gnu-study-alternate
build: /home/azanella/Projects/glibc/build/x86_64-linux-gnu-study-alternate
  glibc.rtld.dircache: yes, glibc.rtld.resolution_cache: no
N=10
  variant     median us     min us  failed openat
  baseline        425.3      420.8             77
  dircache        378.8      370.1              0
  absolute        360.3      347.4              2
N=50
  variant     median us     min us  failed openat
  baseline       2185.2     2175.2           1377
  dircache       1102.6     1096.3              0
  absolute       1023.3     1022.1              2
N=100
  variant     median us     min us  failed openat
  baseline       6330.6     6285.4           5252
  dircache       2165.1     2157.8              0
  absolute       2011.2     2001.9              2


There still some open issues, where it does not handle case-insentive; and
the directories that do not fit the scratch buffer are ignored. 

Also, I am still checking on the GUIX since it seem the fastest strategy because
it basically simulates what Shrinkwrap does through the per-application cache.
But it adds the per-application cache, which I am not fully sure about security
application and it adds the requirement of the extra deployment step.
It also changes the documented search order (cache before DT_RUNPATH).

> 
> The cache is safe only while it selects the same libraries as a normal
> search. Files and directories whose searches are skipped must remain
> unchanged, including paths where no library was found when the note
> was written. Mutable directories must remain in the note as runtime
> searches, in their original order. The writer must also preserve
> hardware-capability selection and account for differences in access
> rights and filesystem namespaces. Changing DT_RUNPATH, DT_NEEDED, or
> recorded paths requires regenerating or removing the note; the loader
> cannot detect stale records.
> 
> The implementation covers direct startup dependencies with DT_RUNPATH
> in the initial namespace. It ignores notes during secure execution,
> auditing, dlopen dependency searches, preload/audit module searches,
> and legacy RPATH searches. Missing or rejected notes, or exhausted
> candidates, fall back to ordinary library search.
> 
> The RFC proposes a glibc-owned note format, with no
> distribution-specific paths or policy. Its note identifiers are
> provisional. Existing patchelf --build-resolution-cache output uses
> different identifiers and would need a matching writer update.
> 
> Questions for review:
> 1. Are these restrictions sufficient for an opt-in cache, or should
> the loader detect stale records before using them?

IMHO no. For upstream, is not enough (1.2). And I think we can the
runpath/rpath caching without the need of the extra note with the
extra cost of some syscalls.

> 2. Should the note bind its records to the object's DT_RUNPATH and
> DT_NEEDED values from the outset?
> 3. Would extending ld.so.cache be preferable, and how should it
> preserve each requesting object's RUNPATH search order?

The ld.so.cache is a global soname -> path map and it has to preserve
each requesting object's RUNPATH order. It becomes the per-object note
stored *out of line* (with an ldconfig regeneration lifecycle on top).

I don't think either Guix or this proposal is preferable to fixing the
search itself.

> 
> This is adapted from Nixpkgs PR #535735 and pennae's earlier per-DSO
> work; the references below include the existing patchelf writer.
> 
> Provenance: Codex (GPT-6) generated substantial parts of the
> adaptation and tests. The patch retains attribution and Assisted-by
> trailers; no DCO signoff is asserted.
> 
> References:
> https://github.com/NixOS/nixpkgs/pull/535735
> https://github.com/NixOS/nixpkgs/pull/207893
> https://github.com/NixOS/patchelf/pull/647
> 
> Regards,
> Domen

[1] https://github.com/llnl/Spindle
[2] https://guix.gnu.org/sr/blog/2021/taming-the-stat-storm-with-a-loader-cache/
[3] https://github.com/fzakaria/shrinkwrap
-------------- next part --------------
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 1621cb1bdeb..984069bfe43 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -53,6 +53,10 @@
 #include <dl-machine-reject-phdr.h>
 #include <dl-prop.h>
 #include <not-cancel.h>
+#include <dl-new-hash.h>
+#include <dl-getdents.h>
+#include <setvmaname.h>
+#include <dirent.h>
 
 #include <endian.h>
 #if BYTE_ORDER == BIG_ENDIAN
@@ -482,6 +486,7 @@ fillin_rpath (char *rpath, struct r_search_path_elem **result, const char *sep,
 	  for (cnt = 0; cnt < ncapstr; ++cnt)
 	    dirp->status[cnt] = init_val;
 
+	  dirp->dirlist = NULL;
 	  dirp->what = what;
 	  if (__glibc_likely (where != NULL))
 	    dirp->where = memcpy ((char *) dirp + sizeof (*dirp) + len + 1
@@ -694,6 +699,7 @@ _dl_init_paths (const char *llp, const char *source,
       *aelem++ = pelem;
 
       pelem->what = "system search path";
+      pelem->dirlist = NULL;
       pelem->where = NULL;
 
       pelem->dirname = strp;
@@ -1723,6 +1729,200 @@ open_verify (const char *name, int fd,
   return fd;
 }
 

+
+/* Negative lookup cache built from a directory scan of a search directory.
+   Only name hashes are kept; a hash hit still goes through open, so a
+   collision costs one syscall and never changes the result.  */
+struct dl_dirlist_t
+{
+  /* The table has 1 << (32 - SHIFT) slots.  */
+  unsigned int shift;
+  uint32_t mask;
+  uint32_t table[];
+};
+
+/* A directory's dirlist is NULL until the current load operation lists
+   it.  Then it is a table, DIRLIST_UNLISTABLE if the directory cannot be
+   listed (kept for the whole process), or DIRLIST_NOROOM if its table
+   did not fit in the operation's arena (cleared by _dl_dirlist_drop).  */
+#define DIRLIST_UNLISTABLE ((struct dl_dirlist_t *) -1)
+#define DIRLIST_NOROOM ((struct dl_dirlist_t *) -2)
+
+static inline bool
+dirlist_valid (const struct dl_dirlist_t *dl)
+{
+  return dl != NULL && dl != DIRLIST_UNLISTABLE && dl != DIRLIST_NOROOM;
+}
+
+static inline uint32_t
+dirlist_key (const char *name)
+{
+  uint32_t h = _dl_new_hash (name);
+  return h != 0 ? h : 1;
+}
+
+/* The GNU hash low bits only depend on the low bits of each character, so
+   take the high bits of a multiplicative hash.  */
+static inline uint32_t
+dirlist_slot (const struct dl_dirlist_t *dl, uint32_t key)
+{
+  return (key * 0x9e3779b9u) >> dl->shift;
+}
+
+enum { DIRLIST_MAX = 2048 };
+
+/* The getdents64 buffer size for about 200 typical entries per call, so a
+   small library directory is read in one call (plus the final empty one).  */
+#define DIRLIST_DBUF_SIZE 8192
+
+/* All the listings of a load operation live in one anonymous mapping of
+   DIRLIST_ARENA_SIZE bytes: the scratch buffers first, then the tables one
+   after another.  The first listing of an operation maps it and
+   _dl_dirlist_drop unmaps it, so it costs nothing unless
+   glibc.rtld.dircache is enabled.  The size also caps the memory of an
+   operation, where a directory whose table does not fit is searched without a
+   listing until the operation ends.
+   N.B: malloc should not be used here, since interposed one may call dlopen,
+   which drops the listings while one is being built.  */
+struct dirlist_arena
+{
+  /* Scratch buffers for object loading, assume serialized access
+     (dl_load_lock or single-threaded startup).  */
+  uint32_t hashes[DIRLIST_MAX];
+  char dbuf[DIRLIST_DBUF_SIZE] __attribute__ ((aligned (8)));
+  /* Bytes of TABLES in use.  Each table takes 8 + 4 * SIZE bytes, so the
+     next one stays aligned.  */
+  size_t used;
+  char tables[] __attribute__ ((aligned (__alignof__ (struct dl_dirlist_t))));
+};
+static struct dirlist_arena *dirlist_arena;
+
+/* Room for the tables of about 3400 small directories (5 to 8 entries,
+   72 bytes each) or 14 of the largest (2048 entries, 16392 bytes).  Only
+   the touched pages use memory, and it is a multiple of every page
+   size.  */
+#define DIRLIST_ARENA_SIZE (256 * 1024)
+_Static_assert (sizeof (struct dirlist_arena) + sizeof (struct dl_dirlist_t)
+		+ 2 * DIRLIST_MAX * sizeof (uint32_t) <= DIRLIST_ARENA_SIZE,
+		"the largest table fits in an empty arena");
+
+static struct dl_dirlist_t *
+dirlist_build (const char *dirname, bool *missing)
+{
+  int fd = __open64_nocancel (dirname, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+  *missing = fd < 0 && (errno == ENOENT || errno == ENOTDIR);
+  if (fd < 0)
+    return DIRLIST_UNLISTABLE;
+  struct dirlist_arena *a = dirlist_arena;
+  if (a == NULL)
+    {
+      a = __mmap (NULL, DIRLIST_ARENA_SIZE, PROT_READ | PROT_WRITE,
+		  MAP_ANON | MAP_PRIVATE, -1, 0);
+      if (a == MAP_FAILED)
+	{
+	  __close_nocancel (fd);
+	  return DIRLIST_NOROOM;
+	}
+      __set_vma_name (a, DIRLIST_ARENA_SIZE, " glibc: loader dircache");
+      dirlist_arena = a;
+    }
+  size_t n = 0;
+  for (;;)
+    {
+      ssize_t r = _dl_getdents (fd, a->dbuf, DIRLIST_DBUF_SIZE);
+      if (r < 0)
+	{
+	  __close_nocancel (fd);
+	  return DIRLIST_UNLISTABLE;
+	}
+      if (r == 0)
+	break;
+      for (ssize_t off = 0; off < r;)
+	{
+	  struct dirent64 *d = (struct dirent64 *) (a->dbuf + off);
+	  off += d->d_reclen;
+	  if (n == DIRLIST_MAX)
+	    {
+	      __close_nocancel (fd);
+	      return DIRLIST_UNLISTABLE;
+	    }
+	  a->hashes[n++] = dirlist_key (d->d_name);
+	}
+    }
+  __close_nocancel (fd);
+
+  /* Build the hash set: an open-addressing table of SIZE = 2^BITS slots,
+     the smallest power of two that is at least 2 * N (and at least 8),
+     so it is at most half full and make absent names lookups the fast
+     path .
+     A slot holds a key, or 0 if it is empty (dirlist_key never returns 0).
+     The home slot of a key is the top BITS bits of a multiplicative hash
+     (dirlist_slot); if it is taken, the next slots are tried, wrapping
+     around with MASK (linear probing).  A key that is already present (two
+     names with the same  hash) is stored once.
+
+     For example, a library directory with ".", "..", "libfoo.so",
+     "libfoo.la" and "pkgconfig" has N = 5, so SIZE = 16, SHIFT = 28 (the
+     home slot is the top 4 bits of KEY * 0x9e3779b9) and MASK = 15, and
+     the table takes 8 + 16 * 4 = 72 bytes.
+
+     The arena is fresh anonymous memory and is never reused, so every
+     slot starts empty.  */
+  unsigned int bits = 3;
+  while ((1u << bits) < 2 * n)
+    ++bits;
+  uint32_t size = 1u << bits;
+  size_t len = sizeof (struct dl_dirlist_t) + size * sizeof (uint32_t);
+  if (DIRLIST_ARENA_SIZE - sizeof *a - a->used < len)
+    return DIRLIST_NOROOM;
+  struct dl_dirlist_t *dl = (struct dl_dirlist_t *) (a->tables + a->used);
+  a->used += len;
+  dl->shift = 32 - bits;
+  dl->mask = size - 1;
+  for (size_t i = 0; i < n; i++)
+    {
+      uint32_t j = dirlist_slot (dl, a->hashes[i]);
+      while (dl->table[j] != 0 && dl->table[j] != a->hashes[i])
+	j = (j + 1) & dl->mask;
+      dl->table[j] = a->hashes[i];
+    }
+  return dl;
+}
+
+/* Listings are trusted only within one load operation, so that a
+   library installed between two operations is found.  Directories that
+   cannot be listed stay marked as such; those that did not fit in the
+   arena are listed again by the next operation.  Tunables do not change
+   after startup, so nothing was listed (and nothing mapped) if
+   glibc.rtld.dircache is off.  */
+void
+_dl_dirlist_drop (void)
+{
+  if (TUNABLE_GET (glibc, rtld, dircache, int32_t, NULL) == 0)
+    return;
+
+  for (struct r_search_path_elem *d = GL(dl_all_dirs); d != NULL;
+       d = d->next)
+    if (d->dirlist != DIRLIST_UNLISTABLE)
+      d->dirlist = NULL;
+
+  if (dirlist_arena != NULL)
+    {
+      __munmap (dirlist_arena, DIRLIST_ARENA_SIZE);
+      dirlist_arena = NULL;
+    }
+}
+
+static bool
+dirlist_contains (const struct dl_dirlist_t *dl, uint32_t key)
+{
+  for (uint32_t j = dirlist_slot (dl, key); dl->table[j] != 0;
+       j = (j + 1) & dl->mask)
+    if (dl->table[j] == key)
+      return true;
+  return false;
+}
+
 /* Try to open NAME in one of the directories in SPS.  Return the fd, or -1.
    If successful, fill in *REALNAME with the malloc'd full directory name.  If
    it turns out that none of the directories in SPS exists, SPS->DIRS is
@@ -1739,6 +1939,9 @@ open_path (const char *name, size_t namelen, int mode,
   int fd = -1;
   const char *current_what = NULL;
   int any = 0;
+  bool use_dircache
+    = TUNABLE_GET (glibc, rtld, dircache, int32_t, NULL) != 0;
+  uint32_t name_key = 0;
 
   if (__glibc_unlikely (dirs == NULL))
     /* We're called before _dl_init_paths when loading the main executable
@@ -1775,12 +1978,66 @@ open_path (const char *name, size_t namelen, int mode,
 	}
 
       edp = (char *) __mempcpy (buf, this_dir->dirname, this_dir->dirnamelen);
+
+      /* List the directory on first use in this load operation and a
+	 directory that cannot be listed is never retried.  The status still
+	 unknown are settled from the listing, where a missing directory, or
+	 one without a glibc-hwcaps entry, settles every hwcaps subdirectory
+	 without probing it.  Like the probes, a status is only set once.  */
+      if (use_dircache && this_dir->dirlist == NULL
+	  && this_dir->dirname[0] == '/'
+	  && (loader == NULL
+	      || GL(dl_ns)[loader->l_ns]._ns_loaded->l_auditing == 0))
+	{
+	  bool missing;
+	  *edp = '\0';
+	  this_dir->dirlist = dirlist_build (buf, &missing);
+	  for (cnt = 0; cnt < ncapstr; ++cnt)
+	    if (this_dir->status[cnt] != unknown)
+	      continue;
+	    else if (missing
+#ifdef SHARED
+		|| (capstr[cnt].len != 0 && dirlist_valid (this_dir->dirlist)
+		    && !dirlist_contains (this_dir->dirlist,
+					  dirlist_key ("glibc-hwcaps")))
+#endif
+		)
+	      this_dir->status[cnt] = nonexisting;
+	    else if (dirlist_valid (this_dir->dirlist)
+#ifdef SHARED
+		     && capstr[cnt].len == 0
+#endif
+		     )
+	      this_dir->status[cnt] = existing;
+	}
+
       for (cnt = 0; fd == -1 && cnt < ncapstr; ++cnt)
 	{
 	  /* Skip this directory if we know it does not exist.  */
 	  if (this_dir->status[cnt] == nonexisting)
 	    continue;
 
+	  /* Skip names absent from this operation's listing of the
+	     directory.  */
+	  if (use_dircache
+#ifdef SHARED
+	      && capstr[cnt].len == 0
+#endif
+	      && dirlist_valid (this_dir->dirlist))
+	    {
+	      if (name_key == 0)
+		name_key = dirlist_key (name);
+	      if (!dirlist_contains (this_dir->dirlist, name_key))
+		{
+		  if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_LIBS))
+		    _dl_debug_printf ("  skipping file=%s%s (not listed)\n",
+				      this_dir->dirname, name);
+		  here_any = 1;
+		  __set_errno (ENOENT);
+		  continue;
+		}
+	    }
+
 #ifdef SHARED
 	  buflen =
 	    ((char *) __mempcpy (__mempcpy (edp, capstr[cnt].str,
diff --git a/elf/dl-open.c b/elf/dl-open.c
index dd711d5ae5c..aa2e737e5e8 100644
--- a/elf/dl-open.c
+++ b/elf/dl-open.c
@@ -489,6 +489,10 @@ dl_open_worker_begin (void *a)
      may not be true if this is a recursive call to dlopen.  */
   _dl_debug_initialize (0, args->nsid);
 
+  /* Libraries may have been installed since startup listed the search
+     directories.  */
+  _dl_dirlist_drop ();
+
   /* Load the named object.  */
   struct link_map *new = args->map;
   if (new == NULL)
@@ -883,6 +887,9 @@ no more namespaces available for dlmopen()"));
   struct dl_exception exception;
   int errcode = _dl_catch_exception (&exception, dl_open_worker, &args);
 
+  /* Directory listings must not outlive this dlopen call.  */
+  _dl_dirlist_drop ();
+
   maybe_report_r_debug_consistent (&args);
 
   /* Do this for both the error and success cases.  The old value has
diff --git a/elf/dl-tunables.list b/elf/dl-tunables.list
index 111649f1455..188361ad017 100644
--- a/elf/dl-tunables.list
+++ b/elf/dl-tunables.list
@@ -113,6 +113,12 @@ glibc {
       maxval: 2
       default: 1
     }
+    dircache {
+      type: INT_32
+      minval: 0
+      maxval: 1
+      default: 0
+    }
   }
 
   mem {
diff --git a/elf/rtld.c b/elf/rtld.c
index 65c10edff20..f3493e9f0eb 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -1945,6 +1945,7 @@ dl_main (const ElfW(Phdr) *phdr,
     rtld_timer_start (&start);
     _dl_map_object_deps (main_map, preloads, npreloads,
 			 state.mode == rtld_mode_trace, 0);
+    _dl_dirlist_drop ();
     rtld_timer_accum (&load_time, start);
   }
 
diff --git a/elf/tst-rtld-list-tunables.exp b/elf/tst-rtld-list-tunables.exp
index 9590021f3ae..9551017425d 100644
--- a/elf/tst-rtld-list-tunables.exp
+++ b/elf/tst-rtld-list-tunables.exp
@@ -10,6 +10,7 @@ glibc.malloc.tcache_count: 0x0 (min: 0x0, max: 0x[f]+)
 glibc.malloc.tcache_max: 0x0 (min: 0x0, max: 0x[f]+)
 glibc.malloc.top_pad: 0x20000 (min: 0x0, max: 0x[f]+)
 glibc.malloc.trim_threshold: 0x0 (min: 0x0, max: 0x[f]+)
+glibc.rtld.dircache: 0 (min: 0, max: 1)
 glibc.rtld.dynamic_sort: 2 (min: 1, max: 2)
 glibc.rtld.enable_secure: 0 (min: 0, max: 1)
 glibc.rtld.execstack: 1 (min: 0, max: 2)
diff --git a/sysdeps/generic/dl-getdents.h b/sysdeps/generic/dl-getdents.h
new file mode 100644
index 00000000000..08744bd6d66
--- /dev/null
+++ b/sysdeps/generic/dl-getdents.h
@@ -0,0 +1,32 @@
+/* Read directory entries for the dynamic loader.  Stub version.
+   Copyright (C) 2026 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#ifndef _DL_GETDENTS_H
+#define _DL_GETDENTS_H
+
+#include <sys/types.h>
+
+static inline ssize_t
+_dl_getdents (int fd __attribute__ ((unused)),
+	      void *buf __attribute__ ((unused)),
+	      size_t len __attribute__ ((unused)))
+{
+  return -1;
+}
+
+#endif /* dl-getdents.h */
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 305ca6e0df2..e2321b31d4d 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -207,6 +207,10 @@ struct r_search_path_elem
     const char *dirname;
     size_t dirnamelen;
 
+    /* Hash set of the entry names of DIRNAME, NULL if not built in the
+       current load operation.  */
+    struct dl_dirlist_t *dirlist;
+
     enum r_dir_status status[0];
   };
 
@@ -933,6 +937,9 @@ struct link_map *_dl_map_new_object (struct link_map *loader,
 				     int type, int trace_mode, int mode,
 					     Lmid_t nsid) attribute_hidden;
 
+/* Release  the directory listings of the current load operation.  */
+void _dl_dirlist_drop (void) attribute_hidden;
+
 
 /* Call _dl_map_object on the dependencies of MAP, and set up
    MAP->l_searchlist.  PRELOADS points to a vector of NPRELOADS previously
diff --git a/sysdeps/unix/sysv/linux/dl-getdents.h b/sysdeps/unix/sysv/linux/dl-getdents.h
new file mode 100644
index 00000000000..1c2a93e202c
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/dl-getdents.h
@@ -0,0 +1,32 @@
+/* Read directory entries for the dynamic loader.  Linux version.
+   Copyright (C) 2026 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#ifndef _DL_GETDENTS_H
+#define _DL_GETDENTS_H
+
+#include <sys/types.h>
+#include <sysdep.h>
+
+static inline ssize_t
+_dl_getdents (int fd, void *buf, size_t len)
+{
+  long int r = INTERNAL_SYSCALL_CALL (getdents64, fd, buf, len);
+  return INTERNAL_SYSCALL_ERROR_P (r) ? -1 : r;
+}
+
+#endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: repro.py
Type: text/x-python-script
Size: 7698 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20261105/896946d0/attachment-0001.bin>


More information about the Libc-alpha mailing list