@@ -51,7 +51,29 @@ function(sourcemeta_add_default_options visibility target)
51
51
# multiplication wraps around using twos-complement representation
52
52
# See https://users.cs.utah.edu/~regehr/papers/overflow12.pdf
53
53
# See https://www.postgresql.org/message-id/1689.1134422394@sss.pgh.pa.us
54
- -fwrapv )
54
+ -fwrapv
55
+
56
+ # See https://best.openssf.org/Compiler-Hardening-Guides/Compiler-Options-Hardening-Guide-for-C-and-C++.html
57
+ -Wformat
58
+ -Wformat=2
59
+ -Werror=format-security
60
+ -fstrict-flex-arrays=3
61
+ -fstack-clash-protection
62
+ -fstack-protector-strong
63
+ -Werror=implicit
64
+ -Werror=incompatible-pointer-types )
65
+
66
+ if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" )
67
+ target_compile_options ("${target} " ${visibility} -fcf-protection=full )
68
+ elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64" )
69
+ target_compile_options ("${target} " ${visibility} -mbranch-protection=standard )
70
+ endif ()
71
+
72
+ target_compile_definitions ("${target} " ${visibility} _FORTIFY_SOURCE=3 )
73
+ target_compile_definitions ("${target} " ${visibility} $< $< CONFIG:Debug> :_GLIBCXX_ASSERTIONS> )
74
+ target_compile_options ("${target} " ${visibility}
75
+ $< $< CONFIG:Release> :-fno-delete-null-pointer-checks -fno-strict-overflow -fno-strict-aliasing -ftrivial-auto-var-init=zero>
76
+ $< $< CONFIG:RelWithDebInfo> :-fno-delete-null-pointer-checks -fno-strict-overflow -fno-strict-aliasing -ftrivial-auto-var-init=zero> )
55
77
endif ()
56
78
57
79
if (SOURCEMETA_COMPILER_LLVM )
@@ -88,7 +110,11 @@ function(sourcemeta_add_default_options visibility target)
88
110
# GCC seems to print a lot of false-positives here
89
111
-Wno-free-nonheap-object
90
112
# Disables runtime type information
91
- -fno-rtti )
113
+ -fno-rtti
114
+
115
+ # See https://best.openssf.org/Compiler-Hardening-Guides/Compiler-Options-Hardening-Guide-for-C-and-C++.html
116
+ -Wtrampolines
117
+ -Wbidi-chars=any )
92
118
endif ()
93
119
endfunction ()
94
120
0 commit comments