• Michael Hudson-Doyle's avatar
    cmd/compile, cmd/link, runtime: on ppc64x, maintain the TOC pointer in R2 when compiling PIC · 368d5484
    Michael Hudson-Doyle authored
    The PowerPC ISA does not have a PC-relative load instruction, which poses
    obvious challenges when generating position-independent code. The way the ELFv2
    ABI addresses this is to specify that r2 points to a per "module" (shared
    library or executable) TOC pointer. Maintaining this pointer requires
    cooperation between codegen and the system linker:
    
     * Non-leaf functions leave space on the stack at r1+24 to save the TOC pointer.
     * A call to a function that *might* have to go via a PLT stub must be followed
       by a nop instruction that the system linker can replace with "ld r1, 24(r1)"
       to restore the TOC pointer (only when dynamically linking Go code).
     * When calling a function via a function pointer, the address of the function
       must be in r12, and the first couple of instructions (the "global entry
       point") of the called function use this to derive the address of the TOC
       for the module it is in.
     * When calling a function that is implemented in the same module, the system
       linker adjusts the call to skip over the instructions mentioned above (the
       "local entry point"), assuming that r2 is already correctly set.
    
    So this changeset adds the global entry point instructions, sets the metadata so
    the system linker knows where the local entry point is, inserts code to save the
    TOC pointer at 24(r1), adds a nop after any call not known to be local and copes
    with the odd non-local code transfer in the runtime (e.g. the stuff around
    jmpdefer). It does not actually compile PIC yet.
    
    Change-Id: I7522e22bdfd2f891745a900c60254fe9e372c854
    Reviewed-on: https://go-review.googlesource.com/15967Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
    368d5484
gcc_ppc64x.S 2.95 KB