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

使用cmake编译example里echo_c++进程启动即报Segmentation fault: 11 #2025

Closed
SillyBoyenjoy opened this issue Nov 28, 2022 · 7 comments
Labels
bug the code does not work as expected kind/coredump

Comments

@SillyBoyenjoy
Copy link

Describe the bug (描述bug)
请问为什么我用cmake编译example里echo_c++里的echo_server进程启动即Segmentation fault: 11,但是直接用Makefile的make编译正常?

Versions (各种版本)
OS:macOS Monterey 12.2.1
Compiler:Clang
brpc:1.3.0
protobuf:3.17.3
cmake version 3.21.3

Additional context/screenshots (更多上下文/截图)
MacBook-Pro:echo_c++ sillyboyenjoy$ cmake -B build && cmake --build build && ./build/echo_server
CMake Deprecation Warning at CMakeLists.txt:18 (cmake_minimum_required):
Compatibility with CMake < 2.8.12 will be removed from a future version of
CMake.

Update the VERSION argument value or use a ... suffix to tell
CMake that the project does not need compatibility with older versions.

-- The C compiler identification is AppleClang 13.1.6.13160021
-- The CXX compiler identification is AppleClang 13.1.6.13160021
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Found Protobuf: /opt/homebrew/lib/libprotobuf.dylib (found version "3.17.3")
-- Looking for clock_gettime
-- Looking for clock_gettime - found
-- CMAKE_CXX_FLAGS: -DGFLAGS_NS=google -DNDEBUG -O2 -D__const__=unused -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer -Wno-deprecated-declarations -Wno-inconsistent-missing-override
-- CMAKE_CXX_COMPILER_ID:Clang
-- Found OpenSSL: /opt/homebrew/Cellar/openssl@3/3.0.0/lib/libcrypto.dylib (found version "3.0.0")
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/sillyboyenjoy/Project/incubator-brpc/example/echo_c++/build
[ 12%] Running cpp protocol buffer compiler on echo.proto
[ 25%] Building CXX object CMakeFiles/echo_server.dir/server.cpp.o
[ 37%] Building CXX object CMakeFiles/echo_server.dir/echo.pb.cc.o
[ 50%] Linking CXX executable echo_server
[ 50%] Built target echo_server
[ 62%] Building CXX object CMakeFiles/echo_client.dir/client.cpp.o
[ 75%] Building CXX object CMakeFiles/echo_client.dir/echo.pb.cc.o
[ 87%] Linking CXX executable echo_client
[100%] Built target echo_client
Segmentation fault: 11

@leaf-potato
Copy link
Contributor

贴下core栈信息:

  1. ulimit -c unlimited 开启coredump
  2. gdb echo_server ${coredump} 查看core栈信息

@SillyBoyenjoy
Copy link
Author

SillyBoyenjoy commented Dec 1, 2022

是mac才会有的问题,以下是lldb的backtrace:

  • frame 0: 0x0000000000000000
    frame 1: 0x00000001ab00f718 libobjc.A.dylibload_images + 1616 frame 2: 0x000000010116b9a8 dylddyld4::RuntimeState::notifyObjCInit(dyld4::Loader const*) + 164
    frame 3: 0x0000000101171cf4 dylddyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array<dyld4::Loader const*>&) const + 196 frame 4: 0x0000000101171cdc dylddyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array<dyld4::Loader const*>&) const + 172
    frame 5: 0x0000000101171dcc dylddyld4::Loader::runInitializersBottomUpPlusUpwardLinks(dyld4::RuntimeState&) const + 124 frame 6: 0x0000000101186db4 dylddyld4::APIs::runAllInitializersForMain() + 312
    frame 7: 0x0000000101161e00 dylddyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) + 3100 frame 8: 0x00000001011610d4 dyldstart + 488

@leaf-potato
Copy link
Contributor

看着不太像,编译没开debug吧

@wwbmmm wwbmmm added bug the code does not work as expected kind/coredump labels Dec 2, 2022
@SillyBoyenjoy
Copy link
Author

应该打开了,dyld是ios系统main执行前的动态链接器?我把LINK_SO打开后bt好像详细了点,问题似乎出在class_name.cpp里面?

  • thread 1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    • frame 0: 0x0000000000000000
      frame 1: 0x00000001012e071c libbrpc.dylibbutil::demangle(name=<unavailable>) at class_name.cpp:54:9 [opt] frame 2: 0x00000001000057f0 echo_server::__cxx_global_var_init.24() at class_name.h:35:62 [opt]
      frame 3: 0x0000000100031c1c dyldinvocation function for block in dyld4::Loader::findAndRunAllInitializers(dyld4::RuntimeState&) const + 164 frame 4: 0x000000010005afcc dyldinvocation function for block in dyld3::MachOAnalyzer::forEachInitializer(Diagnostics&, dyld3::MachOAnalyzer::VMAddrConverter const&, void (unsigned int) block_pointer, void const*) const + 340
      frame 5: 0x0000000100051988 dyldinvocation function for block in dyld3::MachOFile::forEachSection(void (dyld3::MachOFile::SectionInfo const&, bool, bool&) block_pointer) const + 532 frame 6: 0x000000010001df98 dylddyld3::MachOFile::forEachLoadCommand(Diagnostics&, void (load_command const*, bool&) block_pointer) const + 168
      frame 7: 0x000000010005172c dylddyld3::MachOFile::forEachSection(void (dyld3::MachOFile::SectionInfo const&, bool, bool&) block_pointer) const + 192 frame 8: 0x000000010005aa14 dylddyld3::MachOAnalyzer::forEachInitializer(Diagnostics&, dyld3::MachOAnalyzer::VMAddrConverter const&, void (unsigned int) block_pointer, void const*) const + 516
      frame 9: 0x0000000100031b5c dylddyld4::Loader::findAndRunAllInitializers(dyld4::RuntimeState&) const + 172 frame 10: 0x0000000100031d00 dylddyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array<dyld4::Loader const*>&) const + 208
      frame 11: 0x0000000100031dcc dylddyld4::Loader::runInitializersBottomUpPlusUpwardLinks(dyld4::RuntimeState&) const + 124 frame 12: 0x0000000100046db4 dylddyld4::APIs::runAllInitializersForMain() + 312
      frame 13: 0x0000000100021e00 dylddyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) + 3100 frame 14: 0x00000001000210d4 dyldstart + 488

@wwbmmm
Copy link
Contributor

wwbmmm commented Dec 5, 2022

@SillyBoyenjoy 可以试试PR #2037

@SillyBoyenjoy
Copy link
Author

class_name.cpp的问题修复了,后面level db的动态库加载也出现了coredump,采用静态库编译解决了。

@zyong
Copy link

zyong commented Mar 5, 2023

@SillyBoyenjoy 确定问题是修复了吗,今天新clone的代码,运行cmake生成文件,执行就报错
OS:macOS Ventura 13.2.1 (22D68)
Compiler:Clang
brpc:1.4.0. master版本测试也不行
protobuf:3.15.8
cmake version 3.20.1

 ~/Develop/c/brpc/example/echo_c++   origin/release-1.4  cmake -B build && cmake --build build
CMake Deprecation Warning at CMakeLists.txt:18 (cmake_minimum_required):
Compatibility with CMake < 2.8.12 will be removed from a future version of
CMake.

Update the VERSION argument value or use a ... suffix to tell
CMake that the project does not need compatibility with older versions.

-- The C compiler identification is AppleClang 12.0.5.12050022
-- The CXX compiler identification is AppleClang 12.0.5.12050022
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Found Protobuf: /usr/local/lib/libprotobuf.dylib (found version "3.15.8")
-- Looking for clock_gettime
-- Looking for clock_gettime - found
-- Found OpenSSL: /usr/local/opt/openssl/lib/libcrypto.dylib (found version "1.1.1k")
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/zhaoyong/Develop/c/brpc/example/echo_c++/build
[ 12%] Running cpp protocol buffer compiler on echo.proto
[ 25%] Building CXX object CMakeFiles/echo_server.dir/server.cpp.o
[ 75%] Building CXX object CMakeFiles/echo_client.dir/echo.pb.cc.o
[ 87%] Linking CXX executable echo_client
[100%] Built target echo_client

 ~/Develop/c/brpc/example/echo_c++   origin/release-1.4  ./build/echo_server
[1] 89260 segmentation fault ./build/echo_server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug the code does not work as expected kind/coredump
Projects
None yet
Development

No branches or pull requests

4 participants