Skip to content

Commit

Permalink
[build] set _FORTIFY_SOURCE=2 for -O* builds only
Browse files Browse the repository at this point in the history
Summary:
currently building with -DCMAKE_BUILD_TYPE=Debug floods the cli
with warnings about how _FORTIFY_SOURCE=2 requires optimization.

Our Debug build compiles with -O0 because apparently -Og drops some
symbols, so this flag should only be set for Release, RelWithDebInfo
and RelMinSize

h/t @fabien for help with the CMake generator expressions

Test Plan:
  cmake .. -GNinja -DCMAKE_BUILD_TYPE=Debug
  ninja

see no warnings that _FORTIFY_SOURCE requires compiling with
optimization

  cmake .. -GNinja -DCMAKE_BUILD_TYPE=[the other three]
  ninja -nv

see the correct flags `-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2` set
in the dry run output

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D6237
  • Loading branch information
majcosta authored and ftrader committed Jul 3, 2020
1 parent 6342f98 commit bdb2191
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/CMakeLists.txt
Expand Up @@ -126,8 +126,10 @@ if(ENABLE_HARDENING)
# Enable stack protection
add_cxx_compiler_flags(-fstack-protector-all -Wstack-protector)

# Enable some buffer overflow checking
add_compiler_flags(-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2)
# Enable some buffer overflow checking, except in -O0 builds which
# do not support them
add_compiler_flags(-U_FORTIFY_SOURCE)
add_compile_options($<$<NOT:$<CONFIG:Debug>>:-D_FORTIFY_SOURCE=2>)

# Enable ASLR (these flags are primarily targeting MinGw)
add_linker_flags(-Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va)
Expand Down

0 comments on commit bdb2191

Please sign in to comment.