[Bug c++/14232] New: static initialization bug
rwgk at yahoo dot com
gcc-bugzilla@gcc.gnu.org
Sat Feb 21 02:31:00 GMT 2004
Under Mac OS 10.3.2 Boost.Python applications fail at runtime due to a
static initialization bug.
g++ (GCC) 3.4.0 20040220 (prerelease)
Configured with: /net/worm/scratch1/rwgk/gcc-3_4-branch/configure --
prefix=/usr/local_cci/gcc-3_4-branch_2004_02_20 --enable-languages=c,c++
Apple G5 under OS 10.3.2:
Darwin coral.lbl.gov 6.8 Darwin Kernel Version 6.8: Wed Sep 10 15:20:55
PDT 2003; root:xnu/xnu-344.49.obj~2/RELEASE_PPC Power Macintosh powerpc
To reproduce the bug get this completely self-contained package:
http://cci.lbl.gov/~rwgk/bugs/gcc340/gcc340_mac_20040220.tar.gz
To unpack and see the complete information about the source code:
gunzip -c gcc340_mac_20040220.tar.gz | tar xf -
cd gcc340_mac_20040220
more SOURCE_CODE_INFO
It is assumed that g++ == gcc 3.4.0.
The first demonstration should end without a failure:
./demo_static_init_problem_1.csh
The output should end with:
g++ -w -bundle -
bundle_loader /System/Library/Frameworks/Python.framework/Versions/2.3/Python /S
ystem/Library/Frameworks/Python.framework/Versions/2.3/Python -o
libtbx/shared_ptr_ext.so boost/libs/python/test/shared_ptr.os -Llibtbx -
L/net_scarlet/scratch1/rwgk/gcc340_mac/libtbx -lboost_python -lm
scons: done building targets.
python ../boost/libs/python/test/shared_ptr.py
running...
Done.
To show the failure:
./demo_static_init_problem_2.csh
The output should end with:
g++ -w -bundle -
bundle_loader /System/Library/Frameworks/Python.framework/Versions/2.3/Python /S
ystem/Library/Frameworks/Python.framework/Versions/2.3/Python -o
libtbx/shared_ptr_ext.so boost/libs/python/test/shared_ptr.os -Llibtbx -
L/net_scarlet/scratch1/rwgk/gcc340_mac/libtbx -lboost_python -lm
scons: done building targets.
python ../boost/libs/python/test/shared_ptr.py
running...
*****************************************************************
Failure in example: a = New(1)
from line #12 of __main__
Exception raised:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/doc
test.py", line 441, in _run_examples_inner
compileflags, 1) in globs
File "<string>", line 1, in ?
ArgumentError: Python argument types in
shared_ptr_ext.New(int)
did not match C++ signature:
New(b)
*****************************************************************
etc. etc.
The only difference between the first and the second demo is in the file
boost/libs/python/src/converter/registry.cpp:
#ifndef NO_BOOST_PYTHON_CONVERTER_REGISTRY_APPLE_MACH_WORKAROUND
#if defined(__APPLE__) && defined(__MACH__) && defined(__GNUC__) \
&& __GNUC__ == 3 && __GNUC_MINOR__ <= 4 && !defined(__APPLE_CC__)
# define BOOST_PYTHON_CONVERTER_REGISTRY_APPLE_MACH_WORKAROUND
#endif
#endif
In the first demo
NO_BOOST_PYTHON_CONVERTER_REGISTRY_APPLE_MACH_WORKAROUND
is not defined, in the second demo it is. The workaround in
registry.cpp is the result of many hours of trial and error.
I found out that
static registry_t registry;
is newly initialized each time a new Boost.Python extension is
dlopen'ed by Python. This error goes away if the code is rearranged and
std::cout << std::flush; is inserted in the right place!
Comments:
- The same source code works fine with gcc 3.4.0 20040220 under Linux.
- I've observed this bug already with gcc 3.3.1 under OS 10.2.
- Apple's compiler (Xcode 1.1, based on gcc 3.3) does not need the
workaround (but it needs other workarounds and generates
significantly slower code).
Sorry for the big package, but it would be impractical for me to work
out a smaller example. It took several hours already to prepare the set
of reports I am submitting today. I hope you have tools that make it
much easier to pin-point the root of the problem. When you run the demo
the output shows all commands used. You can copy-and-paste the commands
to run them without the build system. If you look at the .csh scripts:
"libtbx.scons" is a replacement for "make". The rest should be obvious
I hope.
--
Summary: static initialization bug
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: rwgk at yahoo dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: powerpc-apple-darwin7.2.0
GCC host triplet: powerpc-apple-darwin7.2.0
GCC target triplet: powerpc-apple-darwin7.2.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14232
More information about the Gcc-bugs
mailing list