public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113958] New: support visibility attribute for typeinfo symbol
@ 2024-02-16 11:18 noelgrandin at gmail dot com
  2024-02-17  0:52 ` [Bug c++/113958] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: noelgrandin at gmail dot com @ 2024-02-16 11:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113958

            Bug ID: 113958
           Summary: support visibility attribute for typeinfo symbol
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: noelgrandin at gmail dot com
  Target Milestone: ---

Currently, if I want to compile with visibility=hidden, and only expose some
parts of a class definition to the linker, I can use

    class Foo {
        __attribute__ ((visibility("default"))) some_member() {}
    };

on the individual class members. Unfortunately, if external code wants to
dynamic_cast that class, then I end up with 

    /usr/bin/ld: libsvxlo.so: undefined reference to `typeinfo for SvxCharView'

When compiling with clang, I can specify

   __attribute__ ((type_visibility("default"))) class Foo {}

to solve the typeinfo linkage problem.

It would be wonderful if GCC could support something similar.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/113958] support visibility attribute for typeinfo symbol
  2024-02-16 11:18 [Bug c++/113958] New: support visibility attribute for typeinfo symbol noelgrandin at gmail dot com
@ 2024-02-17  0:52 ` pinskia at gcc dot gnu.org
  2024-02-17  0:55 ` pinskia at gcc dot gnu.org
  2024-02-17  6:19 ` noelgrandin at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-17  0:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113958

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
You can use visibility on the type even Like:
```
struct __attribute__ ((visibility("default")))   Foo1{
    virtual void some_member() = 0;
};
struct  __attribute__ ((visibility("default")))  Foo  : Foo1 {
    virtual void some_member();
};
```

Which changes the visibility back to default for the whole class.

This is documented here:
https://gcc.gnu.org/onlinedocs/gcc-13.2.0/gcc/Common-Type-Attributes.html#index-visibility-type-attribute


You can also use the `pragma GCC visibility` too in the same way:
https://gcc.gnu.org/onlinedocs/gcc-13.2.0/gcc/Visibility-Pragmas.html#index-pragma_002c-visibility

#pragma GCC visibility push(default)


Though visibility on the struct applies to all methods too. Which I suspect you
want really instead of marking each method as being default.
The pragma push/pop makes it easier to mark the classes you want to be exported
too. E.g. you can wrap including a header file with that to make sure those are
exported.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/113958] support visibility attribute for typeinfo symbol
  2024-02-16 11:18 [Bug c++/113958] New: support visibility attribute for typeinfo symbol noelgrandin at gmail dot com
  2024-02-17  0:52 ` [Bug c++/113958] " pinskia at gcc dot gnu.org
@ 2024-02-17  0:55 ` pinskia at gcc dot gnu.org
  2024-02-17  6:19 ` noelgrandin at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-17  0:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113958

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I am not 100% sure if type_visibility is needed here or in general. You can
also use -fvisibility-inlines-hidden to hide methods that are declared as
inline which I suspect you want really too.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/113958] support visibility attribute for typeinfo symbol
  2024-02-16 11:18 [Bug c++/113958] New: support visibility attribute for typeinfo symbol noelgrandin at gmail dot com
  2024-02-17  0:52 ` [Bug c++/113958] " pinskia at gcc dot gnu.org
  2024-02-17  0:55 ` pinskia at gcc dot gnu.org
@ 2024-02-17  6:19 ` noelgrandin at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: noelgrandin at gmail dot com @ 2024-02-17  6:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113958

--- Comment #3 from Noel Grandin <noelgrandin at gmail dot com> ---
Andrew, the specific application here is a very large (10MLoc) codebase
(LibreOffice), where we have lots of very large classes with tons of methods,
where I want to limit symbol visibility to only the symbols that are needed for
running unit tests.

So sure, technically I could make the whole class visibility=default, and then
annotate most of the methods with visibility=hidden.
Or I could use linker scripts.

But ergonomically, the easiest thing to do is to compile with
visibility=hidden, and then annotate the small subset of symbols I want
exposed.

So this is an ergonomic / quality-of-life feature request, not a bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-02-17  6:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-16 11:18 [Bug c++/113958] New: support visibility attribute for typeinfo symbol noelgrandin at gmail dot com
2024-02-17  0:52 ` [Bug c++/113958] " pinskia at gcc dot gnu.org
2024-02-17  0:55 ` pinskia at gcc dot gnu.org
2024-02-17  6:19 ` noelgrandin at gmail dot com

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).