Next: Xtensa Jump Relaxation, Previous: Xtensa Branch Relaxation, Up: Xtensa Relaxation
Function calls may require relaxation because the Xtensa immediate call
instructions (CALL0
, CALL4
, CALL8
and
CALL12
) provide a PC-relative offset of only 512 Kbytes in either
direction. For larger programs, it may be necessary to use indirect
calls (CALLX0
, CALLX4
, CALLX8
and CALLX12
)
where the target address is specified in a register. The Xtensa
assembler can automatically relax immediate call instructions into
indirect call instructions. This relaxation is done by loading the
address of the called function into the callee's return address register
and then using a CALLX
instruction. So, for example:
call8 func
might be relaxed to:
.literal .L1, func l32r a8, .L1 callx8 a8
Because the addresses of targets of function calls are not generally known until link-time, the assembler must assume the worst and relax all the calls to functions in other source files, not just those that really will be out of range. The linker can recognize calls that were unnecessarily relaxed, and it will remove the overhead introduced by the assembler for those cases where direct calls are sufficient.
Call relaxation is disabled by default because it can have a negative
effect on both code size and performance, although the linker can
usually eliminate the unnecessary overhead. If a program is too large
and some of the calls are out of range, function call relaxation can be
enabled using the ‘--longcalls’ command-line option or the
longcalls
directive (see longcalls).