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
  205
  206
  207
  208
  209
  210
  211
  212
  213
  214
  215
  216
  217
  218
  219
  220
  221
  222
  223
  224
  225
  226
  227
  228
  229
  230
  231
  232
  233
  234
  235
  236
  237
  238
  239
  240
  241
  242
  243
  244
  245
  246
  247
  248
  249
  250
  251
  252
  253
  254
  255
  256
  257
  258
  259
  260
  261
  262
  263
  264
  265
  266
  267
  268
  269
  270
  271
  272
  273
  274
  275
  276
  277
  278
  279
  280
  281
  282
  283
  284
  285
  286
  287
  288
  289
  290
  291
  292
  293
  294
  295
  296
  297
  298
  299
  300
  301
  302
  303
  304
  305
  306
  307
  308
  309
  310
  311
  312
  313
  314
  315
  316
  317
  318
  319
  320
  321
  322
  323
  324
  325
  326
  327
  328
  329
  330
  331
  332
  333
  334
  335
  336
  337
  338
  339
  340
  341
  342
  343
  344
  345
  346
  347
  348
  349
  350
  351
  352
  353
  354
  355
  356
  357
  358
  359
  360
  361
  362
  363
  364
  365
  366
  367
  368
  369
  370
  371
  372
# RUN: ld64.lld -arch x86_64 -r %s -o %t -print_atoms | FileCheck %s \
# RUN: && ld64.lld -arch x86_64 %t -r -print_atoms -o %t2  | FileCheck %s
#
# Test parsing and writing of x86_64 data 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.
#
#_foo:
#  ret
#
#_bar:
#  ret
#
#  .section __DATA,__custom
#L1:
#  .quad 0
#
#  .data
#_d:
#  .quad   _foo
#  .quad   _foo+4
#  .quad   _foo - .
#  .quad   L1
#  .quad   L1 + 2
#  .quad   _foo - .
#  .quad   _foo + 4 - .
#  .quad   L1 - .
#  .long   _foo - .
#  .long   _foo + 4 - .
#  .long   L1 - .
#

--- !mach-o
arch:            x86_64
file-type:       MH_OBJECT
flags:           [  ]
compat-version:  0.0
current-version: 0.0
has-UUID:        false
OS:              unknown
sections:
  - segment:         __TEXT
    section:         __text
    type:            S_REGULAR
    attributes:      [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ]
    address:         0x0000000000000000
    content:         [ 0xC3, 0xC3 ]
  - segment:         __DATA
    section:         __custom
    type:            S_REGULAR
    attributes:      [  ]
    address:         0x0000000000000002
    content:         [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]
  - segment:         __DATA
    section:         __data
    type:            S_REGULAR
    attributes:      [  ]
    address:         0x000000000000000A
    content:         [
#  .quad   _foo
# No addend is needed here as we are referencing _foo directly and that is
# encoded entirely in the X86_64_RELOC_UNSIGNED
                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
#  .quad   _foo+4
# Addend of 4 is needed here as we are referencing _foo from the
# X86_64_RELOC_UNSIGNED, then the addend gives us 4 more.
                       0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
#  .quad   _foo - .
# This is the pair X86_64_RELOC_SUBTRACTOR and X86_64_RELOC_UNSIGNED.
# The subtractor references _d which is the first nonlocal label in this
# section.  The unsigned references _foo.
# Note the addend here is -16 because that is the offset from here back
# to _d.
                       0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
#  .quad   . - _foo
# This is the pair X86_64_RELOC_SUBTRACTOR and X86_64_RELOC_UNSIGNED.
# The subtractor references _d which is the first nonlocal label in this
# section.  The unsigned references _foo.
# Note the addend here is -16 because that is the offset from here back
# to _d.
                       0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
#  .quad   L1
# This is a X86_64_RELOC_UNSIGNED without extern set.
# In this case, we encode the section number for L1 in the relocation, and
# the addend here is the absolute address of the location in that section
# we want to reference.
                       0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
#  .quad   L1 + 2
# This is a X86_64_RELOC_UNSIGNED without extern set.
# In this case, we encode the section number for L1 in the relocation, and
# the addend here is the absolute address of the location in that section
# we want to reference.  We have a 4 because the section is at address 2
# and we want an offset of 2 from there.
                       0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
#  .quad   _foo - .
# This is the pair X86_64_RELOC_SUBTRACTOR and X86_64_RELOC_UNSIGNED.
# The subtractor references _d which is the first nonlocal label in this
# section.  The unsigned references _foo.
# Note the addend here is -40 because that is the offset from here back
# to _d.
                       0xD0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
#  .quad   _foo + 4 - .
# This is the pair X86_64_RELOC_SUBTRACTOR and X86_64_RELOC_UNSIGNED.
# The subtractor references _d which is the first nonlocal label in this
# section.  The unsigned references _foo.
# Note the addend here is -52.  It would have been -56 because that
# would take us from the address of this relocation back to _d.  But as
# we also add 4 for the offset, we get -52.
                       0xCC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
#  .quad   L1 - .
# This is the pair X86_64_RELOC_SUBTRACTOR and X86_64_RELOC_UNSIGNED.
# The subtractor references _d which is the first nonlocal label in this
# section.  The unsigned does not have extern set, so the relocation
# number is the section number for L1.
# Note the addend here is -62. Of that, -64 would be the offset from
# this location from _d.  The remaining 2 is the absolute address
# of L1.
                       0xC2, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
#  .long   _foo - .
# This is the pair X86_64_RELOC_SUBTRACTOR and X86_64_RELOC_UNSIGNED.
# The subtractor references _d which is the first nonlocal label in this
# section.  The unsigned references _foo.
# Note the addend here is -72 because that is the offset from here back
# to _d.
                       0xB8, 0xFF, 0xFF, 0xFF,
#  .long   . - _foo
# This is the pair X86_64_RELOC_SUBTRACTOR and X86_64_RELOC_UNSIGNED.
# The subtractor references _d which is the first nonlocal label in this
# section.  The unsigned references _foo.
# Note the addend here is -76 because that is the offset from here back
# to _d.
                       0xB4, 0xFF, 0xFF, 0xFF,
#  .long   _foo + 4 - .
# This is the pair X86_64_RELOC_SUBTRACTOR and X86_64_RELOC_UNSIGNED.
# The subtractor references _d which is the first nonlocal label in this
# section.  The unsigned references _foo.
# Note the addend here is -76.  It would have been -80 because that
# would take us from the address of this relocation back to _d.  But as
# we also add 4 for the offset, we get -76.
                       0xB4, 0xFF, 0xFF, 0xFF,
#  .long   L1 - .
# This is the pair X86_64_RELOC_SUBTRACTOR and X86_64_RELOC_UNSIGNED.
# The subtractor references _d which is the first nonlocal label in this
# section.  The unsigned does not have extern set, so the relocation
# number is the section number for L1.
# Note the addend here is -82. Of that, -84 would be the offset from
# this location from _d.  The remaining 2 is the absolute address
# of L1.
                       0xAE, 0xFF, 0xFF, 0xFF ]
    relocations:
      - offset:          0x00000054
        type:            X86_64_RELOC_SUBTRACTOR
        length:          2
        pc-rel:          false
        extern:          true
        symbol:          2
      - offset:          0x00000054
        type:            X86_64_RELOC_UNSIGNED
        length:          2
        pc-rel:          false
        extern:          false
        symbol:          2
      - offset:          0x00000050
        type:            X86_64_RELOC_SUBTRACTOR
        length:          2
        pc-rel:          false
        extern:          true
        symbol:          2
      - offset:          0x00000050
        type:            X86_64_RELOC_UNSIGNED
        length:          2
        pc-rel:          false
        extern:          true
        symbol:          0
      - offset:          0x0000004C
        type:            X86_64_RELOC_SUBTRACTOR
        length:          2
        pc-rel:          false
        extern:          true
        symbol:          0
      - offset:          0x0000004C
        type:            X86_64_RELOC_UNSIGNED
        length:          2
        pc-rel:          false
        extern:          true
        symbol:          2
      - offset:          0x00000048
        type:            X86_64_RELOC_SUBTRACTOR
        length:          2
        pc-rel:          false
        extern:          true
        symbol:          2
      - offset:          0x00000048
        type:            X86_64_RELOC_UNSIGNED
        length:          2
        pc-rel:          false
        extern:          true
        symbol:          0
      - offset:          0x00000040
        type:            X86_64_RELOC_SUBTRACTOR
        length:          3
        pc-rel:          false
        extern:          true
        symbol:          2
      - offset:          0x00000040
        type:            X86_64_RELOC_UNSIGNED
        length:          3
        pc-rel:          false
        extern:          false
        symbol:          2
      - offset:          0x00000038
        type:            X86_64_RELOC_SUBTRACTOR
        length:          3
        pc-rel:          false
        extern:          true
        symbol:          2
      - offset:          0x00000038
        type:            X86_64_RELOC_UNSIGNED
        length:          3
        pc-rel:          false
        extern:          true
        symbol:          0
      - offset:          0x00000030
        type:            X86_64_RELOC_SUBTRACTOR
        length:          3
        pc-rel:          false
        extern:          true
        symbol:          2
      - offset:          0x00000030
        type:            X86_64_RELOC_UNSIGNED
        length:          3
        pc-rel:          false
        extern:          true
        symbol:          0
      - offset:          0x00000028
        type:            X86_64_RELOC_UNSIGNED
        length:          3
        pc-rel:          false
        extern:          false
        symbol:          2
      - offset:          0x00000020
        type:            X86_64_RELOC_UNSIGNED
        length:          3
        pc-rel:          false
        extern:          false
        symbol:          2
      - offset:          0x00000018
        type:            X86_64_RELOC_SUBTRACTOR
        length:          3
        pc-rel:          false
        extern:          true
        symbol:          0
      - offset:          0x00000018
        type:            X86_64_RELOC_UNSIGNED
        length:          3
        pc-rel:          false
        extern:          true
        symbol:          2
      - offset:          0x00000010
        type:            X86_64_RELOC_SUBTRACTOR
        length:          3
        pc-rel:          false
        extern:          true
        symbol:          2
      - offset:          0x00000010
        type:            X86_64_RELOC_UNSIGNED
        length:          3
        pc-rel:          false
        extern:          true
        symbol:          0
      - offset:          0x00000008
        type:            X86_64_RELOC_UNSIGNED
        length:          3
        pc-rel:          false
        extern:          true
        symbol:          0
      - offset:          0x00000000
        type:            X86_64_RELOC_UNSIGNED
        length:          3
        pc-rel:          false
        extern:          true
        symbol:          0
local-symbols:
  - name:            _foo
    type:            N_SECT
    sect:            1
    value:           0x0000000000000000
  - name:            _bar
    type:            N_SECT
    sect:            1
    value:           0x0000000000000001
  - name:            _d
    type:            N_SECT
    sect:            3
    value:           0x000000000000000A
page-size:       0x00000000
...


# CHECK:defined-atoms:
# CHECK:  - name:            _d
# CHECK:    type:            data
# CHECK:    content:         [ 00, 00, 00, 00, 00, 00, 00, 00, 04, 00, 00, 00,
# CHECK:                       00, 00, 00, 00, F0, FF, FF, FF, FF, FF, FF, FF,
# CHECK:                       18, 00, 00, 00, 00, 00, 00, 00, {{..}}, {{..}}, 00, 00,
# CHECK:                       00, 00, 00, 00, {{..}}, {{..}}, 00, 00, 00, 00, 00, 00,
# CHECK:                       D0, FF, FF, FF, FF, FF, FF, FF, CC, FF, FF, FF,
# CHECK:                       FF, FF, FF, FF, {{..}}, {{..}}, {{..}}, {{..}}, {{..}}, {{..}}, {{..}}, {{..}},
# CHECK:                       B8, FF, FF, FF, B4, FF, FF, FF, B4, FF, FF, FF,
# CHECK:                       {{..}}, {{..}}, {{..}}, {{..}} ]
# CHECK:    dead-strip:      never
# CHECK:    references:
# CHECK:      - kind:            pointer64
# CHECK:        offset:          0
# CHECK:        target:          _foo
# CHECK:      - kind:            pointer64
# CHECK:        offset:          8
# CHECK:        target:          _foo
# CHECK:        addend:          4
# CHECK:      - kind:            delta64
# CHECK:        offset:          16
# CHECK:        target:          _foo
# CHECK:      - kind:            negDelta64
# CHECK:        offset:          24
# CHECK:        target:          _foo
# CHECK:      - kind:            pointer64Anon
# CHECK:        offset:          32
# CHECK:        target:          L003
# CHECK:      - kind:            pointer64Anon
# CHECK:        offset:          40
# CHECK:        target:          L003
# CHECK:        addend:          2
# CHECK:      - kind:            delta64
# CHECK:        offset:          48
# CHECK:        target:          _foo
# CHECK:      - kind:            delta64
# CHECK:        offset:          56
# CHECK:        target:          _foo
# CHECK:        addend:          4
# CHECK:      - kind:            delta64Anon
# CHECK:        offset:          64
# CHECK:        target:          L003
# CHECK:      - kind:            delta32
# CHECK:        offset:          72
# CHECK:        target:          _foo
# CHECK:      - kind:            negDelta32
# CHECK:        offset:          76
# CHECK:        target:          _foo
# CHECK:      - kind:            delta32
# CHECK:        offset:          80
# CHECK:        target:          _foo
# CHECK:        addend:          4
# CHECK:      - kind:            delta32Anon
# CHECK:        offset:          84
# CHECK:        target:          L003
# CHECK:  - name:            _foo
# CHECK:    content:         [ C3 ]
# CHECK:    dead-strip:      never
# CHECK:  - name:            _bar
# CHECK:    content:         [ C3 ]
# CHECK:    dead-strip:      never
# CHECK:  - ref-name:        L003
# CHECK:    type:            unknown
# CHECK:    content:         [ 00, 00, 00, 00, 00, 00, 00, 00 ]
# CHECK:    section-choice:  custom-required
# CHECK:    section-name:    '__DATA/__custom'
# CHECK:    dead-strip:      never