From patchwork Tue Jul 4 20:03:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1803368 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=G3MZjGTr; dkim-atps=neutral Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QwYg72jY7z20Pf for ; Wed, 5 Jul 2023 06:05:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3479E382EA25 for ; Tue, 4 Jul 2023 20:05:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3479E382EA25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1688501105; bh=YSIHpX7VxFemRxe+xVuQAg+NpbXeCXa6xuGLbwBQWNo=; 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=G3MZjGTr9ev0PfKLX/wF+zUgTXuFLKCVUEa+ZGH1EiKZelolqtQcOtvyS87g+zuT+ 30t25EzkgJFmX7/sxpuzrg4SF3SmnHX4/RvEItVwfcaKdWo+Xe/dUpQMdygAjoLV6J WfZyN7LJG/959UW45Ndkjql9kPUtKyx8L5ybiD0s= 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 [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 479D83853D07 for ; Tue, 4 Jul 2023 20:03:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 479D83853D07 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-149-OnqzXLrnPiucSFf2G9lv2g-1; Tue, 04 Jul 2023 16:03:14 -0400 X-MC-Unique: OnqzXLrnPiucSFf2G9lv2g-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7A9EF101A528 for ; Tue, 4 Jul 2023 20:03:14 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E049A492C13 for ; Tue, 4 Jul 2023 20:03:13 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 13/33] elf: Move __rtld_malloc_init_stubs call into _dl_start_final In-Reply-To: Message-ID: References: X-From-Line: c9fb46cfb1ae40b76b0cf31ee0481b004288da7f Mon Sep 17 00:00:00 2001 Date: Tue, 04 Jul 2023 22:03:12 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.5 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_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" Calling an extern function in a different translation unit before self-relocation is brittle. The compiler may load the address at an earlier point in _dl_start, before self-relocation. In _dl_start_final, the call is behidn a compiler barrier, so this cannot happen. --- elf/rtld.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/elf/rtld.c b/elf/rtld.c index 54a7ade886..4624d99570 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -452,6 +452,8 @@ _dl_start_final (void *arg, struct dl_start_final_info *info) { ElfW(Addr) start_addr; + __rtld_malloc_init_stubs (); + /* Do not use an initializer for these members because it would interfere with __rtld_static_init. */ GLRO (dl_find_object) = &_dl_find_object; @@ -575,8 +577,6 @@ _dl_start (void *arg) function, that way the compiler cannot put accesses to the GOT before ELF_DYNAMIC_RELOCATE. */ - __rtld_malloc_init_stubs (); - #ifdef DONT_USE_BOOTSTRAP_MAP return _dl_start_final (arg); #else