Skip to content

Commit

Permalink
Add some hardening compiler / linker flags.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Sep 28, 2021
1 parent 1dacc0a commit f3a611c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion external/jemalloc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if (NOT JEMALLOC_FOUND)
include(ExternalProject)
ExternalProject_Add(jemalloc
SOURCE_DIR ${jemalloc_loc}
CONFIGURE_COMMAND cd "${jemalloc_loc}" && CC=clang CXX=clang++ EXTRA_CFLAGS=-fPIE EXTRA_CXXFLAGS=-fPIE ./autogen.sh
CONFIGURE_COMMAND cd "${jemalloc_loc}" && export EXTRA_CFLAGS=-fstack-protector-all\ -fPIC\ -D_FORTIFY_SOURCE=2 && export EXTRA_CXXFLAGS=-fstack-protector-all\ -fPIC\ -D_FORTIFY_SOURCE=2 && CC=clang CXX=clang++ ./autogen.sh
INSTALL_COMMAND :
BUILD_IN_SOURCE 1
BUILD_BYPRODUCTS ${jemalloc_loc}/lib/libjemalloc.a
Expand Down
1 change: 1 addition & 0 deletions linux_glib_helper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# https://github.com/desktop-app/legal/blob/master/LEGAL

add_library(linux_glib_helper STATIC)
init_target(linux_glib_helper "(external)")
add_library(desktop-app::linux_glib_helper ALIAS linux_glib_helper)

nice_target_sources(linux_glib_helper ${CMAKE_CURRENT_SOURCE_DIR}
Expand Down
1 change: 1 addition & 0 deletions linux_gtk_helper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# https://github.com/desktop-app/legal/blob/master/LEGAL

add_library(linux_gtk_helper STATIC)
init_target(linux_gtk_helper "(external)")
add_library(desktop-app::linux_gtk_helper ALIAS linux_gtk_helper)

nice_target_sources(linux_gtk_helper ${CMAKE_CURRENT_SOURCE_DIR}
Expand Down
1 change: 1 addition & 0 deletions linux_wayland_helper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# https://github.com/desktop-app/legal/blob/master/LEGAL

add_library(linux_wayland_helper STATIC)
init_target(linux_wayland_helper "(external)")
add_library(desktop-app::linux_wayland_helper ALIAS linux_wayland_helper)

nice_target_sources(linux_wayland_helper ${CMAKE_CURRENT_SOURCE_DIR}
Expand Down
10 changes: 10 additions & 0 deletions options_linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

target_compile_options(common_options
INTERFACE
-fstack-protector-all
-fstack-clash-protection
-fPIC
$<IF:$<CONFIG:Debug>,,-fno-strict-aliasing>
-pipe
Expand All @@ -17,9 +19,17 @@ INTERFACE
-Wno-sign-compare
)

target_compile_definitions(common_options
INTERFACE
$<IF:$<CONFIG:Debug>,,_FORTIFY_SOURCE=2>
)

target_link_options(common_options
INTERFACE
-Wl,--as-needed
-Wl,-z,relro
-Wl,-z,now
-pie
)

if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
Expand Down

0 comments on commit f3a611c

Please sign in to comment.