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

Client static destructor not running #7014

Open
egrimley-arm opened this issue Sep 30, 2024 · 0 comments
Open

Client static destructor not running #7014

egrimley-arm opened this issue Sep 30, 2024 · 0 comments

Comments

@egrimley-arm
Copy link
Contributor

When there are two clients with a non-debug build it appears that a static destructor in the first client does not run:

cd dynamorio

mkdir twoclients && cd twoclients

cat > CMakeLists.txt <<'EOF'
cmake_minimum_required(VERSION 3.7)

project(twoclients)

find_package(DynamoRIO)
if (NOT DynamoRIO_FOUND)
  message(FATAL_ERROR "DynamoRIO package required to build")
endif(NOT DynamoRIO_FOUND)

add_library(client1 SHARED client1.cpp)
configure_DynamoRIO_client(client1)

add_library(client2 SHARED client2.cpp)
configure_DynamoRIO_client(client2)
EOF

cat > client1.cpp <<'EOF'
#include "dr_api.h"

#define CLIENT "client1"

class C {
public:
    C() {
        dr_printf("%s: constructor\n", CLIENT);
    }
    ~C() {
        dr_printf("%s: destructor\n", CLIENT);
    }
};

static C global;

DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
    dr_set_client_name(CLIENT, "");
    dr_set_client_version_string("0.1.0");
    dr_printf("%s: running\n", CLIENT);
}
EOF

cat > client2.cpp <<'EOF'
#include "dr_api.h"

#define CLIENT "client2"

class C {
public:
    C() {
        dr_printf("%s: constructor\n", CLIENT);
    }
    ~C() {
        dr_printf("%s: destructor\n", CLIENT);
    }
};

static C global;

DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
    dr_set_client_name(CLIENT, "");
    dr_set_client_version_string("0.1.0");
    dr_printf("%s: running\n", CLIENT);
}
EOF

cd ../../build
mkdir build-twoclients && cd build-twoclients
cmake -DDynamoRIO_DIR=$PWD/../cmake $PWD/../../dynamorio/twoclients
make
cd ..
bin64/drrun \
  -client build-twoclients/libclient1.so 0 '' \
  -client build-twoclients/libclient2.so 1 '' -- echo echo

With a debug build I see:

client1: constructor
client2: constructor
client1: running
client2: running
echo
client2: destructor
client1: destructor

But with a non-debug build I see:

client1: constructor
client2: constructor
client1: running
client2: running
echo
client2: destructor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant