From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id CCB763857C59 for ; Wed, 16 Sep 2020 17:52:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CCB763857C59 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=joseph_myers@mentor.com IronPort-SDR: wyZNjaDKZrCn8516OcEEd2EZRTvk4a3bB/yg1zcNoRMUAN1SHmy0du52yCqs9t+a17tlPt0VA4 MHQaWD4PSBvha71yJSA/R/9QbV2JJSdFtbjeUS6Vw2DJyAimTPs+C8UxW+UhNVy55YYOpJVIuH GBQWi4Z3OVYz1KEn8wTb08OXNkx7Nux16ZYJl3eyQftXfJfVtZfl8QqFPoDejwKAYi89WcOZAC UPPFgYzn7qJ1Odhfrc7bXV9WVk5NoSdkeLxV3JtoOBs2iy++2EN5ilzI+Js99BWPgHQ25wLHGd LHQ= X-IronPort-AV: E=Sophos;i="5.76,433,1592899200"; d="scan'208";a="55187518" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 16 Sep 2020 09:52:24 -0800 IronPort-SDR: G1IMZ5SopQPFHI54HR4bFKtb0KmYVzL+97EZ5/JLCkeSUVbxu4coHajHtVGlCS2Lo+40BGeRyW SOoEdLc4JalCT3JMDj6sn9japOYsNT3QDvYwCOC3UNUmqphDmxh/Y3MKzeQPxk1k2jZRQS3sz5 /irIrAi0aKMHbQzghfc/5u1Ms2KWeaO6xbhCSO4nxOJ6C9QSSynBNhuvjvFlA1I71cF1BlUhvX arS4Y5GFSYZCsR8ZGFGOtBb22GGzOqD1rilaAEnpqdKj0JBX4WnnCjjq3uXLUk7xnqeMAO884B jqs= Date: Wed, 16 Sep 2020 17:52:19 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: Jeff Law CC: GCC Patches Subject: Re: Problem with static const objects and LTO In-Reply-To: <8770b080-9da3-e8e5-80a7-afde36ab3e5e@redhat.com> Message-ID: References: <8770b080-9da3-e8e5-80a7-afde36ab3e5e@redhat.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-02.mgc.mentorg.com (139.181.222.2) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-3127.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8BIT X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Sep 2020 17:52:27 -0000 On Wed, 16 Sep 2020, Jeff Law via Gcc-patches wrote: > ISTM this is a lot like the problem we have where we inline functions > with static data.   To fix those we use STB_GNU_UNIQUE.  But I don't see > any code in the C front-end which would utilize STB_GNU_UNIQUE.  It's > support seems limited to C++. > > > How is this supposed to work for C? C inline functions don't try to address this. The standard has a rule "An inline definition of a function with external linkage shall not contain a definition of a modifiable object with static or thread storage duration, and shall not contain a reference to an identifier with internal linkage.", which avoids some cases of this, but you can still get multiple copies of objects (with static storage duration, not modifiable, no linkage, i.e. static const defined inside an inline function) as noted in a footnote "Since an inline definition is distinct from the corresponding external definition and from any other corresponding inline definitions in other translation units, all corresponding objects with static storage duration are also distinct in each of the definitions.". -- Joseph S. Myers joseph@codesourcery.com