`cmse_check_address_range` 通过编译器升级改变行为 更新:

问题描述

我使用的是带有 arm 信任区的 Cortex-M33。我的安全固件中有一个安全 api,我可以从我的非安全固件中调用它。一切都按预期工作 - 至少在我将编译器从 gcc-arm-none-eabi-7-2018-q2-update 升级gcc-arm-none-eabi-10-2020-q4-major 之前。

有问题的函数如下所示:

bool __attribute__((cmse_nonsecure_call)) (*Callback_Handler)();

__unused __attribute__((cmse_nonsecure_entry))
bool Secure_SetSomeCallbackHandler(bool (*handler)()) {
    // this cmse-check fails with the compiler in `version gcc-arm-none-eabi-10-2020-q4-major`
    // it works with the `gcc-arm-none-eabi-7-2018-q2-update` though
    handler = cmse_check_address_range(handler,4,CMSE_NONSECURE);
    if (handler == NULL) {
        return false;
    }
    Callback_Handler = handler;
    return true;
}

我使用 cmse_check_address_range 确保提供的指针确实位于非安全空间中。这适用于版本 7,但如果我使用版本 10 编译代码,则返回 NULL。我没有改变源代码或任何其他部分,只是编译器。

我检查了该函数是否有任何变化,但即使是 https://github.com/gcc-mirror/gcc/commits/master/libgcc/config/arm/cmse.c 也没有显示任何变化。

有什么变化吗?也许我没有按预期使用该函数(我需要为函数设置不同的标志吗?但话又说回来,它适用于版本 7。

更新:

解决方法

libgcc 检查 CMSE 支持时似乎是 GCC 错误。

它检查 $?对于 gcc 命令的返回值,但在 Makefile 中它应该使用 $$?相反。

diff --git a/libgcc/config/arm/t-arm b/libgcc/config/arm/t-arm
index 364f40ebe7f9..3625a2590bee 100644
--- a/libgcc/config/arm/t-arm
+++ b/libgcc/config/arm/t-arm
@@ -4,7 +4,7 @@ LIB1ASMFUNCS = _thumb1_case_sqi _thumb1_case_uqi _thumb1_case_shi \

 HAVE_CMSE:=$(findstring __ARM_FEATURE_CMSE,$(shell $(gcc_compile_bare) -dM -E - </dev/null))
 HAVE_V81M:=$(findstring armv8.1-m.main,$(gcc_compile_bare))
-ifeq ($(shell $(gcc_compile_bare) -E -mcmse - </dev/null >/dev/null 2>/dev/null; echo $?),0)
+ifeq ($(shell $(gcc_compile_bare) -E -mcmse - </dev/null >/dev/null 2>/dev/null; echo $$?),0)
 CMSE_OPTS:=-mcmse
 endif

我已报告错误:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99157