Skip to content

Commit

Permalink
Merge branch 'master' into release_11.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
edeiana authored Jan 10, 2025
2 parents ce24d4a + e034f37 commit 0885697
Show file tree
Hide file tree
Showing 21 changed files with 312 additions and 82 deletions.
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# **********************************************************
# Copyright (c) 2010-2024 Google, Inc. All rights reserved.
# Copyright (c) 2010-2025 Google, Inc. All rights reserved.
# Copyright (c) 2009-2010 VMware, Inc. All rights reserved.
# Copyright (c) 2018 Arm Limited All rights reserved.
# **********************************************************
Expand Down Expand Up @@ -1868,6 +1868,13 @@ if (WIN32 AND NOT DISABLE_ZLIB)
set(ZLIB_FOUND OFF)
else ()
find_package(ZLIB)
# FindZLIB doesn't give us any library split so we manually
# convert to static.
set(ZLIB_STATIC_LIBRARIES "")
foreach (lib ${ZLIB_LIBRARIES})
string(REGEX REPLACE "\\.so$" ".a" newlib "${lib}")
list(APPEND ZLIB_STATIC_LIBRARIES ${newlib})
endforeach ()
endif ()
# On Ubuntu 14.10, 32-bit builds fail to link with -lsnappy, just ignore.
if (UNIX AND X64)
Expand Down
7 changes: 5 additions & 2 deletions api/docs/release.dox
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ******************************************************************************
* Copyright (c) 2010-2024 Google, Inc. All rights reserved.
* Copyright (c) 2010-2025 Google, Inc. All rights reserved.
* Copyright (c) 2011 Massachusetts Institute of Technology All rights reserved.
* Copyright (c) 2008-2010 VMware, Inc. All rights reserved.
* ******************************************************************************/
Expand Down Expand Up @@ -129,7 +129,10 @@ changes:
- No compatibility changes yet.

Further non-compatibility-affecting changes include:
- No changes yet.
- Added support for statically linking clients and the DynamoRIO library into
a pure-static application via a new configure_DynamoRIO_static_client() CMake
function and new "_drstatic" static library CMake targets for the provided
extension libraries.

**************************************************
<hr>
Expand Down
55 changes: 46 additions & 9 deletions clients/drcachesim/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# **********************************************************
# Copyright (c) 2015-2024 Google, Inc. All rights reserved.
# Copyright (c) 2015-2025 Google, Inc. All rights reserved.
# **********************************************************

# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -98,6 +98,7 @@ if (ZLIB_FOUND)
"until then, disabling zip output and fast seeking")
set(zip_reader "")
set(zlib_libs ${ZLIB_LIBRARIES})
set(zlib_static_libs ${ZLIB_STATIC_LIBRARIES})
set(ZIP_FOUND OFF)
else ()
file(GLOB minizip_srcs "${minizip_dir}/*.c")
Expand All @@ -117,6 +118,7 @@ if (ZLIB_FOUND)
install_exported_target(minizip ${INSTALL_CLIENTS_LIB})
set(zip_reader reader/zipfile_file_reader.cpp)
set(zlib_libs ${ZLIB_LIBRARIES} minizip)
set(zlib_static_libs ${ZLIB_STATIC_LIBRARIES} minizip)
endif ()
else ()
# XXX: We could ship with a zlib for Windows, or build the third_party/zlib.
Expand Down Expand Up @@ -473,9 +475,13 @@ if (NOT AARCH64 AND NOT APPLE)
endif ()
target_link_libraries(scheduler_launcher ${zlib_libs})

macro(add_drmemtrace name type)
macro(add_drmemtrace name type static_DR no_main)
if (${type} STREQUAL "STATIC")
set(ext_sfx "_static")
if (${static_DR})
set(ext_sfx "_drstatic")
else ()
set(ext_sfx "_static")
endif ()
else ()
set(ext_sfx "")
endif ()
Expand Down Expand Up @@ -519,7 +525,14 @@ macro(add_drmemtrace name type)
endif()

add_library(${name} ${type} ${drmemtrace_srcs})
configure_DynamoRIO_client(${name})
if (${no_main})
append_property_list(TARGET ${name} COMPILE_DEFINITIONS "DRMEMTRACE_NO_MAIN")
endif ()
if (${static_DR})
configure_DynamoRIO_static_client(${name})
else ()
configure_DynamoRIO_client(${name})
endif()
use_DynamoRIO_extension(${name} drmgr${ext_sfx})
use_DynamoRIO_extension(${name} drsyms${ext_sfx})
use_DynamoRIO_extension(${name} drwrap${ext_sfx})
Expand All @@ -536,7 +549,11 @@ macro(add_drmemtrace name type)
if (libsnappy)
target_link_libraries(${name} snappy)
endif ()
target_link_libraries(${name} ${zlib_libs})
if (${static_DR})
target_link_libraries(${name} ${zlib_static_libs})
else ()
target_link_libraries(${name} ${zlib_libs})
endif ()
if (liblz4)
target_link_libraries(${name} lz4)
endif ()
Expand All @@ -547,8 +564,13 @@ macro(add_drmemtrace name type)
install_target(${name} ${INSTALL_CLIENTS_LIB})
endmacro()

add_drmemtrace(drmemtrace SHARED)
add_drmemtrace(drmemtrace_static STATIC)
add_drmemtrace(drmemtrace SHARED OFF OFF)
# This static library links with the DR shared library and has dr_client_main:
add_drmemtrace(drmemtrace_static STATIC OFF OFF)
# This static library links with the DR shared library and has no dr_client_main:
add_drmemtrace(drmemtrace_nomain STATIC OFF ON)
# This static library links with the DR static library and has dr_client_main:
add_drmemtrace(drmemtrace_drstatic STATIC ON OFF)
append_property_list(TARGET drmemtrace_static COMPILE_DEFINITIONS "DRMEMTRACE_STATIC")
# We export drmemtrace.h to the same place as the analysis tool headers
# for simplicity, rather than sticking it into ext/include or sthg.
Expand Down Expand Up @@ -1083,7 +1105,7 @@ if (BUILD_TESTS)
if (LINUX) # Uses mremap.
add_executable(tool.drcacheoff.burst_maps tests/burst_maps.cpp)
configure_DynamoRIO_static(tool.drcacheoff.burst_maps)
use_DynamoRIO_static_client(tool.drcacheoff.burst_maps drmemtrace_static)
use_DynamoRIO_static_client(tool.drcacheoff.burst_maps drmemtrace_nomain)
target_link_libraries(tool.drcacheoff.burst_maps test_helpers)
add_win32_flags(tool.drcacheoff.burst_maps)
endif ()
Expand Down Expand Up @@ -1130,10 +1152,25 @@ if (BUILD_TESTS)
append_property_list(TARGET tool.drcacheoff.burst_client
COMPILE_DEFINITIONS "TEST_APP_DR_CLIENT_MAIN")
configure_DynamoRIO_static(tool.drcacheoff.burst_client)
use_DynamoRIO_static_client(tool.drcacheoff.burst_client drmemtrace_static)
use_DynamoRIO_static_client(tool.drcacheoff.burst_client drmemtrace_nomain)
target_link_libraries(tool.drcacheoff.burst_client test_helpers)
# A nop, keep it for the future Windows support.
add_win32_flags(tool.drcacheoff.burst_client)

# Test a pure-static-link app.
# We ignore "warning: Using 'dlopen' in statically linked applications requires
# at runtime the shared libraries from the glibc version used for linking".
# XXX: We can only successfully build this if static libpthread is available,
# which is only recent glibc 2.34+ such as Ubuntu22+. We also limit to 64-bit
# due to pain building 32-bit on a 64-bit machine.
if (X64 AND "${libpthread}" MATCHES ".a$")
add_executable(tool.drcacheoff.purestatic tests/burst_static.cpp)
append_property_list(TARGET tool.drcacheoff.purestatic
LINK_FLAGS "-static -Wl,--no-export-dynamic")
configure_DynamoRIO_static(tool.drcacheoff.purestatic)
use_DynamoRIO_static_client(tool.drcacheoff.purestatic drmemtrace_drstatic)
target_link_libraries(tool.drcacheoff.purestatic test_helpers)
endif ()
endif ()

if (NOT RISCV64) # TODO i#3544: Port tests to RISC-V 64
Expand Down
46 changes: 46 additions & 0 deletions clients/drcachesim/tests/offline-purestatic.templatex
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
pre-DR init
pre-DR start
pre-DR detach
DynamoRIO statistics:
*Peak threads under DynamoRIO control : *1
.*
all done
pre-DR init
pre-DR start
pre-DR detach
DynamoRIO statistics:
*Peak threads under DynamoRIO control : *1
.*
all done
pre-DR init
pre-DR start
pre-DR detach
DynamoRIO statistics:
*Peak threads under DynamoRIO control : *1
.*
all done
Cache simulation results:
Core #0 \(traced CPU\(s\): #0\)
L1I0 .* stats:
Hits: *[0-9,\.]*
Misses: *[0-9,\.]*
Compulsory misses: *[0-9,\.]*
Invalidations: *0
.* Miss rate: [0-3][,\.]..%
L1D0 .* stats:
Hits: *[0-9,\.]*
Misses: *[0-9,\.]*
Compulsory misses: *[0-9,\.]*
Invalidations: *0
.* Miss rate: [0-3][,\.]..%
Core #1 \(traced CPU\(s\): \)
Core #2 \(traced CPU\(s\): \)
Core #3 \(traced CPU\(s\): \)
LL .* stats:
Hits: *[0-9,\.]*
Misses: *[0-9,\.]*
Compulsory misses: *[0-9,\.]*
Invalidations: *0
.* Local miss rate: *[0-9,.]*%
Child hits: *[0-9,\.]*
Total miss rate: [0-1][,\.]..%
17 changes: 10 additions & 7 deletions clients/drcachesim/tracer/tracer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ******************************************************************************
* Copyright (c) 2011-2024 Google, Inc. All rights reserved.
* Copyright (c) 2011-2025 Google, Inc. All rights reserved.
* Copyright (c) 2010 Massachusetts Institute of Technology All rights reserved.
* ******************************************************************************/

Expand Down Expand Up @@ -2538,14 +2538,17 @@ drmemtrace_client_main(client_id_t id, int argc, const char *argv[])
*/

/* 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.
* as the real client init function and let a separate dr_client_main call
* drmemtrace_client_main. Since dynamorio_static now provides its own weak
* dr_client_main symbol, we can't simply always provide a weak dr_client_main here:
* it must either be present and strong or not present, controlled by the
* DRMEMTRACE_NO_MAIN define.
*/
DR_EXPORT WEAK void
#ifndef DRMEMTRACE_NO_MAIN
DR_EXPORT
void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
dynamorio::drmemtrace::drmemtrace_client_main(id, argc, argv);
}
#endif
41 changes: 36 additions & 5 deletions core/lib/instrument.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ******************************************************************************
* Copyright (c) 2010-2024 Google, Inc. All rights reserved.
* Copyright (c) 2010-2025 Google, Inc. All rights reserved.
* Copyright (c) 2010-2011 Massachusetts Institute of Technology All rights reserved.
* Copyright (c) 2002-2010 VMware, Inc. All rights reserved.
* ******************************************************************************/
Expand Down Expand Up @@ -371,6 +371,19 @@ DECLARE_CXTSWPROT_VAR(static mutex_t client_aux_lib64_lock,
INIT_LOCK_FREE(client_aux_lib64_lock));
#endif

#if defined(STATIC_LIBRARY) && !defined(WINDOWS)
// To support static DR used for both standalone and clients we need to provide
// some copy of client main. There is no WEAK on Windows so we do not support
// this usage there.
WEAK void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
// This will be called when using static DR but no client, so we can't
// assert even though this should not be reached when there is a real
// client whose non-weak dr_client_main overrides this.
}
#endif

/****************************************************************************/
/* INTERNAL ROUTINES */

Expand Down Expand Up @@ -577,8 +590,16 @@ add_client_lib(const char *path, const char *id_str, const char *options)
/* PR 250952: version check */
int *uses_dr_version =
(int *)lookup_library_routine(client_lib, USES_DR_VERSION_NAME);
if (uses_dr_version == NULL || *uses_dr_version < OLDEST_COMPATIBLE_VERSION ||
*uses_dr_version > NEWEST_COMPATIBLE_VERSION) {
bool pure_static = false;
#ifdef STATIC_LIBRARY
if (uses_dr_version == NULL) {
// We assume we're in a pure-static app where dlsym fails.
pure_static = true;
}
#endif
if (!pure_static &&
(uses_dr_version == NULL || *uses_dr_version < OLDEST_COMPATIBLE_VERSION ||
*uses_dr_version > NEWEST_COMPATIBLE_VERSION)) {
/* not a fatal usage error since we want release build to continue */
CLIENT_ASSERT(false,
"client library is incompatible with this version of DR");
Expand All @@ -596,8 +617,9 @@ add_client_lib(const char *path, const char *id_str, const char *options)
// to the dll bounds functions. xref i#3387.
client_start = get_dynamorio_dll_start();
client_end = get_dynamorio_dll_end();
ASSERT(client_start <= (app_pc)uses_dr_version &&
(app_pc)uses_dr_version < client_end);
ASSERT(pure_static ||
(client_start <= (app_pc)uses_dr_version &&
(app_pc)uses_dr_version < client_end));
#else
DEBUG_DECLARE(bool ok =)
shared_library_bounds(client_lib, (byte *)uses_dr_version, NULL,
Expand Down Expand Up @@ -773,6 +795,15 @@ instrument_init(void)
(*init)(client_libs[i].id, client_libs[i].argc, client_libs[i].argv);
else if (legacy != NULL)
(*legacy)(client_libs[i].id);
#if defined(STATIC_LIBRARY) && !defined(WINDOWS)
else {
// For pure-static apps we support only INSTRUMENT_INIT_NAME.
// There is no WEAK support on Windows so we do not support this there
// (plus pure-static is not really practical either).
extern void dr_client_main(uint id, int argc, const char *argv[]);
dr_client_main(client_libs[i].id, client_libs[i].argc, client_libs[i].argv);
}
#endif
}

/* We now initialize the 1st thread before coming here, so we can
Expand Down
10 changes: 7 additions & 3 deletions ext/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# **********************************************************
# Copyright (c) 2010-2022 Google, Inc. All rights reserved.
# Copyright (c) 2010-2025 Google, Inc. All rights reserved.
# Copyright (c) 2010 VMware, Inc. All rights reserved.
# **********************************************************

Expand Down Expand Up @@ -61,8 +61,12 @@ add_dr_defines()

# This lets us share common code among all extensions. We use a macro to
# avoid scope issues and avoid having to call configure_DynamoRIO_global().
macro(configure_extension target is_static)
configure_DynamoRIO_client(${target})
macro(configure_extension target is_static static_DR)
if (${static_DR})
configure_DynamoRIO_static_client(${target})
else ()
configure_DynamoRIO_client(${target})
endif ()

# ensure we rebuild if includes change
add_dependencies(${target} api_headers)
Expand Down
12 changes: 9 additions & 3 deletions ext/drbbdup/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# **********************************************************
# Copyright (c) 2013-2020 Google, Inc. All rights reserved.
# Copyright (c) 2013-2025 Google, Inc. All rights reserved.
# **********************************************************

# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -47,15 +47,21 @@ set(srcs
set(srcs_static ${srcs})

add_library(drbbdup SHARED ${srcs})
configure_extension(drbbdup OFF)
configure_extension(drbbdup OFF OFF)
use_DynamoRIO_extension(drbbdup drcontainers)
use_DynamoRIO_extension(drbbdup drmgr)
use_DynamoRIO_extension(drbbdup drreg)

add_library(drbbdup_static STATIC ${srcs_static})
configure_extension(drbbdup_static ON)
configure_extension(drbbdup_static ON OFF)
use_DynamoRIO_extension(drbbdup_static drcontainers)
use_DynamoRIO_extension(drbbdup_static drmgr_static)
use_DynamoRIO_extension(drbbdup_static drreg_static)

add_library(drbbdup_drstatic STATIC ${srcs_static})
configure_extension(drbbdup_drstatic ON ON)
use_DynamoRIO_extension(drbbdup_drstatic drcontainers_drstatic)
use_DynamoRIO_extension(drbbdup_drstatic drmgr_drstatic)
use_DynamoRIO_extension(drbbdup_drstatic drreg_drstatic)

install_ext_header(drbbdup.h)
10 changes: 7 additions & 3 deletions ext/drcallstack/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# **********************************************************
# Copyright (c) 2021 Google, Inc. All rights reserved.
# Copyright (c) 2021-2025 Google, Inc. All rights reserved.
# **********************************************************

# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -48,11 +48,15 @@ endif ()

add_library(drcallstack SHARED ${srcs})
set(PREFERRED_BASE 0x79800000)
configure_extension(drcallstack OFF)
configure_extension(drcallstack OFF OFF)
target_link_libraries(drcallstack unwind)

add_library(drcallstack_static STATIC ${srcs_static})
configure_extension(drcallstack_static ON)
configure_extension(drcallstack_static ON OFF)
target_link_libraries(drcallstack_static unwind)

add_library(drcallstack_drstatic STATIC ${srcs_static})
configure_extension(drcallstack_drstatic ON ON)
target_link_libraries(drcallstack_drstatic unwind)

install_ext_header(drcallstack.h)
Loading

0 comments on commit 0885697

Please sign in to comment.