I'm currently building a shared library. The goal is to inject this lib in a process.

Unfortunaly when I inject this lib in the process I get a SIGESGV about ostream. Here is a MWE to reproduce the error:

#include <iostream>
void __attribute__((constructor)) onStart() {
    std::cout << "Foo" << std::endl;
void __attribute__((destructor)) onClose() {
    std::cout << "Bar" << std::endl;

The error is the following (when attaching with gdb and dlopen in the process):

Thread 1 "dummy_proc" received signal SIGSEGV, Segmentation fault.
0x00007f317287957a in std::ostream::sentry::sentry (
    this=0x7ffd6bb88ac0, __os=...)
    at /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/ostream.tcc:46
46  /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/ostream.tcc: No such file or directory.
The program being debugged was signaled while in a function called from GDB.

I can't figure out why ostream.tcc is not found.

  • all of the initializer stuff will happen on loading the dynamic library, probably a crash in some of that... could be c++ initializer order hell too, you expect something to be initialized but it doesn't happen in the correct order... not a super easy problem to fix – Grady Player Apr 5 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.