public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Alexander Monakov <amonakov@ispras.ru>
To: Max Sagebaum <max.sagebaum@scicomp.uni-kl.de>
Cc: "gcc-help@gcc.gnu.org" <gcc-help@gcc.gnu.org>
Subject: Re: Detect '-fvisibility=hidden' during pre process or compile time
Date: Fri, 22 Apr 2022 18:09:29 +0300 (MSK)	[thread overview]
Message-ID: <59e49ece-4353-5a81-905a-34c296d3ec8@ispras.ru> (raw)
In-Reply-To: <6e75545cc24f1198502ec3a517a1a7dcb5054742.camel@scicomp.uni-kl.de>

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

  reply	other threads:[~2022-04-22 15:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-22 12:48 Max Sagebaum
2022-04-22 15:09 ` Alexander Monakov [this message]
2022-04-22 16:16   ` Max Sagebaum
2022-04-22 16:44     ` Alexander Monakov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=59e49ece-4353-5a81-905a-34c296d3ec8@ispras.ru \
    --to=amonakov@ispras.ru \
    --cc=gcc-help@gcc.gnu.org \
    --cc=max.sagebaum@scicomp.uni-kl.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).