Skip to content

Commit 94bc3c4

Browse files
committed
Merge bitcoin/bitcoin#30824: cmake: decouple FORTIFY_SOURCE check from Debug build type
30803a3 cmake: decouple FORTIFY_SOURCE check from Debug build type (fanquake) Pull request description: `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. Also somewhat of a followup to bitcoin/bitcoin#30778 (comment). ACKs for top commit: ryanofsky: Code review ACK 30803a3 TheCharlatan: ACK 30803a3 Tree-SHA512: 298f8805a5bb2f1ff54e51ea31324d712c2070cc3eba26561c31001ace4bfa37ae6d18531cbd45e2faf610a0a1b83b420fcde6e329e17f02b021d26563583913
2 parents ba84c27 + 30803a3 commit 94bc3c4

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

CMakeLists.txt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -480,18 +480,21 @@ if(ENABLE_HARDENING)
480480
try_append_linker_flag("/HIGHENTROPYVA" TARGET hardening_interface)
481481
try_append_linker_flag("/NXCOMPAT" TARGET hardening_interface)
482482
else()
483+
484+
# _FORTIFY_SOURCE requires that there is some level of optimization,
485+
# otherwise it does nothing and just creates a compiler warning.
483486
try_append_cxx_flags("-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3"
484487
RESULT_VAR cxx_supports_fortify_source
488+
SOURCE "int main() {
489+
# if !defined __OPTIMIZE__ || __OPTIMIZE__ <= 0
490+
#error
491+
#endif
492+
}"
485493
)
486494
if(cxx_supports_fortify_source)
487-
# When the build configuration is Debug, all optimizations are disabled.
488-
# However, _FORTIFY_SOURCE requires that there is some level of optimization,
489-
# otherwise it does nothing and just creates a compiler warning.
490-
# Since _FORTIFY_SOURCE is a no-op without optimizations, do not enable it
491-
# when the build configuration is Debug.
492495
target_compile_options(hardening_interface INTERFACE
493-
$<$<NOT:$<CONFIG:Debug>>:-U_FORTIFY_SOURCE>
494-
$<$<NOT:$<CONFIG:Debug>>:-D_FORTIFY_SOURCE=3>
496+
-U_FORTIFY_SOURCE
497+
-D_FORTIFY_SOURCE=3
495498
)
496499
endif()
497500
unset(cxx_supports_fortify_source)

0 commit comments

Comments
 (0)