Skip to content

Commit

Permalink
i#2006 generalize drcachesim: set drmemtrace dr_client_main as a weak…
Browse files Browse the repository at this point in the history
… symbol

Adds drmemtrace_client_main as the real drmemtrace initialization
function.

Sets dr_client_main as a weak symbol so that it can be replaced in the
case of the application statically linking multiple clients.

Review-URL: https://codereview.appspot.com/317950043
  • Loading branch information
zhaoqin committed Dec 6, 2016
1 parent 31d1cf3 commit 2f7bebc
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion clients/drcachesim/tracer/tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,8 +805,12 @@ init_offline_dir(void)
return (module_file != INVALID_FILE);
}

/* We export drmemtrace_client_main so that a global dr_client_main can initialize
* drmemtrace client by calling drmemtrace_client_main in a statically linked
* multi-client executable.
*/
DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
drmemtrace_client_main(client_id_t id, int argc, const char *argv[])
{
/* We need 2 reg slots beyond drreg's eflags slots => 3 slots */
drreg_options_t ops = {sizeof(ops), 3, false};
Expand Down Expand Up @@ -915,3 +919,16 @@ dr_client_main(client_id_t id, int argc, const char *argv[])
NOTIFY(0, "Unable to open pagemap: using virtual addresses.\n");
}
}

/* To support statically linked multiple clients, we add drmemtrace_client_main
* as the real client init function and make dr_client_main a weak symbol.
* We could also use alias to link dr_client_main to drmemtrace_client_main.
* A simple call won't add too much overhead, and works both in Windows and Linux.
* To automate the process and minimize the code change, we should investigate the
* approach that uses command-line link option to alias two symbols.
*/
DR_EXPORT WEAK void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
drmemtrace_client_main(id, argc, argv);
}

0 comments on commit 2f7bebc

Please sign in to comment.