mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
cmake: decouple FORTIFY_SOURCE check from Debug build type
`FORTIFY_SOURCE` should be used if `ENABLE_HARDENING=ON` and optimisations are being used. This should not be coupled to any particular build type, because even if the build type is `Debug`, optimisations might still be in use. Fixes: #30800.
This commit is contained in:
parent
d661e2b1b7
commit
30803a35d5
1 changed files with 10 additions and 7 deletions
|
@ -480,18 +480,21 @@ if(ENABLE_HARDENING)
|
||||||
try_append_linker_flag("/HIGHENTROPYVA" TARGET hardening_interface)
|
try_append_linker_flag("/HIGHENTROPYVA" TARGET hardening_interface)
|
||||||
try_append_linker_flag("/NXCOMPAT" TARGET hardening_interface)
|
try_append_linker_flag("/NXCOMPAT" TARGET hardening_interface)
|
||||||
else()
|
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"
|
try_append_cxx_flags("-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3"
|
||||||
RESULT_VAR cxx_supports_fortify_source
|
RESULT_VAR cxx_supports_fortify_source
|
||||||
|
SOURCE "int main() {
|
||||||
|
# if !defined __OPTIMIZE__ || __OPTIMIZE__ <= 0
|
||||||
|
#error
|
||||||
|
#endif
|
||||||
|
}"
|
||||||
)
|
)
|
||||||
if(cxx_supports_fortify_source)
|
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
|
target_compile_options(hardening_interface INTERFACE
|
||||||
$<$<NOT:$<CONFIG:Debug>>:-U_FORTIFY_SOURCE>
|
-U_FORTIFY_SOURCE
|
||||||
$<$<NOT:$<CONFIG:Debug>>:-D_FORTIFY_SOURCE=3>
|
-D_FORTIFY_SOURCE=3
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
unset(cxx_supports_fortify_source)
|
unset(cxx_supports_fortify_source)
|
||||||
|
|
Loading…
Add table
Reference in a new issue