• Cherry Zhang's avatar
    cmd/link: insert trampolines for too-far jumps on ARM · 7c431cb7
    Cherry Zhang authored
    ARM direct CALL/JMP instruction has 24 bit offset, which can only
    encodes jumps within +/-32M. When the target is too far, the top
    bits get truncated and the program jumps wild.
    
    This CL detects too-far jumps and automatically insert trampolines,
    currently only internal linking on ARM.
    
    It is necessary to make the following changes to the linker:
    - Resolve direct jump relocs when assigning addresses to functions.
      this allows trampoline insertion without moving all code that
      already laid down.
    - Lay down packages in dependency order, so that when resolving a
      inter-package direct jump reloc, the target address is already
      known. Intra-package jumps are assumed never too far.
    - a linker flag -debugtramp is added for debugging trampolines:
        "-debugtramp=1 -v" prints trampoline debug message
        "-debugtramp=2"    forces all inter-package jump to use
                           trampolines (currently ARM only)
        "-debugtramp=2 -v" does both
    - Some data structures are changed for bookkeeping.
    
    On ARM, pseudo DIV/DIVU/MOD/MODU instructions now clobber R8
    (unfortunate). In the standard library there is no ARM assembly
    code that uses these instructions, and the compiler no longer emits
    them (CL 29390).
    
    all.bash passes with -debugtramp=2, except a disassembly test (this
    is unavoidable as we changed the instruction).
    
    TBD: debug info of trampolines?
    
    Fixes #17028.
    
    Change-Id: Idcce347ea7e0af77c4079041a160b2f6e114b474
    Reviewed-on: https://go-review.googlesource.com/29397Reviewed-by: 's avatarDavid Crawshaw <crawshaw@golang.org>
    Run-TryBot: Cherry Zhang <cherryyz@google.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    7c431cb7
Name
Last commit
Last update
..
asm.go Loading commit data...
l.go Loading commit data...
obj.go Loading commit data...