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.133.124]) by sourceware.org (Postfix) with ESMTPS id E83B23858D20 for ; Wed, 17 Apr 2024 14:07:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E83B23858D20 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 E83B23858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713362844; cv=none; b=gQ/ws/UxcXlePl6IEtY9auHthg3qnkFy+zvyDCTQs3ymArULC4cthpQm47HuUryy3lIjxnwbXHSCUzBB8GQt6l6CPkH5tLThZ1ejZ83FVYPP4kYi/73ELetih8lkYfge+Va6YsvfbC0IRPb5PxyierQOWwzE0/mByrXARgL/qJI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713362844; c=relaxed/simple; bh=qiwXorKaK4QuzSFFADSAx0/LsXvHI46DoYZj4hpe7sI=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=CXedQPJNMQ5YXriIx9aInna5hV67bGgFVGWhaRKjROf60pNvw/7GYQ28kdR4NxoyVUgP3NDHhlM7k7KcrOnl2AESYq9VKxnpeYN/57nJRhE+sr4E8H6j6OTaSLlhRArl09M1GGGSms1dv/qc4AGaOpsGMRDHICxXdjdCBBTGXaE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713362833; h=from:from:reply-to: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=oHwUkuayYuzN/m8kQbnmw1QzFJLdHmwWz/z9B3HbyNU=; b=NiKvGw4MV0izzwL4cof8NmtQuJ7VIesyhlUuZJT8KdjjCxhyVYsKCWV+0BW8WMflGuTKCo w8knclTvjTT6R9nK3dNRAmgCkmD4SUHbDebFQk0pxRa6BSe10BR1dbssemKgVBX1DzMTxH Am1f8vTAlY8WljEmYYTmbxubPMGLAHc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-38-ksUWuDPNMiqnP2ouuRV58A-1; Wed, 17 Apr 2024 10:07:10 -0400 X-MC-Unique: ksUWuDPNMiqnP2ouuRV58A-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id A053880B518; Wed, 17 Apr 2024 14:07:09 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 62B992026D06; Wed, 17 Apr 2024 14:07:09 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 43HE730b2664588 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 17 Apr 2024 16:07:03 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 43HE73vs2664587; Wed, 17 Apr 2024 16:07:03 +0200 Date: Wed, 17 Apr 2024 16:07:03 +0200 From: Jakub Jelinek To: Jan Hubicka Cc: Jason Merrill , Richard Biener , Patrick Palka , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] c++: Retry the aliasing of base/complete cdtor optimization at import_export_decl time [PR113208] Message-ID: Reply-To: Jakub Jelinek References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-4.3 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 Wed, Apr 17, 2024 at 03:26:53PM +0200, Jan Hubicka wrote: > > > > I've tried to see what actually happens during linking without LTO, so compiled > > pr113208_0.C with -O1 -fkeep-inline-functions -std=c++20 with vanilla trunk > > (so it has those 2 separate comdats, one for C2 and one for C1), though I've > > changed the > > void m(k); > > line to > > __attribute__((noipa)) void m(k) {} > > in the testcase, then compiled > > pr113208_1.C with -O2 -fkeep-inline-functions -std=c++20 -fno-omit-frame-pointer > > so that one can clearly differentiate from where the implementation was > > picked and finally added > > template struct _Vector_base { > > int g() const; > > _Vector_base(int, int); > > }; > > > > struct QualityValue; > > template <> > > _Vector_base::_Vector_base(int, int) {} > > template <> > > int _Vector_base::g() const { return 0; } > > int main () {} > > If I link this, I see _ZN6vectorI12QualityValueEC2ERKS1_ and > > _ZN6vectorI12QualityValueEC1ERKS1_ as separate functions with the > > omitted frame pointer bodies, so clearly the pr113208_0.C versions prevailed > > in both cases. It is unclear why that isn't the case for LTO. > > I think it is because of -fkeep-inline-functions which makes the first > object file to define both symbols, while with LTO we optimize out one > of them. > > So to reproduce same behaviour with non-LTO we would probably need use > -O1 and arrange the contructor to be unilinable instead of using > -fkeep-inline-functions. Ah, you're right. If I compile (the one line modified) pr113208_0.C with -O -fno-early-inlining -fdisable-ipa-inline -std=c++20 it does have just _ZN6vectorI12QualityValueEC2ERKS1_ in _ZN6vectorI12QualityValueEC2ERKS1_ comdat and no _ZN6vectorI12QualityValueEC1ERKS1_ and pr113208_1.C with -O -fno-early-inlining -fdisable-ipa-inline -std=c++20 -fno-omit-frame-pointer and link that together with the above mentioned third *.C file, I see 000000000040112a <_ZN6vectorI12QualityValueEC2ERKS1_>: 40112a: 53 push %rbx 40112b: 48 89 fb mov %rdi,%rbx 40112e: 48 89 f7 mov %rsi,%rdi 401131: e8 9c 00 00 00 call 4011d2 <_ZNK12_Vector_baseI12QualityValueE1gEv> 401136: 89 c2 mov %eax,%edx 401138: be 01 00 00 00 mov $0x1,%esi 40113d: 48 89 df mov %rbx,%rdi 401140: e8 7b 00 00 00 call 4011c0 <_ZN12_Vector_baseI12QualityValueEC1Eii> 401145: 5b pop %rbx 401146: c3 ret i.e. the C2 prevailing from pr113208_0.s where it is the only symbol, and 0000000000401196 <_ZN6vectorI12QualityValueEC1ERKS1_>: 401196: 55 push %rbp 401197: 48 89 e5 mov %rsp,%rbp 40119a: 53 push %rbx 40119b: 48 83 ec 08 sub $0x8,%rsp 40119f: 48 89 fb mov %rdi,%rbx 4011a2: 48 89 f7 mov %rsi,%rdi 4011a5: e8 28 00 00 00 call 4011d2 <_ZNK12_Vector_baseI12QualityValueE1gEv> 4011aa: 89 c2 mov %eax,%edx 4011ac: be 01 00 00 00 mov $0x1,%esi 4011b1: 48 89 df mov %rbx,%rdi 4011b4: e8 07 00 00 00 call 4011c0 <_ZN12_Vector_baseI12QualityValueEC1Eii> 4011b9: 48 8b 5d f8 mov -0x8(%rbp),%rbx 4011bd: c9 leave 4011be: c3 ret which is the C1 alias originally aliased to C2 in C5 comdat. So, that would match linker behavior where it sees C1 -> C2 alias prevails, but a different version of C2 prevails, so let's either make C1 a non-alias or alias to a non-exported symbol or something like that. Though, I admit I have no idea what we do with comdat's during LTO, perhaps doing what I said above could break stuff if linker after seeing the LTO resulting objects decides on prevailing symbols differently. Jakub