Why does linking with pthread cause a segmentation fault?

前端 未结 4 524
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-14 01:15

I have a stripped down simple program with a static variable (\'abc.cpp\'):

#include 

int main(int, char**)
{
  static const std::string a(\         


        
4条回答
  •  花落未央
    2021-01-14 01:21

    It turns out it was the GCC compiler or libstdc++ that is buggy/broken. Linking with pthread shouldn't cause a segfault.

    Clang didn't segfault, which is using the same libstdc++, so that suggests it may be the compiler. I tested with gcc version 5.1.0 (Ubuntu 5.1.0-0ubuntu11~14.04.1) and found it worked, so it confirms the GCC/libstdc++ bug.

    The original GCC 4.9 which was used was from an unofficial test compiler repository (https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test) - not the official Ubuntu repository. However the GCC 5.1 that was tested, was also from the same repository, so at least the bug was fixed there. It is not known as to whether the official Ubuntu GCC 4.8 causes this segfault or not.

提交回复
热议问题