From 2f7bebcc36b52a3a321676c6af9b07018c917ab3 Mon Sep 17 00:00:00 2001 From: Qin Zhao Date: Mon, 21 Nov 2016 14:14:28 -0500 Subject: [PATCH] i#2006 generalize drcachesim: set drmemtrace dr_client_main as a weak 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 --- clients/drcachesim/tracer/tracer.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/clients/drcachesim/tracer/tracer.cpp b/clients/drcachesim/tracer/tracer.cpp index 94959e49ebd..82230e7af84 100644 --- a/clients/drcachesim/tracer/tracer.cpp +++ b/clients/drcachesim/tracer/tracer.cpp @@ -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}; @@ -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); +}