google / googletest

GoogleTest - Google Testing and Mocking Framework
https://google.github.io/googletest/
BSD 3-Clause "New" or "Revised" License
34.75k stars 10.14k forks source link

1.10.0: undefined reference to `typeinfo for google::LogSink' #3385

Open kloczek opened 3 years ago

kloczek commented 3 years ago

I'm trying to compile ceres-solver 2.0.0 test suite against shared googletest library and bui.d fails with:

[ 61%] Linking CXX executable ../../bin/levenberg_marquardt_strategy_test
cd /home/tkloczko/rpmbuild/BUILD/ceres-solver-2.0.0/x86_64-redhat-linux-gnu/internal/ceres && /usr/bin/cmake -E cmake_link_script CMakeFiles/levenberg_marquardt_strategy_test.dir/link.txt --verbose=1
/usr/bin/g++ -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none  -Wmissing-declarations -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-missing-field-initializers -DNDEBUG -Wl,-z,relro -Wl,--as-needed -Wl,--gc-sections -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -flto=auto -flto-partition=none -fuse-linker-plugin CMakeFiles/levenberg_marquardt_strategy_test.dir/levenberg_marquardt_strategy_test.cc.o -o ../../bin/levenberg_marquardt_strategy_test  -Wl,-rpath,/home/tkloczko/rpmbuild/BUILD/ceres-solver-2.0.0/x86_64-redhat-linux-gnu/lib ../../lib/libtest_util.so ../../lib/libceres.so.2.0.0 ../../lib/libgtest.so /usr/lib64/libgflags.so.2.2.2 -lpthread /usr/lib64/libglog.so
/usr/bin/ld: /tmp/ccqko3xE.lto.o:(.data.rel.ro._ZTIN7testing13ScopedMockLogE+0x10): undefined reference to `typeinfo for google::LogSink'
collect2: error: ld returned 1 exit status

googletest is compiled without LTO.

derekmauro commented 3 years ago

https://github.com/google/googletest/blob/master/.github/ISSUE_TEMPLATE/00-bug_report.md

Please use the template when submitting an issue. We ask for important information and cannot look into this issue without the missing information. In particular, we need to know exactly how to reproduce this issue.

kloczek commented 3 years ago

Describe the bug

I cannot build intel-mediasdk because it fails on linkig test units.

cd /home/tkloczko/rpmbuild/BUILD/MediaSDK-intel-mediasdk-21.2.0/x86_64-redhat-linux-gnu/tests/unit/suites/mfx_dispatch/linux && /usr/bin/cmake -E cmake_link_script CMakeFiles/mfx_dispatch_test.dir/link.txt --verbose=1
/usr/bin/g++ -std=c++11 -m64 -g -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -pipe -fPIC -Wall -Wformat -Wformat-security -Wnon-virtual-dtor -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-unused  -DUNIX -D__USE_LARGEFILE64 -D_FILE_OFFSET_BITS=64 -DLINUX -DLINUX32 -DLINUX64  -DMFX_BUILD_INFO="\"Linux-5.11.0-155.fc35.x86_64 5.11.0-155.fc35.x86_64 | GNU 11.0.1 | glibc 2.33.9000\"" -DMFX_API_VERSION="\"1.35\"" -DMFX_GIT_COMMIT="\"hashsum unknown\"" -DMEDIA_VERSION_STR="\"21.2.0\"" -DNDEBUG -fPIE -pie -Wl,-z,relro -Wl,--as-needed -Wl,--gc-sections -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -flto=auto -flto-partition=none -fuse-linker-plugin CMakeFiles/mfx_dispatch_test.dir/mfx_dispatch_test_main.cpp.o CMakeFiles/mfx_dispatch_test.dir/mfx_dispatch_test_cases_libs.cpp.o CMakeFiles/mfx_dispatch_test.dir/mfx_dispatch_test_cases_plugins.cpp.o CMakeFiles/mfx_dispatch_test.dir/mfx_dispatch_test_mocks.cpp.o CMakeFiles/mfx_dispatch_test.dir/mfx_dispatch_test_fixtures.cpp.o -o ../../../../../__bin/RelWithDebInfo/mfx_dispatch_test  ../../../../../__bin/RelWithDebInfo/libmfx.so.1.35 -lgtest -lgmock -lpthread -ldl
/usr/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/11/../../../../lib64/libgmock.so: undefined reference to `testing::internal::ParseInt32(testing::Message const&, char const*, int*)'
collect2: error: ld returned 1 exit status

Steps to reproduce the bug

Does the bug persist in the most recent commit? I'm using release gtest-1.10.0

What operating system and version are you using? Muy own linux distribution x86_64

What compiler and version are you using? gcc 11.0.1 from Fedora rawhide.

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-11.0.1-20210423/obj-x86_64-redhat-linux/isl-install --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.0.1 20210423 (Red Hat 11.0.1-0) (GCC)

What build system are you using? cmake version 3.19.7

Additional context

Doesn't matter am I compiling gtest wit or without LTO. gtest source tree is configured with:

%cmake \
        -D BUILD_SHARED_LIBS=ON \
        -D gmock_build_tests=OFF \
        -D gtest_build_samples=OFF \
        -D gtest_build_tests=OFF \
        -D gtest_disable_pthreads=OFF \
        -D gtest_hide_internal_symbols=ON \
        -D PYTHON_EXECUTABLE=%__python3 \
        %{nil}
kloczek commented 3 years ago

I just changed cmake settings to

%cmake \
        -D BUILD_SHARED_LIBS=ON \
        -D gmock_build_tests=ON \
        -D gtest_build_samples=ON \
        -D gtest_build_tests=ON \
        -D gtest_disable_pthreads=OFF \
        -D gtest_hide_internal_symbols=ON \
        -D PYTHON_EXECUTABLE=%__python3 \
        %{nil}

and I'm able to reporoduce that issue on gtest test units:

[  4%] Linking CXX executable gmock-more-actions_test
cd /home/tkloczko/rpmbuild/BUILD/googletest-release-1.10.0/x86_64-redhat-linux-gnu/googlemock && /usr/bin/cmake -E cmake_link_script CMakeFiles/gmock-more-actions_test.dir/link.txt --verbose=1
/usr/bin/g++ -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -DNDEBUG -Wl,-z,relro -Wl,--as-needed -Wl,--gc-sections -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -rdynamic CMakeFiles/gmock-more-actions_test.dir/test/gmock-more-actions_test.cc.o -o gmock-more-actions_test  -Wl,-rpath,/home/tkloczko/rpmbuild/BUILD/googletest-release-1.10.0/x86_64-redhat-linux-gnu/lib ../lib/libgmock_main.so.1.10.0 ../lib/libgmock.so.1.10.0 ../lib/libgtest.so.1.10.0 -lpthread
/usr/bin/ld: ../lib/libgmock.so.1.10.0: undefined reference to `testing::internal::ParseInt32(testing::Message const&, char const*, int*)'
collect2: error: ld returned 1 exit status
make[2]: *** [googlemock/CMakeFiles/gmock-more-actions_test.dir/build.make:109: googlemock/gmock-more-actions_test] Error 1
kloczek commented 3 years ago

Just made experiment with building gtest with -D gtest_hide_internal_symbols=OFF and looks like gtest is building correctly and ctest test suite finishes without errors. If that missing symbol is internal one that change make sense however qquestion does it make any sense to provide gtest_hide_internal_symbols=[ON|OFF] if switching it off produces binaries with missing symbols?

kloczek commented 3 years ago

So after rebuilding gtest with -D gtest_hide_internal_symbols=OFF I was able to build intel-mediasdk however I'm still not able to build ceres-solver (https://github.com/ceres-solver/ceres-solver/) test units. Linking fails with:

/usr/bin/g++ -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none  -Wmissing-declarations -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-missing-field-initializers -DNDEBUG -Wl,-z,relro -Wl,--as-needed -Wl,--gc-sections -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -flto=auto -flto-partition=none -fuse-linker-plugin CMakeFiles/levenberg_marquardt_strategy_test.dir/levenberg_marquardt_strategy_test.cc.o -o ../../bin/levenberg_marquardt_strategy_test  -Wl,-rpath,/home/tkloczko/rpmbuild/BUILD/ceres-solver-2.0.0/x86_64-redhat-linux-gnu/lib ../../lib/libtest_util.so ../../lib/libceres.so.2.0.0 ../../lib/libgtest.so /usr/lib64/libgflags.so.2.2.2 -lpthread /usr/lib64/libglog.so
/usr/bin/ld: /tmp/ccBHuNJK.lto.o:(.data.rel.ro._ZTIN7testing13ScopedMockLogE+0x10): undefined reference to `typeinfo for google::LogSink'
collect2: error: ld returned 1 exit status