Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix machine outlining for CHERIoT #46

Open
resistor opened this issue Nov 13, 2024 · 3 comments · May be fixed by #74
Open

Fix machine outlining for CHERIoT #46

resistor opened this issue Nov 13, 2024 · 3 comments · May be fixed by #74
Assignees

Comments

@resistor
Copy link
Collaborator

As an embedded platform, we would very much like to reap the code size benefits of MachineOutliner. However, for the moment MachineOutliner is disabled for CHERIoT, as it does not interact well with the backwards sentries used for call/return on CHERIoT. Specifically:

  • The MachineOutliner uses ct0 as a scratch register, both to materialize the outlined function address prior to the call, as well as to hold the return address for the duration of the call to the outlined function. The outlined outlined function then returns through ct0 back to the original function. Notice that this does not use cra, the normal link register.
  • In CHERIoT, any cjal or cjalr instruction that produces a link output, regardless of what register it writes to, always produces a backward sentry otype.
  • The function return variant of cjalr used in the outlined function expects a different otype based on the source register used: for cra it expects a sealed backward sentry, but for all other registers it expects a sealed forward sentry.

Unfortunately, there's no simple way to fix this. A few options are:

  • Restrict outlining to only cases where cra is dead so we can scavenge it.
  • Restrict outlining to only produce outlined functions that end in tail calls
  • Spill/restore the link register around the call to the outlined function, either to the stack or to another register that we scavenge.

The AArch64 backend actually implements all three of these strategies, as an optimization to attain minimal code size. It might make sense to port these strategies from AArch64 to RISCV in upstream, and then have CHERIoT bail out of outlining only when those strategies fail.

resistor added a commit to resistor/llvm-project-1 that referenced this issue Nov 13, 2024
@resistor
Copy link
Collaborator Author

resistor@05503ed

@resistor resistor changed the title Implement machine outlining for CHERIoT Fix machine outlining for CHERIoT Nov 13, 2024
resistor added a commit to resistor/llvm-project-1 that referenced this issue Nov 13, 2024
@davidchisnall
Copy link

sleffler pushed a commit to sleffler/llvm-project that referenced this issue Nov 14, 2024
resistor added a commit to resistor/llvm-project-1 that referenced this issue Nov 20, 2024
resistor added a commit to resistor/llvm-project-1 that referenced this issue Nov 20, 2024
@resistor
Copy link
Collaborator Author

resistor commented Nov 24, 2024

On the CheriotRTOS test suite, re-enabling MachineOutlining reduces code size by approximately 4.4%

@resistor resistor linked a pull request Dec 16, 2024 that will close this issue
@resistor resistor self-assigned this Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants