From patchwork Mon Nov 9 18:40:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 40970 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 97DC5386EC70; Mon, 9 Nov 2020 18:40:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 97DC5386EC70 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1604947238; bh=Mnkile/JvGAQT3T8N8H1xFrQrUD3BkAiPpiVRwBOl3k=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=eeBPqLA+/JRvvay1vqVJDsd/8+/ETPOQda/hM82mJXr+hiq5onv0u2Xp+L6/6KBXq lg1s6m/kAUFHqXphNg5RPl4i/U7zjQVQNUA45chKDli1Ml8xXrPPEWECcJNvOBeOTb NVVxtSzuR2/AZK8PCK9mYKtWbu5pOxfsIxd83wqE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id 3A765385EC57 for ; Mon, 9 Nov 2020 18:40:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3A765385EC57 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-208-DnZrQFj8M3WyAF9n8aa44A-1; Mon, 09 Nov 2020 13:40:32 -0500 X-MC-Unique: DnZrQFj8M3WyAF9n8aa44A-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C34F3805F13 for ; Mon, 9 Nov 2020 18:40:31 +0000 (UTC) Received: from oldenburg2.str.redhat.com (ovpn-113-222.ams2.redhat.com [10.36.113.222]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 15D825B4CD for ; Mon, 9 Nov 2020 18:40:30 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 02/11] elf: Introduce enum opt_format in the ldconfig implementation In-Reply-To: References: Message-Id: Date: Mon, 09 Nov 2020 19:40:29 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, 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-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" --- elf/cache.c | 24 ++++++++++++------------ elf/ldconfig.c | 9 ++++----- sysdeps/generic/ldconfig.h | 9 ++++++++- 3 files changed, 24 insertions(+), 18 deletions(-) Reviewed-by: Adhemerval Zanella diff --git a/elf/cache.c b/elf/cache.c index 1eb1455883..c241c17ef9 100644 --- a/elf/cache.c +++ b/elf/cache.c @@ -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); diff --git a/elf/ldconfig.c b/elf/ldconfig.c index 3768267bac..006198fe59 100644 --- a/elf/ldconfig.c +++ b/elf/ldconfig.c @@ -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; diff --git a/sysdeps/generic/ldconfig.h b/sysdeps/generic/ldconfig.h index b64aab0064..cfec9d4668 100644 --- a/sysdeps/generic/ldconfig.h +++ b/sysdeps/generic/ldconfig.h @@ -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