Repository navigation
backport: bitcoin#30803, #30824, #30865, #30867, #31231, #31359, #31711, #32356 #8176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
70afb28
2c30364
147cc23
475cd02
62d4822
c2ddcca
2d0b184
8756731
4734645
6a82c37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,17 +8,15 @@ | |
| # Centos Stream 9, EOL in May 2027: | ||
| # - CMake 3.26.5, https://mirror.stream.centos.org/9-stream/AppStream/x86_64/os/Packages/ | ||
| cmake_minimum_required(VERSION 3.22) | ||
| if(POLICY CMP0141) | ||
| # MSVC debug information format flags are selected by an abstraction. | ||
| # We want to use the CMAKE_MSVC_DEBUG_INFORMATION_FORMAT variable | ||
| # to select the MSVC debug information format. | ||
| cmake_policy(SET CMP0141 NEW) | ||
| endif() | ||
|
|
||
| if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) | ||
| message(FATAL_ERROR "In-source builds are not allowed.") | ||
| endif() | ||
|
|
||
| # When adjusting CMake flag variables, we must not override those explicitly | ||
| # set by the user. These are a subset of the CACHE_VARIABLES property. | ||
| get_directory_property(precious_variables CACHE_VARIABLES) | ||
|
|
||
| #============================= | ||
| # Project / Package metadata | ||
| #============================= | ||
|
|
@@ -86,6 +84,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) | |
| set(CMAKE_CXX_EXTENSIONS OFF) | ||
|
|
||
| list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/module) | ||
| include(ProcessConfigurations) | ||
|
|
||
| #============================= | ||
| # Configurable options | ||
|
|
@@ -112,14 +111,12 @@ if(WITH_SQLITE) | |
| find_package(SQLite3 3.7.17 REQUIRED) | ||
| endif() | ||
| set(USE_SQLITE ON) | ||
| set(ENABLE_WALLET ON) | ||
| endif() | ||
| option(WITH_BDB "Enable Berkeley DB (BDB) wallet support." OFF) | ||
| cmake_dependent_option(WARN_INCOMPATIBLE_BDB "Warn when using a Berkeley DB (BDB) version other than 4.8." ON "WITH_BDB" OFF) | ||
| if(WITH_BDB) | ||
| find_package(BerkeleyDB 4.8 MODULE REQUIRED) | ||
| set(USE_BDB ON) | ||
| set(ENABLE_WALLET ON) | ||
| if(NOT BerkeleyDB_VERSION VERSION_EQUAL 4.8) | ||
| message(WARNING "Found Berkeley DB (BDB) other than 4.8.\n" | ||
| "BDB (legacy) wallets opened by this build will not be portable!" | ||
|
|
@@ -166,7 +163,9 @@ if(WITH_ZMQ) | |
| find_package(ZeroMQ CONFIG REQUIRED) | ||
| else() | ||
| # The ZeroMQ project has provided config files since v4.2.2. | ||
| # TODO: Switch to find_package(ZeroMQ) at some point in the future. | ||
| # However, mainstream distributions do not yet provide CMake | ||
| # config files for ZeroMQ packages. If they do in the future, | ||
| # find_package(ZeroMQ) may be used instead. | ||
| find_package(PkgConfig REQUIRED) | ||
| pkg_check_modules(libzmq REQUIRED IMPORTED_TARGET libzmq>=4) | ||
| # TODO: This command will be redundant once | ||
|
|
@@ -234,7 +233,7 @@ cmake_dependent_option(ENABLE_PLATFORM_GUI "Enable Dash Platform (usernames, Das | |
|
|
||
| option(BUILD_BENCH "Build bench_bitcoin executable." OFF) | ||
| option(BUILD_FUZZ_BINARY "Build fuzz binary." OFF) | ||
| cmake_dependent_option(BUILD_FOR_FUZZING "Build for fuzzing. Enabling this will disable all other targets and override BUILD_FUZZ_BINARY." OFF "NOT MSVC" OFF) | ||
| option(BUILD_FOR_FUZZING "Build for fuzzing. Enabling this will disable all other targets and override BUILD_FUZZ_BINARY." OFF) | ||
|
|
||
| option(INSTALL_MAN "Install man pages." ON) | ||
|
|
||
|
|
@@ -251,16 +250,8 @@ string(APPEND CMAKE_CXX_LINK_EXECUTABLE " ${APPEND_LDFLAGS}") | |
|
|
||
| set(configure_warnings) | ||
|
|
||
| include(CheckPIESupported) | ||
| check_pie_supported(OUTPUT_VARIABLE check_pie_output LANGUAGES CXX) | ||
| if(CMAKE_CXX_LINK_PIE_SUPPORTED) | ||
| set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
| elseif(NOT WIN32) | ||
| # The warning is superfluous for Windows. | ||
| message(WARNING "PIE is not supported at link time: ${check_pie_output}") | ||
| list(APPEND configure_warnings "Position independent code disabled.") | ||
| endif() | ||
| unset(check_pie_output) | ||
| include(CheckLinkerSupportsPIE) | ||
| check_linker_supports_pie(configure_warnings) | ||
|
|
||
| # The core_interface library aims to encapsulate common build flags. | ||
| # It is a usage requirement for all targets except for secp256k1, which | ||
|
|
@@ -307,11 +298,20 @@ endif() | |
| # Derive this after BUILD_FOR_FUZZING has applied its target overrides. | ||
| set(HAVE_CONSENSUS_LIB ${BUILD_CONSENSUS_LIB}) | ||
|
|
||
| include(ProcessConfigurations) | ||
|
|
||
| include(TryAppendCXXFlags) | ||
| include(TryAppendLinkerFlag) | ||
|
|
||
| # Redefine/adjust per-configuration flags. | ||
| # Dash uses DEBUG_CORE, not upstream's DEBUG, which is what span.h and | ||
| # init/common.cpp check. | ||
| target_compile_definitions(core_interface_debug INTERFACE | ||
| DEBUG_CORE | ||
| DEBUG_LOCKORDER | ||
| DEBUG_LOCKCONTENTION | ||
| RPC_DOC_CHECK | ||
| ABORT_ON_FAILED_ASSUME | ||
| ) | ||
|
|
||
| if(WIN32) | ||
| #[=[ | ||
| This build system supports two ways to build binaries for Windows. | ||
|
|
@@ -592,18 +592,21 @@ if(ENABLE_HARDENING) | |
| try_append_linker_flag("/HIGHENTROPYVA" TARGET hardening_interface) | ||
| try_append_linker_flag("/NXCOMPAT" TARGET hardening_interface) | ||
| else() | ||
|
|
||
| # _FORTIFY_SOURCE requires that there is some level of optimization, | ||
| # otherwise it does nothing and just creates a compiler warning. | ||
| try_append_cxx_flags("-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3" | ||
| RESULT_VAR cxx_supports_fortify_source | ||
| SOURCE "int main() { | ||
| # if !defined __OPTIMIZE__ || __OPTIMIZE__ <= 0 | ||
| #error | ||
| #endif | ||
| }" | ||
| ) | ||
| if(cxx_supports_fortify_source) | ||
| # When the build configuration is Debug, all optimizations are disabled. | ||
| # However, _FORTIFY_SOURCE requires that there is some level of optimization, | ||
| # otherwise it does nothing and just creates a compiler warning. | ||
| # Since _FORTIFY_SOURCE is a no-op without optimizations, do not enable it | ||
| # when the build configuration is Debug. | ||
| target_compile_options(hardening_interface INTERFACE | ||
| $<$<NOT:$<CONFIG:Debug>>:-U_FORTIFY_SOURCE> | ||
| $<$<NOT:$<CONFIG:Debug>>:-D_FORTIFY_SOURCE=3> | ||
| -U_FORTIFY_SOURCE | ||
| -D_FORTIFY_SOURCE=3 | ||
|
Comment on lines
+608
to
+609
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not apply one configuration’s fortify result to every configuration. With Ninja Multi-Config, the probe uses RelWithDebInfo, but these options also reach Debug, whose default flags contain On GCC 12 with glibc 2.35 and
|
||
| ) | ||
|
Comment on lines
598
to
610
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Blocking: Make the FORTIFY probe and flags configuration-specific The probe is executed through CMake's single source: |
||
| endif() | ||
| unset(cxx_supports_fortify_source) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Copyright (c) 2024-present The Bitcoin Core developers | ||
| # Distributed under the MIT software license, see the accompanying | ||
| # file COPYING or https://opensource.org/license/mit/. | ||
|
|
||
| include_guard(GLOBAL) | ||
|
|
||
| function(check_linker_supports_pie warnings) | ||
| # Workaround for a bug in the check_pie_supported() function. | ||
| # See: | ||
| # - https://gitlab.kitware.com/cmake/cmake/-/issues/26463 | ||
| # - https://gitlab.kitware.com/cmake/cmake/-/merge_requests/10034 | ||
| if(CMAKE_VERSION VERSION_LESS 3.32) | ||
| # CMAKE_CXX_COMPILE_OPTIONS_PIE is a list, whereas CMAKE_REQUIRED_FLAGS | ||
| # must be a string. Therefore, a proper conversion is required. | ||
| list(JOIN CMAKE_CXX_COMPILE_OPTIONS_PIE " " CMAKE_REQUIRED_FLAGS) | ||
| endif() | ||
|
|
||
| include(CheckPIESupported) | ||
| check_pie_supported(OUTPUT_VARIABLE output LANGUAGES CXX) | ||
| if(CMAKE_CXX_LINK_PIE_SUPPORTED) | ||
| set(CMAKE_POSITION_INDEPENDENT_CODE ON PARENT_SCOPE) | ||
| elseif(NOT WIN32) | ||
| # The warning is superfluous for Windows. | ||
| message(WARNING "PIE is not supported at link time. See the configure log for details.") | ||
| set(${warnings} ${${warnings}} "Position independent code disabled." PARENT_SCOPE) | ||
| endif() | ||
| endfunction() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include the build type in the fortify probe's cache identity.
With a single-configuration generator, the probe stores its result under a name derived only from the flags and source text. The build type is not part of that name. A Debug configure adds
-O0, so the probe fails and caches the failure. A later reconfigure of the same directory withCMAKE_BUILD_TYPE=Releasereuses that cached failure. The_FORTIFY_SOURCE=3options are then omitted from the Release build, without a warning.Make the probe result depend on the active build type. Clear the cached result when
CMAKE_BUILD_TYPEchanges. Configuration-specific target options do not fix the cached result. A fresh build directory avoids the problem until the change is made. Multi-configuration generators are not affected because they always probe withRelWithDebInfo.