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 35EBE3858D3C for ; Wed, 24 Jan 2024 20:24:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 35EBE3858D3C 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 35EBE3858D3C 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=1706127888; cv=none; b=CWezgTOczP9SJ28xgYSkVvF850p0FcLw5wRHJWISqgQ1HMxc5JCGjuXUq3gzBlx/2lD9NNYbuiA5UQMMHdnCo4sy7SIpawyY328uk7oZ95qG+zNPJf4iy4Ot7Npf0YZTBI09HIWtfegeGEfaPBs/0VhIhu+mWaf9ohykFc/NuzQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706127888; c=relaxed/simple; bh=YG2sGiYV0uhe11axct7H65bQmqD6cnfYtNL/803bk10=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=wPFnYo5pyuv/p6m/N+Rgu57QW+6g5EWPU4GbR9uK57JzOaiMHUa+RB+ZEuzJukcVMOLnfkuJQnwMasv9how8mP4m+SM6QzbLWqjxWe3mcktafnUNLR44oBn1aKhyUMunLUloFJ3yjrzFMGT9BF7kIpUQYHzR8yfgS+dCUUKKJfs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706127886; 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=aJzW3a10DW5Vp+vYGtDCG8j/WVcCh+emuQFaKE5LQ48=; b=hodykIhjHLzw+k1xxCkEFfD3fIl5pDZugoyUeblv5+q42GEjlUisSYakMrA8+U68LNeH6d 3kUPiLPfX+QeNAyHkKcM3Lvgkm8Y5lJUU5pvGDBO603ETvpIllOouuSrWyxpooG8z4jLrw WmX1gzjfYtsUxgKletdsvp3cd05UcgI= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-115-5_FF2nS6Mv6K7d6H-fK9tw-1; Wed, 24 Jan 2024 15:24:45 -0500 X-MC-Unique: 5_FF2nS6Mv6K7d6H-fK9tw-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-78377692045so697915585a.0 for ; Wed, 24 Jan 2024 12:24:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706127884; x=1706732684; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aJzW3a10DW5Vp+vYGtDCG8j/WVcCh+emuQFaKE5LQ48=; b=NeEl+DzWqvvJV1eb8WCBsUHefQ8JRSRBOEIzCyVcEM6iIo1M+GmiNzgyFf1FpWl9qP e0ou1loFMD81Q+3VlX5O5UZ9ZIEjojNq7PXrtZuI7pTQ5ZDfl3o74lHKe8q3Xb6v1Rv1 ulNTfHdsVIiZqjKQFMNOlzVFWZO2bbZ4kB1eYyhTRWslkXJzMUPdzvcmp7c3GmQw2DOX fXlDcq6CMCAUIrxb/hCKyoFHEK3sBwWS5DSMsR7OkHQCvK9x6GKj9qrB97d84Dz7Hpwp 6UtF6JMluJlF3/XgagSrIIaNiLyhPwYny9ZfUd/cBnEB0Z7QYxzlCO80mqUNq4FEyxNJ o/Eg== X-Gm-Message-State: AOJu0YyN1qA+a8/A+yVpRXns/2bhx+xY2kuRh1v7nZFlx72lsmfGA9Xl m3GyYNZiwIGaN6BAj9sVtA9Z2zJpJeV052E1iwxQkS/PBSPiM11tEtbc//gWNK+qzx68/EV5FlZ iYjHrv6YTTfCljtSQ/7t3obyQ1PnZpxNKsfPmKDzcrtujZJAoTVccBuU= X-Received: by 2002:a05:620a:a43:b0:783:7334:1478 with SMTP id j3-20020a05620a0a4300b0078373341478mr8680016qka.140.1706127884508; Wed, 24 Jan 2024 12:24:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IEI1winpEW34v5e8thJPzTQLsqqkLC89WKu0xfdM38g87akksp7vtH6WnQxS0d11Khk0Oc9sw== X-Received: by 2002:a05:620a:a43:b0:783:7334:1478 with SMTP id j3-20020a05620a0a4300b0078373341478mr8680005qka.140.1706127884059; Wed, 24 Jan 2024 12:24:44 -0800 (PST) Received: from [192.168.1.108] (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 g18-20020a05620a13d200b0078395da3735sm3971099qkl.6.2024.01.24.12.24.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 Jan 2024 12:24:43 -0800 (PST) Message-ID: <473bdd7b-d352-4608-b472-843191c8d5f5@redhat.com> Date: Wed, 24 Jan 2024 15:24:42 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] c++/modules: Emit definitions of ODR-used static members imported from modules [PR112899] To: Nathaniel Shead , Patrick Palka Cc: gcc-patches@gcc.gnu.org, Nathan Sidwell References: <659490fd.170a0220.1ce2e.503a@mx.google.com> <36bed0fe-5564-60ed-df91-240d78819add@idea> <65aba461.a70a0220.7fd5c.ad24@mx.google.com> From: Jason Merrill In-Reply-To: <65aba461.a70a0220.7fd5c.ad24@mx.google.com> 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.2 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,RCVD_IN_SORBS_WEB,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 List-Id: On 1/20/24 05:45, Nathaniel Shead wrote: > On Fri, Jan 19, 2024 at 01:57:18PM -0500, Patrick Palka wrote: >> On Wed, 3 Jan 2024, Nathaniel Shead wrote: >>> + if (DECL_CONTEXT (decl) >>> + && RECORD_OR_UNION_TYPE_P (DECL_CONTEXT (decl)) >>> + && !DECL_TEMPLATE_INFO (decl)) >>> + note_static_storage_variable (decl); >> >> It seems this should also handle templated inlines via >> >> && (!DECL_TEMPLATE_INFO (decl) >> || DECL_IMPLICIT_INSTANTIATION (decl)) >> >> otherwise the following fails to link: >> >> $ cat init-5_a.H >> template >> struct __from_chars_alnum_to_val_table { >> static inline int value = 42; >> }; >> >> inline unsigned char >> __from_chars_alnum_to_val() { >> return __from_chars_alnum_to_val_table::value; >> } >> >> $ cat init-6_b.C >> import "init-5_a.H"; >> >> int main() { >> __from_chars_alnum_to_val(); >> } >> >> $ g++ -fmodules-ts -std=c++20 init-5_a.H init-5_b.C >> /usr/bin/ld: /tmp/ccNRaads.o: in function `__from_chars_alnum_to_val()': >> init-6_b.C:(.text._Z25__from_chars_alnum_to_valv[_Z25__from_chars_alnum_to_valv]+0x6): undefined reference to `__from_chars_alnum_to_val_table::value' > > Ah yes, of course, since that's the other context where declarations are > added to 'pending_statics'. > >> By the way I ran into this when testing out std::print with modules: >> >> $ cat std.C >> export module std; >> export import ; >> >> $ cat hello.C >> import std; >> >> int main() { >> std::print("Hello {}!", "World"); >> } >> >> $ g++ -fmodules-ts -std=c++26 -x c++-system-header bits/stdc++.h >> $ g++ -fmodules-ts -std=c++26 std.C hello.C && ./a.out # before >> /usr/bin/ld: /tmp/ccqNgOM1.o: in function `unsigned char std::__detail::__from_chars_alnum_to_val(unsigned char)': >> hello.C:(.text._ZNSt8__detail25__from_chars_alnum_to_valILb0EEEhh[_ZNSt8__detail25__from_chars_alnum_to_valILb0EEEhh]+0x12): undefined reference to `std::__detail::__from_chars_alnum_to_val_table::value' >> $ g++ -fmodules-ts -std=c++26 std.C hello.C && ./a.out # after >> Hello World! >> >> It's great that this is so close to working! > > That's great! > > Here's a new version of the patch with the above fixed. > I also included > your change to only add class variable templates to 'pending_statics' > (and the normal 'static_decl's for non-class otherwise) as otherwise I > could imagine that they would cause issues with this later too. That seems wrong; the 'static_decls' vec is just for checking that static/inline variables got defined. pending_statics has been used for template instantiations for a long time, for non-module code; let's not mess with that in a modules patch. > I know that there's been discussion about the correct ABI for inline > declarations, but personally I'd like to have this fixed for normal uses > in GCC14 at least, and we can revisit the specific cases where various > kinds of declarations are emitted in stage 1. Makes sense. > P.S. As I go to send this, I wonder if maybe something like > 'note_static_member_variable' would be a clearer choice of name than > 'note_static_storage_variable'? Let's call it note_vague_linkage_variable, to go with _fn just above. > -- >8 -- > > Static data members marked 'inline' should be emitted in TUs where they > are ODR-used. We need to make sure that statics imported from modules > are correctly added to the 'pending_statics' map so that they get > emitted if needed, otherwise the attached testcase fails to link. What about non-member variables marked inline, and non-member variable template instantiations? Jason