From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 64D2D3894417 for ; Tue, 18 May 2021 14:26:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 64D2D3894417 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-146-ybNfja3RPoibdSG2pAqYag-1; Tue, 18 May 2021 10:26:12 -0400 X-MC-Unique: ybNfja3RPoibdSG2pAqYag-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E9E9E803639 for ; Tue, 18 May 2021 14:25:32 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-112-137.ams2.redhat.com [10.36.112.137]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 52BA05D6A1 for ; Tue, 18 May 2021 14:25:32 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH 08/10] elf: Do not load libpthread for PTHREAD_IN_LIBC In-Reply-To: References: X-From-Line: e3ad0aceca81d9db786582382b0a3ce4a7b2221c Mon Sep 17 00:00:00 2001 Message-Id: Date: Tue, 18 May 2021 16:25:30 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-12.7 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_LOW, RCVD_IN_MSPIKE_H4, 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-List-Received-Date: Tue, 18 May 2021 14:26:15 -0000 --- elf/dl-load.c | 19 +++++++++++++++++-- elf/dl-version.c | 9 +++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index 918ec7546c..f97cb140f4 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -2029,12 +2029,26 @@ open_path (const char *name, size_t namelen, int mode, /* Map in the shared object file NAME. */ +static inline const char * +object_real_name (const char *name) +{ + /* If libpthread is integrated into libc, treat a request to load + libpthread as a request to load libc (because libc was a + dependency of libpthread). */ +#if PTHREAD_IN_LIBC + if (strcmp (name, LIBPTHREAD_SO) == 0) + return LIBC_SO; +#endif + return name; +} + struct link_map * _dl_map_object (struct link_map *loader, const char *name, int type, int trace_mode, int mode, Lmid_t nsid) { int fd; const char *origname = NULL; + const char *implementation_name = object_real_name (name); char *realname; char *name_copy; struct link_map *l; @@ -2051,7 +2065,7 @@ _dl_map_object (struct link_map *loader, const char *name, yet been opened. */ if (__glibc_unlikely ((l->l_faked | l->l_removed) != 0)) continue; - if (!_dl_name_match_p (name, l)) + if (!_dl_name_match_p (implementation_name, l)) { const char *soname; @@ -2061,7 +2075,7 @@ _dl_map_object (struct link_map *loader, const char *name, soname = ((const char *) D_PTR (l, l_info[DT_STRTAB]) + l->l_info[DT_SONAME]->d_un.d_val); - if (strcmp (name, soname) != 0) + if (strcmp (implementation_name, soname) != 0) continue; /* We have a match on a new name -- cache it. */ @@ -2106,6 +2120,7 @@ _dl_map_object (struct link_map *loader, const char *name, if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_FILES)) _dl_debug_printf ("audit changed filename %s -> %s\n", before, name); + implementation_name = object_real_name (name); if (origname == NULL) origname = before; diff --git a/elf/dl-version.c b/elf/dl-version.c index 914955c2a8..932cffda09 100644 --- a/elf/dl-version.c +++ b/elf/dl-version.c @@ -24,6 +24,7 @@ #include #include #include <_itoa.h> +#include #include @@ -200,6 +201,14 @@ _dl_check_map_versions (struct link_map *map, int verbose, int trace_mode) ElfW(Vernaux) *aux; struct link_map *needed = find_needed (strtab + ent->vn_file, map); +#if PTHREAD_IN_LIBC + /* With an integrated libpthread, check libpthread + references against libc instead. */ + if (needed == NULL + && strcmp (strtab + ent->vn_file, LIBPTHREAD_SO) == 0) + needed = find_needed (LIBC_SO, map); +#endif + /* If NEEDED is NULL this means a dependency was not found and no stub entry was created. This should never happen. */ assert (needed != NULL); -- 2.31.1