glibc-2.25-ldso-nodefaultdirs-option.diff 3.29 KB
Newer Older
1 2 3 4 5
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 49f070f..621b5a3 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -2279,7 +2279,8 @@ _dl_map_object (struct link_map *loader, const char *name,
6

7 8
 	      /* If the loader has the DF_1_NODEFLIB flag set we must not
 		 use a cache entry from any of these directories.  */
9 10 11
-	      if (__glibc_unlikely (l->l_flags_1 & DF_1_NODEFLIB))
+	      if (__glibc_unlikely (l->l_flags_1 & DF_1_NODEFLIB) ||
+                       GLRO(dl_no_default_dirs))
12 13 14 15 16 17 18
 		{
 		  const char *dirp = system_dirs;
 		  unsigned int cnt = 0;
@@ -2321,7 +2322,8 @@ _dl_map_object (struct link_map *loader, const char *name,
       /* Finally, try the default path.  */
       if (fd == -1
 	  && ((l = loader ?: GL(dl_ns)[nsid]._ns_loaded) == NULL
19 20 21
-	      || __glibc_likely (!(l->l_flags_1 & DF_1_NODEFLIB)))
+	      || __glibc_likely (!(l->l_flags_1 & DF_1_NODEFLIB)) ||
+		GLRO(dl_no_default_dirs))
22 23 24 25 26
 	  && rtld_search_dirs.dirs != (void *) -1)
 	fd = open_path (name, namelen, mode & __RTLD_SECURE, &rtld_search_dirs,
 			&realname, &fb, l, LA_SER_DEFAULT, &found_other_class);
@@ -2487,7 +2489,7 @@ _dl_rtld_di_serinfo (struct link_map *loader, Dl_serinfo *si, bool counting)
      a way to indicate that in the results for Dl_serinfo.  */
27

28 29 30
   /* Finally, try the default path.  */
-  if (!(loader->l_flags_1 & DF_1_NODEFLIB))
+  if (!((loader->l_flags_1 & DF_1_NODEFLIB) || GLRO(dl_no_default_dirs)))
31 32
     add_path (&p, &rtld_search_dirs, XXX_default);

33 34 35 36 37 38 39 40
   if (counting)
diff --git a/elf/dl-support.c b/elf/dl-support.c
index 723814a..fccc1d4 100644
--- a/elf/dl-support.c
+++ b/elf/dl-support.c
@@ -61,6 +61,9 @@ const char *_dl_inhibit_rpath;
 /* prefix to be added to all RUNPATHs and RPATHs */
 const char *_dl_rpath_prefix = NULL;
41

42 43 44 45 46
+/* flag: don't search default directories if set. */
+int _dl_no_default_dirs = 0;
+
 /* The map for the object we will profile.  */
 struct link_map *_dl_profile_map;
47

48 49 50 51 52 53
diff --git a/elf/rtld.c b/elf/rtld.c
index ea3af55..75a2415 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -976,6 +976,15 @@ dl_main (const ElfW(Phdr) *phdr,
 	    --_dl_argc;
54
 	    ++_dl_argv;
55
 	  }
56
+	else if (! strcmp (_dl_argv[1], "--nodefaultdirs")
57 58 59 60 61 62
+		 && _dl_argc > 2)
+	  {
+	    GLRO(dl_no_default_dirs) = 1;
+
+	    ++_dl_skip_args;
+	    --_dl_argc;
63
+	    ++_dl_argv;
64
+	  }
65
 	else if (! strcmp (_dl_argv[1], "--library-path")
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
 		 && _dl_argc > 2)
 	  {
@@ -1034,6 +1043,7 @@ of this helper program; chances are you did not intend to run this program.\n\
   --list                list all dependencies and how they are resolved\n\
   --verify              verify that given object really is a dynamically linked\n\
 			object we can handle\n\
+  --nodefaultdirs       Do not search from default directories or cache\n\
   --inhibit-cache       Do not use " LD_SO_CACHE "\n\
   --library-path PATH   use given PATH instead of content of the environment\n\
 			variable LD_LIBRARY_PATH\n\
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 3116188..0759694 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -559,6 +559,8 @@ struct rtld_global_ro
      platforms.  */
   EXTERN uint64_t _dl_hwcap2;
83

84 85 86 87 88
+  EXTERN int _dl_no_default_dirs;
+
 #ifdef SHARED
   /* We add a function table to _rtld_global which is then used to
      call the function instead of going through the PLT.  The result