On PowerPC most functions require a valid TOC pointer.
This is the case because either the function itself needs to use this pointer to access the TOC or because other functions that are called from that function expect a valid TOC pointer in the register R2. The main exception to this is leaf functions that do not access the TOC since they are guaranteed not to need a valid TOC pointer.
This patch introduces a feature that will allow more functions to not require a valid TOC pointer in R2.
The feature works as follows:
- If a function requires a TOC pointer because it accesses the TOC then that will remain as it was before.
- If a funcction requires a TOC pointer only because it has a call to another function that may require a TOC pointer then we can modify the call site as follows:
Call Site Before
bl callee nop
Call Site After
The @notoc relocation tells the linker that the caller does not have a
valid TOC pointer and the nop after the call is removed because it is no
longer needed as we do not need to restore R2 after the call.
This work is done as preparation for upcoming PCRelative work to be done under the future CPU.
The support will only be added under future CPU for now.