You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix Arm calling convention by storing arguments to stack
In the previous implementation, shecc lacked the consideration of
calling convention, so the function arguments were loaded into registers
directly when encountering a function call, regardless of the target
architecture. For the Arm architecture, if the number of arguments is
greater than 4, the additional arguments were still loaded into
registers instead of being passed to stack, causing dynamically linked
programs to execute incorrectly.
To ensure that dynamically linked programs execute correctly, these
changes introduce the following strategy:
- Each function allocates an additional 20 bytes of space using stack.
- 16 bytes are used for the extra arguments.
- 4 bytes are used to save and restore the global pointer stored in
register r12 (ip).
- Because the external call may change register r12, the compiled
program could lose the address of the global stack. Therefore,
4 bytes are allocated to preserve its value.
- If any internal function calls an external function with more than
4 arguments, the extra arguments are stored directly on stack.
- If the callee is an internal function, all arguments are still loaded
into registers.
0 commit comments