* Detect '-fvisibility=hidden' during pre process or compile time @ 2022-04-22 12:48 Max Sagebaum 2022-04-22 15:09 ` Alexander Monakov 0 siblings, 1 reply; 4+ messages in thread From: Max Sagebaum @ 2022-04-22 12:48 UTC (permalink / raw) To: gcc-help 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? 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)<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104631> 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.) We wanted to ask if it is possible to issue a warning during compile time or in the preprocessor that the '-fvisibility=hidden' option is used in our library. Thanks Max ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Detect '-fvisibility=hidden' during pre process or compile time 2022-04-22 12:48 Detect '-fvisibility=hidden' during pre process or compile time Max Sagebaum @ 2022-04-22 15:09 ` Alexander Monakov 2022-04-22 16:16 ` Max Sagebaum 0 siblings, 1 reply; 4+ messages in thread From: Alexander Monakov @ 2022-04-22 15:09 UTC (permalink / raw) To: Max Sagebaum; +Cc: gcc-help 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Detect '-fvisibility=hidden' during pre process or compile time 2022-04-22 15:09 ` Alexander Monakov @ 2022-04-22 16:16 ` Max Sagebaum 2022-04-22 16:44 ` Alexander Monakov 0 siblings, 1 reply; 4+ messages in thread From: Max Sagebaum @ 2022-04-22 16:16 UTC (permalink / raw) To: amonakov; +Cc: gcc-help Hello Alexander, thank you for the answer. Unfortunately, the type needs to be a template parameter. Is there any other way to change the visibility of a member or in addition change the visibility of a template parameter? Thanks Max On Fri, 2022-04-22 at 18:09 +0300, Alexander Monakov wrote: 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 -- Dr. Max Sagebaum Chair for Scientific Computing, TU Kaiserslautern, Bldg/Geb 34, Paul-Ehrlich-Strasse, 67663 Kaiserslautern, Germany Phone: +49 (0)631 205 5638 Fax: +49 (0)631 205 3056 Email: max.sagebaum@scicomp.uni-kl.de<mailto:max.sagebaum@scicomp.uni-kl.de> URL: www.scicomp.uni-kl.de ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Detect '-fvisibility=hidden' during pre process or compile time 2022-04-22 16:16 ` Max Sagebaum @ 2022-04-22 16:44 ` Alexander Monakov 0 siblings, 0 replies; 4+ messages in thread From: Alexander Monakov @ 2022-04-22 16:44 UTC (permalink / raw) To: Max Sagebaum; +Cc: gcc-help On Fri, 22 Apr 2022, Max Sagebaum wrote: > Hello Alexander, > > thank you for the answer. Unfortunately, the type needs to be a template > parameter. Is there any other way to change the visibility of a member or in > addition change the visibility of a template parameter? You can change visibility of the type used as the template parameter; in the small example in the Bugzilla, you could write struct __attribute__((visibility("default"))) S { }; or with a pragma: #pragma GCC visibility push(default) struct S { }; #pragma GCC visibility pop If in your actual library such 'struct S' has many members and you want to avoid making them default-visibility, you could move some of them into a subobject (which then may have hidden visibility). Alexander ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-04-22 16:44 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-04-22 12:48 Detect '-fvisibility=hidden' during pre process or compile time Max Sagebaum 2022-04-22 15:09 ` Alexander Monakov 2022-04-22 16:16 ` Max Sagebaum 2022-04-22 16:44 ` Alexander Monakov
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).