Skip to contentSkip to conversation

arm/optee-os: Backport the clang fixes

PATCH Applied Jon Mason 2 participants 2 messages Sep 27, 2024 – Sep 30, 2024

lore
Share & tools
lore

Jon Mason

author
#0 lore raw

PATCH 1/1 arm/optee-os: Backport the clang fixes

The Clang bug in OP-TEE OS has been resolved (see
https://github.com/OP-TEE/optee_os/issues/6754). Backport those patches and remove the forcing of GCC in the recipe.

---
 ...arm64.h-fix-compile-error-with-Clang.patch | 70 +++++++++++++++++++
 ...002-libutils-zlib-fix-Clang-warnings.patch | 64 +++++++++++++++++
 .../recipes-security/optee/optee-os_4.2.0.bb  |  2 +
 meta-arm/recipes-security/optee/optee.inc     |  3 -
 4 files changed, 136 insertions(+), 3 deletions(-)
 create mode 100644 meta-arm/recipes-security/optee/optee-os/0001-arm64.h-fix-compile-error-with-Clang.patch
 create mode 100644 meta-arm/recipes-security/optee/optee-os/0002-libutils-zlib-fix-Clang-warnings.patch
meta-arm/recipes-security/optee/optee-os/0001-arm64.h-fix-compile-error-with-Clang.patch new file +70 -0
new file mode 100644
index 000000000000..e4508b3435c6
@@ -0,0 +1,70 @@
+From dc9fd53be9d69c4a6bc67d9de951b8f2a92abade Mon Sep 17 00:00:00 2001
+From: Jerome Forissier <[email protected]>
+Date: Fri, 14 Jun 2024 17:51:22 +0200
+Subject: [PATCH 1/2] arm64.h: fix compile error with Clang
+
+Clang 18.1.6 fails to compile OP-TEE OS with the following error:
+
+   CC      out/arm/core/arch/arm/kernel/vfp.o
+ In file included from core/arch/arm/kernel/vfp.c:6:
+ In file included from core/arch/arm/include/arm.h:137:
+ core/arch/arm/include/arm64.h:455:1: error: expected readable system register
+   455 | DEFINE_U32_REG_READWRITE_FUNCS(fpcr)
+       | ^
+ core/arch/arm/include/arm64.h:436:3: note: expanded from macro 'DEFINE_U32_REG_READWRITE_FUNCS'
+   436 |                 DEFINE_U32_REG_READ_FUNC(reg)   \
+       |                 ^
+ core/arch/arm/include/arm64.h:430:3: note: expanded from macro 'DEFINE_U32_REG_READ_FUNC'
+   430 |                 DEFINE_REG_READ_FUNC_(reg, uint32_t, reg)
+       |                 ^
+ core/arch/arm/include/arm64.h:417:15: note: expanded from macro 'DEFINE_REG_READ_FUNC_'
+   417 |         asm volatile("mrs %0, " #asmreg : "=r" (val64));        \
+       |                      ^
+ <inline asm>:1:10: note: instantiated into assembly here
+     1 |         mrs x8, fpcr
+       |                 ^
+
+...and similar ones for fpcr write, as well as fpsr read and write.
+
+Clang 12.0.0 does not have any problem with this code which makes me
+think that it's a Clang/LLVM issue.
+
+Work around the problem by using the coded system register identifiers
+S3_3_c4_c4_0 and S3_3_c4_c4_1 instead of fpcr and fpsr, respectively.
+The values 3-3-4-4-0 and 3-3-4-4-1 are taken from the Arm ARM sections
+C.5.2.8 and C.5.2.9.
+
+Signed-off-by: Jerome Forissier <[email protected]>
+Acked-by: Joakim Bech <[email protected]>
+Acked-by: Jens Wiklander <[email protected]>
+
+Upstream-Status: Backport
+Signed-off-by: Jon Mason <[email protected]>
+
+---
+ core/arch/arm/include/arm64.h | 7 +++++++
+ 1 file changed, 7 insertions(+)
+
+diff --git a/core/arch/arm/include/arm64.h b/core/arch/arm/include/arm64.h
+index 28922631f637..c72b5cd7bbd3 100644
+--- a/core/arch/arm/include/arm64.h
++++ b/core/arch/arm/include/arm64.h
+@@ -452,8 +452,15 @@ static inline __noprof void write_##reg(type val)		\
+ 
+ DEFINE_U32_REG_READWRITE_FUNCS(cpacr_el1)
+ DEFINE_U32_REG_READWRITE_FUNCS(daif)
++#ifdef __clang__
++DEFINE_REG_READ_FUNC_(fpcr, uint32_t, S3_3_c4_c4_0)
++DEFINE_REG_WRITE_FUNC_(fpcr, uint32_t, S3_3_c4_c4_0)
++DEFINE_REG_READ_FUNC_(fpsr, uint32_t, S3_3_c4_c4_1)
++DEFINE_REG_WRITE_FUNC_(fpsr, uint32_t, S3_3_c4_c4_1)
++#else
+ DEFINE_U32_REG_READWRITE_FUNCS(fpcr)
+ DEFINE_U32_REG_READWRITE_FUNCS(fpsr)
++#endif
+ 
+ DEFINE_U32_REG_READ_FUNC(ctr_el0)
+ #define read_ctr() read_ctr_el0()
+-- 
+2.39.5
+
meta-arm/recipes-security/optee/optee-os/0002-libutils-zlib-fix-Clang-warnings.patch new file +64 -0

64 lines not on this page · raw message

meta-arm/recipes-security/optee/optee-os_4.2.0.bb +2 -0
index 33c19f2fa349..3f00c7b3617f 100644
@@ -12,4 +12,6 @@ SRC_URI += " \
     file://0001-compile.mk-use-CFLAGS-from-environment.patch \
     file://0002-link.mk-use-CFLAGS-with-version.o.patch \
     file://0003-link.mk-generate-version.o-in-link-out-dir.patch \
+    file://0001-arm64.h-fix-compile-error-with-Clang.patch \
+    file://0002-libutils-zlib-fix-Clang-warnings.patch \
 "
meta-arm/recipes-security/optee/optee.inc +0 -3
index 37676f14960c..c5514f565172 100644
@@ -14,9 +14,6 @@ OPTEE_ARCH:arm = "arm32"
 OPTEE_ARCH:aarch64 = "arm64"
 OPTEE_CORE = "${@d.getVar('OPTEE_ARCH').upper()}"
 
-# FIXME - breaks with Clang 18.  See https://github.com/OP-TEE/optee_os/issues/6754
-TOOLCHAIN = "gcc"
-
 OPTEE_TOOLCHAIN = "${@d.getVar('TOOLCHAIN') or 'gcc'}"
 OPTEE_COMPILER = "${@bb.utils.contains("BBFILE_COLLECTIONS", "clang-layer", "${OPTEE_TOOLCHAIN}", "gcc", d)}"
 
Signature · 1 line
2.39.3 (Apple Git-146)
Applied
#1 lore raw
Quoted 5 lines · Jon Mason

The Clang bug in OP-TEE OS has been resolved (see
https://github.com/OP-TEE/optee_os/issues/6754). Backport those patches and remove the forcing of GCC in the recipe.

Applied, thanks!

[1/1] arm/optee-os: Backport the clang fixes

      commit: 0d0b8ffac2ae7ad6cb50f4ac2b09349d89267edb

Best regards,

Signature · 1 line
Jon Mason <[email protected]>