[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: btwowc(EOF) hang with gcc 4.4.2

From: Eric Blake
Subject: Re: btwowc(EOF) hang with gcc 4.4.2
Date: Tue, 22 Dec 2009 06:23:38 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20090812 Thunderbird/ Mnenhy/

Hash: SHA1

According to Karl Berry on 12/21/2009 4:51 PM:
>     It's definitely a compiler problem. That extern inline asm alias trickery
> The gcc people say that the behavior is correct; not a bug.
> (I don't understand all of their replies, but the conclusion seems clear.)
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42440
> I don't know if there is a way to change the configure test so it is
> robust against this particular problem.

Yes, we can still change configure to be robust against this problem, by
adding an alarm() call to force a non-zero exit if the compiler
mis-compiled the program (it doesn't fix the underlying bug of the
compiler vs. system header mismatch, nor of why fixincludes didn't work
when the compiler was installed, but at least it would prevent configure
from hanging).

Any objections to the following?

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

>From 78cca4053e17efa6e755d05be99cd69f2911db11 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Tue, 22 Dec 2009 06:19:48 -0700
Subject: [PATCH] btowc: avoid infinite loop

Older glibc headers declared btowc with an extern inline, expecting
old gnu semantics.  Newer gcc uses C99 semantics, and ends up
turning btowc on a constant into an infinite tail recursion.
It is not yet known why gcc's fixincludes does not work around this.

* m4/btowc.m4 (gl_FUNC_BTOWC): Add a timeout.
* doc/posix-functions/btowc.texi (btowc): Document the problem.
Reported by Karl Berry.

Signed-off-by: Eric Blake <address@hidden>
 ChangeLog                      |    7 +++++++
 doc/posix-functions/btowc.texi |    3 +++
 m4/btowc.m4                    |    8 +++++++-
 3 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index efd18cc..92dcc33 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-12-22  Eric Blake  <address@hidden>
+       btowc: avoid infinite loop
+       * m4/btowc.m4 (gl_FUNC_BTOWC): Add a timeout.
+       * doc/posix-functions/btowc.texi (btowc): Document the problem.
+       Reported by Karl Berry.
 2009-11-17  Eric Blake  <address@hidden>

        manywarnings: add more warnings
diff --git a/doc/posix-functions/btowc.texi b/doc/posix-functions/btowc.texi
index b58fa84..03de13f 100644
--- a/doc/posix-functions/btowc.texi
+++ b/doc/posix-functions/btowc.texi
@@ -21,4 +21,7 @@ btowc
 On AIX and Windows platforms, @code{wchar_t} is a 16-bit type and therefore 
 accommodate all Unicode characters.
+Improperly mixing headers from an older glibc with a newer gcc can
+cause miscompilation where btowc enters an infinite tail-recursion.
 @end itemize
diff --git a/m4/btowc.m4 b/m4/btowc.m4
index b46f74f..0f2c9af 100644
--- a/m4/btowc.m4
+++ b/m4/btowc.m4
@@ -1,4 +1,4 @@
-# btowc.m4 serial 4
+# btowc.m4 serial 5
 dnl Copyright (C) 2008-2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -36,8 +36,14 @@ changequote([,])dnl
 #include <stdio.h>
 #include <string.h>
 #include <wchar.h>
+#include <unistd.h>
+#include <signal.h>
 int main ()
+  /* A mismatch between glibc and gcc can cause btowc to go into an
+     infinite loop.  All platforms that lack alarm also lack btowc.  */
+  signal (SIGALRM, SIG_DFL);
+  alarm (5);
   if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
       if (btowc (EOF) != WEOF)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]