Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / include / ws_symbol_export.h
blob3de71a8a16e3520ed067c22610b147ffd4ef4b65
1 /** @file
2 * Cross platform defines for exporting symbols from shared libraries
4 * Wireshark - Network traffic analyzer
5 * By Balint Reczey <balint@balintreczey.hu>
6 * Copyright 2013 Balint Reczey
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
11 #include "ws_compiler_tests.h"
13 /** Reset symbol export behavior.
14 * If you {un}define WS_BUILD_DLL on the fly you'll have to define this
15 * as well.
17 #ifdef RESET_SYMBOL_EXPORT
19 #ifdef SYMBOL_EXPORT_H
20 #undef SYMBOL_EXPORT_H
21 #endif
23 #ifdef WS_DLL_PUBLIC
24 #undef WS_DLL_PUBLIC
25 #endif
27 #ifdef WS_DLL_PUBLIC_DEF
28 #undef WS_DLL_PUBLIC_DEF
29 #endif
31 #ifdef WS_DLL_LOCAL
32 #undef WS_DLL_LOCAL
33 #endif
35 #endif /* RESET_SYMBOL_EXPORT */
37 #ifndef SYMBOL_EXPORT_H
38 #define SYMBOL_EXPORT_H
41 * NOTE: G_HAVE_GNUC_VISIBILITY is defined only if all of
43 * __attribute__ ((visibility ("hidden")))
45 * __attribute__ ((visibility ("internal")))
47 * __attribute__ ((visibility ("protected")))
49 * __attribute__ ((visibility ("default")))
51 * are supported, and at least some versions of GCC from Apple support
52 * "default" and "hidden" but not "internal" or "protected", so it
53 * shouldn't be used to determine whether "hidden" or "default" is
54 * supported.
56 * This also means that we shouldn't use G_GNUC_INTERNAL instead of
57 * WS_DLL_LOCAL, as GLib uses G_HAVE_GNUC_VISIBILITY to determine
58 * whether to use __attribute__ ((visibility ("hidden"))) for
59 * G_GNUC_INTERNAL, and that will not use it even with compilers
60 * that support it.
63 /* Originally copied from GCC Wiki at https://gcc.gnu.org/wiki/Visibility */
64 #if defined _WIN32 || defined __CYGWIN__
65 /* Compiling for Windows, so we use the Windows DLL declarations. */
66 #ifdef WS_BUILD_DLL
68 * Building a DLL; for all definitions, we want dllexport, and
69 * (presumably so source from DLL and source from a program using the
70 * DLL can both include a header that declares APIs and exported data
71 * for the DLL), for declarations, either dllexport or dllimport will
72 * work (they mean the same thing for a declaration when building a DLL).
74 #ifdef __GNUC__
75 /* GCC */
76 #define WS_DLL_PUBLIC_DEF __attribute__ ((dllexport))
77 #else /* ! __GNUC__ */
79 * Presumably MSVC.
80 * Note: actually gcc seems to also support this syntax.
82 #define WS_DLL_PUBLIC_DEF __declspec(dllexport)
83 #endif /* __GNUC__ */
84 #else /* WS_BUILD_DLL */
86 * Building a program; we should only see declarations, not definitions,
87 * with WS_DLL_PUBLIC, and they all represent APIs or data imported
88 * from a DLL, so use dllimport.
90 * For functions, export shouldn't be necessary; for data, it might
91 * be necessary, e.g. if what's declared is an array whose size is
92 * not given in the declaration.
94 #ifdef ENABLE_STATIC
96 * We're building all-static, so we're not building any DLLs.
98 #define WS_DLL_PUBLIC_DEF
99 #elif defined(__GNUC__)
100 /* GCC */
101 #define WS_DLL_PUBLIC_DEF __attribute__ ((dllimport))
102 #else /* ! ENABLE_STATIC && ! __GNUC__ */
104 * Presumably MSVC, and we're not building all-static.
105 * Note: actually gcc seems to also support this syntax.
107 #define WS_DLL_PUBLIC_DEF __declspec(dllimport)
108 #endif
109 #endif /* WS_BUILD_DLL */
112 * Symbols in a DLL are *not* exported unless they're specifically
113 * flagged as exported, so, for a non-static but non-exported
114 * symbol, we don't have to do anything.
116 #define WS_DLL_LOCAL
117 #else /* defined _WIN32 || defined __CYGWIN__ */
119 * Compiling for UN*X, where the dllimport and dllexport stuff
120 * is neither necessary nor supported; just specify the
121 * visibility if we have a compiler that supports doing so.
123 #if WS_IS_AT_LEAST_GNUC_VERSION(3,4) \
124 || WS_IS_AT_LEAST_XL_C_VERSION(12,0)
126 * GCC 3.4 or later, or some compiler asserting compatibility with
127 * GCC 3.4 or later, or XL C 13.0 or later, so we have
128 * __attribute__((visibility()).
132 * Symbols exported from libraries.
134 #define WS_DLL_PUBLIC_DEF __attribute__ ((visibility ("default")))
137 * Non-static symbols *not* exported from libraries.
139 #define WS_DLL_LOCAL __attribute__ ((visibility ("hidden")))
140 #elif WS_IS_AT_LEAST_SUNC_VERSION(5,5)
142 * Sun C 5.5 or later, so we have __global and __hidden.
143 * (Sun C 5.9 and later also have __attribute__((visibility()),
144 * but there's no reason to prefer it with Sun C.)
148 * Symbols exported from libraries.
150 #define WS_DLL_PUBLIC_DEF __global
153 * Non-static symbols *not* exported from libraries.
155 #define WS_DLL_LOCAL __hidden
156 #else
158 * We have neither a way to make stuff not explicitly marked as
159 * visible invisible outside a library nor a way to make stuff
160 * explicitly marked as local invisible outside the library.
164 * Symbols exported from libraries.
166 #define WS_DLL_PUBLIC_DEF
169 * Non-static symbols *not* exported from libraries.
171 #define WS_DLL_LOCAL
172 #endif
173 #endif
176 * You *must* use this for exported data *declarations*; if you use
177 * WS_DLL_PUBLIC_DEF, some compilers, such as MSVC++, will complain
178 * about array definitions with no size.
180 * You must *not* use this for exported data *definitions*, as that
181 * will, for some compilers, cause warnings about items being initialized
182 * and declared extern.
184 * Either can be used for exported *function* declarations and definitions.
186 #define WS_DLL_PUBLIC WS_DLL_PUBLIC_DEF extern
189 * This is necessary to export symbols from wsutil to another DLL
190 * (not an executable) using MSVC.
192 #ifdef _MSC_VER
193 # ifdef BUILD_WSUTIL
194 # define WSUTIL_EXPORT __declspec(dllexport) extern
195 # else
196 # define WSUTIL_EXPORT __declspec(dllimport) extern
197 # endif
198 #else /* _MSC_VER */
199 # define WSUTIL_EXPORT WS_DLL_PUBLIC
200 #endif /* _MSC_VER */
204 #endif /* SYMBOL_EXPORT_H */
207 * Editor modelines - https://www.wireshark.org/tools/modelines.html
209 * Local Variables:
210 * c-basic-offset: 2
211 * tab-width: 8
212 * indent-tabs-mode: nil
213 * End:
215 * vi: set shiftwidth=2 tabstop=8 expandtab:
216 * :indentSize=2:tabSize=8:noTabs=true: