Mark Mitchell <[EMAIL PROTECTED]> writes:

> But, the visibility attribute is only specified in terms of its effects
> on ELF symbols, not as having C++ semantics per se.

[Sorry I'm so late with this reply; I've been busy and am behind on reading
mailing lists.]

The documentation for the visibility attribute was rewritten a year
ago to be in terms of C++ semantics.  It now says:

@item hidden
Hidden visibility indicates that the entity declared will have a new
form of linkage, which we'll call ``hidden linkage''.  Two
declarations of an object with hidden linkage refer to the same object
if they are in the same shared object.
...
In C++, the visibility attribute applies to types as well as functions
and objects, because in C++ types have linkage. ...

It became essential to do this because the previous documentation was
incomprehensible for users who knew C++ but did not understand every
detail of the C++ linkage model---and insane for users who did
understand every detail of some other system's C++ linkage model and
expected that GCC behaved similarly.

GCC's concept of visibility is very different to that of some other
compilers.  I think this should be handled by features the purpose of
which is specifically to emulate those other compilers.  __dllspec
sounds like one of those features; -fvisibility-ms-compat is another.
That has the advantage that since those other compilers are often not
precisely documented, then as our understanding of those compilers
improves and we adjust the feature to match, the amount of code that
need be broken is minimised.

In respect of this specific example, the compiler should not give any
effect to the attribute on 'f' in:

struct __attribute__((visibility("hidden"))) S {
  void f() __attribute__((visibility("default")));
}

because another shared library can define:

struct __attribute__((visibility("default"))) S {
  void f();
}

but the f() functions are different, because they are in different
name spaces; one is in the name space of S in one shared library,
another is in the name space of a different type S that is visible
globally.  I don't have a strong opinion on whether this should be an
error, a warning that the attribute is ignored, or just silently
ignoring the attribute.

Reply via email to