]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
elf: Introduce enum opt_format in the ldconfig implementation
authorFlorian Weimer <fweimer@redhat.com>
Thu, 26 Nov 2020 15:59:44 +0000 (16:59 +0100)
committerFlorian Weimer <fweimer@redhat.com>
Thu, 26 Nov 2020 17:26:52 +0000 (18:26 +0100)
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
elf/cache.c
elf/ldconfig.c
sysdeps/generic/ldconfig.h

index 1eb1455883a72a38b327e10a4d5f507ba5733ce8..c241c17ef9061a7c5ef41fd49dbb9dd624466c76 100644 (file)
@@ -321,13 +321,13 @@ save_cache (const char *cache_name)
   struct cache_file *file_entries = NULL;
   size_t file_entries_size = 0;
 
-  if (opt_format != 2)
+  if (opt_format != opt_format_new)
     {
       /* struct cache_file_new is 64-bit aligned on some arches while
         only 32-bit aligned on other arches.  Duplicate last old
         cache entry so that new cache in ld.so.cache can be used by
         both.  */
-      if (opt_format != 0)
+      if (opt_format != opt_format_old)
        cache_entry_old_count = (cache_entry_old_count + 1) & ~1;
 
       /* And the list of all entries in the old format.  */
@@ -345,7 +345,7 @@ save_cache (const char *cache_name)
   struct cache_file_new *file_entries_new = NULL;
   size_t file_entries_new_size = 0;
 
-  if (opt_format != 0)
+  if (opt_format != opt_format_old)
     {
       /* And the list of all entries in the new format.  */
       file_entries_new_size = sizeof (struct cache_file_new)
@@ -370,7 +370,7 @@ save_cache (const char *cache_name)
      table, we have to adjust all string indices for this so that
      old libc5/glibc 2 dynamic linkers just ignore them.  */
   unsigned int str_offset;
-  if (opt_format != 0)
+  if (opt_format != opt_format_old)
     str_offset = file_entries_new_size;
   else
     str_offset = 0;
@@ -385,13 +385,13 @@ save_cache (const char *cache_name)
        entry = entry->next, ++idx_new)
     {
       /* First the library.  */
-      if (opt_format != 2 && entry->hwcap == 0)
+      if (opt_format != opt_format_new && entry->hwcap == 0)
        {
          file_entries->libs[idx_old].flags = entry->flags;
          /* XXX: Actually we can optimize here and remove duplicates.  */
          file_entries->libs[idx_old].key = str_offset + pad;
        }
-      if (opt_format != 0)
+      if (opt_format != opt_format_old)
        {
          /* We could subtract file_entries_new_size from str_offset -
             not doing so makes the code easier, the string table
@@ -407,9 +407,9 @@ save_cache (const char *cache_name)
       str = mempcpy (str, entry->lib, len);
       str_offset += len;
       /* Then the path.  */
-      if (opt_format != 2 && entry->hwcap == 0)
+      if (opt_format != opt_format_new && entry->hwcap == 0)
        file_entries->libs[idx_old].value = str_offset + pad;
-      if (opt_format != 0)
+      if (opt_format != opt_format_old)
        file_entries_new->libs[idx_new].value = str_offset;
       len = strlen (entry->path) + 1;
       str = mempcpy (str, entry->path, len);
@@ -420,7 +420,7 @@ save_cache (const char *cache_name)
     }
 
   /* Duplicate last old cache entry if needed.  */
-  if (opt_format != 2
+  if (opt_format != opt_format_new
       && idx_old < cache_entry_old_count)
     file_entries->libs[idx_old] = file_entries->libs[idx_old - 1];
 
@@ -438,16 +438,16 @@ save_cache (const char *cache_name)
           temp_name);
 
   /* Write contents.  */
-  if (opt_format != 2)
+  if (opt_format != opt_format_new)
     {
       if (write (fd, file_entries, file_entries_size)
          != (ssize_t) file_entries_size)
        error (EXIT_FAILURE, errno, _("Writing of cache data failed"));
     }
-  if (opt_format != 0)
+  if (opt_format != opt_format_old)
     {
       /* Align cache.  */
-      if (opt_format != 2)
+      if (opt_format != opt_format_new)
        {
          char zero[pad];
          memset (zero, '\0', pad);
index 3768267baca1d0f47ba4a36416110322e8c74d0a..006198fe5919d69e4d6c5f6e6ffbb211fc1d3e3e 100644 (file)
@@ -100,8 +100,7 @@ static int opt_print_cache;
 int opt_verbose;
 
 /* Format to support.  */
-/* 0: only libc5/glibc2; 1: both; 2: only glibc 2.2.  */
-int opt_format = 2;
+enum opt_format opt_format = opt_format_new;
 
 /* Build cache.  */
 static int opt_build_cache = 1;
@@ -281,11 +280,11 @@ parse_opt (int key, char *arg, struct argp_state *state)
       break;
     case 'c':
       if (strcmp (arg, "old") == 0)
-       opt_format = 0;
+       opt_format = opt_format_old;
       else if (strcmp (arg, "compat") == 0)
-       opt_format = 1;
+       opt_format = opt_format_compat;
       else if (strcmp (arg, "new") == 0)
-       opt_format = 2;
+       opt_format = opt_format_new;
       break;
     default:
       return ARGP_ERR_UNKNOWN;
index b64aab0064f4e4ca0f1141d2bf727d066c4bf767..cfec9d4668050244baa72bba1383cb105f15cda4 100644 (file)
@@ -90,7 +90,14 @@ extern char *chroot_canon (const char *chroot, const char *name);
 /* Declared in ldconfig.c.  */
 extern int opt_verbose;
 
-extern int opt_format;
+enum opt_format
+  {
+    opt_format_old = 0,        /* Use struct cache_file.  */
+    opt_format_compat = 1, /* Use both, old format followed by new.  */
+    opt_format_new = 2,        /* Use struct cache_file_new.  */
+  };
+
+extern enum opt_format opt_format;
 
 /* Prototypes for a few program-wide used functions.  */
 #include <programs/xmalloc.h>