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

Fix ODR violation of gtest global variables in gmock #1059

Closed
wants to merge 1 commit into from

Conversation

igorsugak
Copy link

When both gtest and gmock are DSOs configured by cmake, and are dynamically
linked into a program, the program crashes with a double free error upon exit,
if the test program is invoked with at least one gtest flag specified,
or if there is a death test in the program. This is due to ODR violation
of global std::string variables (holding command line arguments) defined in
gtest but duplicated in gmock, because gtest is linked into gmock.
This updates cmake configuration for gmock to remove gtest from gmock
libraries. Notice that the gmock configure script also doesn't link gtest into gmock.
This also removes gmock from gmock_main to be consistent with gtest and
gtest_main.

Tested by running googletest unit tests as well by running tests in a
larger codebase that uses googletest (both DSO and .a) as a testing framework
on a linux system with gcc-4.9 and gcc-5.4.

Potentially also fixes some bugs mentioned in #930

When both gtest and gmock are DSOs configured by cmake, and are dynamically
linked into a program, the program crashes with a double free error upon exit,
if the test program is invoked with at least one gtest flag specified,
or if there is a death test in the program. This is due to ODR violation
of global `std::string` variables (holding command line arguments) defined in
gtest but duplicated in gmock, because gtest is linked into gmock.
This updates cmake configuration for gmock to remove gtest from gmock
libraries. Notice that the gmock configure script also doesn't link gtest into gmock.

Tested by running googletest unit tests as well by running tests in a
larger codebase that uses googletest as a testing framework on a linux
system with gcc-4.9 and gcc-5.4
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@igorsugak
Copy link
Author

Looks like this broke googletest on windows and build on linux when cmake configures from googlemock (not root) directory. I'll update my patch to handle this.

@KiNgMaR
Copy link

KiNgMaR commented Apr 21, 2017

I have run into this error on Linux and can confirm that the patch fixes it.

@gennadiycivil
Copy link
Contributor

Both Travis and AppVeyor failed. Closing

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

Successfully merging this pull request may close these issues.

4 participants