llvm.org GIT mirror llvm / 9cd9208
Fix configure to find arc4random via header files. ISSUE: On Ubuntu 12.04 LTS, arc4random is provided by libbsd.so, which is a transitive dependency of libedit. If a system had libedit on it that was implemented in terms of libbsd.so, then the arc4random test, previously implemented as a linker test, would succeed with -ledit. However, on Ubuntu this would also require a #include <bsd/stdlib.h>. This caused a build breakage on configure-based Ubuntu 12.04 with libedit installed. FIX: This fix changes configure to test for arc4random by searching for it in the standard header files. On Ubuntu 12.04, this test now properly fails to find arc4random as it is not defined in the default header locations. It also tweaks the #define names to match the output of the header check command, which is slightly different than the linker function check #defines. I tested the following scenarios: (1) Ubuntu 12.04 without the libedit package [did not find arc4random, as expected] (2) Ubuntu 12.04 with libedit package [properly did not find arc4random, as expected] (3) Ubuntu 12.04 with most recent libedit, custom built, and not dependent on libbsd.so [properly did not find arc4random, as expected]. (4) FreeBSD 10.0B1 [properly found arc4random, as expected] git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200819 91177308-0d34-0410-b5e6-96231b3b80d8 Todd Fiala 5 years ago
5 changed file(s) with 99 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
17561756 AC_CHECK_FUNCS([getpagesize getrusage getrlimit setrlimit gettimeofday ])
17571757 AC_CHECK_FUNCS([isatty mkdtemp mkstemp ])
17581758 AC_CHECK_FUNCS([mktemp posix_spawn pread realpath sbrk setrlimit ])
1759 AC_CHECK_FUNCS([strerror strerror_r setenv arc4random ])
1759 AC_CHECK_FUNCS([strerror strerror_r setenv ])
17601760 AC_CHECK_FUNCS([strtoll strtoq sysconf malloc_zone_statistics ])
17611761 AC_CHECK_FUNCS([setjmp longjmp sigsetjmp siglongjmp writev])
17621762 AC_CHECK_FUNCS([futimes futimens])
17631763 AC_C_PRINTF_A
17641764 AC_FUNC_RAND48
1765
1766 dnl Check for arc4random accessible via AC_INCLUDES_DEFAULT.
1767 AC_CHECK_DECLS([arc4random])
17651768
17661769 dnl Check the declaration "Secure API" on Windows environments.
17671770 AC_CHECK_DECLS([strerror_s])
116116 endif()
117117
118118 # function checks
119 check_symbol_exists(arc4random "stdlib.h" HAVE_ARC4RANDOM)
119 check_symbol_exists(arc4random "stdlib.h" HAVE_DECL_ARC4RANDOM)
120120 check_symbol_exists(backtrace "execinfo.h" HAVE_BACKTRACE)
121121 check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE)
122122 check_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE)
1852618526
1852718527
1852818528
18529
18530 for ac_func in strerror strerror_r setenv arc4random
18529 for ac_func in strerror strerror_r setenv
1853118530 do
1853218531 as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
1853318532 { echo "$as_me:$LINENO: checking for $ac_func" >&5
1915819157 _ACEOF
1915919158
1916019159 fi
19160
19161
19162 { echo "$as_me:$LINENO: checking whether arc4random is declared" >&5
19163 echo $ECHO_N "checking whether arc4random is declared... $ECHO_C" >&6; }
19164 if test "${ac_cv_have_decl_arc4random+set}" = set; then
19165 echo $ECHO_N "(cached) $ECHO_C" >&6
19166 else
19167 cat >conftest.$ac_ext <<_ACEOF
19168 /* confdefs.h. */
19169 _ACEOF
19170 cat confdefs.h >>conftest.$ac_ext
19171 cat >>conftest.$ac_ext <<_ACEOF
19172 /* end confdefs.h. */
19173 $ac_includes_default
19174 int
19175 main ()
19176 {
19177 #ifndef arc4random
19178 char *p = (char *) arc4random;
19179 return !p;
19180 #endif
19181
19182 ;
19183 return 0;
19184 }
19185 _ACEOF
19186 rm -f conftest.$ac_objext
19187 if { (ac_try="$ac_compile"
19188 case "(($ac_try" in
19189 *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
19190 *) ac_try_echo=$ac_try;;
19191 esac
19192 eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
19193 (eval "$ac_compile") 2>conftest.er1
19194 ac_status=$?
19195 grep -v '^ *+' conftest.er1 >conftest.err
19196 rm -f conftest.er1
19197 cat conftest.err >&5
19198 echo "$as_me:$LINENO: \$? = $ac_status" >&5
19199 (exit $ac_status); } &&
19200 { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
19201 { (case "(($ac_try" in
19202 *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
19203 *) ac_try_echo=$ac_try;;
19204 esac
19205 eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
19206 (eval "$ac_try") 2>&5
19207 ac_status=$?
19208 echo "$as_me:$LINENO: \$? = $ac_status" >&5
19209 (exit $ac_status); }; } &&
19210 { ac_try='test -s conftest.$ac_objext'
19211 { (case "(($ac_try" in
19212 *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
19213 *) ac_try_echo=$ac_try;;
19214 esac
19215 eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
19216 (eval "$ac_try") 2>&5
19217 ac_status=$?
19218 echo "$as_me:$LINENO: \$? = $ac_status" >&5
19219 (exit $ac_status); }; }; then
19220 ac_cv_have_decl_arc4random=yes
19221 else
19222 echo "$as_me: failed program was:" >&5
19223 sed 's/^/| /' conftest.$ac_ext >&5
19224
19225 ac_cv_have_decl_arc4random=no
19226 fi
19227
19228 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
19229 fi
19230 { echo "$as_me:$LINENO: result: $ac_cv_have_decl_arc4random" >&5
19231 echo "${ECHO_T}$ac_cv_have_decl_arc4random" >&6; }
19232 if test $ac_cv_have_decl_arc4random = yes; then
19233
19234 cat >>confdefs.h <<_ACEOF
19235 #define HAVE_DECL_ARC4RANDOM 1
19236 _ACEOF
19237
19238
19239 else
19240 cat >>confdefs.h <<_ACEOF
19241 #define HAVE_DECL_ARC4RANDOM 0
19242 _ACEOF
19243
19244
19245 fi
19246
1916119247
1916219248
1916319249 { echo "$as_me:$LINENO: checking whether strerror_s is declared" >&5
3232 /* Directory where gcc is installed. */
3333 #undef GCC_INSTALL_PREFIX
3434
35 /* Define to 1 if you have the `arc4random' function. */
36 #undef HAVE_ARC4RANDOM
37
3835 /* Define to 1 if you have the `argz_append' function. */
3936 #undef HAVE_ARGZ_APPEND
4037
7370
7471 /* Define to 1 if you have the header file. */
7572 #undef HAVE_CXXABI_H
73
74 /* Define to 1 if you have the declaration of `arc4random', and to 0 if you
75 don't. */
76 #undef HAVE_DECL_ARC4RANDOM
7677
7778 /* Define to 1 if you have the declaration of `FE_ALL_EXCEPT', and to 0 if you
7879 don't. */
342342 return "\033[0m";
343343 }
344344
345 #if !defined(HAVE_ARC4RANDOM)
345 #if !defined(HAVE_DECL_ARC4RANDOM) || !HAVE_DECL_ARC4RANDOM
346346 static unsigned GetRandomNumberSeed() {
347347 // Attempt to get the initial seed from /dev/urandom, if possible.
348348 if (FILE *RandomSource = ::fopen("/dev/urandom", "r")) {
363363 #endif
364364
365365 unsigned llvm::sys::Process::GetRandomNumber() {
366 #if defined(HAVE_ARC4RANDOM)
366 #if defined(HAVE_DECL_ARC4RANDOM) && HAVE_DECL_ARC4RANDOM
367367 return arc4random();
368368 #else
369369 static int x = (::srand(GetRandomNumberSeed()), 0);