]> git.ipfire.org Git - thirdparty/gcc.git/commit
ada: Port System.Stack_Usage to CHERI
authorDaniel King <dmking@adacore.com>
Thu, 12 Jun 2025 09:03:53 +0000 (10:03 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 3 Jul 2025 08:16:27 +0000 (10:16 +0200)
commitd22a59c2518e87de41add2d5daf9cf23149fb1a6
tree3f769ad2c647124355f1b79089a349e1c9db79e6
parent42225526666aeb313fa40303d122c9cf2fb75299
ada: Port System.Stack_Usage to CHERI

This unit performed integer to address conversions to calculate stack addresses
which, on a CHERI target, result in an invalid capability that triggers a
capability tag fault when dereferenced during stack filling. This patch updates
the unit to preserve addresses (capabilities) during the calculations.

The method used to determine the stack base address is also updated to CHERI.
The current method tries to get the stack base from the compiler info for the
current task. If no info is found, then as a fallback it estimates the base by
taking the address of a variable on the stack. This address is then derived to
calculate the range of addresses to fill the stack.

This fallback does not work on CHERI since taking the 'Address of a stack variable
will result in a capability with bounds restricted to that object and attempting to
write outside those bounds triggers a capability bounds fault. Instead, we add a
new function Get_Stack_Base which, on CHERI, gets the exact stack base from the
upper bound of the capability stack pointer (CSP) register. On non-CHERI platforms,
Get_Stack_Base returns the stack base from the compiler info, resulting in the same
behaviour as before on those platforms.

gcc/ada/ChangeLog:

* Makefile.rtl (LIBGNAT_TARGET_PAIRS): New unit s-tsgsba__cheri.adb for morello-freebsd.
* libgnarl/s-tassta.adb (Get_Stack_Base): New function.
* libgnarl/s-tsgsba__cheri.adb: New file for CHERI targets.
* libgnarl/s-tsgsba.adb: New default file for non-CHERI targets.
* libgnat/s-stausa.adb (Fill_Stack, Compute_Result): Port to CHERI.
* libgnat/s-stausa.ads (Initialize_Analyzer, Stack_Analyzer): Port to CHERI.
gcc/ada/Makefile.rtl
gcc/ada/libgnarl/s-tassta.adb
gcc/ada/libgnarl/s-tsgsba.adb [new file with mode: 0644]
gcc/ada/libgnarl/s-tsgsba__cheri.adb [new file with mode: 0644]
gcc/ada/libgnat/s-stausa.adb
gcc/ada/libgnat/s-stausa.ads