map SAL_DLLPUBLIC_RTTI to visibility:default for gcc

Because I want to make more symbols private, but that runs into a
problem with the special symbol "typeinfo for Foo" which is required for
dynamic_cast.

For clang, we can use SAL_DLLPUBLIC_RTTI to make just that magic
"typeinfo for Foo" symbol visible.

But for gcc, we are left with no option but to make the whole class
visible via <MODULE>_DLLPUBLIC.
(I have a feature request logged against gcc to support something like
that at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113958)

But I also don't want to use <MODULE>_DLLPUBLIC, since that blocks
progress of reducing symbol visibility for platforms other than gcc.

So map SAL_DLLPUBLIC_RTTI to visiblity:default for gcc, which means that
only gcc suffers the negative affects of not having that annotation.

However, that runs into the problem that gcc does not like
visibility:default in a couple of places, so I have to introduce some
extra preprocessor stuff.

Change-Id: Ib4fc5c1d2a1f8cf87d5159a4b5684137ec061605
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164356
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin 2024-03-04 14:42:25 +02:00
parent f03cb8214a
commit e8b9bcf021
5 changed files with 18 additions and 4 deletions

View File

@ -3328,7 +3328,11 @@ void EnumType::addComprehensiveGetCppuTypeIncludes(
void EnumType::dumpDeclaration(FileStream& o)
{
o << "\n#if defined LIBO_INTERNAL_ONLY\n";
o << "\n#if defined __GNUC__\n"; // gcc does not like visibility annotation on enum
o << "\nenum class " << id_ << "\n{\n";
o << "\n#else\n";
o << "\nenum class SAL_DLLPUBLIC_RTTI " << id_ << "\n{\n";
o << "\n#endif\n";
o << "\n#else\n";
o << "\nenum SAL_DLLPUBLIC_RTTI " << id_ << "\n{\n";
o << "\n#endif\n";

View File

@ -153,7 +153,8 @@ SAL_DLLPUBLIC void SAL_CALL rtl_freeAlignedMemory (
/** Opaque rtl_arena_type.
*/
typedef struct SAL_DLLPUBLIC_RTTI rtl_arena_st rtl_arena_type;
struct SAL_DLLPUBLIC_RTTI rtl_arena_st;
typedef struct rtl_arena_st rtl_arena_type;
#define RTL_ARENA_NAME_LENGTH 31

View File

@ -1197,7 +1197,8 @@ SAL_DLLPUBLIC double SAL_CALL rtl_ustr_toDouble(
/** @cond INTERNAL */
/** The implementation of a Unicode string.
*/
typedef struct SAL_DLLPUBLIC_RTTI _rtl_uString
struct SAL_DLLPUBLIC_RTTI _rtl_uString;
typedef struct _rtl_uString
{
oslInterlockedCount refCount; /* opaque */
sal_Int32 length;

View File

@ -220,7 +220,7 @@ typedef void * sal_Handle;
# define SAL_DLLPUBLIC_IMPORT __attribute__ ((visibility("hidden")))
# define SAL_DLLPRIVATE __attribute__ ((visibility("hidden")))
# define SAL_DLLPUBLIC_TEMPLATE __attribute__ ((visibility("hidden")))
# define SAL_DLLPUBLIC_RTTI
# define SAL_DLLPUBLIC_RTTI __attribute__ ((visibility("default")))
# else
# define SAL_DLLPUBLIC_EXPORT __attribute__ ((visibility("default")))
# define SAL_JNI_EXPORT __attribute__ ((visibility("default")))
@ -234,7 +234,11 @@ typedef void * sal_Handle;
# define SAL_DLLPUBLIC_RTTI __attribute__ ((visibility("default")))
# endif
# else
# define SAL_DLLPUBLIC_RTTI
// GCC does not have currently have equivalent functionality to clang's type_visibility
// but I have a feature request for that at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113958
// Until that is implemented, just make the whole class visible, which is what I would need to
// do anyhow if something wants to import the typeinfo symbol.
# define SAL_DLLPUBLIC_RTTI __attribute__ ((visibility("default")))
# endif
# endif
# else

View File

@ -39,7 +39,11 @@ namespace com::sun::star::uno { template <typename > class Reference; }
namespace com::sun::star::uno { template <typename > class Sequence; }
namespace com::sun::star::xml::sax { class XAttributeList; }
namespace com::sun::star::xml::sax { class XFastAttributeList; }
#if defined __GNUC__ // gcc does not like visibility annotation on enum
namespace com::sun::star::drawing { enum class FillStyle; }
#else
namespace com::sun::star::drawing { enum class SAL_DLLPUBLIC_RTTI FillStyle; }
#endif
struct XMLPropertyState;
class XMLPropertySetMapper;