Hello,
```
#include "stdio.h"
#include "stdlib.h"
#include "dr_api.h"
int main() {
int set_env_result = setenv("DYNAMORIO_OPTIONS",
"-stderr_mask 0xc -rstats_to_stderr -client_lib ';;-offline'", 1);
printf("Set env result %d\n", set_env_result);
int setup_result = dr_app_setup();
printf("dr setup result %d.\n", setup_result);
dr_app_start();
printf("Hello, World\n");
dr_app_stop_and_cleanup();
return 0;
}
```
And the compile command, I link memtrace client statically into executable start_stop:
```
/usr/bin/c++ -DARM_64 -DDR_HOST_AARCH64 -DDR_HOST_X64 -DHAS_ZLIB \
-DLINUX -DTEST_APP_DR_CLIENT_MAIN -DUNIX -D_LARGEFILE64_SOURCE \
-I${DYNAMO_BUILD_HOME} -I${DYNAMO_BUILD_HOME}/include \
-I${DYNAMO_BUILD_HOME}/ext/include \
-I${DYNAMO_HOME}/clients/drcachesim/common \
-I${DYNAMO_HOME}/clients/drcachesim/reader \
-I${DYNAMO_HOME}/clients/drcachesim/tracer \
-I${DYNAMO_HOME}/clients/drcachesim \
-I${DYNAMO_HOME}/build/clients/include \
-I${DYNAMO_HOME}/core/arch \
-o start_stop.o \
-c start_stop.c
/usr/bin/c++ -Wl,--hash-style=both -Wl,--as-needed \
-rdynamic start_stop.o \
-o start_stop \
${DYNAMO_BUILD_HOME}/lib64/release/libdynamorio_static.a \
${DYNAMO_BUILD_HOME}/clients/lib64/release/libdrmemtrace_static.a \
${DYNAMO_BUILD_HOME}/lib64/libdrlibc.a \
-ldl
```
The trace result shows that I successfully traced subset of execution as expected.
But when I trying to link dynamorio dynamically and load memtrace client during runtime, the trace result shows that this client was not enabled. The source code was modified into:
```
#include "stdio.h"
#include "stdlib.h"
#include "dr_api.h"
int main() {
int set_env_result = setenv("DYNAMORIO_OPTIONS",
"-stderr_mask 0xc -rstats_to_stderr -client_lib '/path/to/libdrmemtrace.so;0;-offline'", 1);
printf("Set env result %d\n", set_env_result);
int setup_result = dr_app_setup();
printf("dr setup result %d.\n", setup_result);
dr_app_start();
printf("Hello, World\n");
dr_app_stop_and_cleanup();
return 0;
}
```
And compile command:
```
/usr/bin/c++ -DARM_64 -DDR_HOST_AARCH64 -DDR_HOST_X64 -DHAS_ZLIB \
-DLINUX -DTEST_APP_DR_CLIENT_MAIN -DUNIX -D_LARGEFILE64_SOURCE \
-I${DYNAMO_BUILD_HOME} -I${DYNAMO_BUILD_HOME}/include \
-I${DYNAMO_BUILD_HOME}/ext/include \
-I${DYNAMO_HOME}/clients/drcachesim/common \
-I${DYNAMO_HOME}/clients/drcachesim/reader \
-I${DYNAMO_HOME}/clients/drcachesim/tracer \
-I${DYNAMO_HOME}/clients/drcachesim \
-I${DYNAMO_HOME}/build/clients/include \
-I${DYNAMO_HOME}/core/arch \
-fPIC \
-o start_stop.o \
-c start_stop.c
/usr/bin/c++ -Wl,--hash-style=both -Wl,--as-needed \
-shared \
-rdynamic start_stop.o \
-o libstart_stop.so \
-ldynamorio \
-L${DYNAMO_BUILD_HOME}/lib64/release/ \
-ldl
```
And I am trying to figure out the reason and found that there are some difference in library loading process between dynamic library and static library. Could anybody help to answer why and how to enable clients dynamically?
Thanks a lot!