From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by sourceware.org (Postfix) with ESMTPS id CBA353857C77 for ; Wed, 14 Oct 2020 14:07:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CBA353857C77 Received: by mail-qt1-x843.google.com with SMTP id h12so2328322qtu.1 for ; Wed, 14 Oct 2020 07:07:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:references:from:autocrypt:subject:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=kGtZ6jgMNBBEYYvfTwC9kNCpkHbwdbDoycPslcZ7YcM=; b=brZfSCvSNl5SkklSabvMcGTbT9qteS3J8In0OyJF1wTOU+M8QUNWGBEQhWcNljBiRq H0bFRYIPjNWNawBuGJAY/3FHaG61yFuRMc+vd7NQW0pimdLlpV3l6ghQGYjRwuupBpuX lwr052FWB3QCp7gX5EXxldhLkr9dZermWMyySRGR+Rv+M8mrrx3Gf+nhnhjHMWpuEMMJ DqX6h0vzRI263jBxj9H+72R5gwEShFkOz6CZ9mT2f+WACNBwmRxnz4qiD376oVfLiESW Ioi0yCqfzzA+Nlp4Xxby/qa6px2Q2hqlP192rUD1DIsv0ni9KuPdtEcdlMY6P/tINKTz uMvQ== X-Gm-Message-State: AOAM533BdIKO+L3B7LLTxL5ysFua1Dq1OYQ2g4HXwCaabHOM54b4jHc7 ITbB6hUGGfffRfY0BRKir0A94OCAJGXBOA== X-Google-Smtp-Source: ABdhPJxRF68GUUEm4kMXemrCusDdIK//r7uKr0Ax9ko2rGNc3DYliRJdRkQS3tdT3qNucNpfjl9uzA== X-Received: by 2002:ac8:31b4:: with SMTP id h49mr5115808qte.258.1602684429123; Wed, 14 Oct 2020 07:07:09 -0700 (PDT) Received: from [192.168.1.4] ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id j16sm1279403qkg.26.2020.10.14.07.07.07 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 14 Oct 2020 07:07:08 -0700 (PDT) To: libc-alpha@sourceware.org References: From: Adhemerval Zanella Autocrypt: addr=adhemerval.zanella@linaro.org; prefer-encrypt=mutual; keydata= mQINBFcVGkoBEADiQU2x/cBBmAVf5C2d1xgz6zCnlCefbqaflUBw4hB/bEME40QsrVzWZ5Nq 8kxkEczZzAOKkkvv4pRVLlLn/zDtFXhlcvQRJ3yFMGqzBjofucOrmdYkOGo0uCaoJKPT186L NWp53SACXguFJpnw4ODI64ziInzXQs/rUJqrFoVIlrPDmNv/LUv1OVPKz20ETjgfpg8MNwG6 iMizMefCl+RbtXbIEZ3TE/IaDT/jcOirjv96lBKrc/pAL0h/O71Kwbbp43fimW80GhjiaN2y WGByepnkAVP7FyNarhdDpJhoDmUk9yfwNuIuESaCQtfd3vgKKuo6grcKZ8bHy7IXX1XJj2X/ BgRVhVgMHAnDPFIkXtP+SiarkUaLjGzCz7XkUn4XAGDskBNfbizFqYUQCaL2FdbW3DeZqNIa nSzKAZK7Dm9+0VVSRZXP89w71Y7JUV56xL/PlOE+YKKFdEw+gQjQi0e+DZILAtFjJLoCrkEX w4LluMhYX/X8XP6/C3xW0yOZhvHYyn72sV4yJ1uyc/qz3OY32CRy+bwPzAMAkhdwcORA3JPb kPTlimhQqVgvca8m+MQ/JFZ6D+K7QPyvEv7bQ7M+IzFmTkOCwCJ3xqOD6GjX3aphk8Sr0dq3 4Awlf5xFDAG8dn8Uuutb7naGBd/fEv6t8dfkNyzj6yvc4jpVxwARAQABtElBZGhlbWVydmFs IFphbmVsbGEgTmV0dG8gKExpbmFybyBWUE4gS2V5KSA8YWRoZW1lcnZhbC56YW5lbGxhQGxp bmFyby5vcmc+iQI3BBMBCAAhBQJXFRpKAhsDBQsJCAcDBRUKCQgLBRYCAwEAAh4BAheAAAoJ EKqx7BSnlI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CH 21/28] elf: Add endianness markup to ld.so.cache Message-ID: <3beb43be-db88-a82a-cae5-0f9f59e648c0@linaro.org> Date: Wed, 14 Oct 2020 11:07:06 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Oct 2020 14:07:12 -0000 On 01/10/2020 13:33, Florian Weimer via Libc-alpha wrote: > 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. Some comments below. > --- > elf/cache.c | 11 ++++++++++ > elf/dl-cache.c | 20 +++++++++++++++++- > sysdeps/generic/dl-cache.h | 43 +++++++++++++++++++++++++++++++++++++- > 3 files changed, 72 insertions(+), 2 deletions(-) > > diff --git a/elf/cache.c b/elf/cache.c > index 1eb1455883..e0aa616352 100644 > --- a/elf/cache.c > +++ b/elf/cache.c > @@ -152,6 +152,14 @@ print_entry (const char *lib, int flag, unsigned int osversion, > printf (") => %s\n", key); > } > > +/* Print an error and exit if the new-file cache is internally > + inconsistent. */ > +static void > +check_new_cache (struct cache_file_new *cache) > +{ > + if (! cache_file_new_matches_endian (cache)) > + error (EXIT_FAILURE, 0, _("Cache file has wrong endianness.\n")); > +} > > /* Print the whole cache file, if a file contains the new cache format > hidden in the old one, print the contents of the new format. */ Ok. > @@ -193,6 +201,7 @@ print_cache (const char *cache_name) > || memcmp (cache_new->version, CACHE_VERSION, > sizeof CACHE_VERSION - 1)) > error (EXIT_FAILURE, 0, _("File is not a cache file.\n")); > + check_new_cache (cache_new); > format = 1; > /* This is where the strings start. */ > cache_data = (const char *) cache_new; Ok. > @@ -222,6 +231,7 @@ print_cache (const char *cache_name) > && memcmp (cache_new->version, CACHE_VERSION, > sizeof CACHE_VERSION - 1) == 0) > { > + check_new_cache (cache_new); > cache_data = (const char *) cache_new; > format = 1; > } Ok. > @@ -361,6 +371,7 @@ save_cache (const char *cache_name) > > file_entries_new->nlibs = cache_entry_count; > file_entries_new->len_strings = total_strlen; > + file_entries_new->flags = cache_file_new_flags_endian; > } > > /* Pad for alignment of cache_file_new. */ Ok. > diff --git a/elf/dl-cache.c b/elf/dl-cache.c > index 93d185e788..3aa8ed6c13 100644 > --- a/elf/dl-cache.c > +++ b/elf/dl-cache.c > @@ -210,6 +210,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; > } Ok. > @@ -231,7 +236,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 > { Ok. > diff --git a/sysdeps/generic/dl-cache.h b/sysdeps/generic/dl-cache.h > index 6b310e9e15..1b04211f6b 100644 > --- a/sysdeps/generic/dl-cache.h > +++ b/sysdeps/generic/dl-cache.h > @@ -16,6 +16,11 @@ > License along with the GNU C Library; if not, see > . */ > > +#ifndef _DL_CACHE_H > +#define _DL_CACHE_H > + > +#include > +#include > #include > > #ifndef _DL_CACHE_DEFAULT_ID Ok. > @@ -83,21 +88,57 @@ struct file_entry_new > uint64_t hwcap; /* Hwcap entry. */ > }; > > +/* See flags member of struct cache_file_new below. */ > +enum > + { > + cache_file_new_flags_endian = (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ > + ? 2 : 3) Why not enumerate the possible values as described below: enum cache_file_new_flags { cache_file_flag_invalid = 1, cache_file_flag_endianess = 2 }; enum { cache_file_new_flags_endian = (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ? cache_file_flag_endianess : 0) | cache_file_flag_invalid }; I think this is slight less confusing than using direct values and more explicit on how the default flags value should be. > + }; > + > struct cache_file_new > { > char magic[sizeof CACHEMAGIC_NEW - 1]; > char version[sizeof CACHE_VERSION - 1]; > uint32_t nlibs; /* Number of entries. */ > uint32_t len_strings; /* Size of string table. */ > - uint32_t unused[5]; /* Leave space for future extensions > + > + /* flags & 3 is used to indicate the endianness of the cache. > + 0: no endianness information available > + (An old ldconfig version without endianness support wrote the file.) > + 1: cache is invalid > + 2: little endian > + 3: big endian > + > + The remaining bits are unused and should be generated as zero and > + ignored by readers. */ > + uint8_t flags; > + > + uint8_t padding_unsed[3]; /* Not used, for future extensions. */ > + > + uint32_t unused[4]; /* Leave space for future extensions > and align to 8 byte boundary. */ > struct file_entry_new libs[0]; /* Entries describing libraries. */ > /* After this the string table of size len_strings is found. */ > }; > > +/* Returns false if *CACHE has the wrong endianness for this > + architecture, and true if the endianness matches (or is > + unknown). */ > +static inline bool > +cache_file_new_matches_endian (const struct cache_file_new *cache) > +{ > + /* A zero value for cache->flags means that no endianness > + information is available. */ > + return cache->flags == 0 > + || (cache->flags & 3) == cache_file_new_flags_endian; > +} > + > + Using the suggestion above: static inline bool cache_file_new_matches_endian (const struct cache_file_new *cache) { return cache->flags == 0 || (cache->flags & (cache_file_flag_endianess | cache_file_flag_invalid)) == cache_file_flag_endianess; } > /* Used to align cache_file_new. */ > #define ALIGN_CACHE(addr) \ > (((addr) + __alignof__ (struct cache_file_new) -1) \ > & (~(__alignof__ (struct cache_file_new) - 1))) > > extern int _dl_cache_libcmp (const char *p1, const char *p2) attribute_hidden; > + > +#endif /* _DL_CACHE_H */ > Ok.