| 1 | Patch-Source: https://github.com/zephyrproject-rtos/gcc/pull/8
|
| 2 |
|
| 3 | From 55addb0c0c5ff5e0aab85574aa26abf175af85c8 Mon Sep 17 00:00:00 2001
|
| 4 | From: Stephanos Ioannidis <[email protected]>
|
| 5 | Date: Mon, 25 Jul 2022 23:10:41 +0900
|
| 6 | Subject: [PATCH] libstdc++: Do not check getentropy and arc4random for cross builds
|
| 7 |
|
| 8 | The "getentropy" and "arc4random" check may not yield a correct result
|
| 9 | for the cross compile builds because linking is often not available for
|
| 10 | them and the C library headers (notoriously, newlib) may still declare
|
| 11 | these function prototypes even if they are not actually part of the
|
| 12 | final library -- for this reason, this commit disables the "getentropy"
|
| 13 | and "arc4random" checks for non-native builds.
|
| 14 |
|
| 15 | This effectively prevents the std::random_device from making use of
|
| 16 | these functions when `--with-newlib` is specified, which is indeed a
|
| 17 | correct behaviour because the newlib does not provide a default stub
|
| 18 | for the "getentropy" function (also note that the newlib "arc4random"
|
| 19 | implementation internally calls the missing "getentropy" function).
|
| 20 |
|
| 21 | For other C libraries, the `GLIBCXX_CROSSCONFIG` function may hard-code
|
| 22 | the availability of these functions by manually defining
|
| 23 | `HAVE_GETENTROPY` and `HAVE_ARC4RANDOM`, or by calling the
|
| 24 | `GLIBCXX_CHECK_GETENTROPY` and `GLIBCXX_CHECK_ARC4RANDOM` functions.
|
| 25 |
|
| 26 | libstdc++-v3:
|
| 27 | * configure.ac: Relocate GLIBCXX_CHECK_GETENTROPY and
|
| 28 | GLIBCXX_CHECK_ARC4RANDOM
|
| 29 | * configure: Regenerate.
|
| 30 |
|
| 31 | Signed-off-by: Stephanos Ioannidis <[email protected]>
|
| 32 | ---
|
| 33 | libstdc++-v3/configure | 300 +++++++++++++++++++-------------------
|
| 34 | libstdc++-v3/configure.ac | 8 +-
|
| 35 | 2 files changed, 154 insertions(+), 154 deletions(-)
|
| 36 |
|
| 37 | diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
|
| 38 | index 0ce74e8202443..5d43b56b03ffa 100755
|
| 39 | |
| 40 | |
| 41 | @@ -28088,6 +28088,156 @@ $as_echo "#define _GLIBCXX_USE_RANDOM_TR1 1" >>confdefs.h
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 | + # Check for other random number APIs
|
| 46 | +
|
| 47 | +
|
| 48 | +
|
| 49 | + ac_ext=cpp
|
| 50 | +ac_cpp='$CXXCPP $CPPFLAGS'
|
| 51 | +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
|
| 52 | +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
|
| 53 | +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
|
| 54 | +
|
| 55 | + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getentropy" >&5
|
| 56 | +$as_echo_n "checking for getentropy... " >&6; }
|
| 57 | +if ${glibcxx_cv_getentropy+:} false; then :
|
| 58 | + $as_echo_n "(cached) " >&6
|
| 59 | +else
|
| 60 | +
|
| 61 | + if test x$gcc_no_link = xyes; then
|
| 62 | + cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
| 63 | +/* end confdefs.h. */
|
| 64 | +#include <unistd.h>
|
| 65 | +int
|
| 66 | +main ()
|
| 67 | +{
|
| 68 | +unsigned i;
|
| 69 | + ::getentropy(&i, sizeof(i));
|
| 70 | + ;
|
| 71 | + return 0;
|
| 72 | +}
|
| 73 | +_ACEOF
|
| 74 | +if ac_fn_cxx_try_compile "$LINENO"; then :
|
| 75 | + glibcxx_cv_getentropy=yes
|
| 76 | +else
|
| 77 | + glibcxx_cv_getentropy=no
|
| 78 | +fi
|
| 79 | +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
| 80 | +else
|
| 81 | + if test x$gcc_no_link = xyes; then
|
| 82 | + as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
|
| 83 | +fi
|
| 84 | +cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
| 85 | +/* end confdefs.h. */
|
| 86 | +#include <unistd.h>
|
| 87 | +int
|
| 88 | +main ()
|
| 89 | +{
|
| 90 | +unsigned i;
|
| 91 | + ::getentropy(&i, sizeof(i));
|
| 92 | + ;
|
| 93 | + return 0;
|
| 94 | +}
|
| 95 | +_ACEOF
|
| 96 | +if ac_fn_cxx_try_link "$LINENO"; then :
|
| 97 | + glibcxx_cv_getentropy=yes
|
| 98 | +else
|
| 99 | + glibcxx_cv_getentropy=no
|
| 100 | +fi
|
| 101 | +rm -f core conftest.err conftest.$ac_objext \
|
| 102 | + conftest$ac_exeext conftest.$ac_ext
|
| 103 | +fi
|
| 104 | +
|
| 105 | +fi
|
| 106 | +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_getentropy" >&5
|
| 107 | +$as_echo "$glibcxx_cv_getentropy" >&6; }
|
| 108 | +
|
| 109 | + if test $glibcxx_cv_getentropy = yes; then
|
| 110 | +
|
| 111 | +$as_echo "#define HAVE_GETENTROPY 1" >>confdefs.h
|
| 112 | +
|
| 113 | + fi
|
| 114 | + ac_ext=c
|
| 115 | +ac_cpp='$CPP $CPPFLAGS'
|
| 116 | +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
|
| 117 | +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
|
| 118 | +ac_compiler_gnu=$ac_cv_c_compiler_gnu
|
| 119 | +
|
| 120 | +
|
| 121 | +
|
| 122 | +
|
| 123 | +
|
| 124 | + ac_ext=cpp
|
| 125 | +ac_cpp='$CXXCPP $CPPFLAGS'
|
| 126 | +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
|
| 127 | +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
|
| 128 | +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
|
| 129 | +
|
| 130 | + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for arc4random" >&5
|
| 131 | +$as_echo_n "checking for arc4random... " >&6; }
|
| 132 | +if ${glibcxx_cv_arc4random+:} false; then :
|
| 133 | + $as_echo_n "(cached) " >&6
|
| 134 | +else
|
| 135 | +
|
| 136 | + if test x$gcc_no_link = xyes; then
|
| 137 | + cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
| 138 | +/* end confdefs.h. */
|
| 139 | +#include <stdlib.h>
|
| 140 | +int
|
| 141 | +main ()
|
| 142 | +{
|
| 143 | +unsigned i = ::arc4random();
|
| 144 | + ;
|
| 145 | + return 0;
|
| 146 | +}
|
| 147 | +_ACEOF
|
| 148 | +if ac_fn_cxx_try_compile "$LINENO"; then :
|
| 149 | + glibcxx_cv_arc4random=yes
|
| 150 | +else
|
| 151 | + glibcxx_cv_arc4random=no
|
| 152 | +fi
|
| 153 | +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
| 154 | +else
|
| 155 | + if test x$gcc_no_link = xyes; then
|
| 156 | + as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
|
| 157 | +fi
|
| 158 | +cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
| 159 | +/* end confdefs.h. */
|
| 160 | +#include <stdlib.h>
|
| 161 | +int
|
| 162 | +main ()
|
| 163 | +{
|
| 164 | +unsigned i = ::arc4random();
|
| 165 | + ;
|
| 166 | + return 0;
|
| 167 | +}
|
| 168 | +_ACEOF
|
| 169 | +if ac_fn_cxx_try_link "$LINENO"; then :
|
| 170 | + glibcxx_cv_arc4random=yes
|
| 171 | +else
|
| 172 | + glibcxx_cv_arc4random=no
|
| 173 | +fi
|
| 174 | +rm -f core conftest.err conftest.$ac_objext \
|
| 175 | + conftest$ac_exeext conftest.$ac_ext
|
| 176 | +fi
|
| 177 | +
|
| 178 | +fi
|
| 179 | +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_arc4random" >&5
|
| 180 | +$as_echo "$glibcxx_cv_arc4random" >&6; }
|
| 181 | +
|
| 182 | + if test $glibcxx_cv_arc4random = yes; then
|
| 183 | +
|
| 184 | +$as_echo "#define HAVE_ARC4RANDOM 1" >>confdefs.h
|
| 185 | +
|
| 186 | + fi
|
| 187 | + ac_ext=c
|
| 188 | +ac_cpp='$CPP $CPPFLAGS'
|
| 189 | +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
|
| 190 | +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
|
| 191 | +ac_compiler_gnu=$ac_cv_c_compiler_gnu
|
| 192 | +
|
| 193 | +
|
| 194 | +
|
| 195 | # For TLS support.
|
| 196 |
|
| 197 |
|
| 198 | @@ -75519,156 +75669,6 @@ $as_echo "#define _GLIBCXX_X86_RDSEED 1" >>confdefs.h
|
| 199 | fi
|
| 200 |
|
| 201 |
|
| 202 | -# Check for other random number APIs
|
| 203 | -
|
| 204 | -
|
| 205 | -
|
| 206 | - ac_ext=cpp
|
| 207 | -ac_cpp='$CXXCPP $CPPFLAGS'
|
| 208 | -ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
|
| 209 | -ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
|
| 210 | -ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
|
| 211 | -
|
| 212 | - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getentropy" >&5
|
| 213 | -$as_echo_n "checking for getentropy... " >&6; }
|
| 214 | -if ${glibcxx_cv_getentropy+:} false; then :
|
| 215 | - $as_echo_n "(cached) " >&6
|
| 216 | -else
|
| 217 | -
|
| 218 | - if test x$gcc_no_link = xyes; then
|
| 219 | - cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
| 220 | -/* end confdefs.h. */
|
| 221 | -#include <unistd.h>
|
| 222 | -int
|
| 223 | -main ()
|
| 224 | -{
|
| 225 | -unsigned i;
|
| 226 | - ::getentropy(&i, sizeof(i));
|
| 227 | - ;
|
| 228 | - return 0;
|
| 229 | -}
|
| 230 | -_ACEOF
|
| 231 | -if ac_fn_cxx_try_compile "$LINENO"; then :
|
| 232 | - glibcxx_cv_getentropy=yes
|
| 233 | -else
|
| 234 | - glibcxx_cv_getentropy=no
|
| 235 | -fi
|
| 236 | -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
| 237 | -else
|
| 238 | - if test x$gcc_no_link = xyes; then
|
| 239 | - as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
|
| 240 | -fi
|
| 241 | -cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
| 242 | -/* end confdefs.h. */
|
| 243 | -#include <unistd.h>
|
| 244 | -int
|
| 245 | -main ()
|
| 246 | -{
|
| 247 | -unsigned i;
|
| 248 | - ::getentropy(&i, sizeof(i));
|
| 249 | - ;
|
| 250 | - return 0;
|
| 251 | -}
|
| 252 | -_ACEOF
|
| 253 | -if ac_fn_cxx_try_link "$LINENO"; then :
|
| 254 | - glibcxx_cv_getentropy=yes
|
| 255 | -else
|
| 256 | - glibcxx_cv_getentropy=no
|
| 257 | -fi
|
| 258 | -rm -f core conftest.err conftest.$ac_objext \
|
| 259 | - conftest$ac_exeext conftest.$ac_ext
|
| 260 | -fi
|
| 261 | -
|
| 262 | -fi
|
| 263 | -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_getentropy" >&5
|
| 264 | -$as_echo "$glibcxx_cv_getentropy" >&6; }
|
| 265 | -
|
| 266 | - if test $glibcxx_cv_getentropy = yes; then
|
| 267 | -
|
| 268 | -$as_echo "#define HAVE_GETENTROPY 1" >>confdefs.h
|
| 269 | -
|
| 270 | - fi
|
| 271 | - ac_ext=c
|
| 272 | -ac_cpp='$CPP $CPPFLAGS'
|
| 273 | -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
|
| 274 | -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
|
| 275 | -ac_compiler_gnu=$ac_cv_c_compiler_gnu
|
| 276 | -
|
| 277 | -
|
| 278 | -
|
| 279 | -
|
| 280 | -
|
| 281 | - ac_ext=cpp
|
| 282 | -ac_cpp='$CXXCPP $CPPFLAGS'
|
| 283 | -ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
|
| 284 | -ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
|
| 285 | -ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
|
| 286 | -
|
| 287 | - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for arc4random" >&5
|
| 288 | -$as_echo_n "checking for arc4random... " >&6; }
|
| 289 | -if ${glibcxx_cv_arc4random+:} false; then :
|
| 290 | - $as_echo_n "(cached) " >&6
|
| 291 | -else
|
| 292 | -
|
| 293 | - if test x$gcc_no_link = xyes; then
|
| 294 | - cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
| 295 | -/* end confdefs.h. */
|
| 296 | -#include <stdlib.h>
|
| 297 | -int
|
| 298 | -main ()
|
| 299 | -{
|
| 300 | -unsigned i = ::arc4random();
|
| 301 | - ;
|
| 302 | - return 0;
|
| 303 | -}
|
| 304 | -_ACEOF
|
| 305 | -if ac_fn_cxx_try_compile "$LINENO"; then :
|
| 306 | - glibcxx_cv_arc4random=yes
|
| 307 | -else
|
| 308 | - glibcxx_cv_arc4random=no
|
| 309 | -fi
|
| 310 | -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
| 311 | -else
|
| 312 | - if test x$gcc_no_link = xyes; then
|
| 313 | - as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
|
| 314 | -fi
|
| 315 | -cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
| 316 | -/* end confdefs.h. */
|
| 317 | -#include <stdlib.h>
|
| 318 | -int
|
| 319 | -main ()
|
| 320 | -{
|
| 321 | -unsigned i = ::arc4random();
|
| 322 | - ;
|
| 323 | - return 0;
|
| 324 | -}
|
| 325 | -_ACEOF
|
| 326 | -if ac_fn_cxx_try_link "$LINENO"; then :
|
| 327 | - glibcxx_cv_arc4random=yes
|
| 328 | -else
|
| 329 | - glibcxx_cv_arc4random=no
|
| 330 | -fi
|
| 331 | -rm -f core conftest.err conftest.$ac_objext \
|
| 332 | - conftest$ac_exeext conftest.$ac_ext
|
| 333 | -fi
|
| 334 | -
|
| 335 | -fi
|
| 336 | -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_arc4random" >&5
|
| 337 | -$as_echo "$glibcxx_cv_arc4random" >&6; }
|
| 338 | -
|
| 339 | - if test $glibcxx_cv_arc4random = yes; then
|
| 340 | -
|
| 341 | -$as_echo "#define HAVE_ARC4RANDOM 1" >>confdefs.h
|
| 342 | -
|
| 343 | - fi
|
| 344 | - ac_ext=c
|
| 345 | -ac_cpp='$CPP $CPPFLAGS'
|
| 346 | -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
|
| 347 | -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
|
| 348 | -ac_compiler_gnu=$ac_cv_c_compiler_gnu
|
| 349 | -
|
| 350 | -
|
| 351 | -
|
| 352 | # This depends on GLIBCXX_ENABLE_SYMVERS and GLIBCXX_IS_NATIVE.
|
| 353 |
|
| 354 | # Do checks for resource limit functions.
|
| 355 | diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac
|
| 356 | index e59bcdb29441f..05cdfcddbc43b 100644
|
| 357 | |
| 358 | |
| 359 | @@ -269,6 +269,10 @@ if $GLIBCXX_IS_NATIVE; then
|
| 360 | # For /dev/random and /dev/urandom for std::random_device.
|
| 361 | GLIBCXX_CHECK_DEV_RANDOM
|
| 362 |
|
| 363 | + # Check for other random number APIs
|
| 364 | + GLIBCXX_CHECK_GETENTROPY
|
| 365 | + GLIBCXX_CHECK_ARC4RANDOM
|
| 366 | +
|
| 367 | # For TLS support.
|
| 368 | GCC_CHECK_TLS
|
| 369 |
|
| 370 | @@ -474,10 +478,6 @@ GLIBCXX_CHECK_X86_RDRAND
|
| 371 | # Check if assembler supports rdseed opcode.
|
| 372 | GLIBCXX_CHECK_X86_RDSEED
|
| 373 |
|
| 374 | -# Check for other random number APIs
|
| 375 | -GLIBCXX_CHECK_GETENTROPY
|
| 376 | -GLIBCXX_CHECK_ARC4RANDOM
|
| 377 | -
|
| 378 | # This depends on GLIBCXX_ENABLE_SYMVERS and GLIBCXX_IS_NATIVE.
|
| 379 | GLIBCXX_CONFIGURE_TESTSUITE
|
| 380 |
|