diff options
author | Florian Weimer <fweimer@redhat.com> | 2020-12-04 09:13:43 +0100 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2020-12-04 09:16:30 +0100 |
commit | 84ba719b260551918965d0a433914de683087645 (patch) | |
tree | 2a3e5e634f104e0ef2f8592f1925955d8ce63db4 /elf/dl-cache.c | |
parent | dad90d528259b669342757c37dedefa8577e2636 (diff) | |
download | glibc-84ba719b260551918965d0a433914de683087645.tar.gz |
elf: Add endianness markup to ld.so.cache (bug 27008)
Use a reserved byte in the new format cache header to indicate whether
the file is in little endian or big endian format. Eventually, this
information could be used to provide a unified cache for qemu-user
and similiar scenarios.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'elf/dl-cache.c')
-rw-r--r-- | elf/dl-cache.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/elf/dl-cache.c b/elf/dl-cache.c index 45894ecd2f..02c46ffb0c 100644 --- a/elf/dl-cache.c +++ b/elf/dl-cache.c @@ -242,6 +242,11 @@ _dl_load_cache_lookup (const char *name) && ((cachesize - sizeof *cache_new) / sizeof (struct file_entry_new) >= ((struct cache_file_new *) file)->nlibs)) { + if (! cache_file_new_matches_endian (file)) + { + __munmap (file, cachesize); + file = (void *) -1; + } cache_new = file; cache = file; } @@ -263,7 +268,20 @@ _dl_load_cache_lookup (const char *name) if (cachesize < (offset + sizeof (struct cache_file_new)) || memcmp (cache_new->magic, CACHEMAGIC_VERSION_NEW, sizeof CACHEMAGIC_VERSION_NEW - 1) != 0) - cache_new = (void *) -1; + cache_new = (void *) -1; + else + { + if (! cache_file_new_matches_endian (cache_new)) + { + /* The old-format part of the cache is bogus as well + if the endianness does not match. (But it is + unclear how the new header can be located if the + endianess does not match.) */ + cache = (void *) -1; + cache_new = (void *) -1; + __munmap (file, cachesize); + } + } } else { |