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
122# define ARCH_CONSTRUCTOR(_name, _priority)
137# define ARCH_DESTRUCTOR(_name, _priority)
145# define ARCH_EMPTY_BASES
147#elif defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
149# define ARCH_PRINTF_FUNCTION(_fmt, _firstArg) \
150 __attribute__((format(printf, _fmt, _firstArg)))
151# define ARCH_SCANF_FUNCTION(_fmt, _firstArg) \
152 __attribute__((format(scanf, _fmt, _firstArg)))
153# define ARCH_NOINLINE __attribute__((noinline))
154# define ARCH_ALWAYS_INLINE __attribute__((always_inline))
155# define ARCH_UNUSED_ARG __attribute__ ((unused))
156# define ARCH_UNUSED_FUNCTION __attribute__((unused))
157# define ARCH_USED_FUNCTION __attribute__((used))
158# define ARCH_EMPTY_BASES
160#elif defined(ARCH_COMPILER_MSVC)
162# define ARCH_PRINTF_FUNCTION(_fmt, _firstArg)
163# define ARCH_SCANF_FUNCTION(_fmt, _firstArg)
164# define ARCH_NOINLINE
165# define ARCH_ALWAYS_INLINE
166# define ARCH_UNUSED_ARG
167# define ARCH_UNUSED_FUNCTION
168# define ARCH_USED_FUNCTION
169# define ARCH_EMPTY_BASES __declspec(empty_bases)
193template <
class StaticInit>
194struct ARCH_HIDDEN Arch_PerLibInit {
198 static StaticInit init;
200template <
class StaticInit>
201StaticInit Arch_PerLibInit<StaticInit>::init;
203#define _ARCH_CAT_NOEXPAND(a, b) a ## b
204#define _ARCH_CAT(a, b) _ARCH_CAT_NOEXPAND(a, b)
205#define _ARCH_ENSURE_PER_LIB_INIT(T, prefix) \
206 static Arch_PerLibInit<T> _ARCH_CAT(prefix, __COUNTER__)
212#elif defined(ARCH_OS_DARWIN)
215struct Arch_ConstructorEntry {
216 typedef void (*Type)(void);
218 unsigned int version:24;
219 unsigned int priority:8;
223# define ARCH_CONSTRUCTOR(_name, _priority) \
224 static void _name(); \
225 static const Arch_ConstructorEntry _ARCH_CAT_NOEXPAND(arch_ctor_, _name) \
226 __attribute__((used, section("__DATA,pxrctor"))) = { \
227 reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
228 static_cast<unsigned>(PXR_VERSION), \
234# define ARCH_DESTRUCTOR(_name, _priority) \
235 static void _name(); \
236 static const Arch_ConstructorEntry _ARCH_CAT_NOEXPAND(arch_dtor_, _name) \
237 __attribute__((used, section("__DATA,pxrdtor"))) = { \
238 reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
239 static_cast<unsigned>(PXR_VERSION), \
244#elif defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
248# define ARCH_CONSTRUCTOR(_name, _priority) \
249 __attribute__((used, section(".pxrctor"), constructor((_priority) + 100))) \
251# define ARCH_DESTRUCTOR(_name, _priority) \
252 __attribute__((used, section(".pxrdtor"), destructor((_priority) + 100))) \
255#elif defined(ARCH_OS_WINDOWS)
257# include "pxr/base/arch/api.h"
260 __declspec(align(16))
261 struct Arch_ConstructorEntry {
262 typedef void (__cdecl *Type)(void);
264 unsigned int version:24;
265 unsigned int priority:8;
269# pragma section(".pxrctor", read)
270# pragma section(".pxrdtor", read)
275struct Arch_ConstructorInit {
276 ARCH_API Arch_ConstructorInit();
277 ARCH_API ~Arch_ConstructorInit();
284# define ARCH_CONSTRUCTOR(_name, _priority) \
285 static void _name(); \
287 __declspec(allocate(".pxrctor")) \
288 extern const Arch_ConstructorEntry \
289 _ARCH_CAT_NOEXPAND(arch_ctor_, _name) = { \
290 reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
291 static_cast<unsigned>(PXR_VERSION), \
295 _ARCH_ENSURE_PER_LIB_INIT(Arch_ConstructorInit, _archCtorInit); \
299# define ARCH_DESTRUCTOR(_name, _priority) \
300 static void _name(); \
302 __declspec(allocate(".pxrdtor")) \
303 extern const Arch_ConstructorEntry \
304 _ARCH_CAT_NOEXPAND(arch_dtor_, _name) = { \
305 reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
306 static_cast<unsigned>(PXR_VERSION), \
310 _ARCH_ENSURE_PER_LIB_INIT(Arch_ConstructorInit, _archCtorInit); \
320PXR_NAMESPACE_CLOSE_SCOPE
Defines symbol visibility macros.