OP-TEE / optee_os

Trusted side of the TEE
Other
1.58k stars 1.07k forks source link

TEE core compile failed when enable the BTI feature #6926

Closed charles1129 closed 4 months ago

charles1129 commented 4 months ago

hi, TEE core compile failed, when enable the BTI feature.

CFG_CORE_BTI=y
GCC Version: 13.2
  1. The TEE core compile success, if add the gnu property. Is this correct?

    aarch64-none-linux-gnu-ld.bfd: out/arm-plat-meson/core/arch/arm/crypto/sm4_armv8a_ce_a64.o: warning: BTI turned on by -z force-bti when all inputs do not have BTI in NOTE section.
    diff --git a/core/arch/arm/crypto/sm4_armv8a_ce_a64.S b/core/arch/arm/crypto/sm4_armv8a_ce_a64.S
    index 1f96bbf84..11619172a 100644
    --- a/core/arch/arm/crypto/sm4_armv8a_ce_a64.S
    +++ b/core/arch/arm/crypto/sm4_armv8a_ce_a64.S
    @@ -1028,3 +1028,5 @@ FUNC ce_sm4_xts_decrypt , :
        frame_pop
        ret
    END_FUNC ce_sm4_xts_decrypt
    +
    +BTI(emit_aarch64_feature_1_and     GNU_PROPERTY_AARCH64_FEATURE_1_BTI)
  2. Another compile error is libgcc.a(_udivdi3.o), do you know how to fix this error?

    aarch64-none-linux-gnu-ld.bfd: /opt/arm-gnu-toolchain-13.2.Rel1-x86_64-aarch64-none-linux-gnu/bin/../lib/gcc/aarch64-none-linux-gnu/13.2.1/libgcc.a(_udivdi3.o): warning: BTI turned on by -z force-bti when all inputs do not have BTI in NOTE section.
    core/arch/arm/kernel/link.mk:192: recipe for target 'out/arm-plat-meson/core/tee.elf' failed
    make: *** [out/arm-plat-meson/core/tee.elf] Error 1

thanks

jforissier commented 4 months ago

Hi @charles1129,

hi, TEE core compile failed, when enable the BTI feature.

CFG_CORE_BTI=y
GCC Version: 13.2
1. The TEE core compile success, if add the gnu property. Is this correct?
aarch64-none-linux-gnu-ld.bfd: out/arm-plat-meson/core/arch/arm/crypto/sm4_armv8a_ce_a64.o: warning: BTI turned on by -z force-bti when all inputs do not have BTI in NOTE section.
diff --git a/core/arch/arm/crypto/sm4_armv8a_ce_a64.S b/core/arch/arm/crypto/sm4_armv8a_ce_a64.S
index 1f96bbf84..11619172a 100644
--- a/core/arch/arm/crypto/sm4_armv8a_ce_a64.S
+++ b/core/arch/arm/crypto/sm4_armv8a_ce_a64.S
@@ -1028,3 +1028,5 @@ FUNC ce_sm4_xts_decrypt , :
        frame_pop
        ret
 END_FUNC ce_sm4_xts_decrypt
+
+BTI(emit_aarch64_feature_1_and     GNU_PROPERTY_AARCH64_FEATURE_1_BTI)

That's the correct fix. Would you mind creating a pull request?

2. Another compile error is libgcc.a(_udivdi3.o), do you know how to fix this error?
aarch64-none-linux-gnu-ld.bfd: /opt/arm-gnu-toolchain-13.2.Rel1-x86_64-aarch64-none-linux-gnu/bin/../lib/gcc/aarch64-none-linux-gnu/13.2.1/libgcc.a(_udivdi3.o): warning: BTI turned on by -z force-bti when all inputs do not have BTI in NOTE section.
core/arch/arm/kernel/link.mk:192: recipe for target 'out/arm-plat-meson/core/tee.elf' failed
make: *** [out/arm-plat-meson/core/tee.elf] Error 1

This one I believe is caused by your toolchain. I don't have this error with the BTI-enabled toolchain that we use in CI (jforissier/optee_os_ci:qemu_check):

$ docker run -it --rm jforissier/optee_os_ci:qemu_check
# /usr/local/bin/aarch64-unknown-linux-uclibc-gcc --version | head -1
aarch64-unknown-linux-uclibc-gcc (crosstool-NG 1.25.0.122_aa6cc4d) 12.2.0
charles1129 commented 4 months ago

thanks for your reply.

That's the correct fix. Would you mind creating a pull request?

No problem. the pull request https://github.com/OP-TEE/optee_os/pull/6928

This one I believe is caused by your toolchain. I don't have this error with the BTI-enabled toolchain that we use in CI (jforissier/optee_os_ci:qemu_check):

The toolchain I used was downloaded from the ARM official website: https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads By the way, different versions(v13/v11/v10) of gcc have this problem. So where do you get the toolchain? And which latest version do you recommend?

jforissier commented 4 months ago

thanks for your reply.

That's the correct fix. Would you mind creating a pull request?

No problem. the pull request #6928

Thanks.

This one I believe is caused by your toolchain. I don't have this error with the BTI-enabled toolchain that we use in CI (jforissier/optee_os_ci:qemu_check):

The toolchain I used was downloaded from the ARM official website: https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads By the way, different versions(v13/v11/v10) of gcc have this problem. So where do you get the toolchain? And which latest version do you recommend?

Good questions :) unfortunately there is no suitable BTI toolchain on the Arm official download page (x86_64 host and Aarch64 target with BTI support). The toolchain that is used in OP-TEE CI is built when creating the Docker image, see: https://github.com/jforissier/docker_optee_os_ci/blob/b330a948a485622881a58125960be64c2b13f18e/Dockerfile#L34-L46.

charles1129 commented 4 months ago

Okay, Thank you