This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

High priority bug?


I just did ran into a weird bug, not sure if you want to fix it
in 3.0 however.  Its kinda hard to produce a short test case,
so I'd like to first ask if this is considered a high priority
bug before trying.

The problem is as follows:

In a shared library I am using the following definition:

  #include <limits>
  int const failure = std::numeric_limits<int>::min();

And I assumed that `failure' was a _constant_ (and hence initialized
at all times), but it turns out that instead it gets initialized as
part of (or after?) __do_global_ctors_aux().  Even more, other global
objects are initialized before this "constant" is initialized - making
my program crash.

The backtrace of the Real Life example is:

(gdb) bt
#0  0x401b1dd1 in __kill () from /lib/libc.so.6
#1  0x401b1baa in raise (sig=3) at ../sysdeps/posix/raise.c:27
#2  0x0804c4ca in libcw::debug::demangle_type(char const*, std::string&) (input=0x40121506 "Pc", output=@0xbffff534) at demangle3.cc:588
#3  0x4004d671 in libcw::debug::_internal_::make_label(char const*) (mangled_name=0x40121506 "Pc") at type_info.cc:40
#4  0x4005c516 in libcw::debug::type_info_ct::type_info_ct(std::type_info const&, unsigned, unsigned) (this=0x4008c028, ti=@0x401257d8, s=4,
    rs=1) at ../include/libcw/type_info.h:39
#5  0x4004de71 in __static_initialization_and_destruction_0(int, int) (__initialize_p=1, __priority=65535)
    at /usr/local/gcc-3.0/include/g++-v3/bits/localefwd.h:92
#6  0x4004df55 in _GLOBAL__I__ZN5libcw5debug7bcd2strEPKci () at /usr/local/gcc-3.0/include/g++-v3/bits/localefwd.h:75
#7  0x40051337 in __do_global_ctors_aux () at /usr/local/gcc-3.0/include/g++-v3/bits/locale_facets.h:97
#8  0x4003a11a in _init () from /home/carlo/c++/libcw/src/libcwd/.libs/libcwd.so.0
#9  0x4000e167 in _dl_init (main_map=0x40017108, argc=1, argv=0xbffff64c, env=0xbffff654) at dl-init.c:112

Where demangle3.cc contains the following code:

...
int const failure = std::numeric_limits<int>::min();
...
void demangle_type(char const* input, std::string& output)
{
...
  if (failure == 0)
    raise(3);		// Line 588

Especially because this line 588 is in the same compilation unit as the definition of `failure'
I am convinced this is a bug: it can't be right that `failure' isn't initialized here.

Or can't I expect global constants to be initialized before we reach main()?

-- 
Carlo Wood <carlo@alinoe.com>

PS Apart from this, I think it is unacceptable that `failure' isn't a real constant.
   I suppose I'll use the 'C' INT_MIN, that will be faster :/.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]