This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Visibility attribute
- From: Matt Austern <austern at apple dot com>
- To: gcc at gcc dot gnu dot org
- Date: Tue, 25 Nov 2003 21:32:56 -0800
- Subject: Visibility attribute
My patch that introduced DECL_VISIBILITY broke the visibility feature
for C; see PR c/13134. I definitely need to fix the compiler, and I
have a patch that does fix things for certain definitions of "fix".
But before I submit it, I'd like to get some feedback on what the
semantics of this feature actually ought to be. As usual, the manual
isn't quite specific enough to be sure. Depending on what we decide,
it might be that the right solution will be for me to back out my patch
entirely.
There are two fundamental questions:
1. If you have multiple declarations of the same function or variable,
may you give them different visibilities? If so, what should be the
semantics?
2. Is it always the case that leaving out the visibility declaration
is the same as explicitly saying that you've got default visibility?
Consider a few test cases.
__attribute__ ((visibility("hidden"))) int x;
int x = 5;
__attribute__ ((visibility("hidden"))) int y;
__attribute__ ((visibility("protected"))) int y = 5;
__attribute__ ((visibility("hidden"))) int z;
__attribute__ ((visibility("default"))) int z = 5;
What do you expect the visibility of x to be in each of these cases?
Here are a number of possible answers to that question:
1. All three of these cases are errors. Every declaration of the same
variable must have the same visibility.
2. The earlier declaration always overrides the later. So x, y, and z
all have hidden visibility.
3. The later declaration always overrides the earlier. So x and z
have default visibility, y has protected visibility.
4. The later declaration overrides the earlier *only if* the later
declaration is something other than default. So x and z have hidden
visibility, y has protected visibility.
5. The later declaration overrides the earlier *only if* the later
declaration explicitly specifies a visibility. So x has hidden
visibility, y has protected visibility, and z has default visibility.
Note that if we choose this answer, we'll be saying that explicitly
specifying default visibility is not the same as not specifying any
visibility.
Option 1 is arguably the most natural. Option 3 is what the compiler
currently does. Option 4 is what I've implemented in my patch. Option
5 scares me; if we decide that's the right answer, then I might have to
back out DECL_VISIBILITY entirely.
Thoughts?
--Matt