Trace subset of execution use dr_app_start

62 views
Skip to first unread message

Woods Arrow

unread,
Nov 1, 2022, 8:58:12 AM11/1/22
to DynamoRIO Users
Hello,
Recently I'm working on tracing a subset of execution as guided by this link:https://dynamorio.org/sec_drcachesim_partial.html. And it does work on this simple demo:
```
#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!

sharma...@google.com

unread,
Nov 2, 2022, 10:56:10 AM11/2/22
to DynamoRIO Users
Hi,
Can you share the exact error message?

Maybe you need to set LD_LIBRARY_PATH properly. The following sequence worked fine for me:

$ export DYNAMORIO_OPTIONS="-client_lib $DR_BUILD_ROOT/clients/lib64/debug/libdrmemtrace.so;;-offline -code_api"
$ export LD_LIBRARY_PATH="$DR_BUILD_ROOT/lib64/debug:"
$ $DR_BUILD_ROOT/suite/tests/bin/api.startstop_avx512lazy

The api.startstop_avx512lazy executable is a very simple app in our test suite (https://github.com/DynamoRIO/dynamorio/blob/eb51ce061f978c51dc334e236587266bfbde37c4/suite/tests/api/startstop_avx512lazy.c), similar to your minimal example. You can also check how it's built by our cmake setup.

Abhinav

Woods Arrow

unread,
Nov 2, 2022, 11:24:19 PM11/2/22
to DynamoRIO Users
Hi,
Thanks for your reply firstly. Your advices do help me and clients are enabled at present. In my circumstance, the key problem is that option '-code_api' in environment DYNAMORIO_OPTIONS should be enabled if application is dynamically linked, while it is not needed if statically linked. Hope it will help more people. Thanks again!

Best regards,
Woods 

Reply all
Reply to author
Forward
0 new messages