[PATCH v5 2/4] Add system-wide tunables: cache ld.so.cache

Yury Khrustalev yury.khrustalev@arm.com
Tue Feb 17 14:22:24 GMT 2026


On Wed, Feb 21, 2024 at 06:47:53PM -0500, DJ Delorie wrote:
> 
> The purpose of this change is twofold:
> 
> 1. The ld.so.cache is cached in memory and only re-read if/when
>    it changes on disk.  This allows us to have much more intensive
>    security checks in the future, without impacting performance as
>    much.  It also allows for cases where the cache is corrupted -
>    we continue using the last valid one.
> 
> 2. We break out the load/check logic so that the cache can be
>    loaded independently of the library lookup, such as for
>    code that only needs to look at the extensions.

This is such an extensive change. Is the existing functionality covered
with any tests?

This commit should probably add more tests too.

> ---
>  elf/dl-cache.c | 254 ++++++++++++++++++++++++++++++++-----------------
>  1 file changed, 169 insertions(+), 85 deletions(-)
> 
> diff --git a/elf/dl-cache.c b/elf/dl-cache.c
> index 9458ffae2a..4612dea835 100644
> --- a/elf/dl-cache.c
> +++ b/elf/dl-cache.c
> @@ -16,6 +16,7 @@
>     License along with the GNU C Library; if not, see
>     <https://www.gnu.org/licenses/>.  */
>  
> +#include <startup.h>

Nit: this include is not needed, it seems

>  #include <assert.h>
>  #include <unistd.h>
>  #include <ldsodefs.h>
> @@ -25,11 +26,18 @@
>  #include <_itoa.h>
>  #include <dl-hwcaps.h>
>  #include <dl-isa-level.h>
> +#include <sys/types.h>
Nit: this one as well seems to be unnecessary

> +#include <fcntl.h>
> +#include <sys/stat.h>
>  
>
> ...
>
> @@ -506,14 +597,7 @@ _dl_load_cache_lookup (const char *name)
>  void
>  _dl_unload_cache (void)
>  {
> -  if (cache != NULL && cache != (struct cache_file *) -1)
> -    {
> -      __munmap (cache, cachesize);
> -      cache = NULL;
> -    }
> -#ifdef SHARED
> -  /* This marks the glibc_hwcaps_priorities array as out-of-date.  */
> -  glibc_hwcaps_priorities_length = 0;
> -#endif
> +  /* Functionality is no longer needed, but kept for internal ABI for
> +     now.  */

This seems really suspicious. This is used in 2 places and presumably
some effect is expected from calling this function and now nothing will
happen?

>  }
>  #endif
> -- 
> 2.47.3
> 


More information about the Libc-alpha mailing list