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_ALWAYS_INLINE __attribute__((always_inline))
163# define ARCH_UNUSED_ARG __attribute__ ((unused))
164# define ARCH_UNUSED_FUNCTION __attribute__((unused))
165# define ARCH_USED_FUNCTION __attribute__((used))
166# define ARCH_EMPTY_BASES
168#elif defined(ARCH_COMPILER_MSVC)
170# define ARCH_PRINTF_FUNCTION(_fmt, _firstArg)
171# define ARCH_SCANF_FUNCTION(_fmt, _firstArg)
172# define ARCH_NOINLINE
173# define ARCH_ALWAYS_INLINE
174# define ARCH_UNUSED_ARG
175# define ARCH_UNUSED_FUNCTION
176# define ARCH_USED_FUNCTION
177# define ARCH_EMPTY_BASES __declspec(empty_bases)
201template <
class StaticInit>
202struct ARCH_HIDDEN Arch_PerLibInit {
206 static StaticInit init;
208template <
class StaticInit>
209StaticInit Arch_PerLibInit<StaticInit>::init;
211#define _ARCH_CAT_NOEXPAND(a, b) a ## b
212#define _ARCH_CAT(a, b) _ARCH_CAT_NOEXPAND(a, b)
213#define _ARCH_ENSURE_PER_LIB_INIT(T, prefix) \
214 static Arch_PerLibInit<T> _ARCH_CAT(prefix, __COUNTER__)
220#elif defined(ARCH_OS_DARWIN)
223struct Arch_ConstructorEntry {
224 typedef void (*Type)(void);
226 unsigned int version:24;
227 unsigned int priority:8;
231# define ARCH_CONSTRUCTOR(_name, _priority, ...) \
232 static void _name(__VA_ARGS__); \
233 static const Arch_ConstructorEntry _ARCH_CAT_NOEXPAND(arch_ctor_, _name) \
234 __attribute__((used, section("__DATA,pxrctor"))) = { \
235 reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
236 static_cast<unsigned>(PXR_VERSION), \
239 static void _name(__VA_ARGS__)
242# define ARCH_DESTRUCTOR(_name, _priority, ...) \
243 static void _name(__VA_ARGS__); \
244 static const Arch_ConstructorEntry _ARCH_CAT_NOEXPAND(arch_dtor_, _name) \
245 __attribute__((used, section("__DATA,pxrdtor"))) = { \
246 reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
247 static_cast<unsigned>(PXR_VERSION), \
250 static void _name(__VA_ARGS__)
252#elif defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
256# define ARCH_CONSTRUCTOR(_name, _priority, ...) \
257 __attribute__((used, section(".pxrctor"), constructor((_priority) + 100))) \
258 static void _name(__VA_ARGS__)
259# define ARCH_DESTRUCTOR(_name, _priority, ...) \
260 __attribute__((used, section(".pxrdtor"), destructor((_priority) + 100))) \
261 static void _name(__VA_ARGS__)
263#elif defined(ARCH_OS_WINDOWS)
265# include "pxr/base/arch/api.h"
268 __declspec(align(16))
269 struct Arch_ConstructorEntry {
270 typedef void (__cdecl *Type)(void);
272 unsigned int version:24;
273 unsigned int priority:8;
277# pragma section(".pxrctor", read)
278# pragma section(".pxrdtor", read)
283struct Arch_ConstructorInit {
284 ARCH_API Arch_ConstructorInit();
285 ARCH_API ~Arch_ConstructorInit();
292# define ARCH_CONSTRUCTOR(_name, _priority, ...) \
293 static void _name(__VA_ARGS__); \
295 __declspec(allocate(".pxrctor")) \
296 extern const Arch_ConstructorEntry \
297 _ARCH_CAT_NOEXPAND(arch_ctor_, _name) = { \
298 reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
299 static_cast<unsigned>(PXR_VERSION), \
303 _ARCH_ENSURE_PER_LIB_INIT(Arch_ConstructorInit, _archCtorInit); \
304 static void _name(__VA_ARGS__)
307# define ARCH_DESTRUCTOR(_name, _priority, ...) \
308 static void _name(__VA_ARGS__); \
310 __declspec(allocate(".pxrdtor")) \
311 extern const Arch_ConstructorEntry \
312 _ARCH_CAT_NOEXPAND(arch_dtor_, _name) = { \
313 reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
314 static_cast<unsigned>(PXR_VERSION), \
318 _ARCH_ENSURE_PER_LIB_INIT(Arch_ConstructorInit, _archCtorInit); \
319 static void _name(__VA_ARGS__)
328PXR_NAMESPACE_CLOSE_SCOPE
Defines symbol visibility macros.