Wireshark  2.9.0-477-g68ec514b
The Wireshark network protocol analyzer
/home/wireshark/builders/wireshark-master/ubuntu-16.04-x64/build/ws_symbol_export.h
1 /*
2  * Cross platform defines for exporting symbols from shared libraries
3  *
4  * Wireshark - Network traffic analyzer
5  * By Balint Reczey <balint@balintreczey.hu>
6  * Copyright 2013 Balint Reczey
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  */
10 
11 #include "ws_compiler_tests.h"
12 
17 #ifdef RESET_SYMBOL_EXPORT
18 
19 #ifdef SYMBOL_EXPORT_H
20 #undef SYMBOL_EXPORT_H
21 #endif
22 
23 #ifdef WS_DLL_PUBLIC
24 #undef WS_DLL_PUBLIC
25 #endif
26 
27 #ifdef WS_DLL_PUBLIC_DEF
28 #undef WS_DLL_PUBLIC_DEF
29 #endif
30 
31 #ifdef WS_DLL_LOCAL
32 #undef WS_DLL_LOCAL
33 #endif
34 
35 #endif /* RESET_SYMBOL_EXPORT */
36 
37 #ifndef SYMBOL_EXPORT_H
38 #define SYMBOL_EXPORT_H
39 
40 /*
41  * NOTE: G_HAVE_GNUC_VISIBILITY is defined only if all of
42  *
43  * __attribute__ ((visibility ("hidden")))
44  *
45  * __attribute__ ((visibility ("internal")))
46  *
47  * __attribute__ ((visibility ("protected")))
48  *
49  * __attribute__ ((visibility ("default")))
50  *
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.
55  *
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.
61  */
62 
63 /* Originally copied from GCC Wiki at http://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
67  /*
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).
73  */
74  #ifdef __GNUC__
75  /* GCC */
76  #define WS_DLL_PUBLIC_DEF __attribute__ ((dllexport))
77  #else /* ! __GNUC__ */
78  /*
79  * Presumably MSVC.
80  * Note: actually gcc seems to also support this syntax.
81  */
82  #define WS_DLL_PUBLIC_DEF __declspec(dllexport)
83  #endif /* __GNUC__ */
84  #else /* WS_BUILD_DLL */
85  /*
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.
89  *
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.
93  */
94  #ifdef __GNUC__
95  /* GCC */
96  #define WS_DLL_PUBLIC_DEF __attribute__ ((dllimport))
97  #elif ! (defined ENABLE_STATIC) /* ! __GNUC__ */
98  /*
99  * Presumably MSVC, and we're not building all-static.
100  * Note: actually gcc seems to also support this syntax.
101  */
102  #define WS_DLL_PUBLIC_DEF __declspec(dllimport)
103  #else /* ! __GNUC__ && ENABLE_STATIC */
104  /*
105  * Presumably MSVC, and we're building all-static, so we're
106  * not building any DLLs.
107  */
108  #define WS_DLL_PUBLIC_DEF
109  #endif /* __GNUC__ */
110  #endif /* WS_BUILD_DLL */
111 
112  /*
113  * Symbols in a DLL are *not* exported unless they're specifically
114  * flagged as exported, so, for a non-static but non-exported
115  * symbol, we don't have to do anything.
116  */
117  #define WS_DLL_LOCAL
118 #else /* defined _WIN32 || defined __CYGWIN__ */
119  /*
120  * Compiling for UN*X, where the dllimport and dllexport stuff
121  * is neither necessary nor supported; just specify the
122  * visibility if we have a compiler that supports doing so.
123  */
124  #if WS_IS_AT_LEAST_GNUC_VERSION(3,4) \
125  || WS_IS_AT_LEAST_XL_C_VERSION(12,0)
126  /*
127  * GCC 3.4 or later, or some compiler asserting compatibility with
128  * GCC 3.4 or later, or XL C 13.0 or later, so we have
129  * __attribute__((visibility()).
130  */
131 
132  /*
133  * Symbols exported from libraries.
134  */
135  #define WS_DLL_PUBLIC_DEF __attribute__ ((visibility ("default")))
136 
137  /*
138  * Non-static symbols *not* exported from libraries.
139  */
140  #define WS_DLL_LOCAL __attribute__ ((visibility ("hidden")))
141  #elif WS_IS_AT_LEAST_SUNC_VERSION(5,5)
142  /*
143  * Sun C 5.5 or later, so we have __global and __hidden.
144  * (Sun C 5.9 and later also have __attribute__((visibility()),
145  * but there's no reason to prefer it with Sun C.)
146  */
147 
148  /*
149  * Symbols exported from libraries.
150  */
151  #define WS_DLL_PUBLIC_DEF __global
152 
153  /*
154  * Non-static symbols *not* exported from libraries.
155  */
156  #define WS_DLL_LOCAL __hidden
157  #else
158  /*
159  * We have neither a way to make stuff not explicitly marked as
160  * visible invisible outside a library nor a way to make stuff
161  * explicitly marked as local invisible outside the library.
162  */
163 
164  /*
165  * Symbols exported from libraries.
166  */
167  #define WS_DLL_PUBLIC_DEF
168 
169  /*
170  * Non-static symbols *not* exported from libraries.
171  */
172  #define WS_DLL_LOCAL
173  #endif
174 #endif
175 
176 /*
177  * You *must* use this for exported data *declarations*; if you use
178  * WS_DLL_PUBLIC_DEF, some compilers, such as MSVC++, will complain
179  * about array definitions with no size.
180  *
181  * You must *not* use this for exported data *definitions*, as that
182  * will, for some compilers, cause warnings about items being initialized
183  * and declared extern.
184  *
185  * Either can be used for exported *function* declarations and definitions.
186  */
187 #define WS_DLL_PUBLIC WS_DLL_PUBLIC_DEF extern
188 
189 #endif /* SYMBOL_EXPORT_H */
190 
191 /*
192  * Editor modelines - http://www.wireshark.org/tools/modelines.html
193  *
194  * Local Variables:
195  * c-basic-offset: 2
196  * tab-width: 8
197  * indent-tabs-mode: nil
198  * End:
199  *
200  * vi: set shiftwidth=2 tabstop=8 expandtab:
201  * :indentSize=2:tabSize=8:noTabs=true:
202  */