User account creation filtered due to spam.

Bug 34297 - static linking with pthreads stl runtime error
Summary: static linking with pthreads stl runtime error
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.6
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2007-11-29 23:49 UTC by TheHighHat
Modified: 2007-11-29 23:59 UTC (History)
1 user (show)

See Also:
Host: i386-redhat-linux
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description TheHighHat 2007-11-29 23:49:51 UTC
Tracking down a problem with a much more rigorous codebase.  Using this contrived example to demonstrate the issue:

#include <iostream>

using namespace std;

// static link this with pthreads to test

int main()
  // this will exit cleanly
  cout << "std::cout" << endl;

  // this will segfault, why?
  cerr << "std::cerr" << endl;

  return 0;

On default setup of RHEL 4, 32bit host and compiler, compile as:

g++ test.C

works fine.  Then statically link:

g++ -static test.C

works fine.  Now use -pthread option:

g++ -pthread test.C

works fine.  Then statically link:

g++ -static -pthread test.C

problem!   The compile and link are both successful.  However, when executing the code, it segfaults.

This does *not* happen on 64bit host and 64bit compiler.

It does happen on 64bit host and 32bit compile (-m32 option).

Note that std::cout does *not* cause segfault, but std::cerr does.

This happens also with g++ 4.1.1 on RHEL4, again in 32bit.


Also, using Intel compilers 9.1 version shows the exact same pathology.  Example

  icpc -static -pthread test.C


I cannot determine the cause, nor can I find a workaround. 

Perhaps there is an issue with the STL in 32bit in GCC?  

--------- details
#  g++ -v

Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=i386-redhat-linux
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-8)

# icpc -V
Intel(R) C++ Compiler for 32-bit applications, Version 9.1    Build 20061103Z Package ID: l_cc_c_9.1.045
Copyright (C) 1985-2006 Intel Corporation.  All rights reserved.

# uname -a
Linux 2.6.9-55.0.2.ELsmp #1 SMP Tue Jun 12 17:59:08 EDT 2007 i686 i686 i386 GNU/Linux
Comment 1 Andrew Pinski 2007-11-29 23:59:15 UTC
This is really a bug in glibc and not GCC.  Static linking never worked correctly with pthreads anyways.