mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-15 23:35:42 -04:00
refactor: only link jemalloc
against executables, not libraries
Linking `jemalloc` against executables is enough to replace *all* malloc functionality with `jemalloc`. Linking it against a library will cause issues for example with Python bindings. The downside is that Python won't be using `jemalloc` by default, but likely malloc won't be the bottleneck when using Python.
This commit is contained in:
parent
38ef05cde2
commit
6b17f3d31f
@ -236,7 +236,6 @@ if(WITH_LIBDWARFS)
|
||||
|
||||
set(DWARFS_HAVE_CPPTRACE ${cpptrace_FOUND})
|
||||
set(DWARFS_HAVE_LIBZSTD ON)
|
||||
set(DWARFS_USE_JEMALLOC ${USE_JEMALLOC})
|
||||
set(DWARFS_HAVE_RICEPP ${ENABLE_RICEPP})
|
||||
set(DWARFS_HAVE_LIBMAGIC ${LIBMAGIC_FOUND})
|
||||
set(DWARFS_HAVE_LIBLZ4 ${LIBLZ4_FOUND})
|
||||
@ -259,7 +258,6 @@ else()
|
||||
add_library(dwarfs_writer ALIAS dwarfs::dwarfs_writer)
|
||||
add_library(dwarfs_rewrite ALIAS dwarfs::dwarfs_rewrite)
|
||||
add_library(dwarfs_extractor ALIAS dwarfs::dwarfs_extractor)
|
||||
set(USE_JEMALLOC ${DWARFS_WITH_JEMALLOC})
|
||||
endif()
|
||||
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/libdwarfs_tool.cmake)
|
||||
@ -626,11 +624,6 @@ foreach(tgt ${LIBDWARFS_TARGETS} ${LIBDWARFS_OBJECT_TARGETS} dwarfs_test_helpers
|
||||
|
||||
target_link_libraries(${tgt} PUBLIC Boost::boost)
|
||||
|
||||
# TODO: need to get USE_JEMALLOC and others from imported libdwarfs
|
||||
if(USE_JEMALLOC)
|
||||
target_link_libraries(${tgt} PRIVATE PkgConfig::JEMALLOC)
|
||||
endif(USE_JEMALLOC)
|
||||
|
||||
if(WITH_LIBDWARFS)
|
||||
target_include_directories(${tgt} PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
|
@ -8,7 +8,6 @@
|
||||
#cmakedefine DWARFS_HAVE_FLAC 1
|
||||
#cmakedefine DWARFS_HAVE_RICEPP 1
|
||||
#cmakedefine DWARFS_HAVE_LIBZSTD 1
|
||||
#cmakedefine DWARFS_USE_JEMALLOC 1
|
||||
#cmakedefine DWARFS_BUILTIN_MANPAGE 1
|
||||
#cmakedefine DWARFS_PERFMON_ENABLED 1
|
||||
#cmakedefine DWARFS_STACKTRACE_ENABLED 1
|
||||
|
@ -38,6 +38,11 @@ endif()
|
||||
target_link_libraries(dwarfs_tool PUBLIC dwarfs_common)
|
||||
target_include_directories(dwarfs_tool PUBLIC tools/include)
|
||||
|
||||
if(USE_JEMALLOC AND JEMALLOC_FOUND)
|
||||
target_link_libraries(dwarfs_tool PRIVATE PkgConfig::JEMALLOC)
|
||||
target_compile_definitions(dwarfs_tool PRIVATE DWARFS_USE_JEMALLOC)
|
||||
endif()
|
||||
|
||||
target_compile_definitions(
|
||||
dwarfs_tool PRIVATE DWARFS_BUILD_ID="${CMAKE_SYSTEM_PROCESSOR}, ${CMAKE_SYSTEM}, ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}"
|
||||
)
|
||||
|
@ -31,10 +31,6 @@
|
||||
|
||||
#include <dwarfs/config.h>
|
||||
|
||||
#ifdef DWARFS_USE_JEMALLOC
|
||||
#include <jemalloc/jemalloc.h>
|
||||
#endif
|
||||
|
||||
#include <dwarfs/block_compressor.h>
|
||||
#include <dwarfs/library_dependencies.h>
|
||||
|
||||
@ -55,25 +51,6 @@ std::string version_to_string(uint64_t version, version_format fmt) {
|
||||
throw std::invalid_argument("unsupported version format");
|
||||
}
|
||||
|
||||
#ifdef DWARFS_USE_JEMALLOC
|
||||
std::string get_jemalloc_version() {
|
||||
#ifdef __APPLE__
|
||||
char const* j = JEMALLOC_VERSION;
|
||||
#else
|
||||
char const* j = nullptr;
|
||||
size_t s = sizeof(j);
|
||||
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
|
||||
::mallctl("version", &j, &s, nullptr, 0);
|
||||
assert(j);
|
||||
#endif
|
||||
std::string rv{j};
|
||||
if (auto pos = rv.find('-'); pos != std::string::npos) {
|
||||
rv.erase(pos, std::string::npos);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
|
||||
std::string library_dependencies::common_as_string() {
|
||||
@ -114,11 +91,6 @@ void library_dependencies::add_common_libraries() {
|
||||
add_library("libcrypto", OPENSSL_version_major(), OPENSSL_version_minor(),
|
||||
OPENSSL_version_patch());
|
||||
add_library("libboost", BOOST_VERSION, version_format::boost);
|
||||
|
||||
#ifdef DWARFS_USE_JEMALLOC
|
||||
add_library("libjemalloc", get_jemalloc_version());
|
||||
#endif
|
||||
|
||||
add_library("phmap", PHMAP_VERSION_MAJOR, PHMAP_VERSION_MINOR,
|
||||
PHMAP_VERSION_PATCH);
|
||||
|
||||
|
@ -36,6 +36,10 @@
|
||||
#include <dwarfs/tool/render_manpage.h>
|
||||
#endif
|
||||
|
||||
#ifdef DWARFS_USE_JEMALLOC
|
||||
#include <jemalloc/jemalloc.h>
|
||||
#endif
|
||||
|
||||
namespace po = boost::program_options;
|
||||
|
||||
namespace boost {
|
||||
@ -50,6 +54,29 @@ void validate(boost::any& v, std::vector<std::string> const&,
|
||||
|
||||
namespace dwarfs::tool {
|
||||
|
||||
namespace {
|
||||
|
||||
#ifdef DWARFS_USE_JEMALLOC
|
||||
std::string get_jemalloc_version() {
|
||||
#ifdef __APPLE__
|
||||
char const* j = JEMALLOC_VERSION;
|
||||
#else
|
||||
char const* j = nullptr;
|
||||
size_t s = sizeof(j);
|
||||
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
|
||||
::mallctl("version", &j, &s, nullptr, 0);
|
||||
assert(j);
|
||||
#endif
|
||||
std::string rv{j};
|
||||
if (auto pos = rv.find('-'); pos != std::string::npos) {
|
||||
rv.erase(pos, std::string::npos);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
|
||||
std::string tool_header(std::string_view tool_name, std::string_view extra_info,
|
||||
extra_deps_fn const& extra_deps) {
|
||||
std::string date;
|
||||
@ -61,6 +88,10 @@ std::string tool_header(std::string_view tool_name, std::string_view extra_info,
|
||||
library_dependencies deps;
|
||||
deps.add_common_libraries();
|
||||
|
||||
#ifdef DWARFS_USE_JEMALLOC
|
||||
deps.add_library("libjemalloc", get_jemalloc_version());
|
||||
#endif
|
||||
|
||||
if (extra_deps) {
|
||||
extra_deps(deps);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user