1

I'm using a Cortex-M33 with arm trust-zone. I have a secure api inside my secure firmware that I can call from my non-secure firmware. All works as expected - at least until I upgraded my compiler from gcc-arm-none-eabi-7-2018-q2-update to gcc-arm-none-eabi-10-2020-q4-major.

The function in question looks like this:

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;
}

I make sure the supplied pointer really is in non-secure space by using cmse_check_address_range. That works for the version 7, but if I compile the code with version 10, NULL is returned. I did not change anything in the source or any other part, just the compiler.

I checked for any changes in that function, but even https://github.com/gcc-mirror/gcc/commits/master/libgcc/config/arm/cmse.c does not show any changes whatsoever.

Did anything change? Maybe I'm using the function not as intended (do I need different flags for functions? But then again, it works with version 7.

Update:

artless noise
  • 21,212
  • 6
  • 68
  • 105
kratenko
  • 7,354
  • 4
  • 36
  • 61
  • 1
    Did you compare the code that was generated for this function with the two compilers ? `gcc-arm-none-eabi-objdump --disassemble=Secure_SetSomeCallbackHandler ` should work. – Frant Feb 17 '21 at 13:25

1 Answers1

2

It seems to be a GCC bug when libgcc checking CMSE support.

It checks $? for the return value of a gcc command, but in Makefile it should use $$? instead.

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

I have reported the bug:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99157

Hsu Hau
  • 604
  • 7
  • 16