Figure A-5 shows the three-word structure defining a function descriptor. Every function that is externally visible has a function descriptor. The first word contains the address of the function. The second word contains the function's TOC pointer. The third word contains an optional environment pointer, which is useful for some programming languages. The loader initializes the function descriptors when a module is loaded for execution.
Figure A-6 shows a C fragment and the assembly code generated by a compiler for a function call by pointer and a function call by name. The instructions indicated by asterisks on the left in the assembly listing represent the function calls.
The function call by pointer uses a system routine, ptrgl, shown in Figure A-7. The "." immediately preceding the function name in the assembly listing is a linker convention indicating that the address of the function is represented by the symbol. The ptrgl routine performs a control transfer to an external function whose address is unknown at compile-link time. On entry, it assumes that GPR11 contains the address of the function descriptor for the function being called. The ptrgl routine acts as a springboard to the external function, which will return directly to the call point and not to ptrgl. A compiler may inline the code for ptrgl.
bl .glink_printf # call glink for printf lwz RTOC,20(SP) # restore TOC pointer
Figure A-8 shows the glink routine, which intercepts the call to the out-of-module function, obtains the location of the callee's function descriptor from the TOC, saves the caller's RTOC value, load RTOC with the callee's TOC address, and transfers control to the function as in the case of call by pointer. This springboard code is unique for each procedure and is generated at link time.