7#ifndef PXR_BASE_ARCH_ATTRIBUTES_H
8#define PXR_BASE_ARCH_ATTRIBUTES_H
21PXR_NAMESPACE_OPEN_SCOPE
36# define ARCH_PRINTF_FUNCTION(_fmt, _firstArg)
50# define ARCH_SCANF_FUNCTION(_fmt, _firstArg)
74# define ARCH_UNUSED_ARG
89# define ARCH_UNUSED_FUNCTION
109# define ARCH_USED_FUNCTION
124# define ARCH_CONSTRUCTOR(_name, _priority)
139# define ARCH_DESTRUCTOR(_name, _priority)
147# define ARCH_EMPTY_BASES
170# define ARCH_NO_SANITIZE_ADDRESS_FUNCTION
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_ALWAYS_INLINE __attribute__((always_inline))
180# define ARCH_UNUSED_ARG __attribute__ ((unused))
181# define ARCH_UNUSED_FUNCTION __attribute__((unused))
182# define ARCH_USED_FUNCTION __attribute__((used))
183# define ARCH_EMPTY_BASES
185#if defined(ARCH_SANITIZE_ADDRESS)
186# define ARCH_NO_SANITIZE_ADDRESS_FUNCTION \
187 __attribute__((no_sanitize_address))
189# define ARCH_NO_SANITIZE_ADDRESS_FUNCTION
195#elif defined(ARCH_COMPILER_MSVC)
197# define ARCH_PRINTF_FUNCTION(_fmt, _firstArg)
198# define ARCH_SCANF_FUNCTION(_fmt, _firstArg)
199# define ARCH_NOINLINE
200# define ARCH_ALWAYS_INLINE
201# define ARCH_UNUSED_ARG
202# define ARCH_UNUSED_FUNCTION
203# define ARCH_USED_FUNCTION
204# define ARCH_EMPTY_BASES __declspec(empty_bases)
206#if defined(ARCH_SANITIZE_ADDRESS)
207# define ARCH_NO_SANITIZE_ADDRESS_FUNCTION \
208 __declspec(no_sanitize_address)
210# define ARCH_NO_SANITIZE_ADDRESS_FUNCTION
238template <
class StaticInit>
239struct ARCH_HIDDEN Arch_PerLibInit {
243 static StaticInit init;
245template <
class StaticInit>
246StaticInit Arch_PerLibInit<StaticInit>::init;
248#define _ARCH_CAT_NOEXPAND(a, b) a ## b
249#define _ARCH_CAT(a, b) _ARCH_CAT_NOEXPAND(a, b)
250#define _ARCH_ENSURE_PER_LIB_INIT(T, prefix) \
251 static Arch_PerLibInit<T> _ARCH_CAT(prefix, __COUNTER__)
257#elif defined(ARCH_OS_DARWIN)
260struct Arch_ConstructorEntry {
261 typedef void (*Type)(void);
263 unsigned int version:24;
264 unsigned int priority:8;
268# define ARCH_CONSTRUCTOR(_name, _priority) \
269 static void _name(); \
270 static const Arch_ConstructorEntry _ARCH_CAT_NOEXPAND(arch_ctor_, _name) \
271 __attribute__((used, section("__DATA,pxrctor"))) = { \
272 reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
273 static_cast<unsigned>(PXR_VERSION), \
279# define ARCH_DESTRUCTOR(_name, _priority) \
280 static void _name(); \
281 static const Arch_ConstructorEntry _ARCH_CAT_NOEXPAND(arch_dtor_, _name) \
282 __attribute__((used, section("__DATA,pxrdtor"))) = { \
283 reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
284 static_cast<unsigned>(PXR_VERSION), \
289#elif defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
293# define ARCH_CONSTRUCTOR(_name, _priority) \
294 __attribute__((used, section(".pxrctor"), constructor((_priority) + 100))) \
296# define ARCH_DESTRUCTOR(_name, _priority) \
297 __attribute__((used, section(".pxrdtor"), destructor((_priority) + 100))) \
300#elif defined(ARCH_OS_WINDOWS)
302# include "pxr/base/arch/api.h"
305 __declspec(align(16))
306 struct Arch_ConstructorEntry {
307 typedef void (__cdecl *Type)(void);
309 unsigned int version:24;
310 unsigned int priority:8;
314# pragma section(".pxrctor", read)
315# pragma section(".pxrdtor", read)
320struct Arch_ConstructorInit {
321 ARCH_API Arch_ConstructorInit();
322 ARCH_API ~Arch_ConstructorInit();
329# define ARCH_CONSTRUCTOR(_name, _priority) \
330 static void _name(); \
332 __declspec(allocate(".pxrctor")) \
333 static const Arch_ConstructorEntry \
334 _ARCH_CAT_NOEXPAND(arch_ctor_, _name) = { \
335 reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
336 static_cast<unsigned>(PXR_VERSION), \
339 void _ARCH_CAT_NOEXPAND(arch_ctor_unused, _name)() { \
340 static const auto unused = \
341 std::addressof(_ARCH_CAT_NOEXPAND(arch_ctor_, _name)); \
344 _ARCH_ENSURE_PER_LIB_INIT(Arch_ConstructorInit, _archCtorInit); \
348# define ARCH_DESTRUCTOR(_name, _priority) \
349 static void _name(); \
351 __declspec(allocate(".pxrdtor")) \
352 static const Arch_ConstructorEntry \
353 _ARCH_CAT_NOEXPAND(arch_dtor_, _name) = { \
354 reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
355 static_cast<unsigned>(PXR_VERSION), \
358 void _ARCH_CAT_NOEXPAND(arch_dtor_unused, _name)() { \
359 static const auto unused = \
360 std::addressof(_ARCH_CAT_NOEXPAND(arch_dtor_, _name)); \
363 _ARCH_ENSURE_PER_LIB_INIT(Arch_ConstructorInit, _archCtorInit); \
373PXR_NAMESPACE_CLOSE_SCOPE
Defines symbol visibility macros.