7#ifndef PXR_BASE_ARCH_ATTRIBUTES_H
8#define PXR_BASE_ARCH_ATTRIBUTES_H
19PXR_NAMESPACE_OPEN_SCOPE
34# define ARCH_PRINTF_FUNCTION(_fmt, _firstArg)
48# define ARCH_SCANF_FUNCTION(_fmt, _firstArg)
72# define ARCH_UNUSED_ARG
87# define ARCH_UNUSED_FUNCTION
107# define ARCH_USED_FUNCTION
126# define ARCH_CONSTRUCTOR(_name, _priority, ...)
145# define ARCH_DESTRUCTOR(_name, _priority, ...)
153# define ARCH_EMPTY_BASES
155#elif defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
157# define ARCH_PRINTF_FUNCTION(_fmt, _firstArg) \
158 __attribute__((format(printf, _fmt, _firstArg)))
159# define ARCH_SCANF_FUNCTION(_fmt, _firstArg) \
160 __attribute__((format(scanf, _fmt, _firstArg)))
161# define ARCH_NOINLINE __attribute__((noinline))
162# define ARCH_UNUSED_ARG __attribute__ ((unused))
163# define ARCH_UNUSED_FUNCTION __attribute__((unused))
164# define ARCH_USED_FUNCTION __attribute__((used))
165# define ARCH_EMPTY_BASES
167#elif defined(ARCH_COMPILER_MSVC)
169# define ARCH_PRINTF_FUNCTION(_fmt, _firstArg)
170# define ARCH_SCANF_FUNCTION(_fmt, _firstArg)
171# define ARCH_NOINLINE
172# define ARCH_UNUSED_ARG
173# define ARCH_UNUSED_FUNCTION
174# define ARCH_USED_FUNCTION
175# define ARCH_EMPTY_BASES __declspec(empty_bases)
199template <
class StaticInit>
200struct ARCH_HIDDEN Arch_PerLibInit {
204 static StaticInit init;
206template <
class StaticInit>
207StaticInit Arch_PerLibInit<StaticInit>::init;
209#define _ARCH_CAT_NOEXPAND(a, b) a ## b
210#define _ARCH_CAT(a, b) _ARCH_CAT_NOEXPAND(a, b)
211#define _ARCH_ENSURE_PER_LIB_INIT(T, prefix) \
212 static Arch_PerLibInit<T> _ARCH_CAT(prefix, __COUNTER__)
218#elif defined(ARCH_OS_DARWIN)
221struct Arch_ConstructorEntry {
222 typedef void (*Type)(void);
224 unsigned int version:24;
225 unsigned int priority:8;
229# define ARCH_CONSTRUCTOR(_name, _priority, ...) \
230 static void _name(__VA_ARGS__); \
231 static const Arch_ConstructorEntry _ARCH_CAT_NOEXPAND(arch_ctor_, _name) \
232 __attribute__((used, section("__DATA,pxrctor"))) = { \
233 reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
234 static_cast<unsigned>(PXR_VERSION), \
237 static void _name(__VA_ARGS__)
240# define ARCH_DESTRUCTOR(_name, _priority, ...) \
241 static void _name(__VA_ARGS__); \
242 static const Arch_ConstructorEntry _ARCH_CAT_NOEXPAND(arch_dtor_, _name) \
243 __attribute__((used, section("__DATA,pxrdtor"))) = { \
244 reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
245 static_cast<unsigned>(PXR_VERSION), \
248 static void _name(__VA_ARGS__)
250#elif defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
254# define ARCH_CONSTRUCTOR(_name, _priority, ...) \
255 __attribute__((used, section(".pxrctor"), constructor((_priority) + 100))) \
256 static void _name(__VA_ARGS__)
257# define ARCH_DESTRUCTOR(_name, _priority, ...) \
258 __attribute__((used, section(".pxrdtor"), destructor((_priority) + 100))) \
259 static void _name(__VA_ARGS__)
261#elif defined(ARCH_OS_WINDOWS)
263# include "pxr/base/arch/api.h"
266 __declspec(align(16))
267 struct Arch_ConstructorEntry {
268 typedef void (__cdecl *Type)(void);
270 unsigned int version:24;
271 unsigned int priority:8;
275# pragma section(".pxrctor", read)
276# pragma section(".pxrdtor", read)
281struct Arch_ConstructorInit {
282 ARCH_API Arch_ConstructorInit();
283 ARCH_API ~Arch_ConstructorInit();
290# define ARCH_CONSTRUCTOR(_name, _priority, ...) \
291 static void _name(__VA_ARGS__); \
293 __declspec(allocate(".pxrctor")) \
294 extern const Arch_ConstructorEntry \
295 _ARCH_CAT_NOEXPAND(arch_ctor_, _name) = { \
296 reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
297 static_cast<unsigned>(PXR_VERSION), \
301 _ARCH_ENSURE_PER_LIB_INIT(Arch_ConstructorInit, _archCtorInit); \
302 static void _name(__VA_ARGS__)
305# define ARCH_DESTRUCTOR(_name, _priority, ...) \
306 static void _name(__VA_ARGS__); \
308 __declspec(allocate(".pxrdtor")) \
309 extern const Arch_ConstructorEntry \
310 _ARCH_CAT_NOEXPAND(arch_dtor_, _name) = { \
311 reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
312 static_cast<unsigned>(PXR_VERSION), \
316 _ARCH_ENSURE_PER_LIB_INIT(Arch_ConstructorInit, _archCtorInit); \
317 static void _name(__VA_ARGS__)
326PXR_NAMESPACE_CLOSE_SCOPE
Defines symbol visibility macros.