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.129.124]) by sourceware.org (Postfix) with ESMTPS id 5AF153858C27 for ; Thu, 12 Jan 2023 14:46:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5AF153858C27 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673534810; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=8A0Yit0bp9sTHs6O/3vk5R0t99IslLw3AfDH6X5vDBc=; b=SXWgF50XlC2UW380mXTwth1Gny2eiNHzz038jYqb7aThaolMC4El+pqjIdgth54wkLY9JI yUvIYqAO01dX2AAOcgcSJoUWu5ieesuaMAdDZE5kl7XJFO7GKI3LHdGetxgynx897dUhNQ y9Fw15/+rzipvF+u4qD5WH5Y+KiFk04= 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-505-u-7Az6vkNY29QwbuTXdvyw-1; Thu, 12 Jan 2023 09:46:47 -0500 X-MC-Unique: u-7Az6vkNY29QwbuTXdvyw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 129BD85A588; Thu, 12 Jan 2023 14:46:47 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.45]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 713C12026D68; Thu, 12 Jan 2023 14:46:46 +0000 (UTC) From: Florian Weimer To: Adhemerval Zanella Cc: libc-alpha@sourceware.org, John Paul Adrian Glaubitz Subject: Re: [PATCH v2] elf: Fix GL(dl_phdr) and GL(dl_phnum) for static builds [BZ #29864] References: <20230112144412.3102134-1-adhemerval.zanella@linaro.org> Date: Thu, 12 Jan 2023 15:46:44 +0100 In-Reply-To: <20230112144412.3102134-1-adhemerval.zanella@linaro.org> (Adhemerval Zanella's message of "Thu, 12 Jan 2023 11:44:12 -0300") Message-ID: <875ydbq08b.fsf@oldenburg.str.redhat.com> 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.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,URIBL_BLACK autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: * Adhemerval Zanella: > The 73fc4e28b9464f0e refactor did not add the GL(dl_phdr) and > GL(dl_phnum) for static build, relying on the __ehdr_start symbol, > which is always added by the static linker, to get the correct values. > > This is problematic in some ways: > > - The segment may see its in-memory size differ from its in-file > size (or the binary may have holes). The Linux has fixed is to > provide concise values for both AT_PHDR and AT_PHNUM (commit > 0da1d5002745c - "fs/binfmt_elf: Fix AT_PHDR for unusual ELF files") > > - Some archs (alpha for instance) the hidden weak reference is not > correctly pulled by the static linker and __ehdr_start address > end up being 0, which makes GL(dl_phdr) and GL(dl_phnum) have both > invalid values (and triggering a segfault later on libc.so while > accessing TLS variables). > > The safer fix is to just restore the previous behavior to setup > GL(dl_phdr) and GL(dl_phnum) for static based on kernel auxv. The > __ehdr_start fallback can also be simplified by not assuming weak > linkage (as for PIE). > > The libc-static.c auxv init logic is moved to dl-support.c, since > the later is build without SHARED and then GLRO macro is defined > to access the variables directly. > > The _dl_phdr is also assumed to be always non NULL, since an invalid > NULL values does not trigger TLS initialization (which is used in > various libc systems). > > Checked on aarch64-linux-gnu, x86_64-linux-gnu, and i686-linux-gnu. > > * Changes from v1: > - Removed auxv_values implicit initialization. > - Removed unused header inclusion. This version looks okay to me. Reviewed-by: Florian Weimer Thanks, Florian