From patchwork Tue Dec 15 10:57:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 41392 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 A8B24384B825; Tue, 15 Dec 2020 10:58:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A8B24384B825 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608029882; bh=q6zB58zc84Tp5YC5P4nRLOud6ND69jepL19XtXpfiqw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=MC8XwIfRTQrsCfvoFaM1pOkzwrhlkpgyrrSzHhFShhnrDclm0ocvB91ErosY7fL7r D9gCHbu+EXE/ij18zceqDLJ8mkpwnKPcVH7ePzE7ALWhqpQayqJbirLaiQ9OlDH0a6 ai1Hk0VtmSVT/ZcrsfWQfmC5SA3tJsQ014p+J5jc= 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 E9B0B385800D for ; Tue, 15 Dec 2020 10:58:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E9B0B385800D 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-22-Rp6Dj8E9NJa-S0PC5H33mg-1; Tue, 15 Dec 2020 05:57:58 -0500 X-MC-Unique: Rp6Dj8E9NJa-S0PC5H33mg-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 2819B59 for ; Tue, 15 Dec 2020 10:57:57 +0000 (UTC) Received: from oldenburg2.str.redhat.com (ovpn-114-148.ams2.redhat.com [10.36.114.148]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8756662923 for ; Tue, 15 Dec 2020 10:57:56 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH] elf: Record libc.so link map when it is the main program (bug 20972) Date: Tue, 15 Dec 2020 11:57:54 +0100 Message-ID: <878s9z9w0d.fsf@oldenburg2.str.redhat.com> 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.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.3 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLACK 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" Otherwise, it will not participate in the dependency sorting. Fixes commit 9ffa50b26b0cb5d3043adf6d3d0b1ea735acc147 ("elf: Include libc.so.6 as main program in dependency sort (bug 20972)"). Reviewed-by: Carlos O'Donell --- elf/rtld.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/elf/rtld.c b/elf/rtld.c index 526360237f..38f11f5b73 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -49,6 +49,7 @@ #include #include #include +#include #include @@ -1609,6 +1610,16 @@ dl_main (const ElfW(Phdr) *phdr, { /* Extract the contents of the dynamic section for easy access. */ elf_get_dynamic_info (main_map, NULL); + + /* If the main map is libc.so, update the base namespace to + refer to this map. If libc.so is loaded later, this happens + in _dl_map_object_from_fd. */ + if (main_map->l_info[DT_SONAME] != NULL + && (strcmp (((const char *) D_PTR (main_map, l_info[DT_STRTAB]) + + main_map->l_info[DT_SONAME]->d_un.d_val), LIBC_SO) + == 0)) + GL(dl_ns)[LM_ID_BASE].libc_map = main_map; + /* Set up our cache of pointers into the hash table. */ _dl_setup_hash (main_map); }