RFC: Make dllimport/dllexport imply default visibility

Andrew Pinski pinskia@gmail.com
Sat Jun 16 00:37:00 GMT 2007


On 6/15/07, Mark Mitchell <mark@codesourcery.com> wrote:
> So, why not:
>
>   struct S __attribute__((visibility("hidden")) {
>     void f();
>     void g() __attribute__((dllimport));
>   };
>   void S::f() { S::g(); };
>
> In any case, in practice, ARM's RealView compiler accepts:
>
>   struct __declspec(notshared) S {
>     __declspec(dllimport) void f();
>     void g();
>   };
>
>   void S::g() {
>     f();
>   }
>
> And, there's a large body of code that uses this.

Because you missed typeinfo is also hidden (not just vtables).

So if you have (which is what you showed):

 struct S __attribute__((visibility("hidden")) {
   void f();
   void g() __attribute__((dllimport));
 };
 void S::f() { S::g(); };

The typeinfo will be hidden and only in the shared library and not
exported (and if it is then that is a bug).

So in an user program you use typeid(S), you will get a link failure.
If f and g are switch around, you will then not get a link failure but
doing a "throw S();" with a catch on the outside, will cause the throw
to be caught by a try{ .... } catch (S &a) ...

Thanks,
Andrew Pinski



More information about the Gcc mailing list