decrypt
[metze/wireshark/wip.git] / ws_symbol_export.h
index ed49ba80aebb211c7966d2c08ecab702e44f9213..4c7a2f710af741a948163a0efb7892af7be5a662 100644 (file)
@@ -5,21 +5,11 @@
  * By Balint Reczey <balint@balintreczey.hu>
  * Copyright 2013 Balint Reczey
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
+#include "ws_compiler_tests.h"
+
 /** Reset symbol export behavior.
  * If you {un}define WS_BUILD_DLL on the fly you'll have to define this
  * as well.
 #ifndef SYMBOL_EXPORT_H
 #define SYMBOL_EXPORT_H
 
+/*
+ * NOTE: G_HAVE_GNUC_VISIBILITY is defined only if all of
+ *
+ *    __attribute__ ((visibility ("hidden")))
+ *
+ *    __attribute__ ((visibility ("internal")))
+ *
+ *    __attribute__ ((visibility ("protected")))
+ *
+ *    __attribute__ ((visibility ("default")))
+ *
+ * are supported, and at least some versions of GCC from Apple support
+ * "default" and "hidden" but not "internal" or "protected", so it
+ * shouldn't be used to determine whether "hidden" or "default" is
+ * supported.
+ *
+ * This also means that we shouldn't use G_GNUC_INTERNAL instead of
+ * WS_DLL_LOCAL, as GLib uses G_HAVE_GNUC_VISIBILITY to determine
+ * whether to use __attribute__ ((visibility ("hidden"))) for
+ * G_GNUC_INTERNAL, and that will not use it even with compilers
+ * that support it.
+ */
+
 /* Originally copied from GCC Wiki at http://gcc.gnu.org/wiki/Visibility */
 #if defined _WIN32 || defined __CYGWIN__
   /* Compiling for Windows, so we use the Windows DLL declarations. */
      */
     #ifdef __GNUC__
       /* GCC */
-#define WS_DLL_PUBLIC_DEF __attribute__ ((dllexport))
+      #define WS_DLL_PUBLIC_DEF __attribute__ ((dllexport))
     #else /* ! __GNUC__ */
       /*
        * Presumably MSVC.
        * Note: actually gcc seems to also support this syntax.
        */
-#define WS_DLL_PUBLIC_DEF __declspec(dllexport)
+      #define WS_DLL_PUBLIC_DEF __declspec(dllexport)
     #endif /* __GNUC__ */
   #else /* WS_BUILD_DLL */
     /*
      */
     #ifdef __GNUC__
       /* GCC */
-#define WS_DLL_PUBLIC_DEF __attribute__ ((dllimport))
+      #define WS_DLL_PUBLIC_DEF __attribute__ ((dllimport))
     #elif ! (defined ENABLE_STATIC) /* ! __GNUC__ */
       /*
        * Presumably MSVC, and we're not building all-static.
        * Note: actually gcc seems to also support this syntax.
        */
-#define WS_DLL_PUBLIC_DEF __declspec(dllimport)
+      #define WS_DLL_PUBLIC_DEF __declspec(dllimport)
     #else /* ! __GNUC__  && ENABLE_STATIC */
       /*
        * Presumably MSVC, and we're building all-static, so we're
        * not building any DLLs.
        */
-#define WS_DLL_PUBLIC_DEF
+      #define WS_DLL_PUBLIC_DEF
     #endif /* __GNUC__ */
   #endif /* WS_BUILD_DLL */
 
   /*
    * Compiling for UN*X, where the dllimport and dllexport stuff
    * is neither necessary nor supported; just specify the
-   * visibility if we have a compiler that claims compatibility
-   * with GCC 4 or later.
+   * visibility if we have a compiler that supports doing so.
    */
-  #if __GNUC__ >= 4
+  #if WS_IS_AT_LEAST_GNUC_VERSION(3,4) \
+      || WS_IS_AT_LEAST_XL_C_VERSION(12,0)
+    /*
+     * GCC 3.4 or later, or some compiler asserting compatibility with
+     * GCC 3.4 or later, or XL C 13.0 or later, so we have
+     * __attribute__((visibility()).
+     */
+
+    /*
+     * Symbols exported from libraries.
+     */
+    #define WS_DLL_PUBLIC_DEF __attribute__ ((visibility ("default")))
+
+    /*
+     * Non-static symbols *not* exported from libraries.
+     */
+    #define WS_DLL_LOCAL  __attribute__ ((visibility ("hidden")))
+  #elif WS_IS_AT_LEAST_SUNC_VERSION(5,5)
+    /*
+     * Sun C 5.5 or later, so we have __global and __hidden.
+     * (Sun C 5.9 and later also have __attribute__((visibility()),
+     * but there's no reason to prefer it with Sun C.)
+     */
+
     /*
      * Symbols exported from libraries.
      */
-#define WS_DLL_PUBLIC_DEF __attribute__ ((visibility ("default")))
+    #define WS_DLL_PUBLIC_DEF __global
 
     /*
      * Non-static symbols *not* exported from libraries.
      */
-#define WS_DLL_LOCAL  __attribute__ ((visibility ("hidden")))
-  #else /* ! __GNUC__ >= 4 */
+    #define WS_DLL_LOCAL __hidden
+  #else
     /*
-     * We have no way to control visibility.
+     * We have neither a way to make stuff not explicitly marked as
+     * visible invisible outside a library nor a way to make stuff
+     * explicitly marked as local invisible outside the library.
+     */
+
+    /*
+     * Symbols exported from libraries.
      */
     #define WS_DLL_PUBLIC_DEF
+
+    /*
+     * Non-static symbols *not* exported from libraries.
+     */
     #define WS_DLL_LOCAL
-  #endif /* __GNUC__ >= 4 */
+  #endif
 #endif
 
 /*
  *
  * Either can be used for exported *function* declarations and definitions.
  */
-#define WS_DLL_PUBLIC  WS_DLL_PUBLIC_DEF extern
+#define WS_DLL_PUBLIC  WS_DLL_PUBLIC_DEF extern
 
 #endif /* SYMBOL_EXPORT_H */
+
+/*
+ * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
+ *
+ * Local Variables:
+ * c-basic-offset: 2
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * vi: set shiftwidth=2 tabstop=8 expandtab:
+ * :indentSize=2:tabSize=8:noTabs=true:
+ */