Google Groupes

Re: [googlemock: 2281] GMock, GCC 5.2 and the sanitizers


Matt Godbolt 28 août 2015 09:21
Envoyé au groupe : Google C++ Mocking Framework
Hi again,

I've been able to reproduce this by checking out the 1.7.0 branch. If one checks out 1.7.0 (from the deprecated GoogleMock repo), and then modifies the make/Makefile to point at GCC 5.2 and a 1.7.0 GoogleTest checkout, this simple test reproduces my problem:

struct Foo { virtual ~Foo() {}; virtual void bar() = 0; };

struct MockFoo : Foo {
        MOCK_METHOD0(bar, void());
    };

TEST(Mock, shouldDoNothing) {
    MockFoo foo;
    foo.bar();
}

---
~/d/g/googlemock ((release-1.7.0)) $ git diff Makefile
diff --git a/make/Makefile b/make/Makefile
index 9ac7449..b05372b 100644
--- a/make/Makefile
+++ b/make/Makefile
@@ -25,7 +25,17 @@ USER_DIR = ../samples
 CPPFLAGS += -isystem $(GTEST_DIR)/include
 
 # Flags passed to the C++ compiler.
-CXXFLAGS += -g -Wall -Wextra -pthread
+CXXFLAGS += -g -Wall -Wextra -pthread \
+  -Wl,-rpath,/home/mgodbolt/.fighome/runtime/gcc/5.2.0-1/lib64 \
+  -fsanitize=address -fsanitize=undefined
+
+CXX=/home/mgodbolt/.fighome/runtime/gcc/5.2.0-1/bin/g++
~/d/g/googlemock ((release-1.7.0)) $ make
/home/mgodbolt/.fighome/runtime/gcc/5.2.0-1/bin/g++ -isystem ../../googletest/include -isystem ../include -g -Wall -Wextra -pthread -Wl,-rpath,/home/mgodbolt/.fighome/runtime/gcc/5.2.0-1/lib64 -fsanitize=address -fsanitize=undefined -c ../test/gmock_test.cc
/home/mgodbolt/.fighome/runtime/gcc/5.2.0-1/bin/g++ -isystem ../../googletest/include -isystem ../include -g -Wall -Wextra -pthread -Wl,-rpath,/home/mgodbolt/.fighome/runtime/gcc/5.2.0-1/lib64 -fsanitize=address -fsanitize=undefined -lpthread gmock_test.o gmock_main.a -o gmock_test
~/d/g/make ((release-1.7.0)) $ ./gmock_test 
Running main() from gmock_main.cc
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from Mock
[ RUN      ] Mock.shouldDoNothing

GMOCK WARNING:
Uninteresting mock function call - returning directly.
    Function call: bar()
Stack trace:
../include/gmock/gmock-spec-builders.h:1530:60: runtime error: member call on null pointer of type 'const struct ResultHolder'
../include/gmock/gmock-spec-builders.h:1530:60: runtime error: member access within null pointer of type 'const struct ResultHolder'
ASAN:SIGSEGV
=================================================================
==89125==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x00000040c41d bp 0x7ffc94da67d0 sp 0x7ffc94da67b0 T0)
    #0 0x40c41c in testing::internal::FunctionMockerBase<void ()>::InvokeWith(std::tr1::tuple<> const&) (/home/mgodbolt/dev/googlemock/make/gmock_test+0x40c41c)
    #1 0x40b892 in testing::internal::FunctionMocker<void ()>::Invoke() (/home/mgodbolt/dev/googlemock/make/gmock_test+0x40b892)
    #2 0x40afe0 in MockFoo::bar() (/home/mgodbolt/dev/googlemock/make/gmock_test+0x40afe0)
    #3 0x407d4d in Mock_shouldDoNothing_Test::TestBody() ../test/gmock_test.cc:53
    #4 0x4ce7b1 in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) ../../googletest/src/gtest.cc:2078
    #5 0x4be5ce in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) ../../googletest/src/gtest.cc:2114
    #6 0x466ac5 in testing::Test::Run() ../../googletest/src/gtest.cc:2151
    #7 0x468d26 in testing::TestInfo::Run() ../../googletest/src/gtest.cc:2326
    #8 0x46ac3d in testing::TestCase::Run() ../../googletest/src/gtest.cc:2444
    #9 0x488ce1 in testing::internal::UnitTestImpl::RunAllTests() ../../googletest/src/gtest.cc:4315
    #10 0x4d2efb in bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) ../../googletest/src/gtest.cc:2078
    #11 0x4c1a92 in bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) ../../googletest/src/gtest.cc:2114
    #12 0x4800e9 in testing::UnitTest::Run() ../../googletest/src/gtest.cc:3926
    #13 0x4eb6ba in RUN_ALL_TESTS() ../../googletest/include/gtest/gtest.h:2288
    #14 0x4eb531 in main ../src/gmock_main.cc:53
    #15 0x7fe426aa3ec4 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21ec4)
    #16 0x407b68  (/home/mgodbolt/dev/googlemock/make/gmock_test+0x407b68)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV ??:0 testing::internal::FunctionMockerBase<void ()>::InvokeWith(std::tr1::tuple<> const&)
==89125==ABORTING

----

I can dig further, but this issue has seemingly been fixed in the head git revision. I couldn't see an obvious commit that might have fixed this, does anyone have any thoughts?

Also; are there any plans to make a new version of GoogleTest available? It seems there's been a good lot of changes (certainly at least combining gmock and gtest, which is a great thing) - it would be great to use the latest version.

Thanks, Matt

On Fri, Aug 28, 2015 at 7:49 AM, Matt Godbolt <ma...@godbolt.org> wrote:


On Thu, Aug 27, 2015 at 5:10 PM, Samuel Benzaquen <sbe...@google.com> wrote:
==58143==ABORTING


This is a bug in the test. Thanks for the report.
Apparently our ASan coverage didn't include this specific test.
I'll get it fixed.

Fab: thanks!
 
 
...this crash goes away if I take out the "undefined" sanitizer, which could either point the finger at a GCC sanitizer bug, or perhaps there's a change buried somewhere in the diffs between 1.7.0 and git head that I haven't spotted (lots of things moved around...).

I could not reproduce this one.
Maybe it is somehow related to the code in ExternmallocOmsTest.cpp?
Sorry, not enough context.

Understood, thanks. I don't believe it to be somethign specific to our code as pretty much any mock usage in our tests caused the same crash. I'll dig into this more on our side and see if I discover how we're misuing gmock incorrectly, or have some other bad compiler flags, else I'll try and whittle it to a reproducible test here.

Thanks for the reply!

Matt :)



--
Matt