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 5B51B3858D35 for ; Tue, 14 May 2024 22:20:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5B51B3858D35 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 5B51B3858D35 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=1715725228; cv=none; b=Ra/psJHW4XaJFN/giFrpmzdVdZSn+AUx7XZt42yYTqfTM9dLq1JQ9jDNLXivQKSpisXLLHUV7AhgJY0DKFeeivcxDIP0D10sLvJruwXFUiBKjwGP6aQEL3S7ntbiIBQ68wE1BzkSphg2/y3hI+gbmHofhcIYMMbdPyXPqn06XXs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715725228; c=relaxed/simple; bh=QhVmDJnx25EV4Q21JwKT+J90iCqZzMwgBwcIz6uxn9k=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=lNrk2SmTY5G21JWb3PnRByI3zrDRqiWHgwJCCojoJ/M0YfJxA4IYKEW3NduDbflUv26Icf1mwIChQ6O8o4lztnw4zpiGj046dQmAI7dwbc3SItTD8pV0/rmE4fNCQeHHaTRypkyc6bby3bExM8L4ooFZT80fb5NddFSzOjRr2kQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715725225; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wzLjlRmlTHJZkbLsOEyl9LX1+VFzOch0WAZhak6Z1es=; b=aWiVy3hll8QaNwAqbQMoJ6OJ7BsgGU5phkXG92K0ZxwIJdD2o/OTHHqCj53Gn5F3G1TY60 cxG9bKINN5mrYR+yzM0XZV94qssicHXfL/v135oBZcDzpewimwRvp02vhZiLnHJuEczESF mvHdAMmR18ZUIn98c1BFN/9zGfEYoeQ= Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-671-lBGFtH9EPGWeI5eR3I9jBw-1; Tue, 14 May 2024 18:20:23 -0400 X-MC-Unique: lBGFtH9EPGWeI5eR3I9jBw-1 Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-3c99c4e8e7fso5909235b6e.1 for ; Tue, 14 May 2024 15:20:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715725222; x=1716330022; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wzLjlRmlTHJZkbLsOEyl9LX1+VFzOch0WAZhak6Z1es=; b=W9YXb3mYgvDvaYlNEL/KKYmH3iZ58ACHAu7J+uaVZMLfUILtPBbNJkYF51mGS04sbW eH3P74J+zKq8I5er+43t+VHGTnsVXAfCcIfB7yQS+vqZvnf3pKf6jLKGZiIWQ9wLXVj7 aIfu0MwYZvIW7nzY1CzRc1sYZ0P32HrBpeSSEB00hQu+Oh8oUmKbBGdUE95urtJF9eAd Wf0Nc15YYS/PVrcCapkDT4c6W+wdkPiwZ9v/UFuJrCvb5vh3KmWkwIVr4GgByEx64D9d pKRMqzyxIvPN+YU4AfP843w7PFkq37K+PoiTNW49PsqihN9xjAtQVolYhib8rsFq8FGB uEHA== X-Forwarded-Encrypted: i=1; AJvYcCWe4CtnN2K/Gu18bRcOhsakHsQQzSdQdrBXbb4Vp7XGg3JQEbkktTsPmYe1YQqnCXIYzw9mEeA6vietqw29bSupDZMCl2Nqyg== X-Gm-Message-State: AOJu0YxyZIVIiei1o/exMbyGXBcXgplr/FVq+wdNbE5EzPHcaMQNA3ZS oEgWTeZa6/EJAt+yZH/ySpyS5Fhi7aC1ml5kSOvbsTu26FY6Dkt3jjRPVrli636GiLnis9ArHjm fX84sjx928hEXOzI2i8sZDfHAW6iOmitBTaErM9A8sHNkdSxkdTF60lf52i9VgB0= X-Received: by 2002:a05:6808:3c6:b0:3c9:60a3:dfb1 with SMTP id 5614622812f47-3c9970492dfmr14714246b6e.21.1715725222443; Tue, 14 May 2024 15:20:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFOz7XM1DEAuKr8kNh0V3VP7gDSCrbsohIh9+dWN0lZlQ+NB+/haLGMONehLt5OVU+L80cqyg== X-Received: by 2002:a05:6808:3c6:b0:3c9:60a3:dfb1 with SMTP id 5614622812f47-3c9970492dfmr14714230b6e.21.1715725222003; Tue, 14 May 2024 15:20:22 -0700 (PDT) Received: from [192.168.1.130] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id af79cd13be357-792bf2fc67esm612091685a.74.2024.05.14.15.20.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 May 2024 15:20:21 -0700 (PDT) Message-ID: <69baa0f6-c590-48c2-a0ad-3af83dfd4301@redhat.com> Date: Tue, 14 May 2024 18:20:20 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++: Optimize in maybe_clone_body aliases even when not at_eof [PR113208] To: Jakub Jelinek Cc: Jonathan Wakely , Jan Hubicka , gcc-patches@gcc.gnu.org, Richard Biener , Patrick Palka References: <5f6569bc-8d94-434c-b66d-137c8e7f5e64@redhat.com> <32bfcf8c-1b45-444c-8729-e560952fe44b@redhat.com> From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.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_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 5/13/24 06:19, Jakub Jelinek wrote: > On Fri, May 10, 2024 at 03:59:25PM -0400, Jason Merrill wrote: >>> 2024-05-09 Jakub Jelinek >>> Jason Merrill >>> >>> PR lto/113208 >>> * cp-tree.h (maybe_optimize_cdtor): Remove. >>> * decl2.cc (tentative_decl_linkage): Call maybe_make_one_only >>> for implicit instantiations of maybe in charge ctors/dtors >>> declared inline. >>> (import_export_decl): Don't call maybe_optimize_cdtor. >>> (c_parse_final_cleanups): Formatting fixes. >>> * optimize.cc (can_alias_cdtor): Adjust condition, for >>> HAVE_COMDAT_GROUP && DECL_ONE_ONLY && DECL_WEAK return true even >>> if not DECL_INTERFACE_KNOWN. >> >>> --- gcc/cp/optimize.cc.jj 2024-04-25 20:33:30.771858912 +0200 >>> +++ gcc/cp/optimize.cc 2024-05-09 17:10:23.920478922 +0200 >>> @@ -220,10 +220,8 @@ can_alias_cdtor (tree fn) >>> gcc_assert (DECL_MAYBE_IN_CHARGE_CDTOR_P (fn)); >>> /* Don't use aliases for weak/linkonce definitions unless we can put both >>> symbols in the same COMDAT group. */ >>> - return (DECL_INTERFACE_KNOWN (fn) >>> - && (SUPPORTS_ONE_ONLY || !DECL_WEAK (fn)) >>> - && (!DECL_ONE_ONLY (fn) >>> - || (HAVE_COMDAT_GROUP && DECL_WEAK (fn)))); >>> + return (DECL_WEAK (fn) ? (HAVE_COMDAT_GROUP && DECL_ONE_ONLY (fn)) >>> + : (DECL_INTERFACE_KNOWN (fn) && !DECL_ONE_ONLY (fn))); >> >> Hmm, would >> >> (DECL_ONE_ONLY (fn) ? HAVE_COMDAT_GROUP >> : (DECL_INTERFACE_KNOWN (fn) && !DECL_WEAK (fn))) >> >> make sense instead? I don't think DECL_WEAK is necessary for COMDAT. > > I think it isn't indeed necessary for COMDAT, although e.g. comdat_linkage > will not call make_decl_one_only if !flag_weak. > > But I think it is absolutely required for the alias cdtor optimization > in question, because otherwise it would be an ABI change. > Consider older version of GCC or some other compiler emitting > _ZN6vectorI12QualityValueEC1ERKS1_ > and > _ZN6vectorI12QualityValueEC2ERKS1_ > symbols not as aliases, each in their own comdat groups, so > .text._ZN6vectorI12QualityValueEC1ERKS1_ in _ZN6vectorI12QualityValueEC1ERKS1_ > comdat group and > .text._ZN6vectorI12QualityValueEC2ERKS1_ in _ZN6vectorI12QualityValueEC2ERKS1_ > comdat group. And then comes GCC with the above patch without the DECL_WEAK > check in there, and decides to use alias, so > _ZN6vectorI12QualityValueEC1ERKS1_ is an alias to > _ZN6vectorI12QualityValueEC2ERKS1_ and both live in > .text._ZN6vectorI12QualityValueEC2ERKS1_ section in > _ZN6vectorI12QualityValueEC5ERKS1_ comdat group. If you mix TUs with this, > the linker can keep one of the section sets from the _ZN6vectorI12QualityValueEC1ERKS1_ > and _ZN6vectorI12QualityValueEC2ERKS1_ and _ZN6vectorI12QualityValueEC5ERKS1_ > comdat groups. If there is no .weak for the symbols, this will fail to > link, one can emit it either the old way or the new way but never both, it > is part of an ABI. > While with .weak, mixing it is possible, worst case one gets some unused > code in the linked binary or shared library. Of course the desirable case > is that there is no mixing and there is no unused code, but if it happens, > no big deal. Without .weak it is a big deal. Makes sense, the patch is OK. Jason