|
|
e354a5 |
commit b44ac4f4c7a8bbe5eaa2701aa9452eaf2c96e1dd
|
|
|
e354a5 |
Author: Florian Weimer <fweimer@redhat.com>
|
|
|
e354a5 |
Date: Fri Dec 4 09:13:43 2020 +0100
|
|
|
e354a5 |
|
|
|
e354a5 |
elf: Process glibc-hwcaps subdirectories in ldconfig
|
|
|
e354a5 |
|
|
|
e354a5 |
Libraries from these subdirectories are added to the cache
|
|
|
e354a5 |
with a special hwcap bit DL_CACHE_HWCAP_EXTENSION, so that
|
|
|
e354a5 |
they are ignored by older dynamic loaders.
|
|
|
e354a5 |
|
|
|
e354a5 |
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
|
|
|
e354a5 |
|
|
|
e354a5 |
diff --git a/elf/cache.c b/elf/cache.c
|
|
|
e354a5 |
index f773cacacf26db1c..dde3d7fefa4105f9 100644
|
|
|
e354a5 |
--- a/elf/cache.c
|
|
|
e354a5 |
+++ b/elf/cache.c
|
|
|
e354a5 |
@@ -40,6 +40,105 @@
|
|
|
e354a5 |
/* Used to store library names, paths, and other strings. */
|
|
|
e354a5 |
static struct stringtable strings;
|
|
|
e354a5 |
|
|
|
e354a5 |
+/* Keeping track of "glibc-hwcaps" subdirectories. During cache
|
|
|
e354a5 |
+ construction, a linear search by name is performed to deduplicate
|
|
|
e354a5 |
+ entries. */
|
|
|
e354a5 |
+struct glibc_hwcaps_subdirectory
|
|
|
e354a5 |
+{
|
|
|
e354a5 |
+ struct glibc_hwcaps_subdirectory *next;
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ /* Interned string with the subdirectory name. */
|
|
|
e354a5 |
+ struct stringtable_entry *name;
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ /* Array index in the cache_extension_tag_glibc_hwcaps section in
|
|
|
e354a5 |
+ the stored cached file. This is computed after all the
|
|
|
e354a5 |
+ subdirectories have been processed, so that subdirectory names in
|
|
|
e354a5 |
+ the extension section can be sorted. */
|
|
|
e354a5 |
+ uint32_t section_index;
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ /* True if the subdirectory is actually used for anything. */
|
|
|
e354a5 |
+ bool used;
|
|
|
e354a5 |
+};
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+const char *
|
|
|
e354a5 |
+glibc_hwcaps_subdirectory_name (const struct glibc_hwcaps_subdirectory *dir)
|
|
|
e354a5 |
+{
|
|
|
e354a5 |
+ return dir->name->string;
|
|
|
e354a5 |
+}
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+/* Linked list of known hwcaps subdirecty names. */
|
|
|
e354a5 |
+static struct glibc_hwcaps_subdirectory *hwcaps;
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+struct glibc_hwcaps_subdirectory *
|
|
|
e354a5 |
+new_glibc_hwcaps_subdirectory (const char *name)
|
|
|
e354a5 |
+{
|
|
|
e354a5 |
+ struct stringtable_entry *name_interned = stringtable_add (&strings, name);
|
|
|
e354a5 |
+ for (struct glibc_hwcaps_subdirectory *p = hwcaps; p != NULL; p = p->next)
|
|
|
e354a5 |
+ if (p->name == name_interned)
|
|
|
e354a5 |
+ return p;
|
|
|
e354a5 |
+ struct glibc_hwcaps_subdirectory *p = xmalloc (sizeof (*p));
|
|
|
e354a5 |
+ p->next = hwcaps;
|
|
|
e354a5 |
+ p->name = name_interned;
|
|
|
e354a5 |
+ p->section_index = 0;
|
|
|
e354a5 |
+ p->used = false;
|
|
|
e354a5 |
+ hwcaps = p;
|
|
|
e354a5 |
+ return p;
|
|
|
e354a5 |
+}
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+/* Helper for sorting struct glibc_hwcaps_subdirectory elements by
|
|
|
e354a5 |
+ name. */
|
|
|
e354a5 |
+static int
|
|
|
e354a5 |
+assign_glibc_hwcaps_indices_compare (const void *l, const void *r)
|
|
|
e354a5 |
+{
|
|
|
e354a5 |
+ const struct glibc_hwcaps_subdirectory *left
|
|
|
e354a5 |
+ = *(struct glibc_hwcaps_subdirectory **)l;
|
|
|
e354a5 |
+ const struct glibc_hwcaps_subdirectory *right
|
|
|
e354a5 |
+ = *(struct glibc_hwcaps_subdirectory **)r;
|
|
|
e354a5 |
+ return strcmp (glibc_hwcaps_subdirectory_name (left),
|
|
|
e354a5 |
+ glibc_hwcaps_subdirectory_name (right));
|
|
|
e354a5 |
+}
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+/* Count the number of hwcaps subdirectories which are actually
|
|
|
e354a5 |
+ used. */
|
|
|
e354a5 |
+static size_t
|
|
|
e354a5 |
+glibc_hwcaps_count (void)
|
|
|
e354a5 |
+{
|
|
|
e354a5 |
+ size_t count = 0;
|
|
|
e354a5 |
+ for (struct glibc_hwcaps_subdirectory *p = hwcaps; p != NULL; p = p->next)
|
|
|
e354a5 |
+ if (p->used)
|
|
|
e354a5 |
+ ++count;
|
|
|
e354a5 |
+ return count;
|
|
|
e354a5 |
+}
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+/* Compute the section_index fields for all */
|
|
|
e354a5 |
+static void
|
|
|
e354a5 |
+assign_glibc_hwcaps_indices (void)
|
|
|
e354a5 |
+{
|
|
|
e354a5 |
+ /* Convert the linked list into an array, so that we can use qsort.
|
|
|
e354a5 |
+ Only copy the subdirectories which are actually used. */
|
|
|
e354a5 |
+ size_t count = glibc_hwcaps_count ();
|
|
|
e354a5 |
+ struct glibc_hwcaps_subdirectory **array
|
|
|
e354a5 |
+ = xmalloc (sizeof (*array) * count);
|
|
|
e354a5 |
+ {
|
|
|
e354a5 |
+ size_t i = 0;
|
|
|
e354a5 |
+ for (struct glibc_hwcaps_subdirectory *p = hwcaps; p != NULL; p = p->next)
|
|
|
e354a5 |
+ if (p->used)
|
|
|
e354a5 |
+ {
|
|
|
e354a5 |
+ array[i] = p;
|
|
|
e354a5 |
+ ++i;
|
|
|
e354a5 |
+ }
|
|
|
e354a5 |
+ assert (i == count);
|
|
|
e354a5 |
+ }
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ qsort (array, count, sizeof (*array), assign_glibc_hwcaps_indices_compare);
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ /* Assign the array indices. */
|
|
|
e354a5 |
+ for (size_t i = 0; i < count; ++i)
|
|
|
e354a5 |
+ array[i]->section_index = i;
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ free (array);
|
|
|
e354a5 |
+}
|
|
|
e354a5 |
+
|
|
|
e354a5 |
struct cache_entry
|
|
|
e354a5 |
{
|
|
|
e354a5 |
struct stringtable_entry *lib; /* Library name. */
|
|
|
e354a5 |
@@ -48,6 +147,10 @@ struct cache_entry
|
|
|
e354a5 |
unsigned int osversion; /* Required OS version. */
|
|
|
e354a5 |
uint64_t hwcap; /* Important hardware capabilities. */
|
|
|
e354a5 |
int bits_hwcap; /* Number of bits set in hwcap. */
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ /* glibc-hwcaps subdirectory. If not NULL, hwcap must be zero. */
|
|
|
e354a5 |
+ struct glibc_hwcaps_subdirectory *hwcaps;
|
|
|
e354a5 |
+
|
|
|
e354a5 |
struct cache_entry *next; /* Next entry in list. */
|
|
|
e354a5 |
};
|
|
|
e354a5 |
|
|
|
e354a5 |
@@ -60,7 +163,7 @@ static const char *flag_descr[] =
|
|
|
e354a5 |
/* Print a single entry. */
|
|
|
e354a5 |
static void
|
|
|
e354a5 |
print_entry (const char *lib, int flag, unsigned int osversion,
|
|
|
e354a5 |
- uint64_t hwcap, const char *key)
|
|
|
e354a5 |
+ uint64_t hwcap, const char *hwcap_string, const char *key)
|
|
|
e354a5 |
{
|
|
|
e354a5 |
printf ("\t%s (", lib);
|
|
|
e354a5 |
switch (flag & FLAG_TYPE_MASK)
|
|
|
e354a5 |
@@ -132,7 +235,9 @@ print_entry (const char *lib, int flag, unsigned int osversion,
|
|
|
e354a5 |
printf (",%d", flag & FLAG_REQUIRED_MASK);
|
|
|
e354a5 |
break;
|
|
|
e354a5 |
}
|
|
|
e354a5 |
- if (hwcap != 0)
|
|
|
e354a5 |
+ if (hwcap_string != NULL)
|
|
|
e354a5 |
+ printf (", hwcap: \"%s\"", hwcap_string);
|
|
|
e354a5 |
+ else if (hwcap != 0)
|
|
|
e354a5 |
printf (", hwcap: %#.16" PRIx64, hwcap);
|
|
|
e354a5 |
if (osversion != 0)
|
|
|
e354a5 |
{
|
|
|
e354a5 |
@@ -158,6 +263,29 @@ print_entry (const char *lib, int flag, unsigned int osversion,
|
|
|
e354a5 |
printf (") => %s\n", key);
|
|
|
e354a5 |
}
|
|
|
e354a5 |
|
|
|
e354a5 |
+/* Returns the string with the name of the glibcs-hwcaps subdirectory
|
|
|
e354a5 |
+ associated with ENTRY->hwcap. file_base must be the base address
|
|
|
e354a5 |
+ for string table indices. */
|
|
|
e354a5 |
+static const char *
|
|
|
e354a5 |
+glibc_hwcaps_string (struct cache_extension_all_loaded *ext,
|
|
|
e354a5 |
+ const void *file_base, size_t file_size,
|
|
|
e354a5 |
+ struct file_entry_new *entry)
|
|
|
e354a5 |
+{
|
|
|
e354a5 |
+ const uint32_t *hwcaps_array
|
|
|
e354a5 |
+ = ext->sections[cache_extension_tag_glibc_hwcaps].base;
|
|
|
e354a5 |
+ if (dl_cache_hwcap_extension (entry) && hwcaps_array != NULL)
|
|
|
e354a5 |
+ {
|
|
|
e354a5 |
+ uint32_t index = (uint32_t) entry->hwcap;
|
|
|
e354a5 |
+ if (index < ext->sections[cache_extension_tag_glibc_hwcaps].size / 4)
|
|
|
e354a5 |
+ {
|
|
|
e354a5 |
+ uint32_t string_table_index = hwcaps_array[index];
|
|
|
e354a5 |
+ if (string_table_index < file_size)
|
|
|
e354a5 |
+ return file_base + string_table_index;
|
|
|
e354a5 |
+ }
|
|
|
e354a5 |
+ }
|
|
|
e354a5 |
+ return NULL;
|
|
|
e354a5 |
+}
|
|
|
e354a5 |
+
|
|
|
e354a5 |
/* Print an error and exit if the new-file cache is internally
|
|
|
e354a5 |
inconsistent. */
|
|
|
e354a5 |
static void
|
|
|
e354a5 |
@@ -167,9 +295,7 @@ check_new_cache (struct cache_file_new *cache)
|
|
|
e354a5 |
error (EXIT_FAILURE, 0, _("Cache file has wrong endianness.\n"));
|
|
|
e354a5 |
}
|
|
|
e354a5 |
|
|
|
e354a5 |
-/* Print the extension information at the cache at start address
|
|
|
e354a5 |
- FILE_BASE, of length FILE_SIZE bytes. The new-format cache header
|
|
|
e354a5 |
- is at CACHE, and the file name for diagnostics is CACHE_NAME. */
|
|
|
e354a5 |
+/* Print the extension information in *EXT. */
|
|
|
e354a5 |
static void
|
|
|
e354a5 |
print_extensions (struct cache_extension_all_loaded *ext)
|
|
|
e354a5 |
{
|
|
|
e354a5 |
@@ -266,7 +392,7 @@ print_cache (const char *cache_name)
|
|
|
e354a5 |
/* Print everything. */
|
|
|
e354a5 |
for (unsigned int i = 0; i < cache->nlibs; i++)
|
|
|
e354a5 |
print_entry (cache_data + cache->libs[i].key,
|
|
|
e354a5 |
- cache->libs[i].flags, 0, 0,
|
|
|
e354a5 |
+ cache->libs[i].flags, 0, 0, NULL,
|
|
|
e354a5 |
cache_data + cache->libs[i].value);
|
|
|
e354a5 |
}
|
|
|
e354a5 |
else if (format == 1)
|
|
|
e354a5 |
@@ -281,11 +407,16 @@ print_cache (const char *cache_name)
|
|
|
e354a5 |
|
|
|
e354a5 |
/* Print everything. */
|
|
|
e354a5 |
for (unsigned int i = 0; i < cache_new->nlibs; i++)
|
|
|
e354a5 |
- print_entry (cache_data + cache_new->libs[i].key,
|
|
|
e354a5 |
- cache_new->libs[i].flags,
|
|
|
e354a5 |
- cache_new->libs[i].osversion,
|
|
|
e354a5 |
- cache_new->libs[i].hwcap,
|
|
|
e354a5 |
- cache_data + cache_new->libs[i].value);
|
|
|
e354a5 |
+ {
|
|
|
e354a5 |
+ const char *hwcaps_string
|
|
|
e354a5 |
+ = glibc_hwcaps_string (&ext, cache, cache_size,
|
|
|
e354a5 |
+ &cache_new->libs[i]);
|
|
|
e354a5 |
+ print_entry (cache_data + cache_new->libs[i].key,
|
|
|
e354a5 |
+ cache_new->libs[i].flags,
|
|
|
e354a5 |
+ cache_new->libs[i].osversion,
|
|
|
e354a5 |
+ cache_new->libs[i].hwcap, hwcaps_string,
|
|
|
e354a5 |
+ cache_data + cache_new->libs[i].value);
|
|
|
e354a5 |
+ }
|
|
|
e354a5 |
print_extensions (&ext;;
|
|
|
e354a5 |
}
|
|
|
e354a5 |
/* Cleanup. */
|
|
|
e354a5 |
@@ -311,8 +442,23 @@ compare (const struct cache_entry *e1, const struct cache_entry *e2)
|
|
|
e354a5 |
return 1;
|
|
|
e354a5 |
else if (e1->flags > e2->flags)
|
|
|
e354a5 |
return -1;
|
|
|
e354a5 |
+ /* Keep the glibc-hwcaps extension entries before the regular
|
|
|
e354a5 |
+ entries, and sort them by their names. search_cache in
|
|
|
e354a5 |
+ dl-cache.c stops searching once the first non-extension entry
|
|
|
e354a5 |
+ is found, so the extension entries need to come first. */
|
|
|
e354a5 |
+ else if (e1->hwcaps != NULL && e2->hwcaps == NULL)
|
|
|
e354a5 |
+ return -1;
|
|
|
e354a5 |
+ else if (e1->hwcaps == NULL && e2->hwcaps != NULL)
|
|
|
e354a5 |
+ return 1;
|
|
|
e354a5 |
+ else if (e1->hwcaps != NULL && e2->hwcaps != NULL)
|
|
|
e354a5 |
+ {
|
|
|
e354a5 |
+ res = strcmp (glibc_hwcaps_subdirectory_name (e1->hwcaps),
|
|
|
e354a5 |
+ glibc_hwcaps_subdirectory_name (e2->hwcaps));
|
|
|
e354a5 |
+ if (res != 0)
|
|
|
e354a5 |
+ return res;
|
|
|
e354a5 |
+ }
|
|
|
e354a5 |
/* Sort by most specific hwcap. */
|
|
|
e354a5 |
- else if (e2->bits_hwcap > e1->bits_hwcap)
|
|
|
e354a5 |
+ if (e2->bits_hwcap > e1->bits_hwcap)
|
|
|
e354a5 |
return 1;
|
|
|
e354a5 |
else if (e2->bits_hwcap < e1->bits_hwcap)
|
|
|
e354a5 |
return -1;
|
|
|
e354a5 |
@@ -337,30 +483,65 @@ enum
|
|
|
e354a5 |
* sizeof (struct cache_extension_section)))
|
|
|
e354a5 |
};
|
|
|
e354a5 |
|
|
|
e354a5 |
-/* Write the cache extensions to FD. The extension directory is
|
|
|
e354a5 |
- assumed to be located at CACHE_EXTENSION_OFFSET. */
|
|
|
e354a5 |
+/* Write the cache extensions to FD. The string table is shifted by
|
|
|
e354a5 |
+ STRING_TABLE_OFFSET. The extension directory is assumed to be
|
|
|
e354a5 |
+ located at CACHE_EXTENSION_OFFSET. assign_glibc_hwcaps_indices
|
|
|
e354a5 |
+ must have been called. */
|
|
|
e354a5 |
static void
|
|
|
e354a5 |
-write_extensions (int fd, uint32_t cache_extension_offset)
|
|
|
e354a5 |
+write_extensions (int fd, uint32_t str_offset,
|
|
|
e354a5 |
+ uint32_t cache_extension_offset)
|
|
|
e354a5 |
{
|
|
|
e354a5 |
assert ((cache_extension_offset % 4) == 0);
|
|
|
e354a5 |
|
|
|
e354a5 |
+ /* The length and contents of the glibc-hwcaps section. */
|
|
|
e354a5 |
+ uint32_t hwcaps_count = glibc_hwcaps_count ();
|
|
|
e354a5 |
+ uint32_t hwcaps_offset = cache_extension_offset + cache_extension_size;
|
|
|
e354a5 |
+ uint32_t hwcaps_size = hwcaps_count * sizeof (uint32_t);
|
|
|
e354a5 |
+ uint32_t *hwcaps_array = xmalloc (hwcaps_size);
|
|
|
e354a5 |
+ for (struct glibc_hwcaps_subdirectory *p = hwcaps; p != NULL; p = p->next)
|
|
|
e354a5 |
+ if (p->used)
|
|
|
e354a5 |
+ hwcaps_array[p->section_index] = str_offset + p->name->offset;
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ /* This is the offset of the generator string. */
|
|
|
e354a5 |
+ uint32_t generator_offset = hwcaps_offset;
|
|
|
e354a5 |
+ if (hwcaps_count == 0)
|
|
|
e354a5 |
+ /* There is no section for the hwcaps subdirectories. */
|
|
|
e354a5 |
+ generator_offset -= sizeof (struct cache_extension_section);
|
|
|
e354a5 |
+ else
|
|
|
e354a5 |
+ /* The string table indices for the hwcaps subdirectories shift
|
|
|
e354a5 |
+ the generator string backwards. */
|
|
|
e354a5 |
+ generator_offset += hwcaps_size;
|
|
|
e354a5 |
+
|
|
|
e354a5 |
struct cache_extension *ext = xmalloc (cache_extension_size);
|
|
|
e354a5 |
ext->magic = cache_extension_magic;
|
|
|
e354a5 |
- ext->count = cache_extension_count;
|
|
|
e354a5 |
|
|
|
e354a5 |
- for (int i = 0; i < cache_extension_count; ++i)
|
|
|
e354a5 |
- {
|
|
|
e354a5 |
- ext->sections[i].tag = i;
|
|
|
e354a5 |
- ext->sections[i].flags = 0;
|
|
|
e354a5 |
- }
|
|
|
e354a5 |
+ /* Extension index current being filled. */
|
|
|
e354a5 |
+ size_t xid = 0;
|
|
|
e354a5 |
|
|
|
e354a5 |
const char *generator
|
|
|
e354a5 |
= "ldconfig " PKGVERSION RELEASE " release version " VERSION;
|
|
|
e354a5 |
- ext->sections[cache_extension_tag_generator].offset
|
|
|
e354a5 |
- = cache_extension_offset + cache_extension_size;
|
|
|
e354a5 |
- ext->sections[cache_extension_tag_generator].size = strlen (generator);
|
|
|
e354a5 |
+ ext->sections[xid].tag = cache_extension_tag_generator;
|
|
|
e354a5 |
+ ext->sections[xid].flags = 0;
|
|
|
e354a5 |
+ ext->sections[xid].offset = generator_offset;
|
|
|
e354a5 |
+ ext->sections[xid].size = strlen (generator);
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ if (hwcaps_count > 0)
|
|
|
e354a5 |
+ {
|
|
|
e354a5 |
+ ++xid;
|
|
|
e354a5 |
+ ext->sections[xid].tag = cache_extension_tag_glibc_hwcaps;
|
|
|
e354a5 |
+ ext->sections[xid].flags = 0;
|
|
|
e354a5 |
+ ext->sections[xid].offset = hwcaps_offset;
|
|
|
e354a5 |
+ ext->sections[xid].size = hwcaps_size;
|
|
|
e354a5 |
+ }
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ ++xid;
|
|
|
e354a5 |
+ ext->count = xid;
|
|
|
e354a5 |
+ assert (xid <= cache_extension_count);
|
|
|
e354a5 |
|
|
|
e354a5 |
- if (write (fd, ext, cache_extension_size) != cache_extension_size
|
|
|
e354a5 |
+ size_t ext_size = (offsetof (struct cache_extension, sections)
|
|
|
e354a5 |
+ + xid * sizeof (struct cache_extension_section));
|
|
|
e354a5 |
+ if (write (fd, ext, ext_size) != ext_size
|
|
|
e354a5 |
+ || write (fd, hwcaps_array, hwcaps_size) != hwcaps_size
|
|
|
e354a5 |
|| write (fd, generator, strlen (generator)) != strlen (generator))
|
|
|
e354a5 |
error (EXIT_FAILURE, errno, _("Writing of cache extension data failed"));
|
|
|
e354a5 |
|
|
|
e354a5 |
@@ -373,6 +554,8 @@ save_cache (const char *cache_name)
|
|
|
e354a5 |
{
|
|
|
e354a5 |
/* The cache entries are sorted already, save them in this order. */
|
|
|
e354a5 |
|
|
|
e354a5 |
+ assign_glibc_hwcaps_indices ();
|
|
|
e354a5 |
+
|
|
|
e354a5 |
struct cache_entry *entry;
|
|
|
e354a5 |
/* Number of cache entries. */
|
|
|
e354a5 |
int cache_entry_count = 0;
|
|
|
e354a5 |
@@ -474,7 +657,11 @@ save_cache (const char *cache_name)
|
|
|
e354a5 |
struct. */
|
|
|
e354a5 |
file_entries_new->libs[idx_new].flags = entry->flags;
|
|
|
e354a5 |
file_entries_new->libs[idx_new].osversion = entry->osversion;
|
|
|
e354a5 |
- file_entries_new->libs[idx_new].hwcap = entry->hwcap;
|
|
|
e354a5 |
+ if (entry->hwcaps == NULL)
|
|
|
e354a5 |
+ file_entries_new->libs[idx_new].hwcap = entry->hwcap;
|
|
|
e354a5 |
+ else
|
|
|
e354a5 |
+ file_entries_new->libs[idx_new].hwcap
|
|
|
e354a5 |
+ = DL_CACHE_HWCAP_EXTENSION | entry->hwcaps->section_index;
|
|
|
e354a5 |
file_entries_new->libs[idx_new].key
|
|
|
e354a5 |
= str_offset + entry->lib->offset;
|
|
|
e354a5 |
file_entries_new->libs[idx_new].value
|
|
|
e354a5 |
@@ -554,7 +741,7 @@ save_cache (const char *cache_name)
|
|
|
e354a5 |
/* Align file position to 4. */
|
|
|
e354a5 |
off64_t old_offset = lseek64 (fd, extension_offset, SEEK_SET);
|
|
|
e354a5 |
assert ((unsigned long long int) (extension_offset - old_offset) < 4);
|
|
|
e354a5 |
- write_extensions (fd, extension_offset);
|
|
|
e354a5 |
+ write_extensions (fd, str_offset, extension_offset);
|
|
|
e354a5 |
}
|
|
|
e354a5 |
|
|
|
e354a5 |
/* Make sure user can always read cache file */
|
|
|
e354a5 |
@@ -588,27 +775,35 @@ save_cache (const char *cache_name)
|
|
|
e354a5 |
|
|
|
e354a5 |
/* Add one library to the cache. */
|
|
|
e354a5 |
void
|
|
|
e354a5 |
-add_to_cache (const char *path, const char *lib, int flags,
|
|
|
e354a5 |
- unsigned int osversion, uint64_t hwcap)
|
|
|
e354a5 |
+add_to_cache (const char *path, const char *filename, const char *soname,
|
|
|
e354a5 |
+ int flags, unsigned int osversion, uint64_t hwcap,
|
|
|
e354a5 |
+ struct glibc_hwcaps_subdirectory *hwcaps)
|
|
|
e354a5 |
{
|
|
|
e354a5 |
struct cache_entry *new_entry = xmalloc (sizeof (*new_entry));
|
|
|
e354a5 |
|
|
|
e354a5 |
struct stringtable_entry *path_interned;
|
|
|
e354a5 |
{
|
|
|
e354a5 |
char *p;
|
|
|
e354a5 |
- if (asprintf (&p, "%s/%s", path, lib) < 0)
|
|
|
e354a5 |
+ if (asprintf (&p, "%s/%s", path, filename) < 0)
|
|
|
e354a5 |
error (EXIT_FAILURE, errno, _("Could not create library path"));
|
|
|
e354a5 |
path_interned = stringtable_add (&strings, p);
|
|
|
e354a5 |
free (p);
|
|
|
e354a5 |
}
|
|
|
e354a5 |
|
|
|
e354a5 |
- new_entry->lib = stringtable_add (&strings, lib);
|
|
|
e354a5 |
+ new_entry->lib = stringtable_add (&strings, soname);
|
|
|
e354a5 |
new_entry->path = path_interned;
|
|
|
e354a5 |
new_entry->flags = flags;
|
|
|
e354a5 |
new_entry->osversion = osversion;
|
|
|
e354a5 |
new_entry->hwcap = hwcap;
|
|
|
e354a5 |
+ new_entry->hwcaps = hwcaps;
|
|
|
e354a5 |
new_entry->bits_hwcap = 0;
|
|
|
e354a5 |
|
|
|
e354a5 |
+ if (hwcaps != NULL)
|
|
|
e354a5 |
+ {
|
|
|
e354a5 |
+ assert (hwcap == 0);
|
|
|
e354a5 |
+ hwcaps->used = true;
|
|
|
e354a5 |
+ }
|
|
|
e354a5 |
+
|
|
|
e354a5 |
/* Count the number of bits set in the masked value. */
|
|
|
e354a5 |
for (size_t i = 0;
|
|
|
e354a5 |
(~((1ULL << i) - 1) & hwcap) != 0 && i < 8 * sizeof (hwcap); ++i)
|
|
|
e354a5 |
diff --git a/elf/ldconfig.c b/elf/ldconfig.c
|
|
|
e354a5 |
index 0fa5aef83f9cd86c..8c66d7e5426d8cc4 100644
|
|
|
e354a5 |
--- a/elf/ldconfig.c
|
|
|
e354a5 |
+++ b/elf/ldconfig.c
|
|
|
e354a5 |
@@ -16,6 +16,7 @@
|
|
|
e354a5 |
along with this program; if not, see <http://www.gnu.org/licenses/>. */
|
|
|
e354a5 |
|
|
|
e354a5 |
#define PROCINFO_CLASS static
|
|
|
e354a5 |
+#include <assert.h>
|
|
|
e354a5 |
#include <alloca.h>
|
|
|
e354a5 |
#include <argp.h>
|
|
|
e354a5 |
#include <dirent.h>
|
|
|
e354a5 |
@@ -41,6 +42,7 @@
|
|
|
e354a5 |
|
|
|
e354a5 |
#include <ldconfig.h>
|
|
|
e354a5 |
#include <dl-cache.h>
|
|
|
e354a5 |
+#include <dl-hwcaps.h>
|
|
|
e354a5 |
|
|
|
e354a5 |
#include <dl-procinfo.h>
|
|
|
e354a5 |
|
|
|
e354a5 |
@@ -85,6 +87,10 @@ struct dir_entry
|
|
|
e354a5 |
dev_t dev;
|
|
|
e354a5 |
const char *from_file;
|
|
|
e354a5 |
int from_line;
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ /* Non-NULL for subdirectories under a glibc-hwcaps subdirectory. */
|
|
|
e354a5 |
+ struct glibc_hwcaps_subdirectory *hwcaps;
|
|
|
e354a5 |
+
|
|
|
e354a5 |
struct dir_entry *next;
|
|
|
e354a5 |
};
|
|
|
e354a5 |
|
|
|
e354a5 |
@@ -338,17 +344,20 @@ new_sub_entry (const struct dir_entry *entry, const char *path,
|
|
|
e354a5 |
new_entry->from_line = entry->from_line;
|
|
|
e354a5 |
new_entry->path = xstrdup (path);
|
|
|
e354a5 |
new_entry->flag = entry->flag;
|
|
|
e354a5 |
+ new_entry->hwcaps = NULL;
|
|
|
e354a5 |
new_entry->next = NULL;
|
|
|
e354a5 |
new_entry->ino = st->st_ino;
|
|
|
e354a5 |
new_entry->dev = st->st_dev;
|
|
|
e354a5 |
return new_entry;
|
|
|
e354a5 |
}
|
|
|
e354a5 |
|
|
|
e354a5 |
-/* Add a single directory entry. */
|
|
|
e354a5 |
-static void
|
|
|
e354a5 |
+/* Add a single directory entry. Return true if the directory is
|
|
|
e354a5 |
+ actually added (because it is not a duplicate). */
|
|
|
e354a5 |
+static bool
|
|
|
e354a5 |
add_single_dir (struct dir_entry *entry, int verbose)
|
|
|
e354a5 |
{
|
|
|
e354a5 |
struct dir_entry *ptr, *prev;
|
|
|
e354a5 |
+ bool added = true;
|
|
|
e354a5 |
|
|
|
e354a5 |
ptr = dir_entries;
|
|
|
e354a5 |
prev = ptr;
|
|
|
e354a5 |
@@ -368,6 +377,7 @@ add_single_dir (struct dir_entry *entry, int verbose)
|
|
|
e354a5 |
ptr->flag = entry->flag;
|
|
|
e354a5 |
free (entry->path);
|
|
|
e354a5 |
free (entry);
|
|
|
e354a5 |
+ added = false;
|
|
|
e354a5 |
break;
|
|
|
e354a5 |
}
|
|
|
e354a5 |
prev = ptr;
|
|
|
e354a5 |
@@ -378,6 +388,73 @@ add_single_dir (struct dir_entry *entry, int verbose)
|
|
|
e354a5 |
dir_entries = entry;
|
|
|
e354a5 |
else if (ptr == NULL)
|
|
|
e354a5 |
prev->next = entry;
|
|
|
e354a5 |
+ return added;
|
|
|
e354a5 |
+}
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+/* Check if PATH contains a "glibc-hwcaps" subdirectory. If so, queue
|
|
|
e354a5 |
+ its subdirectories for glibc-hwcaps processing. */
|
|
|
e354a5 |
+static void
|
|
|
e354a5 |
+add_glibc_hwcaps_subdirectories (struct dir_entry *entry, const char *path)
|
|
|
e354a5 |
+{
|
|
|
e354a5 |
+ /* glibc-hwcaps subdirectories do not nest. */
|
|
|
e354a5 |
+ assert (entry->hwcaps == NULL);
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ char *glibc_hwcaps;
|
|
|
e354a5 |
+ if (asprintf (&glibc_hwcaps, "%s/" GLIBC_HWCAPS_SUBDIRECTORY, path) < 0)
|
|
|
e354a5 |
+ error (EXIT_FAILURE, errno, _("Could not form glibc-hwcaps path"));
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ DIR *dir = opendir (glibc_hwcaps);
|
|
|
e354a5 |
+ if (dir != NULL)
|
|
|
e354a5 |
+ {
|
|
|
e354a5 |
+ while (true)
|
|
|
e354a5 |
+ {
|
|
|
e354a5 |
+ errno = 0;
|
|
|
e354a5 |
+ struct dirent64 *e = readdir64 (dir);
|
|
|
e354a5 |
+ if (e == NULL)
|
|
|
e354a5 |
+ {
|
|
|
e354a5 |
+ if (errno == 0)
|
|
|
e354a5 |
+ break;
|
|
|
e354a5 |
+ else
|
|
|
e354a5 |
+ error (EXIT_FAILURE, errno, _("Listing directory %s"), path);
|
|
|
e354a5 |
+ }
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ /* Ignore hidden subdirectories, including "." and "..", and
|
|
|
e354a5 |
+ regular files. File names containing a ':' cannot be
|
|
|
e354a5 |
+ looked up by the dynamic loader, so skip those as
|
|
|
e354a5 |
+ well. */
|
|
|
e354a5 |
+ if (e->d_name[0] == '.' || e->d_type == DT_REG
|
|
|
e354a5 |
+ || strchr (e->d_name, ':') != NULL)
|
|
|
e354a5 |
+ continue;
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ /* See if this entry eventually resolves to a directory. */
|
|
|
e354a5 |
+ struct stat64 st;
|
|
|
e354a5 |
+ if (fstatat64 (dirfd (dir), e->d_name, &st, 0) < 0)
|
|
|
e354a5 |
+ /* Ignore unreadable entries. */
|
|
|
e354a5 |
+ continue;
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ if (S_ISDIR (st.st_mode))
|
|
|
e354a5 |
+ {
|
|
|
e354a5 |
+ /* This is a directory, so it needs to be scanned for
|
|
|
e354a5 |
+ libraries, associated with the hwcaps implied by the
|
|
|
e354a5 |
+ subdirectory name. */
|
|
|
e354a5 |
+ char *new_path;
|
|
|
e354a5 |
+ if (asprintf (&new_path, "%s/" GLIBC_HWCAPS_SUBDIRECTORY "/%s",
|
|
|
e354a5 |
+ /* Use non-canonicalized path here. */
|
|
|
e354a5 |
+ entry->path, e->d_name) < 0)
|
|
|
e354a5 |
+ error (EXIT_FAILURE, errno,
|
|
|
e354a5 |
+ _("Could not form glibc-hwcaps path"));
|
|
|
e354a5 |
+ struct dir_entry *new_entry = new_sub_entry (entry, new_path,
|
|
|
e354a5 |
+ &st);
|
|
|
e354a5 |
+ free (new_path);
|
|
|
e354a5 |
+ new_entry->hwcaps = new_glibc_hwcaps_subdirectory (e->d_name);
|
|
|
e354a5 |
+ add_single_dir (new_entry, 0);
|
|
|
e354a5 |
+ }
|
|
|
e354a5 |
+ }
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ closedir (dir);
|
|
|
e354a5 |
+ }
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ free (glibc_hwcaps);
|
|
|
e354a5 |
}
|
|
|
e354a5 |
|
|
|
e354a5 |
/* Add one directory to the list of directories to process. */
|
|
|
e354a5 |
@@ -386,6 +463,7 @@ add_dir_1 (const char *line, const char *from_file, int from_line)
|
|
|
e354a5 |
{
|
|
|
e354a5 |
unsigned int i;
|
|
|
e354a5 |
struct dir_entry *entry = xmalloc (sizeof (struct dir_entry));
|
|
|
e354a5 |
+ entry->hwcaps = NULL;
|
|
|
e354a5 |
entry->next = NULL;
|
|
|
e354a5 |
|
|
|
e354a5 |
entry->from_file = strdup (from_file);
|
|
|
e354a5 |
@@ -443,7 +521,9 @@ add_dir_1 (const char *line, const char *from_file, int from_line)
|
|
|
e354a5 |
entry->ino = stat_buf.st_ino;
|
|
|
e354a5 |
entry->dev = stat_buf.st_dev;
|
|
|
e354a5 |
|
|
|
e354a5 |
- add_single_dir (entry, 1);
|
|
|
e354a5 |
+ if (add_single_dir (entry, 1))
|
|
|
e354a5 |
+ /* Add glibc-hwcaps subdirectories if present. */
|
|
|
e354a5 |
+ add_glibc_hwcaps_subdirectories (entry, path);
|
|
|
e354a5 |
}
|
|
|
e354a5 |
|
|
|
e354a5 |
if (opt_chroot)
|
|
|
e354a5 |
@@ -695,15 +775,27 @@ struct dlib_entry
|
|
|
e354a5 |
static void
|
|
|
e354a5 |
search_dir (const struct dir_entry *entry)
|
|
|
e354a5 |
{
|
|
|
e354a5 |
- uint64_t hwcap = path_hwcap (entry->path);
|
|
|
e354a5 |
- if (opt_verbose)
|
|
|
e354a5 |
+ uint64_t hwcap;
|
|
|
e354a5 |
+ if (entry->hwcaps == NULL)
|
|
|
e354a5 |
{
|
|
|
e354a5 |
- if (hwcap != 0)
|
|
|
e354a5 |
- printf ("%s: (hwcap: %#.16" PRIx64 ")", entry->path, hwcap);
|
|
|
e354a5 |
- else
|
|
|
e354a5 |
- printf ("%s:", entry->path);
|
|
|
e354a5 |
- printf (_(" (from %s:%d)\n"), entry->from_file, entry->from_line);
|
|
|
e354a5 |
+ hwcap = path_hwcap (entry->path);
|
|
|
e354a5 |
+ if (opt_verbose)
|
|
|
e354a5 |
+ {
|
|
|
e354a5 |
+ if (hwcap != 0)
|
|
|
e354a5 |
+ printf ("%s: (hwcap: %#.16" PRIx64 ")", entry->path, hwcap);
|
|
|
e354a5 |
+ else
|
|
|
e354a5 |
+ printf ("%s:", entry->path);
|
|
|
e354a5 |
+ }
|
|
|
e354a5 |
}
|
|
|
e354a5 |
+ else
|
|
|
e354a5 |
+ {
|
|
|
e354a5 |
+ hwcap = 0;
|
|
|
e354a5 |
+ if (opt_verbose)
|
|
|
e354a5 |
+ printf ("%s: (hwcap: \"%s\")", entry->path,
|
|
|
e354a5 |
+ glibc_hwcaps_subdirectory_name (entry->hwcaps));
|
|
|
e354a5 |
+ }
|
|
|
e354a5 |
+ if (opt_verbose)
|
|
|
e354a5 |
+ printf (_(" (from %s:%d)\n"), entry->from_file, entry->from_line);
|
|
|
e354a5 |
|
|
|
e354a5 |
char *dir_name;
|
|
|
e354a5 |
char *real_file_name;
|
|
|
e354a5 |
@@ -745,13 +837,15 @@ search_dir (const struct dir_entry *entry)
|
|
|
e354a5 |
&& direntry->d_type != DT_DIR)
|
|
|
e354a5 |
continue;
|
|
|
e354a5 |
/* Does this file look like a shared library or is it a hwcap
|
|
|
e354a5 |
- subdirectory? The dynamic linker is also considered as
|
|
|
e354a5 |
+ subdirectory (if not already processing a glibc-hwcaps
|
|
|
e354a5 |
+ subdirectory)? The dynamic linker is also considered as
|
|
|
e354a5 |
shared library. */
|
|
|
e354a5 |
if (((strncmp (direntry->d_name, "lib", 3) != 0
|
|
|
e354a5 |
&& strncmp (direntry->d_name, "ld-", 3) != 0)
|
|
|
e354a5 |
|| strstr (direntry->d_name, ".so") == NULL)
|
|
|
e354a5 |
&& (direntry->d_type == DT_REG
|
|
|
e354a5 |
- || !is_hwcap_platform (direntry->d_name)))
|
|
|
e354a5 |
+ || (entry->hwcaps == NULL
|
|
|
e354a5 |
+ && !is_hwcap_platform (direntry->d_name))))
|
|
|
e354a5 |
continue;
|
|
|
e354a5 |
|
|
|
e354a5 |
size_t len = strlen (direntry->d_name);
|
|
|
e354a5 |
@@ -799,7 +893,7 @@ search_dir (const struct dir_entry *entry)
|
|
|
e354a5 |
}
|
|
|
e354a5 |
|
|
|
e354a5 |
struct stat64 stat_buf;
|
|
|
e354a5 |
- int is_dir;
|
|
|
e354a5 |
+ bool is_dir;
|
|
|
e354a5 |
int is_link = S_ISLNK (lstat_buf.st_mode);
|
|
|
e354a5 |
if (is_link)
|
|
|
e354a5 |
{
|
|
|
e354a5 |
@@ -837,7 +931,10 @@ search_dir (const struct dir_entry *entry)
|
|
|
e354a5 |
else
|
|
|
e354a5 |
is_dir = S_ISDIR (lstat_buf.st_mode);
|
|
|
e354a5 |
|
|
|
e354a5 |
- if (is_dir && is_hwcap_platform (direntry->d_name))
|
|
|
e354a5 |
+ /* No descending into subdirectories if this directory is a
|
|
|
e354a5 |
+ glibc-hwcaps subdirectory (which are not recursive). */
|
|
|
e354a5 |
+ if (entry->hwcaps == NULL
|
|
|
e354a5 |
+ && is_dir && is_hwcap_platform (direntry->d_name))
|
|
|
e354a5 |
{
|
|
|
e354a5 |
if (!is_link
|
|
|
e354a5 |
&& direntry->d_type != DT_UNKNOWN
|
|
|
e354a5 |
@@ -1028,13 +1125,31 @@ search_dir (const struct dir_entry *entry)
|
|
|
e354a5 |
struct dlib_entry *dlib_ptr;
|
|
|
e354a5 |
for (dlib_ptr = dlibs; dlib_ptr != NULL; dlib_ptr = dlib_ptr->next)
|
|
|
e354a5 |
{
|
|
|
e354a5 |
- /* Don't create links to links. */
|
|
|
e354a5 |
- if (dlib_ptr->is_link == 0)
|
|
|
e354a5 |
- create_links (dir_name, entry->path, dlib_ptr->name,
|
|
|
e354a5 |
- dlib_ptr->soname);
|
|
|
e354a5 |
+ /* The cached file name is the soname for non-glibc-hwcaps
|
|
|
e354a5 |
+ subdirectories (relying on symbolic links; this helps with
|
|
|
e354a5 |
+ library updates that change the file name), and the actual
|
|
|
e354a5 |
+ file for glibc-hwcaps subdirectories. */
|
|
|
e354a5 |
+ const char *filename;
|
|
|
e354a5 |
+ if (entry->hwcaps == NULL)
|
|
|
e354a5 |
+ {
|
|
|
e354a5 |
+ /* Don't create links to links. */
|
|
|
e354a5 |
+ if (dlib_ptr->is_link == 0)
|
|
|
e354a5 |
+ create_links (dir_name, entry->path, dlib_ptr->name,
|
|
|
e354a5 |
+ dlib_ptr->soname);
|
|
|
e354a5 |
+ filename = dlib_ptr->soname;
|
|
|
e354a5 |
+ }
|
|
|
e354a5 |
+ else
|
|
|
e354a5 |
+ {
|
|
|
e354a5 |
+ /* Do not create links in glibc-hwcaps subdirectories, but
|
|
|
e354a5 |
+ still log the cache addition. */
|
|
|
e354a5 |
+ if (opt_verbose)
|
|
|
e354a5 |
+ printf ("\t%s -> %s\n", dlib_ptr->soname, dlib_ptr->name);
|
|
|
e354a5 |
+ filename = dlib_ptr->name;
|
|
|
e354a5 |
+ }
|
|
|
e354a5 |
if (opt_build_cache)
|
|
|
e354a5 |
- add_to_cache (entry->path, dlib_ptr->soname, dlib_ptr->flag,
|
|
|
e354a5 |
- dlib_ptr->osversion, hwcap);
|
|
|
e354a5 |
+ add_to_cache (entry->path, filename, dlib_ptr->soname,
|
|
|
e354a5 |
+ dlib_ptr->flag, dlib_ptr->osversion,
|
|
|
e354a5 |
+ hwcap, entry->hwcaps);
|
|
|
e354a5 |
}
|
|
|
e354a5 |
|
|
|
e354a5 |
/* Free all resources. */
|
|
|
e354a5 |
diff --git a/sysdeps/generic/dl-cache.h b/sysdeps/generic/dl-cache.h
|
|
|
e354a5 |
index 259e843724531630..6adbe3c79a32a4ec 100644
|
|
|
e354a5 |
--- a/sysdeps/generic/dl-cache.h
|
|
|
e354a5 |
+++ b/sysdeps/generic/dl-cache.h
|
|
|
e354a5 |
@@ -99,6 +99,23 @@ struct file_entry_new
|
|
|
e354a5 |
uint64_t hwcap; /* Hwcap entry. */
|
|
|
e354a5 |
};
|
|
|
e354a5 |
|
|
|
e354a5 |
+/* This bit in the hwcap field of struct file_entry_new indicates that
|
|
|
e354a5 |
+ the lower 32 bits contain an index into the
|
|
|
e354a5 |
+ cache_extension_tag_glibc_hwcaps section. Older glibc versions do
|
|
|
e354a5 |
+ not know about this HWCAP bit, so they will ignore these
|
|
|
e354a5 |
+ entries. */
|
|
|
e354a5 |
+#define DL_CACHE_HWCAP_EXTENSION (1ULL << 62)
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+/* Return true if the ENTRY->hwcap value indicates that
|
|
|
e354a5 |
+ DL_CACHE_HWCAP_EXTENSION is used. */
|
|
|
e354a5 |
+static inline bool
|
|
|
e354a5 |
+dl_cache_hwcap_extension (struct file_entry_new *entry)
|
|
|
e354a5 |
+{
|
|
|
e354a5 |
+ /* If DL_CACHE_HWCAP_EXTENSION is set, but other bits as well, this
|
|
|
e354a5 |
+ is a different kind of extension. */
|
|
|
e354a5 |
+ return (entry->hwcap >> 32) == (DL_CACHE_HWCAP_EXTENSION >> 32);
|
|
|
e354a5 |
+}
|
|
|
e354a5 |
+
|
|
|
e354a5 |
/* See flags member of struct cache_file_new below. */
|
|
|
e354a5 |
enum
|
|
|
e354a5 |
{
|
|
|
e354a5 |
@@ -182,6 +199,17 @@ enum cache_extension_tag
|
|
|
e354a5 |
cache file. */
|
|
|
e354a5 |
cache_extension_tag_generator,
|
|
|
e354a5 |
|
|
|
e354a5 |
+ /* glibc-hwcaps subdirectory information. An array of uint32_t
|
|
|
e354a5 |
+ values, which are indices into the string table. The strings
|
|
|
e354a5 |
+ are sorted lexicographically (according to strcmp). The extra
|
|
|
e354a5 |
+ level of indirection (instead of using string table indices
|
|
|
e354a5 |
+ directly) allows the dynamic loader to compute the preference
|
|
|
e354a5 |
+ order of the hwcaps names more efficiently.
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ For this section, 4-byte alignment is required, and the section
|
|
|
e354a5 |
+ size must be a multiple of 4. */
|
|
|
e354a5 |
+ cache_extension_tag_glibc_hwcaps,
|
|
|
e354a5 |
+
|
|
|
e354a5 |
/* Total number of known cache extension tags. */
|
|
|
e354a5 |
cache_extension_count
|
|
|
e354a5 |
};
|
|
|
e354a5 |
@@ -236,6 +264,27 @@ struct cache_extension_all_loaded
|
|
|
e354a5 |
struct cache_extension_loaded sections[cache_extension_count];
|
|
|
e354a5 |
};
|
|
|
e354a5 |
|
|
|
e354a5 |
+/* Performs basic data validation based on section tag, and removes
|
|
|
e354a5 |
+ the sections which are invalid. */
|
|
|
e354a5 |
+static void
|
|
|
e354a5 |
+cache_extension_verify (struct cache_extension_all_loaded *loaded)
|
|
|
e354a5 |
+{
|
|
|
e354a5 |
+ {
|
|
|
e354a5 |
+ /* Section must not be empty, it must be aligned at 4 bytes, and
|
|
|
e354a5 |
+ the size must be a multiple of 4. */
|
|
|
e354a5 |
+ struct cache_extension_loaded *hwcaps
|
|
|
e354a5 |
+ = &loaded->sections[cache_extension_tag_glibc_hwcaps];
|
|
|
e354a5 |
+ if (hwcaps->size == 0
|
|
|
e354a5 |
+ || ((uintptr_t) hwcaps->base % 4) != 0
|
|
|
e354a5 |
+ || (hwcaps->size % 4) != 0)
|
|
|
e354a5 |
+ {
|
|
|
e354a5 |
+ hwcaps->base = NULL;
|
|
|
e354a5 |
+ hwcaps->size = 0;
|
|
|
e354a5 |
+ hwcaps->flags = 0;
|
|
|
e354a5 |
+ }
|
|
|
e354a5 |
+ }
|
|
|
e354a5 |
+}
|
|
|
e354a5 |
+
|
|
|
e354a5 |
static bool __attribute__ ((unused))
|
|
|
e354a5 |
cache_extension_load (const struct cache_file_new *cache,
|
|
|
e354a5 |
const void *file_base, size_t file_size,
|
|
|
e354a5 |
@@ -282,6 +331,7 @@ cache_extension_load (const struct cache_file_new *cache,
|
|
|
e354a5 |
loaded->sections[tag].size = ext->sections[i].size;
|
|
|
e354a5 |
loaded->sections[tag].flags = ext->sections[i].flags;
|
|
|
e354a5 |
}
|
|
|
e354a5 |
+ cache_extension_verify (loaded);
|
|
|
e354a5 |
return true;
|
|
|
e354a5 |
}
|
|
|
e354a5 |
|
|
|
e354a5 |
diff --git a/sysdeps/generic/ldconfig.h b/sysdeps/generic/ldconfig.h
|
|
|
e354a5 |
index b15b142511829436..a8d22f143f867a3e 100644
|
|
|
e354a5 |
--- a/sysdeps/generic/ldconfig.h
|
|
|
e354a5 |
+++ b/sysdeps/generic/ldconfig.h
|
|
|
e354a5 |
@@ -57,8 +57,22 @@ extern void init_cache (void);
|
|
|
e354a5 |
|
|
|
e354a5 |
extern void save_cache (const char *cache_name);
|
|
|
e354a5 |
|
|
|
e354a5 |
-extern void add_to_cache (const char *path, const char *lib, int flags,
|
|
|
e354a5 |
- unsigned int osversion, uint64_t hwcap);
|
|
|
e354a5 |
+struct glibc_hwcaps_subdirectory;
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+/* Return a struct describing the subdirectory for NAME. Reuse an
|
|
|
e354a5 |
+ existing struct if it exists. */
|
|
|
e354a5 |
+struct glibc_hwcaps_subdirectory *new_glibc_hwcaps_subdirectory
|
|
|
e354a5 |
+ (const char *name);
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+/* Returns the name that was specified when
|
|
|
e354a5 |
+ add_glibc_hwcaps_subdirectory was called. */
|
|
|
e354a5 |
+const char *glibc_hwcaps_subdirectory_name
|
|
|
e354a5 |
+ (const struct glibc_hwcaps_subdirectory *);
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+extern void add_to_cache (const char *path, const char *filename,
|
|
|
e354a5 |
+ const char *soname,
|
|
|
e354a5 |
+ int flags, unsigned int osversion, uint64_t hwcap,
|
|
|
e354a5 |
+ struct glibc_hwcaps_subdirectory *);
|
|
|
e354a5 |
|
|
|
e354a5 |
extern void init_aux_cache (void);
|
|
|
e354a5 |
|