1
0
Fork 0

Replace jemalloc with scudo

This should provide a wider support for ARM hardware
This commit is contained in:
Ilya Fedin 2023-11-24 00:56:03 +04:00 committed by John Preston
parent 5abaeaf922
commit c2ef75186a
8 changed files with 44 additions and 122 deletions

View file

@ -5,9 +5,6 @@
# https://github.com/desktop-app/legal/blob/master/LEGAL
add_subdirectory(external)
if (LINUX AND NOT DESKTOP_APP_DISABLE_JEMALLOC)
add_subdirectory(linux_jemalloc_helper)
endif()
if (DESKTOP_APP_USE_ALLOCATION_TRACER)
add_subdirectory(linux_allocation_tracer)
endif()

View file

@ -38,9 +38,6 @@ if (add_hunspell_library)
add_checked_subdirectory(hunspell)
endif()
add_checked_subdirectory(iconv)
if (LINUX AND NOT DESKTOP_APP_DISABLE_JEMALLOC)
add_checked_subdirectory(jemalloc)
endif()
add_checked_subdirectory(jpeg)
add_checked_subdirectory(kcoreaddons)
add_checked_subdirectory(kimageformats)
@ -57,6 +54,9 @@ add_checked_subdirectory(qr_code_generator)
add_checked_subdirectory(ranges)
add_checked_subdirectory(rlottie)
add_checked_subdirectory(rnnoise)
if (LINUX AND NOT DESKTOP_APP_DISABLE_SCUDO)
add_checked_subdirectory(scudo)
endif()
add_checked_subdirectory(ton)
add_checked_subdirectory(variant)
add_checked_subdirectory(vpx)

View file

@ -1,65 +0,0 @@
# This file is part of Desktop App Toolkit,
# a set of libraries for developing nice desktop applications.
#
# For license and copyright information please follow this link:
# https://github.com/desktop-app/legal/blob/master/LEGAL
add_library(external_jemalloc INTERFACE IMPORTED GLOBAL)
add_library(desktop-app::external_jemalloc ALIAS external_jemalloc)
if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
return()
endif()
if (DESKTOP_APP_USE_PACKAGED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(JEMALLOC jemalloc)
if (JEMALLOC_FOUND)
target_include_directories(external_jemalloc SYSTEM
INTERFACE
${JEMALLOC_INCLUDE_DIRS}
)
target_link_libraries(external_jemalloc
INTERFACE
-Wl,--push-state,--no-as-needed,${JEMALLOC_LINK_LIBRARIES},--pop-state
)
return()
endif()
endif()
include(ProcessorCount)
ProcessorCount(N)
include(ExternalProject)
ExternalProject_Add(jemalloc
URL ${third_party_loc}/jemalloc
CONFIGURE_COMMAND env
CC=clang
CXX=clang++
"$<IF:$<OR:$<NOT:$<BOOL:${DESKTOP_APP_USE_PACKAGED}>>,$<BOOL:${DESKTOP_APP_SPECIAL_TARGET}>>,EXTRA_CFLAGS=-fno-omit-frame-pointer -fstack-protector-all -fstack-clash-protection -fcf-protection -DNDEBUG -D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS,=>"
"$<IF:$<OR:$<NOT:$<BOOL:${DESKTOP_APP_USE_PACKAGED}>>,$<BOOL:${DESKTOP_APP_SPECIAL_TARGET}>>,EXTRA_CXXFLAGS=-fno-omit-frame-pointer -fstack-protector-all -fstack-clash-protection -fcf-protection -DNDEBUG -D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS,=>"
./autogen.sh --disable-shared
BUILD_COMMAND make $<$<NOT:$<EQUAL:${N},0>>:-j${N}>
BUILD_IN_SOURCE 1
STEP_TARGETS build
EXCLUDE_FROM_ALL TRUE
BUILD_BYPRODUCTS <SOURCE_DIR>/lib/libjemalloc_pic.a
)
ExternalProject_Get_property(jemalloc SOURCE_DIR)
file(MAKE_DIRECTORY "${SOURCE_DIR}/include")
target_include_directories(external_jemalloc SYSTEM
INTERFACE
${SOURCE_DIR}/include
)
target_link_libraries(external_jemalloc
INTERFACE
-Wl,--push-state,--whole-archive,${SOURCE_DIR}/lib/libjemalloc_pic.a,--pop-state
)
add_dependencies(external_jemalloc jemalloc-build)

35
external/scudo/CMakeLists.txt vendored Normal file
View file

@ -0,0 +1,35 @@
# This file is part of Desktop App Toolkit,
# a set of libraries for developing nice desktop applications.
#
# For license and copyright information please follow this link:
# https://github.com/desktop-app/legal/blob/master/LEGAL
add_library(external_scudo STATIC)
add_library(desktop-app::external_scudo ALIAS external_scudo)
init_target(external_scudo "(external)")
set(scudo_loc ${third_party_loc}/scudo)
# https://llvm.org/docs/ScudoHardenedAllocator.html#library
file(GLOB scudo_srcs ${scudo_loc}/*.cpp)
target_sources(external_scudo
PRIVATE
${scudo_srcs}
)
target_include_directories(external_scudo SYSTEM
PRIVATE
${scudo_loc}/include
)
add_library(external_scudo_options INTERFACE)
target_compile_options(external_scudo_options
INTERFACE
-fno-lto
-Wno-unused-result
)
target_link_libraries(external_scudo
PRIVATE
external_scudo_options
)

View file

@ -1,19 +0,0 @@
# This file is part of Desktop App Toolkit,
# a set of libraries for developing nice desktop applications.
#
# For license and copyright information please follow this link:
# https://github.com/desktop-app/legal/blob/master/LEGAL
add_library(linux_jemalloc_helper OBJECT)
init_target(linux_jemalloc_helper "(external)")
add_library(desktop-app::linux_jemalloc_helper ALIAS linux_jemalloc_helper)
nice_target_sources(linux_jemalloc_helper ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE
linux_jemalloc_helper.cpp
)
target_link_libraries(linux_jemalloc_helper
PRIVATE
desktop-app::external_jemalloc
)

View file

@ -1,25 +0,0 @@
// This file is part of Desktop App Toolkit,
// a set of libraries for developing nice desktop applications.
//
// For license and copyright information please follow this link:
// https://github.com/desktop-app/legal/blob/master/LEGAL
//
#ifdef __FreeBSD__
#include <malloc_np.h>
#else // __FreeBSD__
#include <jemalloc/jemalloc.h>
#endif // !__FreeBSD__
namespace {
class JemallocInitializer {
public:
JemallocInitializer() {
auto backgroundThread = true;
mallctl("background_thread", nullptr, nullptr, &backgroundThread, sizeof(bool));
}
};
static const JemallocInitializer initializer;
} // namespace

View file

@ -99,12 +99,11 @@ if (NOT DESKTOP_APP_USE_PACKAGED OR DESKTOP_APP_SPECIAL_TARGET)
)
endif()
if (NOT DESKTOP_APP_DISABLE_JEMALLOC)
target_link_libraries(common_options
INTERFACE
$<TARGET_OBJECTS:desktop-app::linux_jemalloc_helper>
$<LINK_ONLY:desktop-app::external_jemalloc>
)
if (NOT DESKTOP_APP_DISABLE_SCUDO)
target_link_libraries(common_options
INTERFACE
$<LINK_ONLY:desktop-app::external_scudo>
)
endif()
if (DESKTOP_APP_USE_ALLOCATION_TRACER)

View file

@ -31,7 +31,7 @@ option(DESKTOP_APP_USE_HUNSPELL_ONLY "Disable system spellchecker and use bundle
cmake_dependent_option(DESKTOP_APP_USE_ENCHANT "Use Enchant instead of bundled Hunspell." OFF LINUX OFF)
cmake_dependent_option(DESKTOP_APP_USE_CLD3 "Disable system text language recognition and use bundled cld3 only." OFF APPLE ON)
cmake_dependent_option(DESKTOP_APP_NO_PDB "Disable PDB file generation." OFF WIN32 OFF)
cmake_dependent_option(DESKTOP_APP_DISABLE_JEMALLOC "Disable jemalloc, use system malloc." OFF LINUX OFF)
cmake_dependent_option(DESKTOP_APP_DISABLE_SCUDO "Disable scudo, use system malloc." OFF LINUX OFF)
if (APPLE AND NOT DEFINED DESKTOP_APP_MAC_ARCH)
if (DEFINED CMAKE_OSX_ARCHITECTURES)