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