5 #ifndef __UTILS_MONO_COMPILER_H__
6 #define __UTILS_MONO_COMPILER_H__
9 * This file includes macros used in the runtime to encapsulate different
10 * compiler behaviours.
13 #if defined(HAVE_UNISTD_H)
18 #define MONO_ATTR_USED __attribute__ ((__used__))
20 #define MONO_ATTR_USED
24 #define MONO_ATTR_FORMAT_PRINTF(fmt_pos,arg_pos) __attribute__ ((__format__(__printf__,fmt_pos,arg_pos)))
26 #define MONO_ATTR_FORMAT_PRINTF(fmt_pos,arg_pos)
29 /* Deal with Microsoft C compiler differences */
36 #define pclose _pclose
38 #define mkdir(x) _mkdir(x)
40 #define __func__ __FUNCTION__
45 // ssize_t and SSIZE_MAX are Posix, define for Windows.
46 typedef ptrdiff_t ssize_t
;
48 #define SSIZE_MAX INTPTR_MAX
53 // Quiet Visual Studio linker warning, LNK4221: This object file does not define any previously
54 // undefined public symbols, so it will not be used by any link operation that consumes this library.
55 // And other linkers, e.g. older Apple.
56 #define MONO_EMPTY_SOURCE_FILE(x) extern const char mono_quash_linker_empty_file_warning_ ## x; \
57 const char mono_quash_linker_empty_file_warning_ ## x = 0;
60 #define MONO_PRAGMA_WARNING_PUSH() __pragma(warning (push))
61 #define MONO_PRAGMA_WARNING_DISABLE(x) __pragma(warning (disable:x))
62 #define MONO_PRAGMA_WARNING_POP() __pragma(warning (pop))
64 #define MONO_DISABLE_WARNING(x) \
65 MONO_PRAGMA_WARNING_PUSH() \
66 MONO_PRAGMA_WARNING_DISABLE(x)
68 #define MONO_RESTORE_WARNING \
69 MONO_PRAGMA_WARNING_POP()
71 #define MONO_PRAGMA_WARNING_PUSH()
72 #define MONO_PRAGMA_WARNING_DISABLE(x)
73 #define MONO_PRAGMA_WARNING_POP()
74 #define MONO_DISABLE_WARNING(x)
75 #define MONO_RESTORE_WARNING
78 // If MONO_LLVM_INTERNAL changes, update mono_debug_method_lookup_location declaration.
79 #if !defined(_MSC_VER) && !defined(HOST_SOLARIS) && !defined(_WIN32) && !defined(__CYGWIN__) && !defined(MONOTOUCH) && HAVE_VISIBILITY_HIDDEN
81 #define MONO_LLVM_INTERNAL MONO_API_NO_EXTERN_C
83 #define MONO_LLVM_INTERNAL
86 #define MONO_LLVM_INTERNAL
89 /* Used to mark internal functions used by the profiler modules */
90 #define MONO_PROFILER_API MONO_API
92 /* Used to mark internal functions used by the CoreFX PAL library */
93 #define MONO_PAL_API MONO_API
96 #define MONO_ALWAYS_INLINE __attribute__ ((__always_inline__))
97 #elif defined(_MSC_VER)
98 #define MONO_ALWAYS_INLINE __forceinline
100 #define MONO_ALWAYS_INLINE
104 #define MONO_NEVER_INLINE __attribute__ ((__noinline__))
105 #elif defined(_MSC_VER)
106 #define MONO_NEVER_INLINE __declspec(noinline)
108 #define MONO_NEVER_INLINE
112 #define MONO_COLD __attribute__ ((__cold__))
117 #if defined (__clang__)
118 #define MONO_NO_OPTIMIZATION __attribute__ ((optnone))
119 #elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
120 #define MONO_NO_OPTIMIZATION __attribute__ ((optimize("O0")))
122 #define MONO_NO_OPTIMIZATION /* nothing */
125 #if defined (__GNUC__) && defined (__GNUC_MINOR__) && defined (__GNUC_PATCHLEVEL__)
126 #define MONO_GNUC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
129 #if defined(__has_feature)
131 #if __has_feature(thread_sanitizer)
132 #define MONO_HAS_CLANG_THREAD_SANITIZER 1
134 #define MONO_HAS_CLANG_THREAD_SANITIZER 0
137 #if __has_feature(address_sanitizer)
138 #define MONO_HAS_CLANG_ADDRESS_SANITIZER 1
140 #define MONO_HAS_CLANG_ADDRESS_SANITIZER 0
144 #define MONO_HAS_CLANG_THREAD_SANITIZER 0
145 #define MONO_HAS_CLANG_ADDRESS_SANITIZER 0
148 /* Used to tell Clang's ThreadSanitizer to not report data races that occur within a certain function */
149 #if MONO_HAS_CLANG_THREAD_SANITIZER
150 #define MONO_NO_SANITIZE_THREAD __attribute__ ((no_sanitize("thread")))
152 #define MONO_NO_SANITIZE_THREAD
155 /* Used to tell Clang's AddressSanitizer to turn off instrumentation for a certain function */
156 #if MONO_HAS_CLANG_ADDRESS_SANITIZER
157 #define MONO_NO_SANITIZE_ADDRESS __attribute__ ((no_sanitize("address")))
159 #define MONO_NO_SANITIZE_ADDRESS
162 /* Used when building with Android NDK's unified headers */
163 #if defined(HOST_ANDROID) && defined (ANDROID_UNIFIED_HEADERS)
164 #ifdef HAVE_ANDROID_NDK_VERSION_H
165 #include <android/ndk-version.h>
168 #if __ANDROID_API__ < 21
170 typedef int32_t __mono_off32_t
;
172 #ifdef HAVE_SYS_MMAN_H
173 #include <sys/mman.h>
176 #if __NDK_MAJOR__ < 18
182 /* Unified headers before API 21 do not declare mmap when LARGE_FILES are used (via -D_FILE_OFFSET_BITS=64)
183 * which is always the case when Mono build targets Android. The problem here is that the unified headers
184 * map `mmap` to `mmap64` if large files are enabled but this api exists only in API21 onwards. Therefore
185 * we must carefully declare the 32-bit mmap here without changing the ABI along the way. Carefully because
186 * in this instance off_t is redeclared to be 64-bit and that's not what we want.
188 void* mmap (void*, size_t, int, int, int, __mono_off32_t
);
194 #endif /* __NDK_MAJOR__ < 18 */
196 #ifdef HAVE_SYS_SENDFILE_H
197 #include <sys/sendfile.h>
204 /* Similar thing as with mmap happens with sendfile, except that the off_t is always used (and
205 * mono expects 64-bit offset here */
206 ssize_t
sendfile (int out_fd
, int in_fd
, off_t
* offset
, size_t count
);
212 #endif /* __ANDROID_API__ < 21 */
213 #endif /* HOST_ANDROID && ANDROID_UNIFIED_HEADERS */
215 #endif /* __UTILS_MONO_COMPILER_H__*/