24#ifndef PXR_BASE_ARCH_ATTRIBUTES_H
25#define PXR_BASE_ARCH_ATTRIBUTES_H
36PXR_NAMESPACE_OPEN_SCOPE
51# define ARCH_PRINTF_FUNCTION(_fmt, _firstArg)
65# define ARCH_SCANF_FUNCTION(_fmt, _firstArg)
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, ...)
170# define ARCH_EMPTY_BASES
172#elif defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
174# define ARCH_PRINTF_FUNCTION(_fmt, _firstArg) \
175 __attribute__((format(printf, _fmt, _firstArg)))
176# define ARCH_SCANF_FUNCTION(_fmt, _firstArg) \
177 __attribute__((format(scanf, _fmt, _firstArg)))
178# define ARCH_NOINLINE __attribute__((noinline))
179# define ARCH_UNUSED_ARG __attribute__ ((unused))
180# define ARCH_UNUSED_FUNCTION __attribute__((unused))
181# define ARCH_USED_FUNCTION __attribute__((used))
182# define ARCH_EMPTY_BASES
184#elif defined(ARCH_COMPILER_MSVC)
186# define ARCH_PRINTF_FUNCTION(_fmt, _firstArg)
187# define ARCH_SCANF_FUNCTION(_fmt, _firstArg)
188# define ARCH_NOINLINE
189# define ARCH_UNUSED_ARG
190# define ARCH_UNUSED_FUNCTION
191# define ARCH_USED_FUNCTION
192# define ARCH_EMPTY_BASES __declspec(empty_bases)
216template <
class StaticInit>
217struct ARCH_HIDDEN Arch_PerLibInit {
221 static StaticInit init;
223template <
class StaticInit>
224StaticInit Arch_PerLibInit<StaticInit>::init;
226#define _ARCH_CAT_NOEXPAND(a, b) a ## b
227#define _ARCH_CAT(a, b) _ARCH_CAT_NOEXPAND(a, b)
228#define _ARCH_ENSURE_PER_LIB_INIT(T, prefix) \
229 static Arch_PerLibInit<T> _ARCH_CAT(prefix, __COUNTER__)
235#elif defined(ARCH_OS_DARWIN)
238struct Arch_ConstructorEntry {
239 typedef void (*Type)(void);
241 unsigned int version:24;
242 unsigned int priority:8;
246# define ARCH_CONSTRUCTOR(_name, _priority, ...) \
247 static void _name(__VA_ARGS__); \
248 static const Arch_ConstructorEntry _ARCH_CAT_NOEXPAND(arch_ctor_, _name) \
249 __attribute__((used, section("__DATA,pxrctor"))) = { \
250 reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
254 static void _name(__VA_ARGS__)
257# define ARCH_DESTRUCTOR(_name, _priority, ...) \
258 static void _name(__VA_ARGS__); \
259 static const Arch_ConstructorEntry _ARCH_CAT_NOEXPAND(arch_dtor_, _name) \
260 __attribute__((used, section("__DATA,pxrdtor"))) = { \
261 reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
265 static void _name(__VA_ARGS__)
267#elif defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
271# define ARCH_CONSTRUCTOR(_name, _priority, ...) \
272 __attribute__((used, section(".pxrctor"), constructor((_priority) + 100))) \
273 static void _name(__VA_ARGS__)
274# define ARCH_DESTRUCTOR(_name, _priority, ...) \
275 __attribute__((used, section(".pxrdtor"), destructor((_priority) + 100))) \
276 static void _name(__VA_ARGS__)
278#elif defined(ARCH_OS_WINDOWS)
280# include "pxr/base/arch/api.h"
283 __declspec(align(16))
284 struct Arch_ConstructorEntry {
285 typedef void (__cdecl *Type)(void);
287 unsigned int version:24;
288 unsigned int priority:8;
292# pragma section(".pxrctor", read)
293# pragma section(".pxrdtor", read)
298struct Arch_ConstructorInit {
299 ARCH_API Arch_ConstructorInit();
300 ARCH_API ~Arch_ConstructorInit();
307# define ARCH_CONSTRUCTOR(_name, _priority, ...) \
308 static void _name(__VA_ARGS__); \
310 __declspec(allocate(".pxrctor")) \
311 extern const Arch_ConstructorEntry \
312 _ARCH_CAT_NOEXPAND(arch_ctor_, _name) = { \
313 reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
318 _ARCH_ENSURE_PER_LIB_INIT(Arch_ConstructorInit, _archCtorInit); \
319 static void _name(__VA_ARGS__)
322# define ARCH_DESTRUCTOR(_name, _priority, ...) \
323 static void _name(__VA_ARGS__); \
325 __declspec(allocate(".pxrdtor")) \
326 extern const Arch_ConstructorEntry \
327 _ARCH_CAT_NOEXPAND(arch_dtor_, _name) = { \
328 reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
333 _ARCH_ENSURE_PER_LIB_INIT(Arch_ConstructorInit, _archCtorInit); \
334 static void _name(__VA_ARGS__)
343PXR_NAMESPACE_CLOSE_SCOPE
Defines symbol visibility macros.