[RFC,2/3] ldconfig: Add an option to ignore standard path during ld.so.cache generation

Message ID 20260421090020.59726-3-l.stelmach@samsung.com (mailing list archive)
State New
Headers
Series Use multiple ld.so caches to separate execution environments |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch fail Patch failed to apply to master at the time it was sent

Commit Message

Lukasz Stelmach April 21, 2026, 9 a.m. UTC
  From: Mateusz Moscicki <m.moscicki2@samsung.com>

Add -I/--ignore-standard-dirs option to ignore standard library paths.

With this change, it is possible to generate an ld.so.cache file that
contains only libraries from the directories included in the specified
config, without adding libraries from standard paths such as /lib,
/usr/lib, etc.

Usage:

    cat <<EOF > ldconf.txt
    /opt/lib
    /opt/lib-special
    EOF

    ldconfig -C ld.so.cache.custom -f ldconf.txt -I

Signed-off-by: Mateusz Mościcki <m.moscicki2@samsung.com>
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
---
 elf/ldconfig.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
  

Patch

diff --git a/elf/ldconfig.c b/elf/ldconfig.c
index 0f3ef707dd..2ca763313a 100644
--- a/elf/ldconfig.c
+++ b/elf/ldconfig.c
@@ -111,6 +111,11 @@  static char *cache_file;
 /* Configuration file.  */
 static const char *config_file;
 
+#ifdef DLCONF
+/* Don't add the standard system paths */
+static int opt_ignore_standard;
+#endif /* DLCONF */
+
 /* Name and version of program.  */
 static void print_version (FILE *stream, struct argp_state *state);
 void (*argp_program_version_hook) (FILE *, struct argp_state *)
@@ -133,6 +138,9 @@  static const struct argp_option options[] =
   { NULL, 'l', NULL, 0, N_("Manually link individual libraries."), 0},
   { "format", 'c', N_("FORMAT"), 0, N_("Format to use: new (default), old, or compat"), 0},
   { "ignore-aux-cache", 'i', NULL, 0, N_("Ignore auxiliary cache file"), 0},
+#ifdef DLCONF
+  { "ignore-standard-dirs", 'I', NULL, 0, N_("Ignore standard directories"), 0},
+#endif /* DLCONF */
   { NULL, 0, NULL, 0, NULL, 0 }
 };
 
@@ -198,6 +206,11 @@  parse_opt (int key, char *arg, struct argp_state *state)
       else if (strcmp (arg, "new") == 0)
 	opt_format = opt_format_new;
       break;
+#ifdef DLCONF
+    case 'I':
+      opt_ignore_standard = 1;
+      break;
+#endif /* DLCONF */
     default:
       return ARGP_ERR_UNKNOWN;
     }
@@ -1287,11 +1300,17 @@  main (int argc, char **argv)
   if (!opt_only_cline)
     {
       parse_conf (config_file, true);
-
+#ifdef DLCONF
+      if (!opt_ignore_standard)
+        {
+#endif /* DLCONF */
       /* Always add the standard search paths.  */
       add_system_dir (SLIBDIR);
       if (strcmp (SLIBDIR, LIBDIR))
 	add_system_dir (LIBDIR);
+#ifdef DLCONF
+        }
+#endif /* DLCONF */
     }
 
   const char *aux_cache_file = _PATH_LDCONFIG_AUX_CACHE;