Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Compiling tool as a static binary

6 views
Skip to first unread message

Maksym Planeta

unread,
Jan 13, 2025, 12:50:29 PMJan 13
to DynamoRIO Users
Hi,

I have seen a recent update where Dynamo RIO introduces configure_DynamoRIO_static_client() cmake function to compile static clients. I am not entirely sure what this does, but I was hoping that I can now create my own tool that is a standalone binary and does not require drrun to run.

The cmake file for my old tool looks as follows:

```
cmake_minimum_required(VERSION 3.28)
project(my_tool)

add_library(my_tool SHARED my_tool.c)
find_package(DynamoRIO)
if (NOT DynamoRIO_FOUND)
  message(FATAL_ERROR "DynamoRIO package required to build")
endif(NOT DynamoRIO_FOUND)
configure_DynamoRIO_client(my_tool)
use_DynamoRIO_extension(my_tool drmgr)
```

And it compiles libmy_tool.so library, which I can use like this:

./bin64/drrun -c ../../my_tool/build/libmy_tool.so -- vim

I was hoping that I can recompile my tool by changing cmake file as follows:

cmake_minimum_required(VERSION 3.28)
project(my_tool)

add_executable(my_tool my_tool.c)
set(extra_flags "-DSTATIC_LIBRARY")
find_package(DynamoRIO)
if (NOT DynamoRIO_FOUND)
  message(FATAL_ERROR "DynamoRIO package required to build")
endif(NOT DynamoRIO_FOUND)
configure_DynamoRIO_global(OFF ON)
configure_DynamoRIO_static(my_tool)
configure_DynamoRIO_static_client(my_tool)
use_DynamoRIO_extension(my_tool drmgr_drstatic)

To be able to run the tool as follows:

./../sha_mask/build/my_tool -- vim

But it ends up with immediate segmentation fault.

Could you tell me if what I want is even possible and if yes, how can I achieve it?

--
Regards,
Maksym Planeta

Derek Bruening

unread,
Jan 13, 2025, 1:23:18 PMJan 13
to Maksym Planeta, DynamoRIO Users
Have you seen the documentation on how to create an end-user tool launcher?  Please see https://dynamorio.org/page_deploy.html#tool_frontend "For more extensive actions on launching the tool, a custom front-end executable can be created that replaces drrun ...".

(As the docs 
https://github.com/DynamoRIO/dynamorio/blob/master/make/DynamoRIOConfig.cmake.in#L97 say for configure_DynamoRIO_static_client(), it is for linking DR and a client into a pure-static application which does not sound like what you want.)

--
You received this message because you are subscribed to the Google Groups "DynamoRIO Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dynamorio-use...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/dynamorio-users/f87f5a34-b96e-43d2-8c86-da166c62fd61n%40googlegroups.com.

Maksym Planeta

unread,
Jan 13, 2025, 1:36:35 PMJan 13
to DynamoRIO Users
I actually would like to have drrun and my client tool to be linked together into a single static application. So it seems like exactly what I want.

If I understood your first link correctly, then I will be able to run my tool as follows:

drrun -t my_tool -- vim

If that is correct, than it is not what I want. I would like to have a tool that has minimum library dependencies and static binary sounds the best.

Derek Bruening

unread,
Jan 13, 2025, 1:47:18 PMJan 13
to Maksym Planeta, DynamoRIO Users
On Mon, Jan 13, 2025 at 1:36 PM 'Maksym Planeta' via DynamoRIO Users <dynamor...@googlegroups.com> wrote:
I actually would like to have drrun and my client tool to be linked together into a single static application. So it seems like exactly what I want.

You've misunderstood: the "application" here is the target application to run, not the tool launcher.  if you link DR and your client into the target application, you need to A) have modified the application to call dr_app_start or some other method of invoking DR; and B) be willing to do this separately for every single application you want to run.  I.e., there is no longer any dynamic injection and to run any new target application you have to modify it and rebuild and relink it.
 
If I understood your first link correctly, then I will be able to run my tool as follows:

drrun -t my_tool -- vim

If that is correct, than it is not what I want. I would like to have a tool that has minimum library dependencies and static binary sounds the best.

Please go down to the second half of the content at that link, the part whose text I highlighted.  Repeating what I highlighted: "For more extensive actions on launching the tool, a custom front-end executable can be created that replaces drrun ...".  See the drmemory launcher https://github.com/DynamoRIO/drmemory/blob/master/drmemory/frontend.c or the drmemtrace launcher https://github.com/DynamoRIO/dynamorio/blob/master/clients/drcachesim/launcher.cpp for examples that replace drrun.
 

Maksym Planeta

unread,
Jan 13, 2025, 5:16:59 PMJan 13
to DynamoRIO Users
By any chance, do you know if there is any minimal example for how to build own frontend? Because, for example, drmemory with its 1500 lines for the main file and 3000 lines for the CMakeLists.txt is not the easiest thing to get into.
Reply all
Reply to author
Forward
0 new messages