_FORTIFY_SOURCE requires compiling with optimization (-O)
Opened this issue · 3 comments
netllama commented
On a Fedora36 system, attempting to run the make command throws a large number of warnings such as the following:
[ 80%] Building CXX object CMakeFiles/camhal_static.dir/modules/ia_cipr/src/Command.cpp.o
In file included from /usr/include/c++/12/x86_64-redhat-linux/bits/os_defines.h:39,
from /usr/include/c++/12/x86_64-redhat-linux/bits/c++config.h:2892,
from /usr/include/c++/12/bits/stl_algobase.h:59,
from /usr/include/c++/12/vector:60,
from /root/stuff/ipu6-camera-hal/modules/ia_cipr/include/Command.h:19,
from /root/stuff/ipu6-camera-hal/modules/ia_cipr/src/Command.cpp:19:
/usr/include/features.h:412:4: error: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp]
412 | # warning _FORTIFY_SOURCE requires compiling with optimization (-O)
| ^~~~~~~
This patch makes the failures go away, but I don't understand whether there will be performance impact as a result of the change:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a930feb..a79682f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -83,7 +83,7 @@ set (CMAKE_CXX_STANDARD 11)
add_compile_options(-Wall -Werror
-fstack-protector
-fPIE -fPIC
- -D_FORTIFY_SOURCE=2
+ -D_FORTIFY_SOURCE=0
-DDCHECK_ALWAYS_ON
-Wformat -Wformat-security
)
hao-yao commented
@netllama Did you build with -DCMAKE_BUILD_TYPE=Release? It sets compiler option -O2 which is needed by D_FORTIFY_SOURCE=2.
cbarbu commented
Same error here. Adding
-DCMAKE_BUILD_TYPE=Release
in build.sh, function build_hal_adaptor() {
so that cmake call looks like
command cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=$INSTALL_DIR/install ../
Allowed to compile smoothly build_hal_adaptor