diff --git a/CMakeLists.txt b/CMakeLists.txt index bb8789c..44954c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index d9af92a..34181cc 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -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) diff --git a/external/jemalloc/CMakeLists.txt b/external/jemalloc/CMakeLists.txt deleted file mode 100644 index 9b87c00..0000000 --- a/external/jemalloc/CMakeLists.txt +++ /dev/null @@ -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++ - "$>,$>,EXTRA_CFLAGS=-fno-omit-frame-pointer -fstack-protector-all -fstack-clash-protection -fcf-protection -DNDEBUG -D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS,=>" - "$>,$>,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 $<$>:-j${N}> - BUILD_IN_SOURCE 1 - STEP_TARGETS build - EXCLUDE_FROM_ALL TRUE - BUILD_BYPRODUCTS /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) diff --git a/external/scudo/CMakeLists.txt b/external/scudo/CMakeLists.txt new file mode 100644 index 0000000..3fc79fb --- /dev/null +++ b/external/scudo/CMakeLists.txt @@ -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 +) diff --git a/linux_jemalloc_helper/CMakeLists.txt b/linux_jemalloc_helper/CMakeLists.txt deleted file mode 100644 index 0466d8a..0000000 --- a/linux_jemalloc_helper/CMakeLists.txt +++ /dev/null @@ -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 -) diff --git a/linux_jemalloc_helper/linux_jemalloc_helper.cpp b/linux_jemalloc_helper/linux_jemalloc_helper.cpp deleted file mode 100644 index 76bc863..0000000 --- a/linux_jemalloc_helper/linux_jemalloc_helper.cpp +++ /dev/null @@ -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 -#else // __FreeBSD__ -#include -#endif // !__FreeBSD__ - -namespace { - -class JemallocInitializer { -public: - JemallocInitializer() { - auto backgroundThread = true; - mallctl("background_thread", nullptr, nullptr, &backgroundThread, sizeof(bool)); - } -}; - -static const JemallocInitializer initializer; - -} // namespace diff --git a/options_linux.cmake b/options_linux.cmake index 2351d6c..bd93f79 100644 --- a/options_linux.cmake +++ b/options_linux.cmake @@ -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 - $ - $ - ) +if (NOT DESKTOP_APP_DISABLE_SCUDO) + target_link_libraries(common_options + INTERFACE + $ + ) endif() if (DESKTOP_APP_USE_ALLOCATION_TRACER) diff --git a/variables.cmake b/variables.cmake index 67af35b..ddc1c58 100644 --- a/variables.cmake +++ b/variables.cmake @@ -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)