[glib] gmodule: Add the visibility attribute to G_MODULE_EXPORT on gcc



commit 553329358c9e6845d567bb7367ae404c21d22dea
Author: Philip Withnall <withnall endlessm com>
Date:   Mon Feb 13 11:46:59 2017 +0000

    gmodule: Add the visibility attribute to G_MODULE_EXPORT on gcc
    
    For versions of GCC which support it (≥ 4), define G_MODULE_EXPORT as
    __attribute__((visibility("default"))). This is normally a no-op, unless
    compiling with -fvisibility=hidden, in which case it marks a symbol to
    be publicly exported from the library, which is what G_MODULE_EXPORT is
    for. Previously G_MODULE_EXPORT has only worked on Windows.
    
    The compatibility check for whether the compiler supports
    __attribute__((visibility)) is based on the __GNUC__ define, and is
    similar to the check done in configure.ac for defining G_GNUC_INTERNAL.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=778287

 gmodule/gmodule.c |   12 +++++++++---
 gmodule/gmodule.h |    4 +++-
 2 files changed, 12 insertions(+), 4 deletions(-)
---
diff --git a/gmodule/gmodule.c b/gmodule/gmodule.c
index f02dbbc..a5da991 100644
--- a/gmodule/gmodule.c
+++ b/gmodule/gmodule.c
@@ -167,9 +167,15 @@
 /**
  * G_MODULE_EXPORT:
  *
- * Used to declare functions exported by modules. This is a no-op on Linux
- * and Unices, but when compiling for Windows, it marks a symbol to be
- * exported from the library or executable being built.
+ * Used to declare functions exported by libraries or modules.
+ *
+ * When compiling for Windows, it marks the symbol as `dllexport`.
+ *
+ * When compiling for Linux and Unices, it marks the symbol as having `default`
+ * visibility. This is no-op unless the code is being compiled with a
+ * non-default
+ * [visibility flag](https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#index-fvisibility-1260)
+ * such as `hidden`.
  */
 
 /**
diff --git a/gmodule/gmodule.h b/gmodule/gmodule.h
index 194fa6e..aa98f00 100644
--- a/gmodule/gmodule.h
+++ b/gmodule/gmodule.h
@@ -35,7 +35,9 @@ G_BEGIN_DECLS
 #define        G_MODULE_IMPORT         extern
 #ifdef G_PLATFORM_WIN32
 #  define      G_MODULE_EXPORT         __declspec(dllexport)
-#else /* !G_PLATFORM_WIN32 */
+#elif __GNUC__ >= 4
+#  define      G_MODULE_EXPORT         __attribute__((visibility("default")))
+#else /* !G_PLATFORM_WIN32 && __GNUC__ < 4 */
 #  define      G_MODULE_EXPORT
 #endif /* !G_PLATFORM_WIN32 */
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]