Bug 236169 - devel/googletest isn't compiling with pthreads support; requires downstream users to link in libpthread
Summary: devel/googletest isn't compiling with pthreads support; requires downstream u...
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Enji Cooper
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-03-03 01:01 UTC by Enji Cooper
Modified: 2019-03-04 22:02 UTC (History)
3 users (show)

See Also:
ngie: maintainer-feedback+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Enji Cooper freebsd_committer 2019-03-03 01:01:40 UTC
gtest, compiled from ports, is looking for libpthread, but not compiling pthreads support into the library, resulting in something like the following when a testcase is run:

$ ./expect_nonfatal_failure_demo 

[ FATAL ] ./include/gtest/internal/gtest-port.h:2214:: pthread_key_create(&key, &DeleteThreadLocalValue)failed with error 78

Upstream's configure.ac is broken. Switching to their cmake infrastructure will unbreak this (sending out a review for this, soon).

$ ./expect_nonfatal_failure_demo 
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from FailingTest
[ RUN      ] FailingTest.AlwaysFails
[       OK ] FailingTest.AlwaysFails (0 ms)
[----------] 1 test from FailingTest (0 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (0 ms total)
[  PASSED  ] 1 test.
Comment 1 Enji Cooper freebsd_committer 2019-03-03 01:26:15 UTC
Here's why:

$ ldd ./googletest/lib/.libs/libgtest.so.0.0.0
./googletest/lib/.libs/libgtest.so.0.0.0:
        libc++.so.1 => /usr/lib/libc++.so.1 (0x8006df000)
        libcxxrt.so.1 => /lib/libcxxrt.so.1 (0x8007a9000)
        libm.so.5 => /lib/libm.so.5 (0x8007cc000)
        libc.so.7 => /lib/libc.so.7 (0x800249000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x800e00000)

If you look at `googletest/Makefile.am`, `PTHREAD_CFLAGS` is set, but not used, resulting in pthread support not being linked in.

cmake isn't the internally supported Google option, but it's at least externally supported, so it makes sense to migrate more towards that method of building/installing googletest.

I filed an upstream PR here: https://github.com/google/googletest/issues/2162 .
Comment 2 Enji Cooper freebsd_committer 2019-03-04 21:33:25 UTC
Adding LIBS+= -lpthread to the Makefile works and is the minimal fix.

Given that the googletest tests from ports don't work and enough has changed between 1.8.1 and master, it's better to move forward with the minimal fix and address the cmake restructuring in the 1.9.0 release, when it becomes available.
Comment 3 commit-hook freebsd_committer 2019-03-04 21:52:12 UTC
A commit references this bug:

Author: ngie
Date: Mon Mar  4 21:51:53 UTC 2019
New revision: 494654
URL: https://svnweb.freebsd.org/changeset/ports/494654

Log:
  devel/googletest: require libpthread

  As noted by @asomers in rS300906 (`cddl/usr.sbin/zfsd/tests/Makefile`
  specifically), googletest requires libpthread in order to function, if
  `-DGTEST_HAS_PTHREAD` is defined.

  While this is true, the code was not being linked against libpthread,
  resulting in libgtest being broken, and thus all tests reliant on the library
  broken at runtime.

  Adding `LIBS+= -lpthread` unbreaks the tests that use pthread support
  internally.

  PR:		236169
  Reviewed by:	jbeich
  Approved by:	jbeich (maintainer)
  Differential Revision: https://reviews.freebsd.org/D19463

Changes:
  head/devel/googletest/Makefile