[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#908946: ldconfig: Default to the new format for ld.so.cache



Package: glibc
Version: 2.27-6
Tags: patch

glibc has supported the new ld.so.cache format for 18+ years, and the
old/compat versions date back to around the libc5 era. Switching to the
new format makes the cache smaller, and slightly faster to load.

The attached patch switches to the new format by default. I've also
submitted this patch upstream at
https://sourceware.org/bugzilla/show_bug.cgi?id=23668 .
diff --git a/debian/local/manpages/ldconfig.8 b/debian/local/manpages/ldconfig.8
index 505a1c84..d6722bc0 100644
--- a/debian/local/manpages/ldconfig.8
+++ b/debian/local/manpages/ldconfig.8
@@ -112,7 +112,7 @@ the current cache.
 .B \-c\ \-\-format=FORMAT
 Use
 .B FORMAT
-for the cache file. Choices are old, new and compat (the default).
+for the cache file. Choices are old, compat, and new (the default).
 .TP
 .B \-i \-\-ignore-aux-cache
 Ignore auxiliary cache file.
diff --git a/debian/patches/any/ldconfig-new-format.diff b/debian/patches/any/ldconfig-new-format.diff
new file mode 100644
index 00000000..b0f4126e
--- /dev/null
+++ b/debian/patches/any/ldconfig-new-format.diff
@@ -0,0 +1,74 @@
+From 1183d8acf478e36b7e427db295b9763859822c79 Mon Sep 17 00:00:00 2001
+From: Josh Triplett <josh@joshtriplett.org>
+Date: Sun, 16 Sep 2018 04:20:34 -0700
+Subject: [PATCH] Default to the new format for ld.so.cache
+
+glibc has supported this format for 18+ years.
+
+Reorder conditionals to look for the new format first.
+
+        * elf/ldconfig.c: Default to the new format for ld.so.cache. glibc has
+        supported this format for 18+ years.
+        * elf/dl-cache.c (_dl_load_cache_lookup): Reorder conditionals to look
+        for the new format first.
+---
+ elf/dl-cache.c | 16 ++++++++--------
+ elf/ldconfig.c |  4 ++--
+ 4 files changed, 20 insertions(+), 10 deletions(-)
+
+diff --git a/elf/dl-cache.c b/elf/dl-cache.c
+index 6ee5153ff9..75bd9d9536 100644
+--- a/elf/dl-cache.c
++++ b/elf/dl-cache.c
+@@ -203,7 +203,14 @@ _dl_load_cache_lookup (const char *name)
+ 	 - the old format with the new format in it
+ 	 - only the new format
+ 	 The following checks if the cache contains any of these formats.  */
+-      if (file != MAP_FAILED && cachesize > sizeof *cache
++      if (file != MAP_FAILED && cachesize > sizeof *cache_new
++	       && memcmp (file, CACHEMAGIC_VERSION_NEW,
++			  sizeof CACHEMAGIC_VERSION_NEW - 1) == 0)
++	{
++	  cache_new = file;
++	  cache = file;
++	}
++      else if (file != MAP_FAILED && cachesize > sizeof *cache
+ 	  && memcmp (file, CACHEMAGIC, sizeof CACHEMAGIC - 1) == 0)
+ 	{
+ 	  size_t offset;
+@@ -220,13 +227,6 @@ _dl_load_cache_lookup (const char *name)
+ 			 sizeof CACHEMAGIC_VERSION_NEW - 1) != 0)
+ 	    cache_new = (void *) -1;
+ 	}
+-      else if (file != MAP_FAILED && cachesize > sizeof *cache_new
+-	       && memcmp (file, CACHEMAGIC_VERSION_NEW,
+-			  sizeof CACHEMAGIC_VERSION_NEW - 1) == 0)
+-	{
+-	  cache_new = file;
+-	  cache = file;
+-	}
+       else
+ 	{
+ 	  if (file != MAP_FAILED)
+diff --git a/elf/ldconfig.c b/elf/ldconfig.c
+index fbdd814edf..1ce4a29566 100644
+--- a/elf/ldconfig.c
++++ b/elf/ldconfig.c
+@@ -95,7 +95,7 @@ int opt_verbose;
+
+ /* Format to support.  */
+ /* 0: only libc5/glibc2; 1: both; 2: only glibc 2.2.  */
+-int opt_format = 1;
++int opt_format = 2;
+
+ /* Build cache.  */
+ static int opt_build_cache = 1;
+@@ -148,7 +148,7 @@ static const struct argp_option options[] =
+   { NULL, 'f', N_("CONF"), 0, N_("Use CONF as configuration file"), 0},
+   { NULL, 'n', NULL, 0, N_("Only process directories specified on the command line.  Don't build cache."), 0},
+   { NULL, 'l', NULL, 0, N_("Manually link individual libraries."), 0},
+-  { "format", 'c', N_("FORMAT"), 0, N_("Format to use: new, old or compat (default)"), 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},
+   { NULL, 0, NULL, 0, NULL, 0 }
+ };
diff --git a/debian/patches/series b/debian/patches/series
index 54ab40df..e7c3f3ad 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -188,3 +188,4 @@ any/submitted-resolv-unaligned.diff
 any/submitted-intl-tstgettext.diff
 any/local-cudacc-float128.diff
 any/git-abilist-ignore-absolute.diff
+any/ldconfig-new-format.diff

Reply to: