...

Text file src/cmd/go/testdata/script/trampoline_reuse_test.txt

Documentation: cmd/go/testdata/script

     1# Verify PPC64 does not reuse a trampoline which is too far away.
     2# This tests an edge case where the direct call relocation addend should
     3# be ignored when computing the distance from the direct call to the
     4# already placed trampoline
     5[short] skip
     6[!GOARCH:ppc64] [!GOARCH:ppc64le] skip
     7[GOOS:aix] skip
     8
     9# Note, this program does not run. Presumably, 'DWORD $0' is simpler to
    10# assembly 2^26 or so times.
    11#
    12# We build something which should be laid out as such:
    13#
    14# bar.Bar
    15# main.Func1
    16# bar.Bar+400-tramp0
    17# main.BigAsm
    18# main.Func2
    19# bar.Bar+400-tramp1
    20#
    21# bar.Bar needs to be placed far enough away to generate relocations
    22# from main package calls. and main.Func1 and main.Func2 are placed
    23# a bit more than the direct call limit apart, but not more than 0x400
    24# bytes beyond it (to verify the reloc calc).
    25
    26go build
    27
    28-- go.mod --
    29
    30module foo
    31
    32go 1.19
    33
    34-- main.go --
    35
    36package main
    37
    38import "foo/bar"
    39
    40func Func1()
    41
    42func main() {
    43        Func1()
    44        bar.Bar2()
    45}
    46
    47-- foo.s --
    48
    49TEXT main·Func1(SB),0,$0-0
    50        CALL bar·Bar+0x400(SB)
    51        CALL main·BigAsm(SB)
    52// A trampoline will be placed here to bar.Bar
    53
    54// This creates a gap sufficiently large to prevent trampoline reuse
    55#define NOP64 DWORD $0; DWORD $0; DWORD $0; DWORD $0; DWORD $0; DWORD $0; DWORD $0; DWORD $0;
    56#define NOP256 NOP64 NOP64 NOP64 NOP64
    57#define NOP2S10 NOP256 NOP256 NOP256 NOP256
    58#define NOP2S12 NOP2S10 NOP2S10 NOP2S10 NOP2S10
    59#define NOP2S14 NOP2S12 NOP2S12 NOP2S12 NOP2S12
    60#define NOP2S16 NOP2S14 NOP2S14 NOP2S14 NOP2S14
    61#define NOP2S18 NOP2S16 NOP2S16 NOP2S16 NOP2S16
    62#define NOP2S20 NOP2S18 NOP2S18 NOP2S18 NOP2S18
    63#define NOP2S22 NOP2S20 NOP2S20 NOP2S20 NOP2S20
    64#define NOP2S24 NOP2S22 NOP2S22 NOP2S22 NOP2S22
    65#define BIGNOP NOP2S24 NOP2S24
    66TEXT main·BigAsm(SB),0,$0-0
    67        // Fill to the direct call limit so Func2 must generate a new trampoline.
    68        // As the implicit trampoline above is just barely unreachable.
    69        BIGNOP
    70        MOVD $main·Func2(SB), R3
    71
    72TEXT main·Func2(SB),0,$0-0
    73        CALL bar·Bar+0x400(SB)
    74// Another trampoline should be placed here.
    75
    76-- bar/bar.s --
    77
    78#define NOP64 DWORD $0; DWORD $0; DWORD $0; DWORD $0; DWORD $0; DWORD $0; DWORD $0; DWORD $0;
    79#define NOP256 NOP64 NOP64 NOP64 NOP64
    80#define NOP2S10 NOP256 NOP256 NOP256 NOP256
    81#define NOP2S12 NOP2S10 NOP2S10 NOP2S10 NOP2S10
    82#define NOP2S14 NOP2S12 NOP2S12 NOP2S12 NOP2S12
    83#define NOP2S16 NOP2S14 NOP2S14 NOP2S14 NOP2S14
    84#define NOP2S18 NOP2S16 NOP2S16 NOP2S16 NOP2S16
    85#define NOP2S20 NOP2S18 NOP2S18 NOP2S18 NOP2S18
    86#define NOP2S22 NOP2S20 NOP2S20 NOP2S20 NOP2S20
    87#define NOP2S24 NOP2S22 NOP2S22 NOP2S22 NOP2S22
    88#define BIGNOP NOP2S24 NOP2S24 NOP2S10
    89// A very big not very interesting function.
    90TEXT bar·Bar(SB),0,$0-0
    91        BIGNOP
    92
    93-- bar/bar.go --
    94
    95package bar
    96
    97func Bar()
    98
    99func Bar2() {
   100}

View as plain text