Bug #942

Build fails on IA-32 Linux with gcc 4.3.2

Added by antares (Michael Klishin) over 11 years ago. Updated over 9 years ago.

Target version:
ruby -v:


I have the following build failure on IA-32 on Linux, gcc version is 4.3.2.

Build trace:

gcc -v:

configure flags:
./configure --program-suffix=1.9.1 --prefix=/usr/local/ruby1.9.1 --enable-debug

This happens on ruby_1_9_1 branch, on the tip.


Updated by mike (Michael Selig) over 11 years ago

I reported this on ruby-core last week ([ruby-core:20850] Re: Problems compiling R20933 on Ubuntu 8.10 Linux), expecting a quick reply & fix, but nothing appears to have been done. Here is an extract from it:


I managed to compile sprintf.c by commenting out the following 4 lines:

#undef vsnprintf
#undef snprintf



Updated by usa (Usaku NAKAMURA) over 11 years ago

  • Assignee set to nobu (Nobuyoshi Nakada)

We know that this is a bug of gcc.
( )

nobu is looking for the way to avoid the bug.


Updated by znmeb (Ed Borasky) over 11 years ago

Did you capture a log of the entire build process? I'm running a 64-bit Linux with gcc 4.3.2 and it works for me. Here's my build script -- maybe there's a step missing from yours:

#! /bin/bash -v
export DIR='ruby'
rm -fr ${DIR}
svn co ruby
cd ${DIR}
./configure --prefix=/home/znmeb/test 2>&1 | tee ../ruby-configure.log
make -j1 2>&1 | tee ../ruby-make.log
make test 2>&1 | tee ../ruby-test.log
make install 2>&1 | tee ../ruby-install.log
cd ..

s> gcc --version
gcc (SUSE Linux) 4.3.2 [gcc-4_3-branch revision 141291]
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO



Updated by shyouhei (Shyouhei Urabe) over 11 years ago

Usaku NAKAMURA wrote:

We know that this is a bug of gcc.
( )

And I have a workaround that passes "make test" on my ubuntu intrepid box.

Index: branches/ruby_1_9_1/
--- branches/ruby_1_9_1/ (revision 21148)
+++ branches/ruby_1_9_1/ (working copy)
@@ -776,6 +776,68 @@
yes) ac_cv_func_erf=no;;

+# Ubuntu intrepid's libc6 2.8~20080505-0ubuntu7 has this problem.
+# Debian GNU/Linux Etch's libc6 2.3.6.ds1-13etch8 has no problem.
+AC_CACHE_CHECK(for broken ``extern inline'' of glibc-2.7,

  • rb_cv_broken_glibc_extern_inline,
  • [AC_TRY_COMPILE([ +typedef struct +{
  • void *a;
  • void *b; +} T; +extern void *foo (const char *, const char *); +extern void *bar (void *, const char *, T); +extern int baz (const char *, int); + +extern inline attribute ((always_inline, gnu_inline)) int +baz (const char *x, int y) +{
  • return 2; +} + +int +baz (const char *x, int y) +{
  • return 1; +} + +int xa, xb; + +static void * +inl (const char *x, const char *y) +{
  • T t = { &xa, &xb };
  • int *f = (int *) __builtin_malloc (sizeof (int));
  • const char *z;
  • int o = 0;
  • void *r = 0; +
  • for (z = y; *z; z++)
  • {
  • if (*z == 'r')
  • o |= 1;
  • if (*z == 'w')
  • o |= 2;
  • }
  • if (o == 1)
  • *f = baz (x, 0);
  • if (o == 2)
  • *f = baz (x, 1);
  • if (o == 3)
  • *f = baz (x, 2); +
  • if (o && *f > 0)
  • r = bar (f, "w", t);
  • return r; +}],[inl("x", "y")],
  • rb_cv_broken_glibc_extern_inline=no,
  • rb_cv_broken_glibc_extern_inline=yes)]) +case $rb_cv_broken_glibc_extern_inline in
  • yes) AC_DEFINE(HAVE_BROKEN_EXTERN_INLINE);; +esac + AC_REPLACE_FUNCS(dup2 memmove strerror\ strchr strstr crypt flock vsnprintf\ isnan finite isinf hypot acosh erf tgamma lgamma_r cbrt \ Index: branches/ruby_1_9_1/ChangeLog =================================================================== --- branches/ruby_1_9_1/ChangeLog (revision 21148) +++ branches/ruby_1_9_1/ChangeLog (working copy) @@ -1,3 +1,9 @@ +Mon Dec 29 16:03:03 2008 URABE Shyouhei +
  • * sprintf.c: detect broken gcc. [ruby-core:20944] +
    • ditto. + Sun Dec 28 18:36:33 2008 Yuki Sonoda (Yugui)
    • test/rubygems/test_gem_command.rb Index: branches/ruby_1_9_1/sprintf.c =================================================================== --- branches/ruby_1_9_1/sprintf.c (revision 21148) +++ branches/ruby_1_9_1/sprintf.c (working copy) @@ -25,6 +25,12 @@ #define BITSPERDIG (SIZEOF_BDIGITS*CHAR_BIT) #define EXTENDSIGN(n, l) (((~0 << (n)) >> (((n)*(l)) % BITSPERDIG)) & ~(~0 << (n)))

+#undef snprintf
+/* [ruby-core:20944] /
+#define snprintf rb_snprintf_evil_gcc4_and_glibc2_7_need_this_f_ing_workaround_
static void fmt_setup(char

static char*
@@ -1082,7 +1088,9 @@
# endif
#undef vsnprintf
#undef snprintf
#define BSD__dtoa ruby_dtoa



Updated by yugui (Yuki Sonoda) over 11 years ago

  • Category set to core
  • Target version changed from 1.9.1 Release Candidate to 1.9.1 RC2




Updated by shyouhei (Shyouhei Urabe) over 11 years ago

Michael Selig wrote:

The basic issue here seems to me that "missing/vsnprintf.c" is being
included even though snprintf() & vsnprintf() exist, and there is INHO
an ugly kludge to get this to work. The "proper" Ruby way should be to
change all calls to snprintf() & vsnprintf() to rb_snprintf() &
rb_vsnprintf() if there is a "permanent" Ruby replacement for them. This
wouldn't cause this compiler problem.

We already have rb_sprintf(). This is why sprintf.c exists.

But why do thay need replacing in Linux in the first place?

Because the world is not built on top of Linux. Direct reason why we chose to
include missing/vsnprintf.c rather than to check snprintf sanity in configure,
is that checking itself should go insanely complex. It's much easier for us to
silently ignore system-provided routines. Linux insanity is that it doesn't
give us a chance to ignore glibc's.

Another reason for us to avoid libc-provided fuctions is that we don't want our
printf variants to depend on locales, especially in representing floating point
numbers. Localization mechanisms should be implemented on other layers than
Ruby's core.



Updated by antares (Michael Klishin) over 11 years ago

It is resolved now and can be closed, thank you.


Updated by matz (Yukihiro Matsumoto) over 11 years ago

  • Status changed from Open to Closed



Also available in: Atom PDF