Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GoogleMock segfaults if built with option "-D gtest_disable_pthreads=ON" #3583

Open
ingo-h opened this issue Sep 27, 2021 · 1 comment
Open
Labels

Comments

@ingo-h
Copy link

ingo-h commented Sep 27, 2021

Describe the bug

I built GoogleTest without pthread on Linux and successful compile tests with it using mocks. When running these tests all of them crash with a final message "Segmentation fault". They should pass.

Steps to reproduce the bug

I cloned GoogleTest and stay in its root directory. Here I use this simple test program:

~$ cat test_simple.cpp
#include "gmock/gmock.h"
#include "gtest/gtest.h"

// simple mocked class
// -------------------
class Foo {
    virtual int GetInt() const = 0;
};

class MockFoo : public Foo {
  public:
    MOCK_METHOD(int, GetInt, (), (const, override));
};

// simple testsuite
//-----------------
TEST(simpleTestSuite, simpleMockTest) {
    MockFoo mockedFoo;

    EXPECT_CALL(mockedFoo, GetInt()).Times(1);
    EXPECT_EQ(mockedFoo.GetInt(), 0);
}

// main entry
// ----------
int main(int argc, char** argv) {
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}

Now verify that it runs successful with default configure/build of GoogleTest:

~$ cmake -S . -B build
~$ cmake --build build

and compile the simple test:

~$ g++ -std=c++11 -otest_simple -I./googletest/include/ -I./googlemock/include/ ./test_simple.cpp ./build/lib/libgtest.a ./build/lib/libgmock.a -lpthread

run it:

~$ ./test_simple
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from simpleTestSuite
[ RUN      ] simpleTestSuite.simpleMockTest
[       OK ] simpleTestSuite.simpleMockTest (0 ms)
[----------] 1 test from simpleTestSuite (0 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (0 ms total)
[  PASSED  ] 1 test.

So far so good. Now build GoogleTest with option -D gtest_disable_pthreads=ON and compile the simple test:

~$ rm -rf build
~$ cmake -S . -B build -D gtest_disable_pthreads=ON
~$ cmake --build build

On compiling the simple test I do not need option -lpthread of course.

 ~$ g++ -std=c++11 -otest_simple -I./googletest/include/ -I./googlemock/include/ ./test_simple.cpp ./build/lib/libgtest.a ./build/lib/libgmock.a
/usr/bin/ld: /tmp/ccGIohZm.o: in function `testing::internal::ThreadLocal<testing::Sequence*>::GetOrCreateValue() const':
test_simple.cpp:(.text._ZNK7testing8internal11ThreadLocalIPNS_8SequenceEE16GetOrCreateValueEv[_ZNK7testing8internal11ThreadLocalIPNS_8SequenceEE16GetOrCreateValueEv]+0x16): undefined reference to `pthread_getspecific'
/usr/bin/ld: test_simple.cpp:(.text._ZNK7testing8internal11ThreadLocalIPNS_8SequenceEE16GetOrCreateValueEv[_ZNK7testing8internal11ThreadLocalIPNS_8SequenceEE16GetOrCreateValueEv]+0x79): undefined reference to `pthread_setspecific'
collect2: error: ld returned 1 exit status

Huh? Why that? Ok, appended -lpthread again, compile and run the test:

~$ ./test_simple
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from simpleTestSuite
[ RUN      ] simpleTestSuite.simpleMockTest
Segmentation fault

Does the bug persist in the most recent commit?

Yes.

What operating system and version are you using?

~$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

What compiler and version are you using?

~$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/10/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 10.2.1-6' --with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-10 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-10-Km9U7s/gcc-10-10.2.1/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-10-Km9U7s/gcc-10-10.2.1/debian/tmp-gcn/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-mutex
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.1 20210110 (Debian 10.2.1-6)

What build system are you using?

~$ cmake --version
cmake version 3.18.4

CMake suite maintained and supported by Kitware (kitware.com/cmake).

Additional context

This should be seen in context with #3577

@ingo-h ingo-h added the bug label Sep 27, 2021
@Toptachamann
Copy link

Toptachamann commented Jul 25, 2022

Hello,
I was able to reproduce the same bug on

~$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.4 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.4 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

Are there any updates on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants