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

i#3161: Add pure-static-client-DR-app support #7177

Merged
merged 10 commits into from
Jan 10, 2025
Merged

Conversation

derekbruening
Copy link
Contributor

@derekbruening derekbruening commented Jan 8, 2025

Adds support for statically linking a client and DR into a pure-static application.

The code support for this involves expecting to not find symbols via dlsym and to instead directly invoke dr_client_main(). A weak copy of dr_client_main() is added to avoid problems with static DR used in standalone mode.

Since even static client libraries today pull in the shared DR library, getting CMake to build a pure static binary with a client occupies the bulk of the changes here:

  • A new cmake routine configure_DynamoRIO_static_client() is added which links with dynamorio_static instead of dynamorio.

  • Static libz libraries are identified in an admittedly hacky manner.

  • A new client library variant "_drstatic" is added (alongside today's base shared library and "_static" variant) for all the ext/ libraries. This is identical to "_static" except it uses configure_DynamoRIO_static_client(). A drmemtrace_drstatic variant is also added, which also links with static libz.

  • The drmemtrace weak dr_client_main no longer works with the new dynamorio_static weak symbol so it is instead made strong and removed completely when DRMEMTRACE_NO_MAIN is defined; a drmemtrace_nomain variant is created with this set.

A new test tool.drcacheoff.purestatic is added which verifies that a static client and DR linked into a pure-static binary all work together. It is difficult to get it to link on Ubuntu20, when cross-compiling, and in other setups due to the need for a static libpthread and other requirements, so the test is limited to Ubuntu22 64-bit where it is added to the test list there and confirmed to be built and run:

 8/11 Test #414: code_api|tool.drcacheoff.purestatic ...   Passed    2.04 sec

Fixes #3161

Adds support for statically linking a client and DR into a pure-static
application.

The code support for this involves expecting to not find symbols via
dlsym and to instead directly invoke dr_client_main().  A weak copy of
dr_client_main() is added to avoid problems with static DR used in
standalone mode.

Since even static client libraries today pull in the shared DR
library, getting CMake to build a pure static binary with a client
occupies the bulk of the changes here:

+ A new cmake routine configure_DynamoRIO_static_client() is added which
  links with dynamorio_static instead of dynamorio.

+ Static libz libraries are identified in an admittedly hacky manner.

+ A new client library variant "_drstatic" is added (alongside today's
  base shared library and "_static" variant) for all the ext/
  libraries. This is identical to "_static" except it uses
  configure_DynamoRIO_static_client().  A drmemtrace_drstatic variant is
  also added, which also links with static libz.

A new test tool.drcacheoff.purestatic is added which verifies that a
static client and DR linked into a pure-static binary all work
together.

Fixes #3161
…Ubuntu22 test list; remove libc6-dev packages
…EAK_MAIN is defined, which is only true for a new drmemtrace_weakmain target. This is require to avoid collisions with the new weak dr_client_main in dynamrio_static. The drmemtrace_drstatic does not define DRMEMTRACE_WEAK_MAIN so the new test is updated to not expect those output lines.
…ine dr_client_main; rm assert from weak main b/c non-client uses run it
@abhinav92003
Copy link
Contributor

Perhaps you meant to request review and not assign the PR to me?

@derekbruening
Copy link
Contributor Author

Perhaps you meant to request review and not assign the PR to me?

Oops, yes. Fixed.

clients/drcachesim/CMakeLists.txt Show resolved Hide resolved
clients/drcachesim/CMakeLists.txt Outdated Show resolved Hide resolved
clients/drcachesim/CMakeLists.txt Outdated Show resolved Hide resolved
core/lib/instrument.c Show resolved Hide resolved
@derekbruening derekbruening merged commit e034f37 into master Jan 10, 2025
17 checks passed
@derekbruening derekbruening deleted the i3161-pure-static branch January 10, 2025 19:09
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

Successfully merging this pull request may close these issues.

Support a pure-static app with DR linked in
2 participants