24 #ifndef PXR_BASE_ARCH_ATTRIBUTES_H
25 #define PXR_BASE_ARCH_ATTRIBUTES_H
36 PXR_NAMESPACE_OPEN_SCOPE
51 # define ARCH_PRINTF_FUNCTION(_fmt, _firstArg)
65 # define ARCH_SCANF_FUNCTION(_fmt, _firstArg)
75 # define ARCH_NOINLINE
89 # define ARCH_UNUSED_ARG
104 # define ARCH_UNUSED_FUNCTION
124 # define ARCH_USED_FUNCTION
143 # define ARCH_CONSTRUCTOR(_name, _priority, ...)
162 # define ARCH_DESTRUCTOR(_name, _priority, ...)
164 #elif defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
166 # define ARCH_PRINTF_FUNCTION(_fmt, _firstArg) \
167 __attribute__((format(printf, _fmt, _firstArg)))
168 # define ARCH_SCANF_FUNCTION(_fmt, _firstArg) \
169 __attribute__((format(scanf, _fmt, _firstArg)))
170 # define ARCH_NOINLINE __attribute__((noinline))
171 # define ARCH_UNUSED_ARG __attribute__ ((unused))
172 # define ARCH_UNUSED_FUNCTION __attribute__((unused))
173 # define ARCH_USED_FUNCTION __attribute__((used))
175 #elif defined(ARCH_COMPILER_MSVC)
177 # define ARCH_PRINTF_FUNCTION(_fmt, _firstArg)
178 # define ARCH_SCANF_FUNCTION(_fmt, _firstArg)
179 # define ARCH_NOINLINE // __declspec(noinline)
180 # define ARCH_UNUSED_ARG
181 # define ARCH_UNUSED_FUNCTION
182 # define ARCH_USED_FUNCTION
206 template <
class StaticInit>
207 struct ARCH_HIDDEN Arch_PerLibInit {
211 static StaticInit init;
213 template <
class StaticInit>
214 StaticInit Arch_PerLibInit<StaticInit>::init;
216 #define _ARCH_CAT_NOEXPAND(a, b) a ## b
217 #define _ARCH_CAT(a, b) _ARCH_CAT_NOEXPAND(a, b)
218 #define _ARCH_ENSURE_PER_LIB_INIT(T, prefix) \
219 static Arch_PerLibInit<T> _ARCH_CAT(prefix, __COUNTER__)
225 #elif defined(ARCH_OS_DARWIN)
228 struct Arch_ConstructorEntry {
229 typedef void (*Type)(void);
231 unsigned int version:24;
232 unsigned int priority:8;
236 # define ARCH_CONSTRUCTOR(_name, _priority, ...) \
237 static void _name(__VA_ARGS__); \
238 static const Arch_ConstructorEntry _ARCH_CAT_NOEXPAND(arch_ctor_, _name) \
239 __attribute__((used, section("__DATA,pxrctor"))) = { \
240 reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
244 static void _name(__VA_ARGS__)
247 # define ARCH_DESTRUCTOR(_name, _priority, ...) \
248 static void _name(__VA_ARGS__); \
249 static const Arch_ConstructorEntry _ARCH_CAT_NOEXPAND(arch_dtor_, _name) \
250 __attribute__((used, section("__DATA,pxrdtor"))) = { \
251 reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
255 static void _name(__VA_ARGS__)
257 #elif defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
261 # define ARCH_CONSTRUCTOR(_name, _priority, ...) \
262 __attribute__((used, section(".pxrctor"), constructor((_priority) + 100))) \
263 static void _name(__VA_ARGS__)
264 # define ARCH_DESTRUCTOR(_name, _priority, ...) \
265 __attribute__((used, section(".pxrdtor"), destructor((_priority) + 100))) \
266 static void _name(__VA_ARGS__)
268 #elif defined(ARCH_OS_WINDOWS)
270 # include "pxr/base/arch/api.h"
273 __declspec(align(16))
274 struct Arch_ConstructorEntry {
275 typedef void (__cdecl *Type)(void);
277 unsigned int version:24;
278 unsigned int priority:8;
282 # pragma section(".pxrctor", read)
283 # pragma section(".pxrdtor", read)
288 struct Arch_ConstructorInit {
289 ARCH_API Arch_ConstructorInit();
290 ARCH_API ~Arch_ConstructorInit();
297 # define ARCH_CONSTRUCTOR(_name, _priority, ...) \
298 static void _name(__VA_ARGS__); \
300 __declspec(allocate(".pxrctor")) \
301 extern const Arch_ConstructorEntry \
302 _ARCH_CAT_NOEXPAND(arch_ctor_, _name) = { \
303 reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
308 _ARCH_ENSURE_PER_LIB_INIT(Arch_ConstructorInit, _archCtorInit); \
309 static void _name(__VA_ARGS__)
312 # define ARCH_DESTRUCTOR(_name, _priority, ...) \
313 static void _name(__VA_ARGS__); \
315 __declspec(allocate(".pxrdtor")) \
316 extern const Arch_ConstructorEntry \
317 _ARCH_CAT_NOEXPAND(arch_dtor_, _name) = { \
318 reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
323 _ARCH_ENSURE_PER_LIB_INIT(Arch_ConstructorInit, _archCtorInit); \
324 static void _name(__VA_ARGS__)
333 PXR_NAMESPACE_CLOSE_SCOPE
335 #endif // PXR_BASE_ARCH_ATTRIBUTES_H
Defines symbol visibility macros.