From patchwork Fri Aug 23 12:21:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1976026 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=BvundgLh; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) 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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WqzjP6DjGz1yNr for ; Fri, 23 Aug 2024 22:22:33 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B00473875DCE for ; Fri, 23 Aug 2024 12:22:31 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 0757E3861807 for ; Fri, 23 Aug 2024 12:21:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0757E3861807 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0757E3861807 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724415688; cv=none; b=FEJmb/vbSdChK0kiAe4FGT6ZV+HjLhDlGfUQWZM9Kjc4WQv1pgLNaoaKgx1DJ1rkTqQSyjDybonvHJugxS5+flyccmZN1tP++4t4P6bGoELX7gd2kpJ5cNMdfefNH060XHDppeSngi++k43/bgF9AWq4SGb0kpdlJysFCEso6zs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724415688; c=relaxed/simple; bh=e93rgDRxyjY6wIhq6syo/GNXay8zxA8gQ6RSXYxUceo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ijmq5UNKpBBysKtbSHPssUngleSo5/ZLNgOTDUL9meKlcVHMmnlmBQW9nuX+djVeC5h3yuTzE411ox23+LpTL4W5AueH6CST3CtLzU3kjsNwk3zXfzVoCaHGC/+Q2tbTAis2uildW7EnLeaCOkrKHz+wzOTd7rAth+xE1VHhT7U= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724415685; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=7Rkwb4iKeK3HY+wL++wKtH2Cxq1IqiFtP/GX9X3loGs=; b=BvundgLhFBy/oYglImxrJoSuJsEGeMV1cBADBo7EAVeJ6haWxof1EwdPKReb/DoDywk/k1 nNBiWGe5BqMSC6McqkYYkTRF1eeN5Otxi3GbtwLNHGMUXVAATprkDIZfsYnnwgLJtT+Mko zgYdT30s8dqWwq7VcnhqT5NDeOK9QGQ= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-517-e7An0QJHPPmpuCpZSS5sPg-1; Fri, 23 Aug 2024 08:21:23 -0400 X-MC-Unique: e7An0QJHPPmpuCpZSS5sPg-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BE96A1955D53; Fri, 23 Aug 2024 12:21:22 +0000 (UTC) Received: from localhost (unknown [10.42.28.41]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 242E31954B39; Fri, 23 Aug 2024 12:21:21 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Make debug sequence members mutable [PR116369] Date: Fri, 23 Aug 2024 13:21:06 +0100 Message-ID: <20240823122120.959471-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-linux. Pushed to trunk. -- >8 -- We need to be able to attach debug mode iterators to const containers, so the safe iterator constructor uses const_cast to get a modifiable pointer to the container. If the container was defined as const, that const_cast to access its members results in undefined behaviour. PR 116369 shows a case where it results in a segfault because the container is in a rodata section (which shouldn't have happened, but the undefined behaviour in the library still exists in any case). This makes the _M_iterators and _M_const_iterators data members mutable, so that it's safe to modify them even if the declared type of the container is a const type. Ideally we would not need the const_cast at all. Instead, the _M_attach member (and everything it calls) should be const-qualified. That would work fine now, because the members that it ends up modifying are mutable. Making that change would require a number of new exports from the shared library, and would require retaining the old non-const member functions (maybe as symbol aliases) for backwards compatibility. That might be worth changing at some point, but isn't done here. libstdc++-v3/ChangeLog: PR c++/116369 * include/debug/safe_base.h (_Safe_sequence_base::_M_iterators): Add mutable specifier. (_Safe_sequence_base::_M_const_iterators): Likewise. --- libstdc++-v3/include/debug/safe_base.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/debug/safe_base.h b/libstdc++-v3/include/debug/safe_base.h index d5fbe4b1320..88d7f0b05c8 100644 --- a/libstdc++-v3/include/debug/safe_base.h +++ b/libstdc++-v3/include/debug/safe_base.h @@ -205,10 +205,10 @@ namespace __gnu_debug public: /// The list of mutable iterators that reference this container - _Safe_iterator_base* _M_iterators; + mutable _Safe_iterator_base* _M_iterators; /// The list of constant iterators that reference this container - _Safe_iterator_base* _M_const_iterators; + mutable _Safe_iterator_base* _M_const_iterators; /// The container version number. This number may never be 0. mutable unsigned int _M_version;