]> code.ossystems Code Review - meta-freescale.git/commitdiff
optee-os: backport gcc10 compilation fix from upstream
authorAndrey Zhizhikin <andrey.zhizhikin@leica-geosystems.com>
Sat, 30 May 2020 22:27:24 +0000 (22:27 +0000)
committerOtavio Salvador <otavio@ossystems.com.br>
Tue, 23 Jun 2020 11:44:02 +0000 (08:44 -0300)
Backport PR 3891 [1] from OP-TEE upstream repository. This PR solves
GCC10 compilation issue when new compiler option `outline-atomics` is
not implemented and causes the linker error.

In addition, above upstream PR solves issue with 'cc-option` macro,
which is necessary to be used to provide comptibility with GCC <10 to
disable the `outline-atomics` option, since it is present only in GCC10.

[1]: https://github.com/OP-TEE/optee_os/pull/3891

Signed-off-by: Andrey Zhizhikin <andrey.zhizhikin@leica-geosystems.com>
recipes-security/optee-imx/optee-os/0001-arm64-Disable-outline-atomics-when-compiling.patch [deleted file]
recipes-security/optee-imx/optee-os/0001-optee-os-fix-gcc10-compilation-issue-and-missing-cc-.patch [new file with mode: 0644]
recipes-security/optee-imx/optee-os_3.2.0.imx.bb

diff --git a/recipes-security/optee-imx/optee-os/0001-arm64-Disable-outline-atomics-when-compiling.patch b/recipes-security/optee-imx/optee-os/0001-arm64-Disable-outline-atomics-when-compiling.patch
deleted file mode 100644 (file)
index 605dacc..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-From ef5327d7e9d74a433b0a1f2ca2f4cf3953797350 Mon Sep 17 00:00:00 2001
-From: Andrey Zhizhikin <andrey.z@gmail.com>
-Date: Fri, 22 May 2020 21:01:15 +0000
-Subject: [PATCH] arm64: Disable outline-atomics when compiling
-
-This is a backport of upstream patch [1] with adaptions to optee-imx
-version in this layer.
-
-Original patch uses $(call cc-option,-mno-outline-atomics,) to disable
-outline-atomics which itself is broken and required 4 additional patches
-to be compatible with gcc and clang.
-
-This is resolved in the upstream PR [2], which is applicable to the
-latest upstream version.
-
-NXP fork contains old version of OP-TEE, and therefore would receive the
-update for Makefiles with new version. Since it is not required to make
-current NXP version compatible with old compiler versions on master
-branch - outline-atomics are disabled directly.
-
-Original patch description:
----------------------------------------------------------------------
-Disables the automatic detection of LSE (Large System Extension)
-instructions when compiling AArch64 code. GCC 10 implements this
-detection in libgcc using __getauxval(), which optee doesn't implement.
-This requires that the proper -mcpu is passed to GCC so that the code
-can be correctly compiled to use either LSE or load-store-exclusive.
-
-Fixes linker errors like the following when compiling with GCC 10:
-
- aarch64-linux-ld.bfd: libgcc.a(lse-init.o):
-    in function `init_have_lse_atomics':
- lse-init.c:44: undefined reference to `__getauxval'
- core/arch/arm/kernel/link.mk:38:
-    recipe for target 'build/core/all_objs.o' failed
----------------------------------------------------------------------
-
-Upstream-Status: Backport [e07c2b062846df4385542f4e4fe08b40cf7d8191]
-
-Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
-
-[1]: https://github.com/OP-TEE/optee_os/pull/3891/commits/e07c2b062846df4385542f4e4fe08b40cf7d8191
-[2]: https://github.com/OP-TEE/optee_os/pull/3891
-Signed-off-by: Andrey Zhizhikin <andrey.z@gmail.com>
----
- core/arch/arm/arm.mk | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/core/arch/arm/arm.mk b/core/arch/arm/arm.mk
-index aa101be8..8cb2b2e2 100644
---- a/core/arch/arm/arm.mk
-+++ b/core/arch/arm/arm.mk
-@@ -88,7 +88,7 @@ arm32-platform-aflags-no-hard-float ?=
- arm64-platform-cflags-no-hard-float ?= -mgeneral-regs-only
- arm64-platform-cflags-hard-float ?=
--arm64-platform-cflags-generic ?= -mstrict-align
-+arm64-platform-cflags-generic ?= -mstrict-align -mno-outline-atomics
- ifeq ($(DEBUG),1)
- # For backwards compatibility
--- 
-2.17.1
-
diff --git a/recipes-security/optee-imx/optee-os/0001-optee-os-fix-gcc10-compilation-issue-and-missing-cc-.patch b/recipes-security/optee-imx/optee-os/0001-optee-os-fix-gcc10-compilation-issue-and-missing-cc-.patch
new file mode 100644 (file)
index 0000000..509c7fb
--- /dev/null
@@ -0,0 +1,158 @@
+From 027a3b9a33fbb23e1d1d7ed6411d4d112d2a55a1 Mon Sep 17 00:00:00 2001
+From: Andrey Zhizhikin <andrey.z@gmail.com>
+Date: Sat, 30 May 2020 22:00:59 +0000
+Subject: [PATCH] optee-os: fix gcc10 compilation issue and missing cc-options
+
+Backport PR 3891 from upstream to imx fork, which addressed compilation
+failure when GCC10 is used.
+
+Additional changes ported fixed cc-options macro, which allows to query
+compiler used if the desired option exists before it could be set. This
+solves also the build issues when GCC9 is used to build this component.
+
+Upstream-Status: Backport [https://github.com/OP-TEE/optee_os/pull/3891]
+
+Signed-off-by: Andrey Zhizhikin <andrey.z@gmail.com>
+---
+ core/arch/arm/arm.mk | 21 ++++++++++++++++-----
+ core/core.mk         |  5 +----
+ mk/cc-option.mk      |  9 +++++++++
+ mk/gcc.mk            |  2 +-
+ ta/mk/ta_dev_kit.mk  |  3 +++
+ ta/ta.mk             |  1 +
+ 6 files changed, 31 insertions(+), 10 deletions(-)
+ create mode 100644 mk/cc-option.mk
+
+diff --git a/core/arch/arm/arm.mk b/core/arch/arm/arm.mk
+index aa101be8..4123d85d 100644
+--- a/core/arch/arm/arm.mk
++++ b/core/arch/arm/arm.mk
+@@ -1,3 +1,16 @@
++# Setup compiler for the core module
++ifeq ($(CFG_ARM64_core),y)
++arch-bits-core := 64
++else
++arch-bits-core := 32
++endif
++CROSS_COMPILE_core := $(CROSS_COMPILE$(arch-bits-core))
++COMPILER_core := $(COMPILER)
++include mk/$(COMPILER_core).mk
++
++# Defines the cc-option macro using the compiler set for the core module
++include mk/cc-option.mk
++
+ CFG_LTC_OPTEE_THREAD ?= y
+ # Size of emulated TrustZone protected SRAM, 448 kB.
+ # Only applicable when paging is enabled.
+@@ -88,7 +101,7 @@ arm32-platform-aflags-no-hard-float ?=
+ arm64-platform-cflags-no-hard-float ?= -mgeneral-regs-only
+ arm64-platform-cflags-hard-float ?=
+-arm64-platform-cflags-generic ?= -mstrict-align
++arm64-platform-cflags-generic := -mstrict-align $(call cc-option,-mno-outline-atomics,)
+ ifeq ($(DEBUG),1)
+ # For backwards compatibility
+@@ -117,14 +130,12 @@ core-platform-aflags += $(platform-aflags-generic)
+ core-platform-aflags += $(platform-aflags-debug-info)
+ ifeq ($(CFG_ARM64_core),y)
+-arch-bits-core := 64
+ core-platform-cppflags += $(arm64-platform-cppflags)
+ core-platform-cflags += $(arm64-platform-cflags)
+ core-platform-cflags += $(arm64-platform-cflags-generic)
+ core-platform-cflags += $(arm64-platform-cflags-no-hard-float)
+ core-platform-aflags += $(arm64-platform-aflags)
+ else
+-arch-bits-core := 32
+ core-platform-cppflags += $(arm32-platform-cppflags)
+ core-platform-cflags += $(arm32-platform-cflags)
+ core-platform-cflags += $(arm32-platform-cflags-no-hard-float)
+@@ -196,5 +207,5 @@ ta-mk-file-export-add-ta_arm64 += CROSS_COMPILE64 ?= $$(CROSS_COMPILE)_nl_
+ ta-mk-file-export-add-ta_arm64 += CROSS_COMPILE_ta_arm64 ?= $$(CROSS_COMPILE64)_nl_
+ endif
+-# Set cross compiler prefix for each submodule
+-$(foreach sm, core $(ta-targets), $(eval CROSS_COMPILE_$(sm) ?= $(CROSS_COMPILE$(arch-bits-$(sm)))))
++# Set cross compiler prefix for each TA target
++$(foreach sm, $(ta-targets), $(eval CROSS_COMPILE_$(sm) ?= $(CROSS_COMPILE$(arch-bits-$(sm)))))
+diff --git a/core/core.mk b/core/core.mk
+index c05815f3..68f45552 100644
+--- a/core/core.mk
++++ b/core/core.mk
+@@ -8,6 +8,7 @@ arch-dir       := core/arch/$(ARCH)
+ platform-dir  := $(arch-dir)/plat-$(PLATFORM)
+ include $(platform-dir)/conf.mk
+ include mk/config.mk
++# $(ARCH).mk also sets the compiler for the core module
+ include core/arch/$(ARCH)/$(ARCH).mk
+ PLATFORM_$(PLATFORM) := y
+@@ -16,10 +17,6 @@ PLATFORM_FLAVOR_$(PLATFORM_FLAVOR) := y
+ $(call cfg-depends-all,CFG_PAGED_USER_TA,CFG_WITH_PAGER CFG_WITH_USER_TA)
+ include core/crypto.mk
+-# Setup compiler for this sub module
+-COMPILER_$(sm)                ?= $(COMPILER)
+-include mk/$(COMPILER_$(sm)).mk
+-
+ cppflags$(sm) += -D__KERNEL__
+ cppflags$(sm) += -Icore/include
+diff --git a/mk/cc-option.mk b/mk/cc-option.mk
+new file mode 100644
+index 00000000..4699fbcc
+--- /dev/null
++++ b/mk/cc-option.mk
+@@ -0,0 +1,9 @@
++_cc-option-supported = $(if $(shell $(CC$(sm)) $(1) -c -x c /dev/null -o /dev/null 2>/dev/null >/dev/null || echo "Not supported"),,1)
++_cc-opt-cached-var-name = $(subst =,~,$(strip cached-cc-option-$(1)-$(subst $(empty) $(empty),,$(CC$(sm)))))
++define _cc-option
++$(eval _var_name := $(call _cc-opt-cached-var-name,$(1)))
++$(eval $(_var_name) := $(if $(filter $(origin $(_var_name)),undefined),$(call _cc-option-supported,$(1)),$($(_var_name))))
++$(if $($(_var_name)),$(1),$(2))
++endef
++cc-option = $(strip $(call _cc-option,$(1),$(2)))
++
+diff --git a/mk/gcc.mk b/mk/gcc.mk
+index 1f2c5990..c53a23b1 100644
+--- a/mk/gcc.mk
++++ b/mk/gcc.mk
+@@ -12,7 +12,7 @@ nostdinc$(sm)        := -nostdinc -isystem $(shell $(CC$(sm)) \
+                       -print-file-name=include 2> /dev/null)
+ # Get location of libgcc from gcc
+-libgcc$(sm)   := $(shell $(CC$(sm)) $(CFLAGS$(arch-bits-$(sm))) $(comp-cflags$(sm)) \
++libgcc$(sm)   := $(shell $(CC$(sm)) $(CFLAGS$(arch-bits-$(sm))) \
+                       -print-libgcc-file-name 2> /dev/null)
+ # Define these to something to discover accidental use
+diff --git a/ta/mk/ta_dev_kit.mk b/ta/mk/ta_dev_kit.mk
+index fa0bddfe..ae70ef87 100644
+--- a/ta/mk/ta_dev_kit.mk
++++ b/ta/mk/ta_dev_kit.mk
+@@ -78,6 +78,9 @@ clean:
+       @$(cmd-echo-silent) '  CLEAN   $(O)'
+       ${q}if [ -d "$(O)" ]; then $(RMDIR) $(O); fi
++include  $(ta-dev-kit-dir$(sm))/mk/$(COMPILER_$(sm)).mk
++include  $(ta-dev-kit-dir$(sm))/mk/cc-option.mk
++
+ subdirs = .
+ include  $(ta-dev-kit-dir)/mk/subdir.mk
+diff --git a/ta/ta.mk b/ta/ta.mk
+index 32353de3..9c64319d 100644
+--- a/ta/ta.mk
++++ b/ta/ta.mk
+@@ -98,6 +98,7 @@ $(foreach f, $(libfiles), \
+ # Copy .mk files
+ ta-mkfiles = mk/compile.mk mk/subdir.mk mk/gcc.mk mk/cleandirs.mk \
++      mk/cc-option.mk \
+       ta/arch/$(ARCH)/link.mk ta/arch/$(ARCH)/link_shlib.mk \
+       ta/mk/ta_dev_kit.mk
+-- 
+2.17.1
+
index aeaa9b328ab6103becd7ab2aae6ab23d1d72cbec..d2c8294028412c38aea99e80f175ab0cdc1a28e5 100644 (file)
@@ -14,7 +14,7 @@ OPTEE_OS_SRC ?= "git://source.codeaurora.org/external/imx/imx-optee-os.git;proto
 SRC_URI = "\
        ${OPTEE_OS_SRC};branch=${SRCBRANCH} \
        file://0001-scripts-update-scripts-to-use-python3.patch \
-       file://0001-arm64-Disable-outline-atomics-when-compiling.patch \
+       file://0001-optee-os-fix-gcc10-compilation-issue-and-missing-cc-.patch \
 "
 
 SRCREV = "6d99b525af752ecdaabdca6098b2564b2665f2b2"