From patchwork Thu Oct 1 16:31:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 40593 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 796D53857C41; Thu, 1 Oct 2020 16:32:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 796D53857C41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1601569921; bh=JCGDv2EewNKuMJ4lJreFmZtnHDddTkycT9NGl8o6Y3c=; 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=oNi1OI+iGn+r2CeYgzRJJouRtwAqTXqtaQh0/+uE2g7pArcG9TktPGLwpkVVXouBQ +8W/FHHDc120AHqQGgnF1ZWHrmA4BQCvOgFRb3xXnXYf/WdOJ4OgjmDbyX4M1ZbJeQ 4asDM9UqR6p50KIoBNqD3i+81jGAw800wFsvFiaM= 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 EE0EC3857C41 for ; Thu, 1 Oct 2020 16:31:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EE0EC3857C41 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-498-IdSsiyubNSOWeY1KcZ0xLw-1; Thu, 01 Oct 2020 12:31:54 -0400 X-MC-Unique: IdSsiyubNSOWeY1KcZ0xLw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C69A781CAFA for ; Thu, 1 Oct 2020 16:31:38 +0000 (UTC) Received: from oldenburg2.str.redhat.com (ovpn-114-84.ams2.redhat.com [10.36.114.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 38A7D60BF1 for ; Thu, 1 Oct 2020 16:31:38 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 01/28] elf: Do not search HWCAP subdirectories in statically linked binaries In-Reply-To: References: Message-Id: <75fdede6bc2db8a3638c1402855b2c5245f4b545.1601569371.git.fweimer@redhat.com> Date: Thu, 01 Oct 2020 18:31:36 +0200 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.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.4 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" This functionality does not seem to be useful since static dlopen is mostly used for iconv/character set conversion and NSS support. gconv modules are loaded with full paths anyway, so that the HWCAP subdirectory logic does not apply. Reviewed-by: Adhemerval Zanella --- NEWS | 4 ++++ elf/Makefile | 4 ++-- elf/dl-load.c | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index ce05d05b16..902fa3a7f8 100644 --- a/NEWS +++ b/NEWS @@ -33,6 +33,10 @@ Deprecated and removed features, and other changes affecting compatibility: * The mallinfo function is marked deprecated. Callers should call mallinfo2 instead. +* When dlopen is used in statically linked programs, alternative library + implementations from HWCAP subdirectories are no longer loaded. + Instead, the default implementation is used. + Changes to build and runtime requirements: [Add changes to build and runtime requirements here] diff --git a/elf/Makefile b/elf/Makefile index c587e9f06e..e0a8bf2998 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -29,7 +29,7 @@ routines = $(all-dl-routines) dl-support dl-iteratephdr \ # The core dynamic linking functions are in libc for the static and # profiled libraries. -dl-routines = $(addprefix dl-,load lookup object reloc deps hwcaps \ +dl-routines = $(addprefix dl-,load lookup object reloc deps \ runtime init fini debug misc \ version profile tls origin scope \ execstack open close trampoline \ @@ -59,7 +59,7 @@ elide-routines.os = $(all-dl-routines) dl-support enbl-secure dl-origin \ # ld.so uses those routines, plus some special stuff for being the program # interpreter and operating independent of libc. rtld-routines = rtld $(all-dl-routines) dl-sysdep dl-environ dl-minimal \ - dl-error-minimal dl-conflict + dl-error-minimal dl-conflict dl-hwcaps all-rtld-routines = $(rtld-routines) $(sysdep-rtld-routines) CFLAGS-dl-runtime.c += -fexceptions -fasynchronous-unwind-tables diff --git a/elf/dl-load.c b/elf/dl-load.c index 646c5dca40..5ba117d597 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -101,9 +101,13 @@ int __stack_prot attribute_hidden attribute_relro static struct r_search_path_struct env_path_list attribute_relro; /* List of the hardware capabilities we might end up using. */ +#ifdef SHARED static const struct r_strlenpair *capstr attribute_relro; static size_t ncapstr attribute_relro; static size_t max_capstrlen attribute_relro; +#else +enum { ncapstr = 1, max_capstrlen = 0 }; +#endif /* Get the generated information about the trusted directories. Use @@ -691,9 +695,11 @@ _dl_init_paths (const char *llp) /* Fill in the information about the application's RPATH and the directories addressed by the LD_LIBRARY_PATH environment variable. */ +#ifdef SHARED /* Get the capabilities. */ capstr = _dl_important_hwcaps (GLRO(dl_platform), GLRO(dl_platformlen), &ncapstr, &max_capstrlen); +#endif /* First set up the rest of the default search directory entries. */ aelem = rtld_search_dirs.dirs = (struct r_search_path_elem **) @@ -1521,11 +1527,15 @@ print_search_path (struct r_search_path_elem **list, for (cnt = 0; cnt < ncapstr; ++cnt) if ((*list)->status[cnt] != nonexisting) { +#ifdef SHARED char *cp = __mempcpy (endp, capstr[cnt].str, capstr[cnt].len); if (cp == buf || (cp == buf + 1 && buf[0] == '/')) cp[0] = '\0'; else cp[-1] = '\0'; +#else + *endp = '\0'; +#endif _dl_debug_printf_c (first ? "%s" : ":%s", buf); first = 0; @@ -1886,11 +1896,15 @@ open_path (const char *name, size_t namelen, int mode, if (this_dir->status[cnt] == nonexisting) continue; +#ifdef SHARED buflen = ((char *) __mempcpy (__mempcpy (edp, capstr[cnt].str, capstr[cnt].len), name, namelen) - buf); +#else + buflen = (char *) __mempcpy (edp, name, namelen) - buf; +#endif /* Print name we try if this is wanted. */ if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_LIBS))