File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,40 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
111
111
endforeach ()
112
112
endif ()
113
113
114
+ # Add compiler-specific hardening flags.
115
+ if (CMAKE_CXX_COMPILER_ID MATCHES "^(Clang|GNU)$" )
116
+ add_compile_options (
117
+ # Warn about potentially unsafe code.
118
+ -Wall
119
+ # Warn about implicit conversions that potentially alter a value.
120
+ -Wconversion
121
+ # Check argument types of format string function calls, e.g., printf.
122
+ -Wformat
123
+ # Check for potential security issues in format string function calls.
124
+ -Wformat-security
125
+ # Revert strict aliasing enabled at optimization levels -O2, -O3, -Os.
126
+ -fno-strict-aliasing
127
+ # Check for buffer overflows such as stack smashing attacks.
128
+ -fstack-protector
129
+ # Enable fortified wrappers of GNU C library functions.
130
+ -D_FORTIFY_SOURCE=2
131
+ )
132
+
133
+ # We need to support CMake 3.10, add_link_options() was added in CMake 3.13.
134
+ # link_libraries() passes flags through as long as they do not contain spaces.
135
+ # https://cmake.org/cmake/help/v3.13/command/add_link_options.html
136
+ link_libraries (
137
+ # Check objects for unresolved symbol references.
138
+ -Wl,--no-undefined
139
+ # Mark library as not requiring executable stack.
140
+ -Wl,-z,noexecstack
141
+ # Resolve all symbols when program is started, instead of on first use.
142
+ -Wl,-z,now
143
+ # Mark Global Offset Table read-only after resolving symbols.
144
+ -Wl,-z,relro
145
+ )
146
+ endif ()
147
+
114
148
# https://clang.llvm.org/docs/AddressSanitizer.html
115
149
option (ACL_WITH_ASAN "Build with address sanitizer" OFF )
116
150
message (STATUS "Build with address sanitizer: ${ACL_WITH_ASAN} " )
You can’t perform that action at this time.
0 commit comments