2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
16 #ifndef incl_HPHP_PORTABILITY_H_
17 #define incl_HPHP_PORTABILITY_H_
19 #include <folly/Likely.h> // defining LIKELY/UNLIKELY is part of this header
20 #include <folly/Portability.h>
21 #include <folly/CPortability.h> // FOLLY_DISABLE_ADDRESS_SANITIZER, FOLLY_EXPORT
23 //////////////////////////////////////////////////////////////////////
26 * Various macros to make certain things conditional on either
27 * compiler or architecture.
29 * Currently we don't *really* compile on anything other than gcc or
30 * sometimes clang, and there are some parts of the code using
31 * __attribute__ stuff directly, but some things go through these
32 * macros to make it maybe easier to change later.
35 //////////////////////////////////////////////////////////////////////
37 // TODO: does clang define __GNUC__ ?
39 # define __attribute__(x)
42 //////////////////////////////////////////////////////////////////////
44 #ifdef ATTRIBUTE_UNUSED
45 # undef ATTRIBUTE_UNUSED
47 #ifdef ATTRIBUTE_PRINTF
48 # undef ATTRIBUTE_PRINTF
50 #ifdef ATTRIBUTE_PRINTF_STRING
51 # undef ATTRIBUTE_PRINTF_STRING
54 #define ATTRIBUTE_PRINTF_STRING FOLLY_PRINTF_FORMAT
57 #define ATTRIBUTE_PRINTF(a1, a2)
59 # define __thread __declspec(thread)
61 #define ATTRIBUTE_UNUSED
62 #define ATTRIBUTE_USED
64 #define ALWAYS_INLINE __forceinline
65 #define EXTERNALLY_VISIBLE
67 #define NEVER_INLINE __declspec(noinline)
71 #define ATTRIBUTE_PRINTF(a1, a2) \
72 __attribute__((__format__ (__printf__, a1, a2)))
73 #define ATTRIBUTE_UNUSED __attribute__((__unused__))
74 #define ATTRIBUTE_USED __attribute__((__used__))
76 # define FLATTEN /*nop*/
77 # define ALWAYS_INLINE inline
78 # define INLINE_FLATTEN inline
80 # define FLATTEN __attribute__((__flatten__))
81 # define ALWAYS_INLINE inline __attribute__((__always_inline__))
82 # define INLINE_FLATTEN inline __attribute__((__always_inline__,__flatten__))
84 #define NEVER_INLINE __attribute__((__noinline__))
85 #define UNUSED __attribute__((__unused__))
90 #define NO_OPT [[clang::optnone]]
91 #define EXTERNALLY_VISIBLE ATTRIBUTE_USED FOLLY_EXPORT
93 #define NO_OPT __attribute__((__optimize__("O0")))
94 #define EXTERNALLY_VISIBLE __attribute__((__externally_visible__))
98 # define HHVM_ATTRIBUTE_WEAK __attribute__((__weak__))
99 #elif defined(__clang__)
100 # define HHVM_ATTRIBUTE_WEAK __attribute__((__weak_import__))
102 # define HHVM_ATTRIBUTE_WEAK
106 # define DEBUG_ONLY /* nop */
108 # define DEBUG_ONLY UNUSED
113 * AARCH64 needs to create a walkable stack frame for
114 * getFrameRegs() when a FixupEntry isIndirect()
117 #define AARCH64_WALKABLE_FRAME() asm("" ::: "memory");
119 #define AARCH64_WALKABLE_FRAME()
124 * We need to keep some unreferenced functions from being removed by
125 * the linker. There is no compile time mechanism for doing this, but
126 * by putting them in the same section as some other, referenced function
127 * in the same file, we can keep them around.
129 * So this macro should be used to mark at least one function that is
130 * referenced, and other functions that are not referenced in the same
133 * Note: this may not work properly with LTO. We'll revisit when/if we
137 # define KEEP_SECTION \
138 __attribute__((__section__(".text.keep")))
140 # define KEEP_SECTION \
141 __attribute__((__section__(".text,.text.keep")))
144 #if defined(__APPLE__)
145 // OS X has a macro "isset" defined in this header. Force the include so we can
146 // make sure the macro gets undef'd. (I think this also applies to BSD, but we
147 // can cross that road when we come to it.)
148 # include <sys/param.h>
154 //////////////////////////////////////////////////////////////////////
155 // DECLARE_FRAME_POINTER
157 #if defined(__x86_64__)
159 # define DECLARE_FRAME_POINTER(fp) \
160 auto const fp = (ActRec*) __builtin_frame_address(0)
161 # define FRAME_POINTER_IS_ACCURATE
163 #elif defined(_M_X64)
165 // TODO: FIXME! Without this implemented properly, the JIT
166 // will fail "pretty spectacularly".
167 # define DECLARE_FRAME_POINTER(fp) \
168 always_assert(false); \
169 register ActRec* fp = nullptr;
171 #elif defined(__AARCH64EL__)
173 # if defined(__clang__)
174 # define DECLARE_FRAME_POINTER(fp) register ActRec* fp = (ActRec*) \
175 __builtin_frame_address(0)
177 # define DECLARE_FRAME_POINTER(fp) register ActRec* fp asm("x29")
180 #elif defined(__powerpc64__)
182 # if defined(__clang__)
183 # error Clang implementation not done for PPC64
185 # define DECLARE_FRAME_POINTER(fp) \
186 auto const fp = (ActRec*) __builtin_frame_address(0)
187 # define FRAME_POINTER_IS_ACCURATE
191 # error What are the stack and frame pointers called on your architecture?
195 //////////////////////////////////////////////////////////////////////
196 // CALLEE_SAVED_BARRIER
199 // Unfortunately, we have no way to tell MSVC to do this, so we'll
200 // probably have to use a pair of assembly stubs to manage this.
201 #define CALLEE_SAVED_BARRIER() always_assert(false);
202 #elif defined (__powerpc64__)
203 // After gcc 5.4.1 we can't clobber r30 on PPC64 anymore because it's used as
205 #if __GNUC__ > 5 || (__GNUC__ == 5 && (__GNUC_MINOR__ >= 4) && \
206 (__GNUC_PATCHLEVEL__ >= 1))
207 #define CALLEE_SAVED_BARRIER()\
208 asm volatile("" : : : "r2", "r14", "r15", "r16", "r17", "r18", "r19",\
209 "r20", "r21", "r22", "r23", "r24", "r25", "r26", "r27", \
210 "r28", "r29", "cr2", "cr3", "cr4", "v20", "v21", "v22", \
211 "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", \
214 // On gcc versions < 5.4.1 we need to include r30 on barrier as it's not
216 #define CALLEE_SAVED_BARRIER()\
217 asm volatile("" : : : "r2", "r14", "r15", "r16", "r17", "r18", "r19",\
218 "r20", "r21", "r22", "r23", "r24", "r25", "r26", "r27", \
219 "r28", "r29", "r30", "cr2", "cr3", "cr4", "v20", "v21", \
220 "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", \
223 #elif defined (__AARCH64EL__)
224 #define CALLEE_SAVED_BARRIER()\
225 asm volatile("" : : : "x19", "x20", "x21", "x22", "x23", "x24", "x25",\
226 "x26", "x27", "x28", \
227 "d8", "d9", "d10", "d11", "d12", "d13", "d14", "d15")
229 #define CALLEE_SAVED_BARRIER()\
230 asm volatile("" : : : "rbx", "r12", "r13", "r14", "r15");
233 //////////////////////////////////////////////////////////////////////
235 // We reserve the exit status 127 to signal a failure in the
236 // interpreter. 127 is a valid exit code on all reasonable
237 // architectures: POSIX requires at least 8 unsigned bits and
238 // Windows 32 signed bits.
239 #define HPHP_EXIT_FAILURE 127
241 //////////////////////////////////////////////////////////////////////
244 #define USE_FOLLY_SYMBOLIZER 1
245 // Linking in libbfd is a gigantic PITA, but if folly symbolizer doesn't
246 // work on your platform, you'll need to figure it out.
247 #define HAVE_LIBBFD 1
251 // The value doesn't matter, but it must be defined before you include
253 #define PACKAGE "hhvm"
256 //////////////////////////////////////////////////////////////////////
259 # include "hphp/util/portability/fnmatch.h"
260 # include "hphp/util/portability/glob.h"
261 # include "hphp/util/portability/rand_r.h"
262 # include "hphp/util/portability/strfmon.h"
265 #if defined(_MSC_VER) && _MSC_FULL_VER <= 190023506 // 2015 Update 1 or below
266 // MSVC2015 has an issue with getting function pointers to templated functions
267 // if the expected result type isn't auto. Unfortunately, when I made the
268 // initial bug report, I oversimplified the use-case, and, while the case I
269 // reported was indeed fixed in Update 1 RC, none of our actual uses of it were
271 // This is being tracked at MS as #163251.
272 # define MSVC_REQUIRE_AUTO_TEMPLATED_OVERLOAD 1
273 // 2015 RTM doesn't like it when you try to add via a double duration.
274 // Bug Report: https://connect.microsoft.com/VisualStudio/feedback/details/1839243
275 # define MSVC_NO_STD_CHRONO_DURATION_DOUBLE_ADD 1
279 #define ASM_LOCAL_LABEL(x) "L" x
281 #define ASM_LOCAL_LABEL(x) ".L" x