unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob 9d578bb3d9f3923d674ea4fc11fdd545da47ff0e 4320 bytes (raw)
name: gnu/packages/patches/glibc-dl-cache.patch 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
 
Read the shared library cache relative to $ORIGIN instead of reading
from /etc/ld.so.cache.  Also arrange so that this cache takes
precedence over RUNPATH.

diff --git a/elf/dl-cache.c b/elf/dl-cache.c
index 93d185e788..6a2989bd4c 100644
--- a/elf/dl-cache.c
+++ b/elf/dl-cache.c
@@ -171,6 +171,33 @@ _dl_cache_libcmp (const char *p1, const char *p2)
   return *p1 - *p2;
 }
 
+/* Special value representing the lack of an ld.so cache.  */
+static const char ld_so_cache_lacking[] = "/ld.so cache is lacking";
+
+/* Return the per-application ld.so cache, relative to $ORIGIN, or NULL if
+   that fails for some reason.  Do not return the system-wide LD_SO_CACHE
+   since on a foreign distro it would contain invalid information.  */
+static const char *
+ld_so_cache (void)
+{
+  static const char *loader_cache;
+
+  if (loader_cache == NULL)
+    {
+      const char suffix[] = "/../etc/ld.so.cache";
+      const char *origin = _dl_get_origin ();
+
+      /* Note: We can't use 'malloc' because it can be interposed.  */
+      char *cache = alloca (strlen (origin) + sizeof suffix);
+
+      strcpy (cache, origin);
+      strcat (cache, suffix);
+
+      loader_cache = __strdup (cache) ?: ld_so_cache_lacking;
+    }
+
+  return loader_cache;
+}
 
 /* Look up NAME in ld.so.cache and return the file name stored there, or null
    if none is found.  The cache is loaded if it was not already.  If loading
@@ -190,12 +217,15 @@ _dl_load_cache_lookup (const char *name)
 
   /* Print a message if the loading of libs is traced.  */
   if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_LIBS))
-    _dl_debug_printf (" search cache=%s\n", LD_SO_CACHE);
+    _dl_debug_printf (" search cache=%s\n", ld_so_cache ());
+
+  if (__glibc_unlikely (ld_so_cache () == ld_so_cache_lacking))
+    return NULL;
 
   if (cache == NULL)
     {
       /* Read the contents of the file.  */
-      void *file = _dl_sysdep_read_whole_file (LD_SO_CACHE, &cachesize,
+      void *file = _dl_sysdep_read_whole_file (ld_so_cache (), &cachesize,
 					       PROT_READ);
 
       /* We can handle three different cache file formats here:
diff --git a/elf/dl-load.c b/elf/dl-load.c
index f3201e7c14..a69aec3428 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -2152,28 +2152,6 @@ _dl_map_object (struct link_map *loader, const char *name,
 			loader ?: GL(dl_ns)[LM_ID_BASE]._ns_loaded,
 			LA_SER_LIBPATH, &found_other_class);
 
-      /* Look at the RUNPATH information for this binary.  */
-      if (fd == -1 && loader != NULL
-	  && cache_rpath (loader, &loader->l_runpath_dirs,
-			  DT_RUNPATH, "RUNPATH"))
-	fd = open_path (name, namelen, mode,
-			&loader->l_runpath_dirs, &realname, &fb, loader,
-			LA_SER_RUNPATH, &found_other_class);
-
-      if (fd == -1)
-        {
-          realname = _dl_sysdep_open_object (name, namelen, &fd);
-          if (realname != NULL)
-            {
-              fd = open_verify (realname, fd,
-                                &fb, loader ?: GL(dl_ns)[nsid]._ns_loaded,
-                                LA_SER_CONFIG, mode, &found_other_class,
-                                false);
-              if (fd == -1)
-                free (realname);
-            }
-        }
-
 #ifdef USE_LDCONFIG
       if (fd == -1
 	  && (__glibc_likely ((mode & __RTLD_SECURE) == 0)
@@ -2232,6 +2210,28 @@ _dl_map_object (struct link_map *loader, const char *name,
 	}
 #endif
 
+      /* Look at the RUNPATH information for this binary.  */
+      if (fd == -1 && loader != NULL
+	  && cache_rpath (loader, &loader->l_runpath_dirs,
+			  DT_RUNPATH, "RUNPATH"))
+	fd = open_path (name, namelen, mode,
+			&loader->l_runpath_dirs, &realname, &fb, loader,
+			LA_SER_RUNPATH, &found_other_class);
+
+      if (fd == -1)
+        {
+          realname = _dl_sysdep_open_object (name, namelen, &fd);
+          if (realname != NULL)
+            {
+              fd = open_verify (realname, fd,
+                                &fb, loader ?: GL(dl_ns)[nsid]._ns_loaded,
+                                LA_SER_CONFIG, mode, &found_other_class,
+                                false);
+              if (fd == -1)
+                free (realname);
+            }
+        }
+
       /* Finally, try the default path.  */
       if (fd == -1
 	  && ((l = loader ?: GL(dl_ns)[nsid]._ns_loaded) == NULL

debug log:

solving 9d578bb3d9 ...
found 9d578bb3d9 in https://yhetil.org/guix-patches/20201127090523.3853-1-ludo@gnu.org/

applying [1/1] https://yhetil.org/guix-patches/20201127090523.3853-1-ludo@gnu.org/
diff --git a/gnu/packages/patches/glibc-dl-cache.patch b/gnu/packages/patches/glibc-dl-cache.patch
new file mode 100644
index 0000000000..9d578bb3d9

1:18: trailing whitespace.
 
1:46: trailing whitespace.
 
1:50: trailing whitespace.
 
1:58: trailing whitespace.
 
1:64: space before tab in indent.
 					       PROT_READ);
Checking patch gnu/packages/patches/glibc-dl-cache.patch...
Applied patch gnu/packages/patches/glibc-dl-cache.patch cleanly.
warning: squelched 8 whitespace errors
warning: 13 lines add whitespace errors.

index at:
100644 9d578bb3d9f3923d674ea4fc11fdd545da47ff0e	gnu/packages/patches/glibc-dl-cache.patch

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).