Zend.m4 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. dnl This file contains Zend specific autoconf macros.
  2. dnl
  3. dnl ZEND_CHECK_FLOAT_PRECISION
  4. dnl
  5. dnl x87 floating point internal precision control checks
  6. dnl See: http://wiki.php.net/rfc/rounding
  7. dnl
  8. AC_DEFUN([ZEND_CHECK_FLOAT_PRECISION],[
  9. AC_MSG_CHECKING([for usable _FPU_SETCW])
  10. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  11. #include <fpu_control.h>
  12. ]],[[
  13. fpu_control_t fpu_oldcw, fpu_cw;
  14. volatile double result;
  15. double a = 2877.0;
  16. volatile double b = 1000000.0;
  17. _FPU_GETCW(fpu_oldcw);
  18. fpu_cw = (fpu_oldcw & ~_FPU_EXTENDED & ~_FPU_SINGLE) | _FPU_DOUBLE;
  19. _FPU_SETCW(fpu_cw);
  20. result = a / b;
  21. _FPU_SETCW(fpu_oldcw);
  22. ]])],[ac_cfp_have__fpu_setcw=yes],[ac_cfp_have__fpu_setcw=no])
  23. if test "$ac_cfp_have__fpu_setcw" = "yes" ; then
  24. AC_DEFINE(HAVE__FPU_SETCW, 1, [whether _FPU_SETCW is present and usable])
  25. AC_MSG_RESULT(yes)
  26. else
  27. AC_MSG_RESULT(no)
  28. fi
  29. AC_MSG_CHECKING([for usable fpsetprec])
  30. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  31. #include <machine/ieeefp.h>
  32. ]],[[
  33. fp_prec_t fpu_oldprec;
  34. volatile double result;
  35. double a = 2877.0;
  36. volatile double b = 1000000.0;
  37. fpu_oldprec = fpgetprec();
  38. fpsetprec(FP_PD);
  39. result = a / b;
  40. fpsetprec(fpu_oldprec);
  41. ]])], [ac_cfp_have_fpsetprec=yes], [ac_cfp_have_fpsetprec=no])
  42. if test "$ac_cfp_have_fpsetprec" = "yes" ; then
  43. AC_DEFINE(HAVE_FPSETPREC, 1, [whether fpsetprec is present and usable])
  44. AC_MSG_RESULT(yes)
  45. else
  46. AC_MSG_RESULT(no)
  47. fi
  48. AC_MSG_CHECKING([for usable _controlfp])
  49. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  50. #include <float.h>
  51. ]],[[
  52. unsigned int fpu_oldcw;
  53. volatile double result;
  54. double a = 2877.0;
  55. volatile double b = 1000000.0;
  56. fpu_oldcw = _controlfp(0, 0);
  57. _controlfp(_PC_53, _MCW_PC);
  58. result = a / b;
  59. _controlfp(fpu_oldcw, _MCW_PC);
  60. ]])], [ac_cfp_have__controlfp=yes], [ac_cfp_have__controlfp=no])
  61. if test "$ac_cfp_have__controlfp" = "yes" ; then
  62. AC_DEFINE(HAVE__CONTROLFP, 1, [whether _controlfp is present usable])
  63. AC_MSG_RESULT(yes)
  64. else
  65. AC_MSG_RESULT(no)
  66. fi
  67. AC_MSG_CHECKING([for usable _controlfp_s])
  68. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  69. #include <float.h>
  70. ]],[[
  71. unsigned int fpu_oldcw, fpu_cw;
  72. volatile double result;
  73. double a = 2877.0;
  74. volatile double b = 1000000.0;
  75. _controlfp_s(&fpu_cw, 0, 0);
  76. fpu_oldcw = fpu_cw;
  77. _controlfp_s(&fpu_cw, _PC_53, _MCW_PC);
  78. result = a / b;
  79. _controlfp_s(&fpu_cw, fpu_oldcw, _MCW_PC);
  80. ]])], [ac_cfp_have__controlfp_s=yes], [ac_cfp_have__controlfp_s=no])
  81. if test "$ac_cfp_have__controlfp_s" = "yes" ; then
  82. AC_DEFINE(HAVE__CONTROLFP_S, 1, [whether _controlfp_s is present and usable])
  83. AC_MSG_RESULT(yes)
  84. else
  85. AC_MSG_RESULT(no)
  86. fi
  87. AC_MSG_CHECKING([whether FPU control word can be manipulated by inline assembler])
  88. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  89. /* nothing */
  90. ]],[[
  91. unsigned int oldcw, cw;
  92. volatile double result;
  93. double a = 2877.0;
  94. volatile double b = 1000000.0;
  95. __asm__ __volatile__ ("fnstcw %0" : "=m" (*&oldcw));
  96. cw = (oldcw & ~0x0 & ~0x300) | 0x200;
  97. __asm__ __volatile__ ("fldcw %0" : : "m" (*&cw));
  98. result = a / b;
  99. __asm__ __volatile__ ("fldcw %0" : : "m" (*&oldcw));
  100. ]])], [ac_cfp_have_fpu_inline_asm_x86=yes], [ac_cfp_have_fpu_inline_asm_x86=no])
  101. if test "$ac_cfp_have_fpu_inline_asm_x86" = "yes" ; then
  102. AC_DEFINE(HAVE_FPU_INLINE_ASM_X86, 1, [whether FPU control word can be manipulated by inline assembler])
  103. AC_MSG_RESULT(yes)
  104. else
  105. AC_MSG_RESULT(no)
  106. fi
  107. ])
  108. dnl
  109. dnl LIBZEND_BASIC_CHECKS
  110. dnl
  111. dnl Basic checks specific for the Zend engine library.
  112. dnl
  113. AC_DEFUN([LIBZEND_BASIC_CHECKS],[
  114. AC_REQUIRE([AC_PROG_CC])
  115. AC_CHECK_HEADERS([cpuid.h])
  116. dnl
  117. dnl LIBZEND_DLSYM_CHECK
  118. dnl
  119. dnl Ugly hack to check if dlsym() requires a leading underscore in symbol name.
  120. dnl
  121. AC_DEFUN([LIBZEND_DLSYM_CHECK],[
  122. AC_MSG_CHECKING([whether dlsym() requires a leading underscore in symbol names])
  123. _LT_AC_TRY_DLOPEN_SELF([
  124. AC_MSG_RESULT(no)
  125. ], [
  126. AC_MSG_RESULT(yes)
  127. AC_DEFINE(DLSYM_NEEDS_UNDERSCORE, 1, [Define if dlsym() requires a leading underscore in symbol names. ])
  128. ], [
  129. AC_MSG_RESULT(no)
  130. ], [])
  131. ])
  132. dnl Checks for library functions.
  133. AC_CHECK_FUNCS(getpid kill sigsetjmp)
  134. ZEND_CHECK_FLOAT_PRECISION
  135. ])
  136. dnl
  137. dnl LIBZEND_OTHER_CHECKS
  138. dnl
  139. AC_DEFUN([LIBZEND_OTHER_CHECKS],[
  140. AC_MSG_CHECKING(whether to enable thread-safety)
  141. AC_MSG_RESULT($ZEND_ZTS)
  142. AC_MSG_CHECKING(whether to enable Zend debugging)
  143. AC_MSG_RESULT($ZEND_DEBUG)
  144. if test "$ZEND_DEBUG" = "yes"; then
  145. AC_DEFINE(ZEND_DEBUG,1,[ ])
  146. echo " $CFLAGS" | grep ' -g' >/dev/null || DEBUG_CFLAGS="-g"
  147. if test "$CFLAGS" = "-g -O2"; then
  148. CFLAGS=-g
  149. fi
  150. else
  151. AC_DEFINE(ZEND_DEBUG,0,[ ])
  152. fi
  153. test -n "$GCC" && CFLAGS="-Wall -Wextra -Wno-strict-aliasing -Wno-unused-parameter -Wno-sign-compare $CFLAGS"
  154. dnl Check if compiler supports -Wno-clobbered (only GCC)
  155. AX_CHECK_COMPILE_FLAG([-Wno-clobbered], CFLAGS="-Wno-clobbered $CFLAGS", , [-Werror])
  156. dnl Check for support for implicit fallthrough level 1, also add after previous CFLAGS as level 3 is enabled in -Wextra
  157. AX_CHECK_COMPILE_FLAG([-Wimplicit-fallthrough=1], CFLAGS="$CFLAGS -Wimplicit-fallthrough=1", , [-Werror])
  158. AX_CHECK_COMPILE_FLAG([-Wduplicated-cond], CFLAGS="-Wduplicated-cond $CFLAGS", , [-Werror])
  159. AX_CHECK_COMPILE_FLAG([-Wlogical-op], CFLAGS="-Wlogical-op $CFLAGS", , [-Werror])
  160. AX_CHECK_COMPILE_FLAG([-Wformat-truncation], CFLAGS="-Wformat-truncation $CFLAGS", , [-Werror])
  161. AX_CHECK_COMPILE_FLAG([-Wstrict-prototypes], CFLAGS="-Wstrict-prototypes $CFLAGS", , [-Werror])
  162. AX_CHECK_COMPILE_FLAG([-fno-common], CFLAGS="-fno-common $CFLAGS", , [-Werror])
  163. test -n "$DEBUG_CFLAGS" && CFLAGS="$CFLAGS $DEBUG_CFLAGS"
  164. if test "$ZEND_ZTS" = "yes"; then
  165. AC_DEFINE(ZTS,1,[ ])
  166. CFLAGS="$CFLAGS -DZTS"
  167. fi
  168. AC_C_INLINE
  169. AC_MSG_CHECKING(target system is Darwin)
  170. if echo "$target" | grep "darwin" > /dev/null; then
  171. AC_DEFINE([DARWIN], 1, [Define if the target system is darwin])
  172. AC_MSG_RESULT(yes)
  173. else
  174. AC_MSG_RESULT(no)
  175. fi
  176. dnl Test and set the alignment define for ZEND_MM. This also does the
  177. dnl logarithmic test for ZEND_MM.
  178. AC_MSG_CHECKING(for MM alignment and log values)
  179. AC_RUN_IFELSE([AC_LANG_SOURCE([[
  180. #include <stdio.h>
  181. #include <stdlib.h>
  182. typedef union _mm_align_test {
  183. void *ptr;
  184. double dbl;
  185. long lng;
  186. } mm_align_test;
  187. #if (defined (__GNUC__) && __GNUC__ >= 2)
  188. #define ZEND_MM_ALIGNMENT (__alignof__ (mm_align_test))
  189. #else
  190. #define ZEND_MM_ALIGNMENT (sizeof(mm_align_test))
  191. #endif
  192. int main()
  193. {
  194. int i = ZEND_MM_ALIGNMENT;
  195. int zeros = 0;
  196. FILE *fp;
  197. while (i & ~0x1) {
  198. zeros++;
  199. i = i >> 1;
  200. }
  201. fp = fopen("conftest.zend", "w");
  202. fprintf(fp, "%d %d\n", ZEND_MM_ALIGNMENT, zeros);
  203. fclose(fp);
  204. return 0;
  205. }
  206. ]])], [
  207. LIBZEND_MM_ALIGN=`cat conftest.zend | cut -d ' ' -f 1`
  208. LIBZEND_MM_ALIGN_LOG2=`cat conftest.zend | cut -d ' ' -f 2`
  209. AC_DEFINE_UNQUOTED(ZEND_MM_ALIGNMENT, $LIBZEND_MM_ALIGN, [ ])
  210. AC_DEFINE_UNQUOTED(ZEND_MM_ALIGNMENT_LOG2, $LIBZEND_MM_ALIGN_LOG2, [ ])
  211. ], [], [
  212. dnl Cross compilation needs something here.
  213. AC_DEFINE_UNQUOTED(ZEND_MM_ALIGNMENT, 8, [ ])
  214. AC_DEFINE_UNQUOTED(ZEND_MM_ALIGNMENT_LOG2, 3, [ ])
  215. ])
  216. AC_MSG_RESULT(done)
  217. AC_CHECK_FUNCS(mremap)
  218. AC_ARG_ENABLE([zend-signals],
  219. [AS_HELP_STRING([--disable-zend-signals],
  220. [whether to enable zend signal handling])],
  221. [ZEND_SIGNALS=$enableval],
  222. [ZEND_SIGNALS=yes])
  223. AC_CHECK_FUNCS([sigaction], [], [
  224. ZEND_SIGNALS=no
  225. ])
  226. if test "$ZEND_SIGNALS" = "yes"; then
  227. AC_DEFINE(ZEND_SIGNALS, 1, [Use zend signal handling])
  228. CFLAGS="$CFLAGS -DZEND_SIGNALS"
  229. fi
  230. AC_MSG_CHECKING(whether to enable zend signal handling)
  231. AC_MSG_RESULT($ZEND_SIGNALS)
  232. ])
  233. AC_MSG_CHECKING(whether /dev/urandom exists)
  234. if test -r "/dev/urandom" && test -c "/dev/urandom"; then
  235. AC_DEFINE([HAVE_DEV_URANDOM], 1, [Define if the target system has /dev/urandom device])
  236. AC_MSG_RESULT(yes)
  237. else
  238. AC_MSG_RESULT(no)
  239. fi
  240. AC_ARG_ENABLE([gcc-global-regs],
  241. [AS_HELP_STRING([--disable-gcc-global-regs],
  242. [whether to enable GCC global register variables])],
  243. [ZEND_GCC_GLOBAL_REGS=$enableval],
  244. [ZEND_GCC_GLOBAL_REGS=yes])
  245. AC_MSG_CHECKING(for global register variables support)
  246. if test "$ZEND_GCC_GLOBAL_REGS" != "no"; then
  247. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  248. #if defined(__GNUC__)
  249. # define ZEND_GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
  250. #else
  251. # define ZEND_GCC_VERSION 0
  252. #endif
  253. #if defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(i386)
  254. # define ZEND_VM_FP_GLOBAL_REG "%esi"
  255. # define ZEND_VM_IP_GLOBAL_REG "%edi"
  256. #elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__x86_64__)
  257. # define ZEND_VM_FP_GLOBAL_REG "%r14"
  258. # define ZEND_VM_IP_GLOBAL_REG "%r15"
  259. #elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__powerpc64__)
  260. # define ZEND_VM_FP_GLOBAL_REG "r28"
  261. # define ZEND_VM_IP_GLOBAL_REG "r29"
  262. #elif defined(__IBMC__) && ZEND_GCC_VERSION >= 4002 && defined(__powerpc64__)
  263. # define ZEND_VM_FP_GLOBAL_REG "r28"
  264. # define ZEND_VM_IP_GLOBAL_REG "r29"
  265. #elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__aarch64__)
  266. # define ZEND_VM_FP_GLOBAL_REG "x27"
  267. # define ZEND_VM_IP_GLOBAL_REG "x28"
  268. #else
  269. # error "global register variables are not supported"
  270. #endif
  271. typedef int (*opcode_handler_t)(void);
  272. register void *FP __asm__(ZEND_VM_FP_GLOBAL_REG);
  273. register const opcode_handler_t *IP __asm__(ZEND_VM_IP_GLOBAL_REG);
  274. int emu(const opcode_handler_t *ip, void *fp) {
  275. const opcode_handler_t *orig_ip = IP;
  276. void *orig_fp = FP;
  277. IP = ip;
  278. FP = fp;
  279. while ((*ip)());
  280. FP = orig_fp;
  281. IP = orig_ip;
  282. }
  283. ]], [[
  284. ]])], [
  285. ZEND_GCC_GLOBAL_REGS=yes
  286. ], [
  287. ZEND_GCC_GLOBAL_REGS=no
  288. ])
  289. fi
  290. if test "$ZEND_GCC_GLOBAL_REGS" = "yes"; then
  291. AC_DEFINE([HAVE_GCC_GLOBAL_REGS], 1, [Define if the target system has support for global register variables])
  292. else
  293. HAVE_GCC_GLOBAL_REGS=no
  294. fi
  295. AC_MSG_RESULT($ZEND_GCC_GLOBAL_REGS)
  296. dnl Check whether __cpuid_count is available.
  297. AC_CACHE_CHECK(whether __cpuid_count is available, ac_cv_cpuid_count_available, [
  298. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  299. #include <cpuid.h>
  300. ]], [[
  301. unsigned eax, ebx, ecx, edx;
  302. __cpuid_count(0, 0, eax, ebx, ecx, edx);
  303. ]])], [
  304. ac_cv_cpuid_count_available=yes
  305. ], [
  306. ac_cv_cpuid_count_available=no
  307. ])])
  308. if test "$ac_cv_cpuid_count_available" = "yes"; then
  309. AC_DEFINE([HAVE_CPUID_COUNT], 1, [whether __cpuid_count is available])
  310. fi