-fstack-check undefined reference to __gnat_stack_check

When I have added -fstack-check to an ARM cortex light project then I get the build error undefined reference to __gnat_stack_check.

It works fine on a full runtime.

Is that expected?

Can it be fixed?

It seems that I would need to implement __gnat_stack_check myself :thinking:

Would storage_error still be raised without it upon allocations using new?

I have been looking into the '83 Booch components as well as the SPARK containers and I can use bounded forms but they aren’t so easily considered as bytes due to the convenience of handling records etc… (not a huge deal). Handling storage_error the way the unbounded forms do seems pretty neat, though. Obviously it would require testing.

You might see if @simonjwright 's lighter FreeRTOS runtime has a good example of the stack checker. I don’t know for certain if he implemented it, but given the scope of the runtime, it might be likely.

1 Like

No, sorry. My usual scheme of compiling with -c -u -gnatG (to see what the compiler does when calling the runtime) fails; must be at a lower level.

Given that, the obvious scheme would be to look at one of the full (embedded ?) runtimes and see what they do,


… which I just did. Look at gnarl/s-btstch.ad[bs] in one of the embedded runtimes.

My FreeRTOS-based RTSs use FreeRTOS’s stack checking, so I’ve had no need to look into this, but I just rebuilt some Ada Drivers Library-based test code using GCC 13.2 and got this problem. I can’t immediately see where -fstack_check=specific is getting passed to the compiler (not in my GPRs, and not at first sight in ada_drivers_library.gpr either).

1 Like