Just a note on the severity, I've marked this as a "blocker" because it seems
quite basic and it makes it impossible for us to use GCC/G++ to generate a
thread safe shared object for use with JNI. Please adjust as appropriate.
I'm not sure if this is a g++ bug or a libstdc++ bug, I've followed David
Edelsohn's suggestion that it's a library problem, but it's triggered by a
difference in a compiler option and the resulting initialization code, with the
complications produced by AIX xcoff linking thrown in for good measure.
I've reduced this to a three file example. The first file contains a main and
tries to use a static string declared in the second (header) file which it
includes. The third file contains the actual definition of the static string.
If I compile this with -pthread it dies with a SEGV because the string objects
are uninitialized and it's trying to follow a null pointer. Compiled without
-pthread it works just fine. David and I have comfirmed this with multiple
versions of the OS (5.2, 5.3) and gcc (4.1.1, 4.1.2, 4.2). According to him it
works in 4.3, but since that's still a development version it's not really a
viable option for production software yet.
I'd love to hear that this isn't a bug and that we just need to change some
copilation or link flag, but
[EMAIL PROTECTED] aix_gcc_problem]$ g++ -v
Using built-in specs.
Target: powerpc-ibm-aix5.3.0.0
Configured with: ../gcc-4.1.1/configure --prefix=/usr/local
--enable-languages=c,c++ --enable-long-long --enable-threads=aix
--enable-version-specific-runtime-libs --enable-shared --with-as=/usr/bin/as
--with-ld=/usr/bin/ld --with-ar=/usr/bin/ar
Thread model: aix
gcc version 4.1.1
[EMAIL PROTECTED] aix_gcc_problem]$ cat main.cpp
#include
#include
#include
#include
using namespace std;
namespace foo {
extern const string a;
}
namespace foo {
extern const string a = "Hello world!";
}
int main(int argc, char **argv)
{
std::cout << foo::a << std::endl;
std::cout << Res::InvalidDayOfWeek << std::endl;
for (int i = 0 ; i < argc ; ++i)
std::cout << argv[i] << std::endl;
}
[EMAIL PROTECTED] aix_gcc_problem]$ cat StatusMessageIDs_mini.h
#ifndef STATUSMESSAGEIDS_INCLUDE_GUARD
#define STATUSMESSAGEIDS_INCLUDE_GUARD
#include
namespace Res // contains all resource ids
{
typedef const std::string ID;
extern ID InvalidDayOfWeek;
} // namespace Res
#endif // STATUSMESSAGEIDS_INCLUDE_GUARD
[EMAIL PROTECTED] aix_gcc_problem]$ cat StatusMessageIDs_mini.cpp
#include "StatusMessageIDs_mini.h"
namespace Res // contains all resource ids
{
extern ID InvalidDayOfWeek("engine.status.agorai.invalidDayOfWeek");
} // namespace Res
[EMAIL PROTECTED] aix_gcc_problem]$ cat example.sh
#!/bin/bash
CXX=g++
CXX_OPTS="-fPIC -Wall -Werror -mminimal-toc -ggdb3"
#CXX_OPTS="-pthread $CXX_OPTS"
rm -f *.[oa] example
$CXX $CXX_OPTS -I. -o main.o -c main.cpp
$CXX $CXX_OPTS -o StatusMessageIDs_mini.o -c StatusMessageIDs_mini.cpp
/usr/bin/ar cr libexample.a ./StatusMessageIDs_mini.o
/usr/bin/ranlib libexample.a
$CXX $CXX_OPTS main.o ./libexample.a -o example
echo
./example a b c
--
Summary: SegV on AIX 5.3 due to uninit'ed static object when
using -pthread
Product: gcc
Version: 4.1.1
Status: UNCONFIRMED
Severity: blocker
Priority: P3
Component: libstdc++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: tom dot culliton at oracle dot com
GCC build triplet: powerpc-ibm-aix5.3.0.0
GCC host triplet: powerpc-ibm-aix5.3.0.0
GCC target triplet: powerpc-ibm-aix5.3.0.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31282