reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
  161
  162
  163
  164
  165
  166
  167
  168
  169
  170
  171
  172
  173
  174
  175
  176
  177
  178
  179
  180
  181
  182
  183
  184
  185
  186
  187
  188
  189
  190
  191
  192
  193
  194
  195
  196
  197
  198
  199
  200
  201
  202
  203
  204
# RUN: ld64.lld -arch x86_64 -r -print_atoms %s -o %t | FileCheck %s \
# RUN:  && ld64.lld -arch x86_64 -r -print_atoms %t -o %t2 | FileCheck %s
#
# Test parsing and writing of x86_64 text relocations.
#
# The first step tests if the supplied mach-o file is parsed into the correct
# set of references.  The second step verifies relocations can be round-tripped
# by writing to a new .o file, then parsing that file which should result in
# the same references.
#
#_test:
#  call  _foo
#  call  _foo+4
#  movq  _foo@GOTPCREL(%rip), %rax
#  pushq _foo@GOTPCREL(%rip)
#  movl  _foo(%rip), %eax
#  movl  _foo+4(%rip), %eax
#  movb  $0x12, _foo(%rip)
#  movw  $0x1234, _foo(%rip)
#  movl  $0x12345678, _foo(%rip)
#  movl  L2(%rip), %eax
#  movb  $0x12, L2(%rip)
#  movw  $0x1234, L2(%rip)
#  movl  $0x12345678, L2(%rip)
#
#  .data
#L2: .long 0


--- !mach-o
arch:            x86_64
file-type:       MH_OBJECT
flags:           [  ]
sections:
  - segment:         __TEXT
    section:         __text
    type:            S_REGULAR
    attributes:      [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ]
    address:         0x0000000000000000
    content:         [ 0xE8, 0x00, 0x00, 0x00, 0x00, 0xE8, 0x04, 0x00,
                       0x00, 0x00, 0x48, 0x8B, 0x05, 0x04, 0x00, 0x00,
                       0x00, 0xFF, 0x35, 0x04, 0x00, 0x00, 0x00, 0x8B,
                       0x05, 0x00, 0x00, 0x00, 0x00, 0x8B, 0x05, 0x04,
                       0x00, 0x00, 0x00, 0xC6, 0x05, 0xFF, 0xFF, 0xFF,
                       0xFF, 0x12, 0x66, 0xC7, 0x05, 0xFE, 0xFF, 0xFF,
                       0xFF, 0x34, 0x12, 0xC7, 0x05, 0xFC, 0xFF, 0xFF,
                       0xFF, 0x78, 0x56, 0x34, 0x12, 0x8B, 0x05, 0x1A,
                       0x00, 0x00, 0x00, 0xc6, 0x05, 0x13, 0x00, 0x00,
		       0x00, 0x12, 0x66, 0xc7, 0x05, 0x0a, 0x00, 0x00,
		       0x00, 0x34, 0x12, 0xc7, 0x05, 0x00, 0x00, 0x00,
		       0x00, 0x78, 0x56, 0x34, 0x12 ]
    relocations:
      - offset:          0x00000055
        type:            X86_64_RELOC_SIGNED_4
        length:          2
        pc-rel:          true
        extern:          false
        symbol:          2
      - offset:          0x0000004d
        type:            X86_64_RELOC_SIGNED_2
        length:          2
        pc-rel:          true
        extern:          false
        symbol:          2
      - offset:          0x00000045
        type:            X86_64_RELOC_SIGNED_1
        length:          2
        pc-rel:          true
        extern:          false
        symbol:          2
      - offset:          0x0000003F
        type:            X86_64_RELOC_SIGNED
        length:          2
        pc-rel:          true
        extern:          false
        symbol:          2
      - offset:          0x00000035
        type:            X86_64_RELOC_SIGNED_4
        length:          2
        pc-rel:          true
        extern:          true
        symbol:          1
      - offset:          0x0000002D
        type:            X86_64_RELOC_SIGNED_2
        length:          2
        pc-rel:          true
        extern:          true
        symbol:          1
      - offset:          0x00000025
        type:            X86_64_RELOC_SIGNED_1
        length:          2
        pc-rel:          true
        extern:          true
        symbol:          1
      - offset:          0x0000001F
        type:            X86_64_RELOC_SIGNED
        length:          2
        pc-rel:          true
        extern:          true
        symbol:          1
      - offset:          0x00000019
        type:            X86_64_RELOC_SIGNED
        length:          2
        pc-rel:          true
        extern:          true
        symbol:          1
      - offset:          0x00000013
        type:            X86_64_RELOC_GOT
        length:          2
        pc-rel:          true
        extern:          true
        symbol:          1
      - offset:          0x0000000D
        type:            X86_64_RELOC_GOT_LOAD
        length:          2
        pc-rel:          true
        extern:          true
        symbol:          1
      - offset:          0x00000006
        type:            X86_64_RELOC_BRANCH
        length:          2
        pc-rel:          true
        extern:          true
        symbol:          1
      - offset:          0x00000001
        type:            X86_64_RELOC_BRANCH
        length:          2
        pc-rel:          true
        extern:          true
        symbol:          1
  - segment:         __DATA
    section:         __data
    type:            S_REGULAR
    attributes:      [  ]
    address:         0x000000000000005D
    content:         [ 0x00, 0x00, 0x00, 0x00 ]
local-symbols:
  - name:            _test
    type:            N_SECT
    sect:            1
    value:           0x0000000000000000
undefined-symbols:
  - name:            _foo
    type:            N_UNDF
    scope:           [ N_EXT ]
    value:           0x0000000000000000
...

# CHECK: defined-atoms:
# CHECK:   - ref-name:        [[LABEL:L[0-9]+]]
# CHECK:     type:            data
# CHECK:     content:         [ 00, 00, 00, 00 ]
# CHECK:  - name:            _test
# CHECK:    references:
# CHECK:      - kind:            branch32
# CHECK:        offset:          1
# CHECK:        target:          _foo
# CHECK:      - kind:            branch32
# CHECK:        offset:          6
# CHECK:        target:          _foo
# CHECK:        addend:          4
# CHECK:      - kind:            ripRel32GotLoad
# CHECK:        offset:          13
# CHECK:        target:          _foo
# CHECK:        addend:          4
# CHECK:      - kind:            ripRel32Got
# CHECK:        offset:          19
# CHECK:        target:          _foo
# CHECK:        addend:          4
# CHECK:      - kind:            ripRel32
# CHECK:        offset:          25
# CHECK:        target:          _foo
# CHECK:      - kind:            ripRel32
# CHECK:        offset:          31
# CHECK:        target:          _foo
# CHECK:        addend:          4
# CHECK:      - kind:            ripRel32Minus1
# CHECK:        offset:          37
# CHECK:        target:          _foo
# CHECK-NOT:    addend:
# CHECK:      - kind:            ripRel32Minus2
# CHECK:        offset:          45
# CHECK:        target:          _foo
# CHECK-NOT:    addend:
# CHECK:      - kind:            ripRel32Minus4
# CHECK:        offset:          53
# CHECK:        target:          _foo
# CHECK-NOT:    addend:
# CHECK:      - kind:            ripRel32Anon
# CHECK:        offset:          63
# CHECK:        target:          [[LABEL]]
# CHECK-NOT:    addend:
# CHECK:      - kind:            ripRel32Minus1Anon
# CHECK:        offset:          69
# CHECK:        target:          [[LABEL]]
# CHECK-NOT:    addend:
# CHECK:      - kind:            ripRel32Minus2Anon
# CHECK:        offset:          77
# CHECK:        target:          [[LABEL]]
# CHECK-NOT:    addend:
# CHECK:      - kind:            ripRel32Minus4Anon
# CHECK:        offset:          85
# CHECK:        target:          [[LABEL]]
# CHECK-NOT:    addend: