@@ -73,4 +73,48 @@ include(cmake-modules/build/CompilerFlags)
7373# Hardening
7474# ##############################################################################
7575
76+ # Comment `-Wl,-z,nodlopen` for dlopen call
77+ if (NOT MSVC )
78+ set (USE_HARDENING_FLAGS
79+ -D_GLIBCXX_ASSERTIONS # Enable assertions
80+ -U_FORTIFY_SOURCE # Disable stack protector
81+ -D_FORTIFY_SOURCE=3 # Enable stack protector
82+ -fstack-protector-strong # Enable stack protector
83+ -fcf-protection # Control Flow Guard
84+ -fstack-clash-protection # Control Flow Guard
85+ -Wimplicit-fallthrough # Enabled in compiler flags by default
86+ -fstrict-flex-arrays=3 # Enable strict array bounds
87+ -Wformat # Enabled in compiler flags by default
88+ -Wformat=2 # Enabled in compiler flags by default
89+ # -Wl,-z,nodlopen # Restrict dlopen(3) calls to shared objects
90+ -Wl,-z,noexecstack # Enable data execution prevention by marking stack
91+ # memory as non-executable
92+ -Wl,-z,relro # Mark relocation table entries resolved at load-time as
93+ # read-only
94+ -Wl,-z,now # Mark relocation table entries resolved at load-time as
95+ # read-only. It impacts startup performance
96+ "-fsanitize=undefined -fsanitize-minimal-runtime" # Enable minimal runtime
97+ # undefined behavior sanitizer
98+ -fno-delete-null-pointer-checks
99+ -fno-strict-overflow
100+ -fno-strict-aliasing
101+ -ftrivial-auto-var-init=zero
102+ -Wtrampolines # Enable trampolines(gcc only)
103+ -mbranch-protection=standard # Enable indirect branches(aarch64 only)
104+ CACHE STRING "Additional hardening compilation flags for GCC/Clang" )
105+
106+ set (USE_HARDENING_LINKS
107+ -fstack-protector-strong # Enable stack protector
108+ "-fsanitize=undefined -fsanitize-minimal-runtime" # Enable minimal runtime
109+ # undefined behavior sanitizer -Wl,-z,nodlopen # Restrict dlopen(3) calls
110+ # to shared objects
111+ -Wl,-z,noexecstack # Enable data execution prevention by marking stack
112+ # memory as non-executable
113+ -Wl,-z,relro # Mark relocation table entries resolved at load-time as
114+ # read-only
115+ -Wl,-z,now # Mark relocation table entries resolved at load-time as
116+ # read-only. It impacts startup performance
117+ CACHE STRING "Additional hardening linking flags for GCC/Clang" )
118+ endif ()
119+
76120include (cmake-modules/build /Hardening)
0 commit comments