★ wanayoo — archive 1999 https://github.com/actor-framework/actor-framework/issues/919Nouvelle recherche | Portail wanayoo
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

SEGFAULT when running statically compiled CAF application #919

Open
hanyizhao opened this issue Sep 24, 2019 · 9 comments
Open

SEGFAULT when running statically compiled CAF application #919

hanyizhao opened this issue Sep 24, 2019 · 9 comments
Labels
bug

Comments

@hanyizhao
Copy link

@hanyizhao hanyizhao commented Sep 24, 2019

I use Debian 10 with gcc 8.3.0

I build the core library:
./configure --prefix=/home/hanyizhao/build/caf --build-type=Release --build-static-only --core-only --static-runtime

But when I tested my program, it crashed.

`Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt
#0 0x0000000000000000 in ?? ()
#1 0x0000000000481a58 in caf::logger::thread_local_aid(unsigned long) ()
#2 0x00000000004a47ec in caf::scheduled_actor::launch(caf::execution_unit*, bool, bool) ()
#3 0x000000000041c2ec in caf::actor_system::actor_system(caf::actor_system_config&) ()
#4 0x000000000040c8dd in main ()
`

@josephnoir
Copy link
Member

@josephnoir josephnoir commented Sep 24, 2019

Hi,

I'd like to reproduce this. So far I got a Docker image of Debian 10 with the same g++ version. I built CAF with the same config parameters you used, only adjusting the prefix and installed the library.

With that setup I tried a few examples and they built and executed without problems (hello_world, dancing_kirby, dining_philosophers).

Do you have further information on how to reproduce this?

@hanyizhao
Copy link
Author

@hanyizhao hanyizhao commented Sep 24, 2019 •

Thank you. @josephnoir

There are more details.

This is the code:
main.txt

This is the CMakeLists.txt

CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0)
PROJECT(CAF_TEST)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -std=c++11 -g")

SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static -static-libgcc -static-libstdc++")

INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/../../build/caf/include)
LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/../../build/caf/lib)
LINK_LIBRARIES(caf_core_static pthread)
ADD_EXECUTABLE(CAF_TEST main.cpp)

@josephnoir
Copy link
Member

@josephnoir josephnoir commented Sep 24, 2019

Ok, was able to reproduce this. I adjusted the CMakeLists.txt a bit, but it now requires the FindCAF.cmake file that is shipped with CAF. (It checks for CAF in /caf-static/ which is my configure prefix. Can be changed through CAF_ROOT_DIR.)

CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0)
PROJECT(CAF_TEST)

set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -std=c++11 -g")

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static -static-libgcc -static-libstdc++")

if(NOT CAF_ROOT_DIR)
  set(CAF_ROOT_DIR "/caf-static/")
endif()
find_package(CAF COMPONENTS core)
if (CAF_FOUND)
  include_directories(${CAF_INCLUDE_DIRS})
else ()
  message(FATAL_ERROR "Could not find CAF.")
endif()

add_executable(main main.cpp)
target_link_libraries(main ${CAF_LIBRARY_CORE} pthread)

Long story short. I get the same behavior. The key are the CMAKE_EXE_LINKER_FLAGS, without them everything works. I'll take a closer look tomorrow.

@josephnoir
Copy link
Member

@josephnoir josephnoir commented Sep 25, 2019 •

A simpler example to reproduce the error is the following program.

#include <thread>
#include <iostream>

int main() {
  std::cout << "Thread id: " << std::this_thread::get_id() << std::endl;
}

I can compile it (g++ command is below), but it fails to execute as well. Linking pthread statically seems to be a known problem, but the whole archive options supposedly addresses it.

$ g++ -m64 -std=c++11  -static -o thread-test thread-test.cpp -pthread -Wl,--whole-archive -lpthread -Wl,--no-whole-archive

The stack trace is the same for the CAF example--provided you build everything with debug symbols.

#0  0x0000000000000000 in ?? ()
#1  0x00000000004041ca in __gthread_self() ()
#2  0x000000000040424a in std::this_thread::get_id() ()
#3  0x0000000000404121 in main ()

Edit:

nm shows that the symbol for __gthread_self is in included in the binary.

$ nm thread-test | grep gthread
00000000004041c1 t _ZL14__gthread_selfv
00000000004041ab t _ZL18__gthread_active_pv
00000000005b3150 d _ZZL18__gthread_active_pvE20__gthread_active_ptr
root@79d621d48317:/caf-test# 
@josephnoir
Copy link
Member

@josephnoir josephnoir commented Sep 25, 2019

Hm. The minimal example that just calls std::this_thread::get_id() can be "fixed" by compiling it as follows (the difference is the flag -D_GLIBCXX_GTHREAD_USE_WEAK=0). Doesn't seem to make a difference for the CAF example ... or at least I haven't figured out how to apply it correctly.

$ g++ -D_GLIBCXX_GTHREAD_USE_WEAK=0 -m64 -std=c++11 -static -static-libgcc -static-libstdc++ -o thread-test thread-test.cpp -pthread -Wl,--whole-archive -lpthread -Wl,--no-whole-archive
@Neverlord Neverlord added the bug label Sep 25, 2019
@Neverlord Neverlord changed the title Runtime error: caf::logger::thread_local_aid(unsigned long) () SEGFAULT when running statically compiled CAF application Sep 25, 2019
@Neverlord
Copy link
Member

@Neverlord Neverlord commented Oct 1, 2019

@hanyizhao this might be related to zeek/zeek#610, which boiled down to static builds not settings -fPIC. This is fixed in master as of 2804c31. Does that change anything for you?

@hanyizhao
Copy link
Author

@hanyizhao hanyizhao commented Oct 29, 2019

@Neverlord Still have this problem.

@Neverlord
Copy link
Member

@Neverlord Neverlord commented Oct 30, 2019

Ok, thanks for checking. We'll probably add Debian to our CI soon. Once we have that up and running I'll add static builds to the build matrix to reproduce (and fix) this.

@Neverlord
Copy link
Member

@Neverlord Neverlord commented May 6, 2020

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

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.