Skip to content

Commit bd72e25

Browse files
committed
libstdc++: Do not check getentropy and arc4random for cross builds
The "getentropy" and "arc4random" check may not yield a correct result for the cross compile builds because linking is often not available for them and the C library headers (notoriously, newlib) may still declare these function prototypes even if they are not actually part of the final library -- for this reason, this commit disables the "getentropy" and "arc4random" checks for non-native builds. This effectively prevents the std::random_device from making use of these functions when `--with-newlib` is specified, which is indeed a correct behaviour because the newlib does not provide a default stub for the "getentropy" function (also note that the newlib "arc4random" implementation internally calls the missing "getentropy" function). For other C libraries, the `GLIBCXX_CROSSCONFIG` function may hard-code the availability of these functions by manually defining `HAVE_GETENTROPY` and `HAVE_ARC4RANDOM`, or by calling the `GLIBCXX_CHECK_GETENTROPY` and `GLIBCXX_CHECK_ARC4RANDOM` functions. libstdc++-v3: * configure.ac: Relocate GLIBCXX_CHECK_GETENTROPY and GLIBCXX_CHECK_ARC4RANDOM * configure: Regenerate. Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
1 parent 6d11ef7 commit bd72e25

File tree

2 files changed

+154
-154
lines changed

2 files changed

+154
-154
lines changed

libstdc++-v3/configure

Lines changed: 150 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -28088,6 +28088,156 @@ $as_echo "#define _GLIBCXX_USE_RANDOM_TR1 1" >>confdefs.h
2808828088

2808928089

2809028090

28091+
# Check for other random number APIs
28092+
28093+
28094+
28095+
ac_ext=cpp
28096+
ac_cpp='$CXXCPP $CPPFLAGS'
28097+
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
28098+
ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
28099+
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
28100+
28101+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for getentropy" >&5
28102+
$as_echo_n "checking for getentropy... " >&6; }
28103+
if ${glibcxx_cv_getentropy+:} false; then :
28104+
$as_echo_n "(cached) " >&6
28105+
else
28106+
28107+
if test x$gcc_no_link = xyes; then
28108+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
28109+
/* end confdefs.h. */
28110+
#include <unistd.h>
28111+
int
28112+
main ()
28113+
{
28114+
unsigned i;
28115+
::getentropy(&i, sizeof(i));
28116+
;
28117+
return 0;
28118+
}
28119+
_ACEOF
28120+
if ac_fn_cxx_try_compile "$LINENO"; then :
28121+
glibcxx_cv_getentropy=yes
28122+
else
28123+
glibcxx_cv_getentropy=no
28124+
fi
28125+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
28126+
else
28127+
if test x$gcc_no_link = xyes; then
28128+
as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
28129+
fi
28130+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
28131+
/* end confdefs.h. */
28132+
#include <unistd.h>
28133+
int
28134+
main ()
28135+
{
28136+
unsigned i;
28137+
::getentropy(&i, sizeof(i));
28138+
;
28139+
return 0;
28140+
}
28141+
_ACEOF
28142+
if ac_fn_cxx_try_link "$LINENO"; then :
28143+
glibcxx_cv_getentropy=yes
28144+
else
28145+
glibcxx_cv_getentropy=no
28146+
fi
28147+
rm -f core conftest.err conftest.$ac_objext \
28148+
conftest$ac_exeext conftest.$ac_ext
28149+
fi
28150+
28151+
fi
28152+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_getentropy" >&5
28153+
$as_echo "$glibcxx_cv_getentropy" >&6; }
28154+
28155+
if test $glibcxx_cv_getentropy = yes; then
28156+
28157+
$as_echo "#define HAVE_GETENTROPY 1" >>confdefs.h
28158+
28159+
fi
28160+
ac_ext=c
28161+
ac_cpp='$CPP $CPPFLAGS'
28162+
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
28163+
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
28164+
ac_compiler_gnu=$ac_cv_c_compiler_gnu
28165+
28166+
28167+
28168+
28169+
28170+
ac_ext=cpp
28171+
ac_cpp='$CXXCPP $CPPFLAGS'
28172+
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
28173+
ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
28174+
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
28175+
28176+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for arc4random" >&5
28177+
$as_echo_n "checking for arc4random... " >&6; }
28178+
if ${glibcxx_cv_arc4random+:} false; then :
28179+
$as_echo_n "(cached) " >&6
28180+
else
28181+
28182+
if test x$gcc_no_link = xyes; then
28183+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
28184+
/* end confdefs.h. */
28185+
#include <stdlib.h>
28186+
int
28187+
main ()
28188+
{
28189+
unsigned i = ::arc4random();
28190+
;
28191+
return 0;
28192+
}
28193+
_ACEOF
28194+
if ac_fn_cxx_try_compile "$LINENO"; then :
28195+
glibcxx_cv_arc4random=yes
28196+
else
28197+
glibcxx_cv_arc4random=no
28198+
fi
28199+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
28200+
else
28201+
if test x$gcc_no_link = xyes; then
28202+
as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
28203+
fi
28204+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
28205+
/* end confdefs.h. */
28206+
#include <stdlib.h>
28207+
int
28208+
main ()
28209+
{
28210+
unsigned i = ::arc4random();
28211+
;
28212+
return 0;
28213+
}
28214+
_ACEOF
28215+
if ac_fn_cxx_try_link "$LINENO"; then :
28216+
glibcxx_cv_arc4random=yes
28217+
else
28218+
glibcxx_cv_arc4random=no
28219+
fi
28220+
rm -f core conftest.err conftest.$ac_objext \
28221+
conftest$ac_exeext conftest.$ac_ext
28222+
fi
28223+
28224+
fi
28225+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_arc4random" >&5
28226+
$as_echo "$glibcxx_cv_arc4random" >&6; }
28227+
28228+
if test $glibcxx_cv_arc4random = yes; then
28229+
28230+
$as_echo "#define HAVE_ARC4RANDOM 1" >>confdefs.h
28231+
28232+
fi
28233+
ac_ext=c
28234+
ac_cpp='$CPP $CPPFLAGS'
28235+
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
28236+
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
28237+
ac_compiler_gnu=$ac_cv_c_compiler_gnu
28238+
28239+
28240+
2809128241
# For TLS support.
2809228242

2809328243

@@ -75519,156 +75669,6 @@ $as_echo "#define _GLIBCXX_X86_RDSEED 1" >>confdefs.h
7551975669
fi
7552075670

7552175671

75522-
# Check for other random number APIs
75523-
75524-
75525-
75526-
ac_ext=cpp
75527-
ac_cpp='$CXXCPP $CPPFLAGS'
75528-
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
75529-
ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
75530-
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
75531-
75532-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for getentropy" >&5
75533-
$as_echo_n "checking for getentropy... " >&6; }
75534-
if ${glibcxx_cv_getentropy+:} false; then :
75535-
$as_echo_n "(cached) " >&6
75536-
else
75537-
75538-
if test x$gcc_no_link = xyes; then
75539-
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
75540-
/* end confdefs.h. */
75541-
#include <unistd.h>
75542-
int
75543-
main ()
75544-
{
75545-
unsigned i;
75546-
::getentropy(&i, sizeof(i));
75547-
;
75548-
return 0;
75549-
}
75550-
_ACEOF
75551-
if ac_fn_cxx_try_compile "$LINENO"; then :
75552-
glibcxx_cv_getentropy=yes
75553-
else
75554-
glibcxx_cv_getentropy=no
75555-
fi
75556-
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
75557-
else
75558-
if test x$gcc_no_link = xyes; then
75559-
as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
75560-
fi
75561-
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
75562-
/* end confdefs.h. */
75563-
#include <unistd.h>
75564-
int
75565-
main ()
75566-
{
75567-
unsigned i;
75568-
::getentropy(&i, sizeof(i));
75569-
;
75570-
return 0;
75571-
}
75572-
_ACEOF
75573-
if ac_fn_cxx_try_link "$LINENO"; then :
75574-
glibcxx_cv_getentropy=yes
75575-
else
75576-
glibcxx_cv_getentropy=no
75577-
fi
75578-
rm -f core conftest.err conftest.$ac_objext \
75579-
conftest$ac_exeext conftest.$ac_ext
75580-
fi
75581-
75582-
fi
75583-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_getentropy" >&5
75584-
$as_echo "$glibcxx_cv_getentropy" >&6; }
75585-
75586-
if test $glibcxx_cv_getentropy = yes; then
75587-
75588-
$as_echo "#define HAVE_GETENTROPY 1" >>confdefs.h
75589-
75590-
fi
75591-
ac_ext=c
75592-
ac_cpp='$CPP $CPPFLAGS'
75593-
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
75594-
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
75595-
ac_compiler_gnu=$ac_cv_c_compiler_gnu
75596-
75597-
75598-
75599-
75600-
75601-
ac_ext=cpp
75602-
ac_cpp='$CXXCPP $CPPFLAGS'
75603-
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
75604-
ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
75605-
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
75606-
75607-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for arc4random" >&5
75608-
$as_echo_n "checking for arc4random... " >&6; }
75609-
if ${glibcxx_cv_arc4random+:} false; then :
75610-
$as_echo_n "(cached) " >&6
75611-
else
75612-
75613-
if test x$gcc_no_link = xyes; then
75614-
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
75615-
/* end confdefs.h. */
75616-
#include <stdlib.h>
75617-
int
75618-
main ()
75619-
{
75620-
unsigned i = ::arc4random();
75621-
;
75622-
return 0;
75623-
}
75624-
_ACEOF
75625-
if ac_fn_cxx_try_compile "$LINENO"; then :
75626-
glibcxx_cv_arc4random=yes
75627-
else
75628-
glibcxx_cv_arc4random=no
75629-
fi
75630-
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
75631-
else
75632-
if test x$gcc_no_link = xyes; then
75633-
as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
75634-
fi
75635-
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
75636-
/* end confdefs.h. */
75637-
#include <stdlib.h>
75638-
int
75639-
main ()
75640-
{
75641-
unsigned i = ::arc4random();
75642-
;
75643-
return 0;
75644-
}
75645-
_ACEOF
75646-
if ac_fn_cxx_try_link "$LINENO"; then :
75647-
glibcxx_cv_arc4random=yes
75648-
else
75649-
glibcxx_cv_arc4random=no
75650-
fi
75651-
rm -f core conftest.err conftest.$ac_objext \
75652-
conftest$ac_exeext conftest.$ac_ext
75653-
fi
75654-
75655-
fi
75656-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_arc4random" >&5
75657-
$as_echo "$glibcxx_cv_arc4random" >&6; }
75658-
75659-
if test $glibcxx_cv_arc4random = yes; then
75660-
75661-
$as_echo "#define HAVE_ARC4RANDOM 1" >>confdefs.h
75662-
75663-
fi
75664-
ac_ext=c
75665-
ac_cpp='$CPP $CPPFLAGS'
75666-
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
75667-
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
75668-
ac_compiler_gnu=$ac_cv_c_compiler_gnu
75669-
75670-
75671-
7567275672
# This depends on GLIBCXX_ENABLE_SYMVERS and GLIBCXX_IS_NATIVE.
7567375673

7567475674
# Do checks for resource limit functions.

libstdc++-v3/configure.ac

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ if $GLIBCXX_IS_NATIVE; then
269269
# For /dev/random and /dev/urandom for std::random_device.
270270
GLIBCXX_CHECK_DEV_RANDOM
271271

272+
# Check for other random number APIs
273+
GLIBCXX_CHECK_GETENTROPY
274+
GLIBCXX_CHECK_ARC4RANDOM
275+
272276
# For TLS support.
273277
GCC_CHECK_TLS
274278

@@ -474,10 +478,6 @@ GLIBCXX_CHECK_X86_RDRAND
474478
# Check if assembler supports rdseed opcode.
475479
GLIBCXX_CHECK_X86_RDSEED
476480

477-
# Check for other random number APIs
478-
GLIBCXX_CHECK_GETENTROPY
479-
GLIBCXX_CHECK_ARC4RANDOM
480-
481481
# This depends on GLIBCXX_ENABLE_SYMVERS and GLIBCXX_IS_NATIVE.
482482
GLIBCXX_CONFIGURE_TESTSUITE
483483

0 commit comments

Comments
 (0)