Skip to content

Commit 086f9ad

Browse files
committed
Use AX_CHECK_COMPILE_FLAG macro to check for -fvisibility=hidden support.
The existing check for -fvisibility=hidden support came from a time when only GCC had it. The test for it used a regular expression to parse the GCC major version from the output of `$CC --version`, and would look for version 4 or greater. The regular expression used to accomplish this is doomed, however, since GCC can be built with a custom version string (--with-pkgversion). Moreover, the $CC variable can be set to something that confuses it but is otherwise valid. For example, it would fail with CC=x86_64-pc-linux-gnu-gcc. This commit fixes two aspects of the feature test. First, it no longer limits the test to GCC. At least clang now supports the flag, and can make use of it when GCC is its backend. Second, support for the flag is tested directly, by attempting to pass it to the compiler, rather than by parsing its version string. The latter is accomplished with a new macro, AX_CHECK_COMPILE_FLAG, taken from the autoconf archive. The new macro has been added to acinclude.m4, and the test stanza in configure.in has been replaced with a single call to the new macro. Note that the new macro calls AC_PREREQ(2.64) -- a more stringent requirement than the existing AC_PREREQ(2.59) in configure.in. The difference represents about six years of autoconf releases, from v2.59 in December of 2003 to v2.64 in July of 2009. This problem was noticed by Brian Evans, who also suggested the fix. PHP-Bug: 73062
1 parent d1535da commit 086f9ad

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

acinclude.m4

+18
Original file line numberDiff line numberDiff line change
@@ -3231,3 +3231,21 @@ AC_DEFUN([PHP_CHECK_BUILTIN_SSUBLL_OVERFLOW], [
32313231
[$have_builtin_ssubll_overflow], [Whether the compiler supports __builtin_ssubll_overflow])
32323232
32333233
])
3234+
3235+
dnl This macro hails from the autoconf archive. This revision is
3236+
dnl from 2015-01-06.
3237+
AC_DEFUN([AX_CHECK_COMPILE_FLAG],
3238+
[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
3239+
AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
3240+
AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
3241+
ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
3242+
_AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
3243+
AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
3244+
[AS_VAR_SET(CACHEVAR,[yes])],
3245+
[AS_VAR_SET(CACHEVAR,[no])])
3246+
_AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
3247+
AS_VAR_IF(CACHEVAR,yes,
3248+
[m4_default([$2], :)],
3249+
[m4_default([$3], :)])
3250+
AS_VAR_POPDEF([CACHEVAR])dnl
3251+
])dnl AX_CHECK_COMPILE_FLAGS

configure.in

+4-14
Original file line numberDiff line numberDiff line change
@@ -285,20 +285,10 @@ case $host_cpu in
285285
;;
286286
esac
287287

288-
dnl activate some gcc specific optimizations for gcc >= 4
289-
if test "$GCC" = "yes"; then
290-
case $host_alias in
291-
*darwin*)
292-
GCC_MAJOR_VERSION=`$CC -dumpversion | /usr/bin/sed -nE '1s/([[0-9]]+)\.[[0-9]]+\..*/\1/;1p'`
293-
;;
294-
*)
295-
GCC_MAJOR_VERSION=`$CC --version | $SED -n '1s/[[^0-9]]*//;1s/\..*//;1p'`
296-
;;
297-
esac
298-
if test $GCC_MAJOR_VERSION -ge 4; then
299-
CFLAGS="$CFLAGS -fvisibility=hidden"
300-
fi
301-
fi
288+
dnl Mark symbols hidden by default if the compiler (for example, gcc >= 4)
289+
dnl supports it. This can help reduce the binary size and startup time.
290+
AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],
291+
[CFLAGS="$CFLAGS -fvisibility=hidden"])
302292

303293
case $host_alias in
304294
*solaris*)

0 commit comments

Comments
 (0)