parallaxsecond / parsec

Platform AbstRaction for SECurity service
https://parsec.community/
Apache License 2.0
469 stars 67 forks source link

Parsec fails to compile for arm32 #647

Closed gowthamsk-arm closed 1 year ago

gowthamsk-arm commented 1 year ago

Parsec is compiled in yocto using meta-parsec sub-layer in the meta-security layer. The repo for this can be found here. As part of the CI pipelines, the parsec service is compiled for arm32 and arm64 machines.

The parsec service do_compile task fails for the arm32 machine in the meta-security CI pipeline.

2022-10-13 17:50:30 - INFO - Summary: 1 task failed: 2022-10-13 17:50:30 - INFO - /home/gitlab-runner/builds/CAxQb6fJ/0/akuster/meta-security/meta-parsec/recipes-parsec/parsec-service/parsec-service_1.0.0.bb:do_compile 2022-10-13 17:50:30 - INFO - Summary: There were 25 WARNING messages. 2022-10-13 17:50:30 - INFO - Summary: There was 1 ERROR message, returning a non-zero exit code. 2022-10-13 17:50:30 - ERROR - Command "/home/gitlab-runner/builds/CAxQb6fJ/0/akuster/meta-security/build$ /home/gitlab-runner/builds/CAxQb6fJ/0/akuster/meta-security/poky/bitbake/bin/bitbake -k -c build security-build-image" failed --- Error summary --- ERROR: parsec-service-1.0.0-r0 do_compile: ExecutionError('/home/gitlab-runner/builds/CAxQb6fJ/0/akuster/meta-security/build/tmp/work/cortexa15t2hf-neon-poky-linux-gnueabi/parsec-service/1.0.0-r0/temp/run.do_compile.2463197', 101, None, None) ERROR: Logfile of failure stored in: /home/gitlab-runner/builds/CAxQb6fJ/0/akuster/meta-security/build/tmp/work/cortexa15t2hf-neon-poky-linux-gnueabi/parsec-service/1.0.0-r0/temp/log.do_compile.2463197 ERROR: Task (/home/gitlab-runner/builds/CAxQb6fJ/0/akuster/meta-security/meta-parsec/recipes-parsec/parsec-service/parsec-service_1.0.0.bb:do_compile) failed with exit code '1'

Thanks to @anta5010 for reporting this.

anta5010 commented 1 year ago

the problem is with compiling mbedcrypto. something defines conflict compiler parameters:

2022-10-21 13:51:24 - INFO     - |   -- Build files have been written to: /home/gitlab-runner/builds/CAxQb6fJ/0/akuster/meta-security/build/tmp/work/cortexa15t2hf-neon-poky-linux-gnueabi/parsec-service/1.1.0-r0/build/target/armv7-poky-linux-gnueabihf/release/build/psa-crypto-sys-27138bbd20e170af/out/build
2022-10-21 13:51:24 - INFO     - |   running: "cmake" "--build" "." "--target" "install" "--config" "Release" "--"
2022-10-21 13:51:24 - INFO     - |   [  1%] Building C object library/CMakeFiles/mbedcrypto.dir/aesni.c.o
2022-10-21 13:51:24 - INFO     - |   [  3%] Building C object library/CMakeFiles/mbedcrypto.dir/asn1write.c.o
2022-10-21 13:51:24 - INFO     - |   [  3%] Building C object library/CMakeFiles/mbedcrypto.dir/aria.c.o
2022-10-21 13:51:24 - INFO     - |   [  5%] Building C object library/CMakeFiles/mbedcrypto.dir/base64.c.o
2022-10-21 13:51:24 - INFO     - |   [  5%] Building C object library/CMakeFiles/mbedcrypto.dir/aes.c.o
2022-10-21 13:51:24 - INFO     - |   [  6%] Building C object library/CMakeFiles/mbedcrypto.dir/bignum.c.o
2022-10-21 13:51:24 - INFO     - |   [  7%] Building C object library/CMakeFiles/mbedcrypto.dir/asn1parse.c.o
2022-10-21 13:51:24 - INFO     - |   [  8%] Building C object library/CMakeFiles/mbedcrypto.dir/ccm.c.o
2022-10-21 13:51:24 - INFO     - |   [ 10%] Building C object library/CMakeFiles/mbedcrypto.dir/camellia.c.o
2022-10-21 13:51:24 - INFO     - |
2022-10-21 13:51:24 - INFO     - |   --- stderr
2022-10-21 13:51:24 - INFO     - |   CMake Warning:
2022-10-21 13:51:24 - INFO     - |     Manually-specified variables were not used by the project:
2022-10-21 13:51:24 - INFO     - |
2022-10-21 13:51:24 - INFO     - |       CMAKE_ASM_COMPILER
2022-10-21 13:51:24 - INFO     - |       CMAKE_ASM_FLAGS
2022-10-21 13:51:24 - INFO     - |       CMAKE_CXX_COMPILER
2022-10-21 13:51:24 - INFO     - |       CMAKE_CXX_FLAGS
2022-10-21 13:51:24 - INFO     - |
2022-10-21 13:51:24 - INFO     - |
2022-10-21 13:51:24 - INFO     - |   cc1: error: switch '-mcpu=cortex-a15' conflicts with switch '-march=armv7-a+fp' [-Werror]
2022-10-21 13:51:24 - INFO     - |   cc1: error: switch '-mcpu=cortex-a15' conflicts with switch '-march=armv7-a+fp' [-Werror]
2022-10-21 13:51:24 - INFO     - |   cc1: error: switch '-mcpu=cortex-a15' conflicts with switch '-march=armv7-a+fp' [-Werror]
2022-10-21 13:51:24 - INFO     - |   cc1: error: switch '-mcpu=cortex-a15' conflicts with switch '-march=armv7-a+fp' [-Werror]
2022-10-21 13:51:24 - INFO     - |   cc1: error: switch '-mcpu=cortex-a15' conflicts with switch '-march=armv7-a+fp' [-Werror]
2022-10-21 13:51:24 - INFO     - |   cc1: error: switch '-mcpu=cortex-a15' conflicts with switch '-march=armv7-a+fp' [-Werror]
2022-10-21 13:51:24 - INFO     - |   cc1: error: switch '-mcpu=cortex-a15' conflicts with switch '-march=armv7-a+fp' [-Werror]
2022-10-21 13:51:24 - INFO     - |   cc1: error: switch '-mcpu=cortex-a15' conflicts with switch '-march=armv7-a+fp' [-Werror]
2022-10-21 13:51:24 - INFO     - |   cc1: error: switch '-mcpu=cortex-a15' conflicts with switch '-march=armv7-a+fp' [-Werror]
2022-10-21 13:51:24 - INFO     - |   cc1: all warnings being treated as errors
2022-10-21 13:51:24 - INFO     - |   make[2]: *** [library/CMakeFiles/mbedcrypto.dir/build.make:90: library/CMakeFiles/mbedcrypto.dir/aesni.c.o] Error 1
2022-10-21 13:51:24 - INFO     - |   make[2]: *** Waiting for unfinished jobs....
2022-10-21 13:51:24 - INFO     - |   cc1: all warnings being treated as errors
2022-10-21 13:51:24 - INFO     - |   make[2]: *** [library/CMakeFiles/mbedcrypto.dir/build.make:118: library/CMakeFiles/mbedcrypto.dir/asn1parse.c.o] Error 1
2022-10-21 13:51:24 - INFO     - |   cc1: all warnings being treated as errors
2022-10-21 13:51:24 - INFO     - |   cc1: all warnings being treated as errors
2022-10-21 13:51:24 - INFO     - |   make[2]: *** [library/CMakeFiles/mbedcrypto.dir/build.make:146: library/CMakeFiles/mbedcrypto.dir/base64.c.o] Error 1
2022-10-21 13:51:24 - INFO     - |   make[2]: *** [library/CMakeFiles/mbedcrypto.dir/build.make:132: library/CMakeFiles/mbedcrypto.dir/asn1write.c.o] Error 1
2022-10-21 13:51:24 - INFO     - |   cc1: all warnings being treated as errors
2022-10-21 13:51:24 - INFO     - |   make[2]: *** [library/CMakeFiles/mbedcrypto.dir/build.make:188: library/CMakeFiles/mbedcrypto.dir/ccm.c.o] Error 1
2022-10-21 13:51:24 - INFO     - |   cc1: all warnings being treated as errors
2022-10-21 13:51:24 - INFO     - |   make[2]: *** [library/CMakeFiles/mbedcrypto.dir/build.make:104: library/CMakeFiles/mbedcrypto.dir/aria.c.o] Error 1
2022-10-21 13:51:24 - INFO     - |   cc1: all warnings being treated as errors
2022-10-21 13:51:24 - INFO     - |   make[2]: *** [library/CMakeFiles/mbedcrypto.dir/build.make:174: library/CMakeFiles/mbedcrypto.dir/camellia.c.o] Error 1
2022-10-21 13:51:24 - INFO     - |   cc1: all warnings being treated as errors
2022-10-21 13:51:24 - INFO     - |   make[2]: *** [library/CMakeFiles/mbedcrypto.dir/build.make:76: library/CMakeFiles/mbedcrypto.dir/aes.c.o] Error 1
2022-10-21 13:51:24 - INFO     - |   cc1: all warnings being treated as errors
2022-10-21 13:51:24 - INFO     - |   make[2]: *** [library/CMakeFiles/mbedcrypto.dir/build.make:160: library/CMakeFiles/mbedcrypto.dir/bignum.c.o] Error 1
2022-10-21 13:51:24 - INFO     - |   make[1]: *** [CMakeFiles/Makefile2:166: library/CMakeFiles/mbedcrypto.dir/all] Error 2
2022-10-21 13:51:24 - INFO     - |   make: *** [Makefile:136: all] Error 2
2022-10-21 13:51:24 - INFO     - |   thread 'main' panicked at '
2022-10-21 13:51:24 - INFO     - |   command did not execute successfully, got: exit status: 2
anta5010 commented 1 year ago

After this change (using RUST_HOST_SYS instead of HOST_SYS): https://github.com/yoctoproject/poky/commit/5c45b73c8fa445b5192bb9fac1bc80b038b44c0d builds of parsec-service recipe for qemuarm machine started to fail.

This is the cargo build command before the change:

cargo build -v --target arm-poky-linux-gnueabi 

and this is after:

cargo build -v --target armv7-poky-linux-gnueabihf

The problem is that some Rust crates build dependency C libraries using "cc-rs" crate. This crate adds some compiler parameters depending on target “arch” and for “armv7" these parameters conflicts with compiler parameter defined by Yocto via TUNE_CCARGS: https://github.com/rust-lang/cc-rs/blob/53fb72c87e5769a299f1886ead831901b9c775d6/src/lib.rs#L1700

We noticed it with qemuarm, but there might be other conflicts as well. (If -Werror is used then builds would fail, otherwise it would be just a warning which is easy to miss)

To fix the issue in our parsec-service recipe we can define “CRATE_CC_NO_DEFAULTS” env variable which disables adding compiler flags in "cc-rs": https://github.com/rust-lang/cc-rs#external-configuration-via-environment-variables

diff --git a/meta-parsec/recipes-parsec/parsec-service/parsec-service_1.1.0.bb b/meta-parsec/recipes-parsec/parsec-service/parsec-service_1.1.0.bb
index 218b776..c046906 100644
--- a/meta-parsec/recipes-parsec/parsec-service/parsec-service_1.1.0.bb
+++ b/meta-parsec/recipes-parsec/parsec-service/parsec-service_1.1.0.bb
@@ -25,6 +25,14 @@ PACKAGECONFIG[TS] = "trusted-service-provider,,libts,libts"
 PARSEC_FEATURES = "${@d.getVar('PACKAGECONFIG_CONFARGS',True).strip().replace(' ', ',')}"
 CARGO_BUILD_FLAGS += " --features ${PARSEC_FEATURES}"

+# OE passes the right options via compiler cmdline via TUNE_CCARGS.
+# There might be conflicts between Yocto settings and complier settings
+# defined in cc-rs rust crate used for compiling C libraries.
+# Lets depend on Yocto settings instead of setting it explicitly in cc-rs.
+
+CRATE_CC_NO_DEFAULTS ?= "true"
+export CRATE_CC_NO_DEFAULTS
+
 export BINDGEN_EXTRA_CLANG_ARGS
 target = "${@d.getVar('TARGET_SYS',True).replace('-', ' ')}"
 BINDGEN_EXTRA_CLANG_ARGS = "${@bb.utils.contains('target', 'arm', \

But, before updating parsec-service recipes I opened a discussion with OE-Core maintainers if this setting should be automatically applied to all rust Yocto recipes. If they agree then we don't need to update our recipe.

anta5010 commented 1 year ago

Discussion on oe-core@: https://lists.openembedded.org/g/openembedded-core/topic/94539875

a bug to follow the discussion: https://bugzilla.yoctoproject.org/show_bug.cgi?id=14947

anta5010 commented 1 year ago

The bug fix has been merged into OE core. Closing the issue.