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

symbolize_unittest fails with static library (BUILD_SHARED_LIBS=OFF) and disabled usage of gtest (WITH_GTEST=OFF) #630

Closed
Arfrever opened this issue Mar 31, 2021 · 7 comments
Labels
Milestone

Comments

@Arfrever
Copy link

In current trunk of glog, when building with -DWITH_GTEST=ON:

$ make test
Running tests...
Test project /tmp/glog_build
      Start  1: demangle
 1/10 Test  #1: demangle .........................   Passed    0.00 sec
      Start  2: logging
 2/10 Test  #2: logging ..........................   Passed    1.34 sec
      Start  3: signalhandler
 3/10 Test  #3: signalhandler ....................   Passed    0.00 sec
      Start  4: stacktrace
 4/10 Test  #4: stacktrace .......................   Passed    0.00 sec
      Start  5: stl_logging
 5/10 Test  #5: stl_logging ......................   Passed    0.00 sec
      Start  6: symbolize
 6/10 Test  #6: symbolize ........................   Passed    0.00 sec
      Start  7: cmake_package_config_init
 7/10 Test  #7: cmake_package_config_init ........   Passed    0.02 sec
      Start  8: cmake_package_config_generate
 8/10 Test  #8: cmake_package_config_generate ....   Passed    0.76 sec
      Start  9: cmake_package_config_build
 9/10 Test  #9: cmake_package_config_build .......   Passed    1.03 sec
      Start 10: cmake_package_config_cleanup
10/10 Test #10: cmake_package_config_cleanup .....   Passed    0.01 sec

100% tests passed, 0 tests failed out of 10

Total Test time (real) =   3.19 sec

And with -DWITH_GTEST=OFF:

$ make test
Running tests...
Test project /tmp/glog_build
      Start  1: demangle
 1/10 Test  #1: demangle .........................   Passed    0.01 sec
      Start  2: logging
 2/10 Test  #2: logging ..........................   Passed    1.37 sec
      Start  3: signalhandler
 3/10 Test  #3: signalhandler ....................   Passed    0.00 sec
      Start  4: stacktrace
 4/10 Test  #4: stacktrace .......................   Passed    0.00 sec
      Start  5: stl_logging
 5/10 Test  #5: stl_logging ......................   Passed    0.00 sec
      Start  6: symbolize
 6/10 Test  #6: symbolize ........................Subprocess aborted***Exception:   0.01 sec
      Start  7: cmake_package_config_init
 7/10 Test  #7: cmake_package_config_init ........   Passed    0.03 sec
      Start  8: cmake_package_config_generate
 8/10 Test  #8: cmake_package_config_generate ....   Passed    0.89 sec
      Start  9: cmake_package_config_build
 9/10 Test  #9: cmake_package_config_build .......   Passed    1.09 sec
      Start 10: cmake_package_config_cleanup
10/10 Test #10: cmake_package_config_cleanup .....   Passed    0.02 sec

90% tests passed, 1 tests failed out of 10

Total Test time (real) =   3.44 sec

The following tests FAILED:
          6 - symbolize (Subprocess aborted)
Errors while running CTest
make: *** [Makefile:126: test] Error 8
$ ./symbolize_unittest
F20210331 18:28:41.426044 13463 symbolize_unittest.cc:335] CHECK_STREQ failed: symbol == "non_inline_func" (google::thread_msg_data vs. non_inline_func)
*** Check failure stack trace: ***
    @     0x55bb674a3672  google::LogMessage::Fail()
    @     0x55bb674a3552  google::LogMessage::SendToLog()
    @     0x55bb674a2e1e  google::LogMessage::Flush()
    @     0x55bb674a6baf  google::LogMessageFatal::~LogMessageFatal()
    @     0x55bb6749c437  TestWithPCInsideNonInlineFunction
    @     0x55bb6749c6c6  google::thread_msg_data
    @     0x7f5b407c1e60  __libc_start_main
    @     0x55bb6749ba5a  google::thread_msg_data
Aborted
@sergiud
Copy link
Collaborator

sergiud commented Mar 31, 2021

Unfortunately, I cannot reproduce the problem. I must assume the test failed prior to the recent WITH_GTEST addition. Can you bisect?

@Arfrever
Copy link
Author

It seems that this problem was introduced by commit c30896d ("cmake: export symbols selectively").

@sergiud
Copy link
Collaborator

sergiud commented Mar 31, 2021

If this is true then the issue is non-critical. I guess the bundled googletest.h somehow interferes with symbol resolution.

Questions:

  • What platform are you on?
  • Static or shared build?
  • Any special options enabled?
  • Libunwind version?

@Arfrever
Copy link
Author

  • GNU/Linux, x86_64, GCC 10.2.0
  • Shared libraries
  • No special options
  • Problem reproduced with both standard libunwind 1.5.0 and LLVM libunwind 12 (and with gtest enabled, symbolize_unittest passes with both standard libunwind and LLVM libunwind)

@sergiud
Copy link
Collaborator

sergiud commented Mar 31, 2021

Thanks. After playing around, I could reproduce the issue using GCC 10.2.0. However, only when building a static lib.

Would you mind posting the output of cmake -LA? Simply run the command in your build directory. Also the output of make VERBOSE=1 would be helpful.

In the meantime, you can test the following change:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1f68698..957a6f2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -672,6 +672,8 @@ if (BUILD_TESTING)
     )
 
     target_link_libraries (symbolize_unittest PRIVATE ${_GLOG_TEST_LIBS})
+    set_target_properties (symbolize_unittest PROPERTIES
+      CXX_VISIBILITY_PRESET default)
   endif (HAVE_SYMBOLIZE)
 
   add_executable (demangle_unittest

With -fvisibility=hidden, for some reason the return address is always replaced by google::thread_msg_data which is strange because this symbol is not even exported. Also, gdb backtrace does not agree with the one reported by glog:

Using host libthread_db library "/usr/lib/libthread_db.so.1".
Test case TestWithPCInsideNonInlineFunction passed.
F20210401 00:17:20.356626 513648 symbolize_unittest.cc:357] CHECK_STREQ failed: symbol == "main" (google::thread_msg_data vs. main)
*** Check failure stack trace: ***
    @     0x55555555fcea  google::LogMessage::Fail()
    @     0x555555562413  google::LogMessage::SendToLog()
    @     0x55555555f823  google::LogMessage::Flush()
    @     0x5555555629f9  google::LogMessageFatal::~LogMessageFatal()
    @     0x55555555ccb9  TestWithReturnAddress()
    @     0x55555555b4c1  google::thread_msg_data
    @     0x7ffff7a23b25  __libc_start_main
    @     0x55555555ca7e  _start

Program received signal SIGABRT, Aborted.
0x00007ffff7a38ef5 in raise () from /usr/lib/libc.so.6
(gdb) up
#1  0x00007ffff7a22862 in abort () from /usr/lib/libc.so.6
(gdb) 
#2  0x000055555555b3a9 in google::DumpStackTraceAndExit () at ../src/utilities.cc:159
159	  abort();
(gdb) bt
#0  0x00007ffff7a38ef5 in raise () from /usr/lib/libc.so.6
#1  0x00007ffff7a22862 in abort () from /usr/lib/libc.so.6
#2  0x000055555555b3a9 in google::DumpStackTraceAndExit () at ../src/utilities.cc:159
#3  0x000055555555fcea in google::LogMessage::Fail () at ../src/logging.cc:1878
#4  0x0000555555562413 in google::LogMessage::SendToLog (this=0x7fffffffde90) at ../src/logging.cc:1835
#5  0x000055555555f823 in google::LogMessage::Flush (this=0x7fffffffde90) at ../src/logging.cc:1695
#6  0x00005555555629f9 in google::LogMessageFatal::~LogMessageFatal (this=<optimized out>, __in_chrg=<optimized out>) at ../src/logging.cc:2454
#7  0x000055555555ccb9 in TestWithReturnAddress () at ../src/symbolize_unittest.cc:357
#8  0x000055555555b4c1 in main (argc=<optimized out>, argv=<optimized out>) at ../src/symbolize_unittest.cc:412

Note the difference between function names at 0x55555555b4c1 and 0x000055555555b4c1 in both stack frames. It is not clear to me why this difference arises. Disabling TLS also fixes the issue.

@Arfrever
Copy link
Author

Arfrever commented Apr 1, 2021

cmake -LA
make VERBOSE=1

I confirm that symbolize_unittest (and full test suite) passes with your patch for CMakeLists.txt (with both -DWITH_GTEST=OFF and -DWITH_GTEST=ON).

I see BUILD_SHARED_LIBS:BOOL=OFF in output of cmake -LA...
After configuring with cmake -DBUILD_SHARED_LIBS=ON -DWITH_GTEST=OFF ${source_directory}, full test suite passes even without your patch.

@Arfrever Arfrever changed the title symbolize_unittest fails with disabled usage of gtest symbolize_unittest fails with static library (BUILD_SHARED_LIBS=OFF) and disabled usage of gtest (WITH_GTEST=OFF) Apr 1, 2021
@sergiud sergiud added the bug label Apr 1, 2021
@sergiud sergiud added this to the 0.7 milestone Jan 8, 2024
@sergiud
Copy link
Collaborator

sergiud commented Jan 8, 2024

I believe this is no longer an issue, see #409 (comment).

Please do let me know if you observe the problem with glog at head.

@sergiud sergiud closed this as completed Jan 8, 2024
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