Bug 56475 - Incorrect result of configure test for /dev/random (_GLIBCXX_USE_RANDOM_TR1) for MinGW platform (and others?)
Summary: Incorrect result of configure test for /dev/random (_GLIBCXX_USE_RANDOM_TR1) ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.7.2
: P3 normal
Target Milestone: 4.8.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-27 18:59 UTC by Karlson2k
Modified: 2013-03-01 13:29 UTC (History)
1 user (show)

See Also:
Host: mingw32
Target: mingw32, mingw32-w64
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Karlson2k 2013-02-27 18:59:51 UTC
When building native compiler for MinGW/MinGW-w64 'configure' checks for /dev/random simply by 

    if test -r /dev/random && test -r /dev/urandom; then
      glibcxx_cv_random_tr1=yes;
    else
      glibcxx_cv_random_tr1=no;
    fi

Result of this test is incorrect at least for MinGW. MinGW shell is executed in MSYS subsystem, so those devices is available for shell, but MinGW compiled programs will have no access to /dev/random.
For some other platforms situation can be the same (/dev/random available for shell, but not for compiled program).

I suggest to do a real compile-link-execute test instead of weak shell emulation.
Comment 1 Paolo Carlini 2013-02-27 19:12:56 UTC
We had an AC_TRY_RUN test, but such kind of test give a lot of problems and we removed it. We had:

  AC_TRY_RUN([#include <stdio.h>
	      int main()
	      {
                return !(fopen("/dev/random", "r")
                         && fopen("/dev/urandom", "r"));
	      }	      
	     ],
             [ac_random_tr1=yes], [ac_random_tr1=no],
	     [ac_random_tr1=no])
  ])

Kai, can you suggest something working on MinGW and not using an AC_TRY_RUN? Or you can just special case MinGW. I have no way of testing such fixes, sorry.
Comment 2 Karlson2k 2013-02-27 19:28:17 UTC
Better to open random devices with "rb"? Or just 'stat' device?
Comment 3 Kai Tietz 2013-02-27 19:45:53 UTC
(In reply to comment #1)
> We had an AC_TRY_RUN test, but such kind of test give a lot of problems and we
> removed it. We had:
> 
>   AC_TRY_RUN([#include <stdio.h>
>           int main()
>           {
>                 return !(fopen("/dev/random", "r")
>                          && fopen("/dev/urandom", "r"));
>           }          
>          ],
>              [ac_random_tr1=yes], [ac_random_tr1=no],
>          [ac_random_tr1=no])
>   ])
> 
> Kai, can you suggest something working on MinGW and not using an AC_TRY_RUN? Or
> you can just special case MinGW. I have no way of testing such fixes, sorry.

Well, AC_TRY_RUN is for sure the wrong approach here.  As such tests are failing badly on cross-compilers.
I think sanest way to solve this is by special-casing mingw targets.
Comment 4 Paolo Carlini 2013-02-27 20:24:30 UTC
I agree. Care to send a patch for that?
Comment 5 Karlson2k 2013-02-27 22:07:21 UTC
(In reply to comment #3)
> Well, AC_TRY_RUN is for sure the wrong approach here.  As such tests are
> failing badly on cross-compilers.
> I think sanest way to solve this is by special-casing mingw targets.

This test is already skipped for cross-compilers and done only for native compilers.
So AC_TRY_RUN is the only solution, that can check compiler's capabilities (and not the shell's).
Comment 6 Kai Tietz 2013-02-28 08:43:30 UTC
(In reply to comment #4)
> I agree. Care to send a patch for that?

Well, something like this should fix the issue:

Index: acinclude.m4
===================================================================
--- acinclude.m4        (Revision 196329)
+++ acinclude.m4        (Arbeitskopie)
@@ -1739,7 +1739,10 @@ AC_DEFUN([GLIBCXX_CHECK_RANDOM_TR1], [
   AC_MSG_CHECKING([for "/dev/random" and "/dev/urandom" for TR1 random_device])

   AC_CACHE_VAL(glibcxx_cv_random_tr1, [
     if test -r /dev/random && test -r /dev/urandom; then
-      glibcxx_cv_random_tr1=yes;
+      case ${target_os} in
+       *mingw*) glibcxx_cv_random_tr1=no ;;
+       *) glibcxx_cv_random_tr1=yes ;;
+      esac
     else
       glibcxx_cv_random_tr1=no;
     fi
Comment 7 Paolo Carlini 2013-02-28 09:45:50 UTC
Good. I would say, please add a one line comment mentioning the MSYS subsystem issue, etc, test and commit at your ease. Thanks!
Comment 8 Kai Tietz 2013-03-01 10:23:28 UTC
Author: ktietz
Date: Fri Mar  1 10:23:21 2013
New Revision: 196371

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196371
Log:
	PR libstdc++/56475
	* acinclude.m4 (GLIBCXX_CHECK_RANDOM_TR1): Disable check for
	mingw-targets.
	* configure: Regenerated.


Modified:
    trunk/libstdc++-v3/acinclude.m4
    trunk/libstdc++-v3/configure
Comment 9 Kai Tietz 2013-03-01 10:27:05 UTC
Fixed on trunk.
Comment 10 Karlson2k 2013-03-01 13:29:40 UTC
Could you fix 4.7 branch too?