diff --git a/ChangeLog b/ChangeLog index 0708e5e75..71fd567b5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2018-02-04 Alexei Podtelezhnikov + + [unix] Use -fvisibility=hidden. + + It is now widely recommended that ELF shared libraries hide symbols + except those with explicit __attribute__((visibility("default"))). + This is supported by all major compilers and should rather be an + option in libtool. + + * builds/unix/configure.raw: Add -fvisibility=hidden to CFLAGS. + * builds/unix/ftconfig.in, builds/vms/ftconfig.h, + include/freetype/config/ftconfig.h (FT_EXPORT): Use visibility + attribute. + 2018-01-27 Werner Lemberg [truetype] Better protection against invalid VF data. diff --git a/builds/unix/configure.raw b/builds/unix/configure.raw index d76c32452..3d175834a 100644 --- a/builds/unix/configure.raw +++ b/builds/unix/configure.raw @@ -299,6 +299,18 @@ AC_SUBST([XX_CFLAGS]) AC_SUBST([XX_ANSIFLAGS]) +# It is recommended that shared libraries hide symbols except those with +# explicit __attribute__((visibility("default"))). +# +AC_MSG_CHECKING([for -fvisibility=hidden compiler flag]) +orig_CFLAGS="${CFLAGS}" +CFLAGS="${CFLAGS} -fvisibility=hidden" +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])], + AC_MSG_RESULT(yes), + CFLAGS="${orig_CFLAGS}" + AC_MSG_RESULT(no)) + + # All library tests below try `pkg-config' first. If that fails, a function # from the library is tested in the traditional autoconf way (zlib, bzip2), # or a config script is called (libpng). diff --git a/builds/unix/ftconfig.in b/builds/unix/ftconfig.in index ca9058834..b9c21da2c 100644 --- a/builds/unix/ftconfig.in +++ b/builds/unix/ftconfig.in @@ -454,9 +454,9 @@ FT_BEGIN_HEADER #endif /* !FT_BASE_DEF */ - /* When compiling FreeType as a DLL, some systems/compilers need a */ - /* special attribute in front OR after the return type of function */ - /* declarations. */ + /* When compiling FreeType as a DLL or DSO with hidden visibility */ + /* some systems/compilers need a special attribute in front OR after */ + /* the return type of function declarations. */ /* */ /* Two macros are used within the FreeType source code to define */ /* exported library functions: FT_EXPORT and FT_EXPORT_DEF. */ @@ -487,21 +487,28 @@ FT_BEGIN_HEADER /* */ #ifndef FT_EXPORT -#ifdef __cplusplus +#ifdef FT2_BUILD_LIBRARY + +#if defined( _WIN32 ) && ( defined( _DLL ) || defined( DLL_EXPORT ) ) +#define FT_EXPORT( x ) __declspec( dllexport ) x +#elif defined( __GNUC__ ) && __GNUC__ >= 4 +#define FT_EXPORT( x ) __attribute__(( visibility( "default" ) )) x +#elif defined( __cplusplus ) #define FT_EXPORT( x ) extern "C" x #else #define FT_EXPORT( x ) extern x #endif -#ifdef _WIN32 -#if defined( FT2_BUILD_LIBRARY ) && \ - ( defined( _DLL ) || defined( DLL_EXPORT ) ) -#undef FT_EXPORT -#define FT_EXPORT( x ) __declspec( dllexport ) x -#elif defined( FT2_DLLIMPORT ) -#undef FT_EXPORT +#else + +#if defined( FT2_DLLIMPORT ) #define FT_EXPORT( x ) __declspec( dllimport ) x +#elif defined( __cplusplus ) +#define FT_EXPORT( x ) extern "C" x +#else +#define FT_EXPORT( x ) extern x #endif + #endif #endif /* !FT_EXPORT */ diff --git a/builds/vms/ftconfig.h b/builds/vms/ftconfig.h index d87ea69c3..021e2c651 100644 --- a/builds/vms/ftconfig.h +++ b/builds/vms/ftconfig.h @@ -406,9 +406,9 @@ FT_BEGIN_HEADER #endif /* !FT_BASE_DEF */ - /* When compiling FreeType as a DLL, some systems/compilers need a */ - /* special attribute in front OR after the return type of function */ - /* declarations. */ + /* When compiling FreeType as a DLL or DSO with hidden visibility */ + /* some systems/compilers need a special attribute in front OR after */ + /* the return type of function declarations. */ /* */ /* Two macros are used within the FreeType source code to define */ /* exported library functions: FT_EXPORT and FT_EXPORT_DEF. */ @@ -439,21 +439,28 @@ FT_BEGIN_HEADER /* */ #ifndef FT_EXPORT -#ifdef __cplusplus +#ifdef FT2_BUILD_LIBRARY + +#if defined( _WIN32 ) && ( defined( _DLL ) || defined( DLL_EXPORT ) ) +#define FT_EXPORT( x ) __declspec( dllexport ) x +#elif defined( __GNUC__ ) && __GNUC__ >= 4 +#define FT_EXPORT( x ) __attribute__(( visibility( "default" ) )) x +#elif defined( __cplusplus ) #define FT_EXPORT( x ) extern "C" x #else #define FT_EXPORT( x ) extern x #endif -#ifdef _WIN32 -#if defined( FT2_BUILD_LIBRARY ) && \ - ( defined( _DLL ) || defined( DLL_EXPORT ) ) -#undef FT_EXPORT -#define FT_EXPORT( x ) __declspec( dllexport ) x -#elif defined( FT2_DLLIMPORT ) -#undef FT_EXPORT +#else + +#if defined( FT2_DLLIMPORT ) #define FT_EXPORT( x ) __declspec( dllimport ) x +#elif defined( __cplusplus ) +#define FT_EXPORT( x ) extern "C" x +#else +#define FT_EXPORT( x ) extern x #endif + #endif #endif /* !FT_EXPORT */ diff --git a/include/freetype/config/ftconfig.h b/include/freetype/config/ftconfig.h index 8ff143ea3..eedebf408 100644 --- a/include/freetype/config/ftconfig.h +++ b/include/freetype/config/ftconfig.h @@ -422,9 +422,9 @@ FT_BEGIN_HEADER #endif /* !FT_BASE_DEF */ - /* When compiling FreeType as a DLL, some systems/compilers need a */ - /* special attribute in front OR after the return type of function */ - /* declarations. */ + /* When compiling FreeType as a DLL or DSO with hidden visibility */ + /* some systems/compilers need a special attribute in front OR after */ + /* the return type of function declarations. */ /* */ /* Two macros are used within the FreeType source code to define */ /* exported library functions: FT_EXPORT and FT_EXPORT_DEF. */ @@ -455,21 +455,28 @@ FT_BEGIN_HEADER /* */ #ifndef FT_EXPORT -#ifdef __cplusplus +#ifdef FT2_BUILD_LIBRARY + +#if defined( _WIN32 ) && ( defined( _DLL ) || defined( DLL_EXPORT ) ) +#define FT_EXPORT( x ) __declspec( dllexport ) x +#elif defined( __GNUC__ ) && __GNUC__ >= 4 +#define FT_EXPORT( x ) __attribute__(( visibility( "default" ) )) x +#elif defined( __cplusplus ) #define FT_EXPORT( x ) extern "C" x #else #define FT_EXPORT( x ) extern x #endif -#ifdef _WIN32 -#if defined( FT2_BUILD_LIBRARY ) && \ - ( defined( _DLL ) || defined( DLL_EXPORT ) ) -#undef FT_EXPORT -#define FT_EXPORT( x ) __declspec( dllexport ) x -#elif defined( FT2_DLLIMPORT ) -#undef FT_EXPORT +#else + +#if defined( FT2_DLLIMPORT ) #define FT_EXPORT( x ) __declspec( dllimport ) x +#elif defined( __cplusplus ) +#define FT_EXPORT( x ) extern "C" x +#else +#define FT_EXPORT( x ) extern x #endif + #endif #endif /* !FT_EXPORT */