Revision history   OpenPOWER Library

 5.1.5. Local function calls

The linker must resolve any local function call between functions that differ in their usage of the TOC register to point to a stub in accordance with section 2.2.1 "Function Call Linkage Protocol" of the ELFv2 ABI specification.

In particular, when a function using r2 as the TOC pointer register, as indicated by the R_PPC64_REL24 relocation on the call site, calls a function that does not preserve r2, as indicated by the st_other field in the symbol table entry for the target symbol, the linker must create a stub that ensures the TOC pointer is saved to the TOC save slot on the stack, unless the calling routine indicates that it has already performed this operation by using the R_PPC64_TOCSAVE relocation on the nop instruction following the call. In addition, the linker must modify the nop instruction following the call to an instruction that restores the TOC pointer from the TOC save slot on the stack.

In the opposite case, when a function that does not use r2 as the TOC pointer register, as indicated by the R_PPC64_REL24_NOTOC relocation on the call site, calls a function that uses the TOC pointer register, as indicated by the st_other field in the symbol table entry for the target symbol, the linker must create a stub that calls the target function's global entry point while that entry point address is present in the r12 register.