From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by sourceware.org (Postfix) with ESMTPS id 328473858C2C for ; Fri, 22 Apr 2022 15:09:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 328473858C2C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=ispras.ru Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=ispras.ru Received: from [10.10.3.121] (unknown [10.10.3.121]) by mail.ispras.ru (Postfix) with ESMTPS id 1D07C4076260; Fri, 22 Apr 2022 15:09:29 +0000 (UTC) Date: Fri, 22 Apr 2022 18:09:29 +0300 (MSK) From: Alexander Monakov To: Max Sagebaum cc: "gcc-help@gcc.gnu.org" Subject: Re: Detect '-fvisibility=hidden' during pre process or compile time In-Reply-To: <6e75545cc24f1198502ec3a517a1a7dcb5054742.camel@scicomp.uni-kl.de> Message-ID: <59e49ece-4353-5a81-905a-34c296d3ec8@ispras.ru> References: <6e75545cc24f1198502ec3a517a1a7dcb5054742.camel@scicomp.uni-kl.de> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Apr 2022 15:09:34 -0000 On Fri, 22 Apr 2022, Max Sagebaum wrote: > Hello @ all, > > Short question: Is there a way to detect the option '-fvisibility=hidden' > during the preprocessor or the compile time, such that a warning to the user > can be issued, that the library might not support it? No (note that visibility can change during optimization, like when during LTO the compiler learns that external references will not be possible). > Long question: We develop a header only library where we have a static > structure member inside of a class. We require that this static member is seen > by all operations on this class. > > If our library is included with '-fvisibility=hidden' then we get multiple > symbols of the same static member. We tried to fix this by declaring the > static member with '__attribute__((visibility("default")))' but for members > which are structs this does not seem to work. I filed an bug report about > this and got the answer, that this is not a bug but the behavior is as > desired. > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104631 Well, it is not a matter of a scalar vs a struct type. The issue is that the containing class is a template, and when you instantiate it, template parameter has hidden visibility. I've posted a short example to the above bug. > Since we can not change the visibility of the static member and do not want to > change the visibility of the while library. (Since there is the real use case, > that our library is only used in a different library and all the symbols do > not need to be exposed.) You can change the visibility of the member if you don't require that its type is a template parameter. Alexander