Skip to content

Commit d778ed2

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 <[email protected]>
1 parent 563d764 commit d778ed2

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
@@ -26110,6 +26110,156 @@ $as_echo "#define _GLIBCXX_USE_RANDOM_TR1 1" >>confdefs.h
2611026110

2611126111

2611226112

26113+
# Check for other random number APIs
26114+
26115+
26116+
26117+
ac_ext=cpp
26118+
ac_cpp='$CXXCPP $CPPFLAGS'
26119+
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
26120+
ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
26121+
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
26122+
26123+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for getentropy" >&5
26124+
$as_echo_n "checking for getentropy... " >&6; }
26125+
if ${glibcxx_cv_getentropy+:} false; then :
26126+
$as_echo_n "(cached) " >&6
26127+
else
26128+
26129+
if test x$gcc_no_link = xyes; then
26130+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
26131+
/* end confdefs.h. */
26132+
#include <unistd.h>
26133+
int
26134+
main ()
26135+
{
26136+
unsigned i;
26137+
::getentropy(&i, sizeof(i));
26138+
;
26139+
return 0;
26140+
}
26141+
_ACEOF
26142+
if ac_fn_cxx_try_compile "$LINENO"; then :
26143+
glibcxx_cv_getentropy=yes
26144+
else
26145+
glibcxx_cv_getentropy=no
26146+
fi
26147+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
26148+
else
26149+
if test x$gcc_no_link = xyes; then
26150+
as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
26151+
fi
26152+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
26153+
/* end confdefs.h. */
26154+
#include <unistd.h>
26155+
int
26156+
main ()
26157+
{
26158+
unsigned i;
26159+
::getentropy(&i, sizeof(i));
26160+
;
26161+
return 0;
26162+
}
26163+
_ACEOF
26164+
if ac_fn_cxx_try_link "$LINENO"; then :
26165+
glibcxx_cv_getentropy=yes
26166+
else
26167+
glibcxx_cv_getentropy=no
26168+
fi
26169+
rm -f core conftest.err conftest.$ac_objext \
26170+
conftest$ac_exeext conftest.$ac_ext
26171+
fi
26172+
26173+
fi
26174+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_getentropy" >&5
26175+
$as_echo "$glibcxx_cv_getentropy" >&6; }
26176+
26177+
if test $glibcxx_cv_getentropy = yes; then
26178+
26179+
$as_echo "#define HAVE_GETENTROPY 1" >>confdefs.h
26180+
26181+
fi
26182+
ac_ext=c
26183+
ac_cpp='$CPP $CPPFLAGS'
26184+
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
26185+
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
26186+
ac_compiler_gnu=$ac_cv_c_compiler_gnu
26187+
26188+
26189+
26190+
26191+
26192+
ac_ext=cpp
26193+
ac_cpp='$CXXCPP $CPPFLAGS'
26194+
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
26195+
ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
26196+
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
26197+
26198+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for arc4random" >&5
26199+
$as_echo_n "checking for arc4random... " >&6; }
26200+
if ${glibcxx_cv_arc4random+:} false; then :
26201+
$as_echo_n "(cached) " >&6
26202+
else
26203+
26204+
if test x$gcc_no_link = xyes; then
26205+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
26206+
/* end confdefs.h. */
26207+
#include <stdlib.h>
26208+
int
26209+
main ()
26210+
{
26211+
unsigned i = ::arc4random();
26212+
;
26213+
return 0;
26214+
}
26215+
_ACEOF
26216+
if ac_fn_cxx_try_compile "$LINENO"; then :
26217+
glibcxx_cv_arc4random=yes
26218+
else
26219+
glibcxx_cv_arc4random=no
26220+
fi
26221+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
26222+
else
26223+
if test x$gcc_no_link = xyes; then
26224+
as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
26225+
fi
26226+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
26227+
/* end confdefs.h. */
26228+
#include <stdlib.h>
26229+
int
26230+
main ()
26231+
{
26232+
unsigned i = ::arc4random();
26233+
;
26234+
return 0;
26235+
}
26236+
_ACEOF
26237+
if ac_fn_cxx_try_link "$LINENO"; then :
26238+
glibcxx_cv_arc4random=yes
26239+
else
26240+
glibcxx_cv_arc4random=no
26241+
fi
26242+
rm -f core conftest.err conftest.$ac_objext \
26243+
conftest$ac_exeext conftest.$ac_ext
26244+
fi
26245+
26246+
fi
26247+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_arc4random" >&5
26248+
$as_echo "$glibcxx_cv_arc4random" >&6; }
26249+
26250+
if test $glibcxx_cv_arc4random = yes; then
26251+
26252+
$as_echo "#define HAVE_ARC4RANDOM 1" >>confdefs.h
26253+
26254+
fi
26255+
ac_ext=c
26256+
ac_cpp='$CPP $CPPFLAGS'
26257+
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
26258+
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
26259+
ac_compiler_gnu=$ac_cv_c_compiler_gnu
26260+
26261+
26262+
2611326263
# For TLS support.
2611426264

2611526265

@@ -51569,156 +51719,6 @@ $as_echo "#define _GLIBCXX_X86_RDSEED 1" >>confdefs.h
5156951719
fi
5157051720

5157151721

51572-
# Check for other random number APIs
51573-
51574-
51575-
51576-
ac_ext=cpp
51577-
ac_cpp='$CXXCPP $CPPFLAGS'
51578-
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
51579-
ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
51580-
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
51581-
51582-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for getentropy" >&5
51583-
$as_echo_n "checking for getentropy... " >&6; }
51584-
if ${glibcxx_cv_getentropy+:} false; then :
51585-
$as_echo_n "(cached) " >&6
51586-
else
51587-
51588-
if test x$gcc_no_link = xyes; then
51589-
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
51590-
/* end confdefs.h. */
51591-
#include <unistd.h>
51592-
int
51593-
main ()
51594-
{
51595-
unsigned i;
51596-
::getentropy(&i, sizeof(i));
51597-
;
51598-
return 0;
51599-
}
51600-
_ACEOF
51601-
if ac_fn_cxx_try_compile "$LINENO"; then :
51602-
glibcxx_cv_getentropy=yes
51603-
else
51604-
glibcxx_cv_getentropy=no
51605-
fi
51606-
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
51607-
else
51608-
if test x$gcc_no_link = xyes; then
51609-
as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
51610-
fi
51611-
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
51612-
/* end confdefs.h. */
51613-
#include <unistd.h>
51614-
int
51615-
main ()
51616-
{
51617-
unsigned i;
51618-
::getentropy(&i, sizeof(i));
51619-
;
51620-
return 0;
51621-
}
51622-
_ACEOF
51623-
if ac_fn_cxx_try_link "$LINENO"; then :
51624-
glibcxx_cv_getentropy=yes
51625-
else
51626-
glibcxx_cv_getentropy=no
51627-
fi
51628-
rm -f core conftest.err conftest.$ac_objext \
51629-
conftest$ac_exeext conftest.$ac_ext
51630-
fi
51631-
51632-
fi
51633-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_getentropy" >&5
51634-
$as_echo "$glibcxx_cv_getentropy" >&6; }
51635-
51636-
if test $glibcxx_cv_getentropy = yes; then
51637-
51638-
$as_echo "#define HAVE_GETENTROPY 1" >>confdefs.h
51639-
51640-
fi
51641-
ac_ext=c
51642-
ac_cpp='$CPP $CPPFLAGS'
51643-
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
51644-
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
51645-
ac_compiler_gnu=$ac_cv_c_compiler_gnu
51646-
51647-
51648-
51649-
51650-
51651-
ac_ext=cpp
51652-
ac_cpp='$CXXCPP $CPPFLAGS'
51653-
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
51654-
ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
51655-
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
51656-
51657-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for arc4random" >&5
51658-
$as_echo_n "checking for arc4random... " >&6; }
51659-
if ${glibcxx_cv_arc4random+:} false; then :
51660-
$as_echo_n "(cached) " >&6
51661-
else
51662-
51663-
if test x$gcc_no_link = xyes; then
51664-
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
51665-
/* end confdefs.h. */
51666-
#include <stdlib.h>
51667-
int
51668-
main ()
51669-
{
51670-
unsigned i = ::arc4random();
51671-
;
51672-
return 0;
51673-
}
51674-
_ACEOF
51675-
if ac_fn_cxx_try_compile "$LINENO"; then :
51676-
glibcxx_cv_arc4random=yes
51677-
else
51678-
glibcxx_cv_arc4random=no
51679-
fi
51680-
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
51681-
else
51682-
if test x$gcc_no_link = xyes; then
51683-
as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
51684-
fi
51685-
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
51686-
/* end confdefs.h. */
51687-
#include <stdlib.h>
51688-
int
51689-
main ()
51690-
{
51691-
unsigned i = ::arc4random();
51692-
;
51693-
return 0;
51694-
}
51695-
_ACEOF
51696-
if ac_fn_cxx_try_link "$LINENO"; then :
51697-
glibcxx_cv_arc4random=yes
51698-
else
51699-
glibcxx_cv_arc4random=no
51700-
fi
51701-
rm -f core conftest.err conftest.$ac_objext \
51702-
conftest$ac_exeext conftest.$ac_ext
51703-
fi
51704-
51705-
fi
51706-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_arc4random" >&5
51707-
$as_echo "$glibcxx_cv_arc4random" >&6; }
51708-
51709-
if test $glibcxx_cv_arc4random = yes; then
51710-
51711-
$as_echo "#define HAVE_ARC4RANDOM 1" >>confdefs.h
51712-
51713-
fi
51714-
ac_ext=c
51715-
ac_cpp='$CPP $CPPFLAGS'
51716-
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
51717-
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
51718-
ac_compiler_gnu=$ac_cv_c_compiler_gnu
51719-
51720-
51721-
5172251722
# This depends on GLIBCXX_ENABLE_SYMVERS and GLIBCXX_IS_NATIVE.
5172351723

5172451724
# Do checks for resource limit functions.

libstdc++-v3/configure.ac

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

288+
# Check for other random number APIs
289+
GLIBCXX_CHECK_GETENTROPY
290+
GLIBCXX_CHECK_ARC4RANDOM
291+
288292
# For TLS support.
289293
GCC_CHECK_TLS
290294

@@ -517,10 +521,6 @@ GLIBCXX_CHECK_X86_RDRAND
517521
# Check if assembler supports rdseed opcode.
518522
GLIBCXX_CHECK_X86_RDSEED
519523

520-
# Check for other random number APIs
521-
GLIBCXX_CHECK_GETENTROPY
522-
GLIBCXX_CHECK_ARC4RANDOM
523-
524524
# This depends on GLIBCXX_ENABLE_SYMVERS and GLIBCXX_IS_NATIVE.
525525
GLIBCXX_CONFIGURE_TESTSUITE
526526

0 commit comments

Comments
 (0)