fix(toolchains): Add -Wstrict-aliasing compiler option
Add the -Wstrict-aliasing=1 compiler option and fixes errors
related to it.
Fixes #34
Change-Id: Ie2f7821d56b0cb0185c614aa916d8c9756148507
Signed-off-by: Jacob Man Chun Yiu <jacobmanchun.yiu@arm.com>
diff --git a/configs/t_cose/0001-Remove-alias-warnings-for-t_cose_sign_add_signer.patch b/configs/t_cose/0001-Remove-alias-warnings-for-t_cose_sign_add_signer.patch
new file mode 100644
index 0000000..c110f92
--- /dev/null
+++ b/configs/t_cose/0001-Remove-alias-warnings-for-t_cose_sign_add_signer.patch
@@ -0,0 +1,40 @@
+From 09c33eb2de865b063f687612ab744d7e6a4028b8 Mon Sep 17 00:00:00 2001
+From: Jacob Man Chun Yiu <jacobmanchun.yiu@arm.com>
+Date: Mon, 10 Feb 2025 14:49:29 +0000
+Subject: [PATCH] Remove alias warnings for t_cose_sign_add_signer
+
+When tf-rmm is built with Wstrict-aliasing=2 compiler option, we get
+aliasing issues with this function.
+
+As a temporary fix, we remove alias warnings using pragma diagnostics
+
+Signed-off-by: Jacob Man Chun Yiu <jacobmanchun.yiu@arm.com>
+---
+ inc/t_cose/t_cose_sign_sign.h | 4 +++-
+ 1 file changed, 3 insertions(+), 1 deletion(-)
+
+diff --git a/inc/t_cose/t_cose_sign_sign.h b/inc/t_cose/t_cose_sign_sign.h
+index 2f2a1e3..ffb066d 100644
+--- a/inc/t_cose/t_cose_sign_sign.h
++++ b/inc/t_cose/t_cose_sign_sign.h
+@@ -434,7 +434,8 @@ t_cose_sign_add_body_header_params(struct t_cose_sign_sign_ctx *me,
+ me->added_body_parameters = parameters;
+ }
+
+-
++#pragma GCC diagnostic push
++#pragma GCC diagnostic ignored "-Wstrict-aliasing"
+ static inline void
+ t_cose_sign_add_signer(struct t_cose_sign_sign_ctx *context,
+ struct t_cose_signature_sign *signer)
+@@ -442,6 +443,7 @@ t_cose_sign_add_signer(struct t_cose_sign_sign_ctx *context,
+ /* Use base class function to add a signer/recipient to the linked list. */
+ t_cose_link_rs((struct t_cose_rs_obj **)&context->signers, (struct t_cose_rs_obj *)signer);
+ }
++#pragma GCC diagnostic pop
+
+ #ifdef __cplusplus
+ }
+--
+2.43.0
+
diff --git a/lib/t_cose/CMakeLists.txt b/lib/t_cose/CMakeLists.txt
index f947bd4..8bcd39a 100644
--- a/lib/t_cose/CMakeLists.txt
+++ b/lib/t_cose/CMakeLists.txt
@@ -17,12 +17,17 @@
set(T_COSE_PATCH_DIR "${RMM_SOURCE_DIR}/configs/t_cose")
set(T_COSE_PATCH_FILES
"${T_COSE_PATCH_DIR}/0001-Add-t_cose_key_encode-API.patch"
- "${T_COSE_PATCH_DIR}/0001-Add-compile-time-option-for-el3-signing.patch")
+ "${T_COSE_PATCH_DIR}/0001-Add-compile-time-option-for-el3-signing.patch"
+ "${T_COSE_PATCH_DIR}/0001-Remove-alias-warnings-for-t_cose_sign_add_signer.patch")
Git_Apply_Patches(${T_COSE_SOURCE_DIR} "${T_COSE_PATCH_FILES}")
#TODO: Eliminate warning suppression once the t_cose submodule is updated to
# a released version.
+
+# Avoid strict-aliasing for external repository t_cose
+string(REPLACE "-Wstrict-aliasing=1" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
+
target_compile_options(t_cose
PRIVATE
"-Wno-maybe-uninitialized"
diff --git a/toolchains/common.cmake b/toolchains/common.cmake
index c3eb449..d099c5b 100644
--- a/toolchains/common.cmake
+++ b/toolchains/common.cmake
@@ -20,7 +20,7 @@
string(APPEND CMAKE_${language}_FLAGS_INIT "-Wno-type-limits ")
string(APPEND CMAKE_${language}_FLAGS_INIT "-gdwarf-4 ")
string(APPEND CMAKE_${language}_FLAGS_INIT "-D_FORTIFY_SOURCE=2 ")
- string(APPEND CMAKE_${language}_FLAGS_DEBUG_INIT "-Og -Wnull-dereference ")
+ string(APPEND CMAKE_${language}_FLAGS_DEBUG_INIT "-Og -Wnull-dereference -Wstrict-aliasing=1 ")
string(APPEND CMAKE_${language}_FLAGS_RELEASE_INIT "-g ")
endforeach()