File: weak-binding.s

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (171 lines) | stat: -rw-r--r-- 7,335 bytes parent folder | download | duplicates (14)
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
# REQUIRES: x86
# RUN: rm -rf %t; split-file %s %t
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/libfoo.s -o %t/libfoo.o
# RUN: %lld -dylib %t/libfoo.o -o %t/libfoo.dylib
# RUN: %lld %t/test.o -L%t -lfoo -o %t/test -lSystem
# RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn --rebase --bind --lazy-bind --weak-bind \
# RUN:     --full-contents %t/test | FileCheck --check-prefixes=COMMON,CHECK %s

# RUN: %lld -fixup_chains %t/test.o -L%t -lfoo -o %t/chained -lSystem
# RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn --syms --full-contents %t/chained > %t/chained.objdump
# RUN: llvm-objdump --no-print-imm-hex --macho --dyld-info %t/chained >> %t/chained.objdump
# RUN: FileCheck %s --check-prefixes=COMMON,CHAINED < %t/chained.objdump

# CHAINED: SYMBOL TABLE:
# CHAINED: [[#%x,WEAK_INT:]] l     F __TEXT,__text _weak_internal{{$}}

# COMMON:      Contents of section __DATA_CONST,__got:
## Check that this section contains a nonzero pointer. It should point to
## _weak_external_for_gotpcrel.
# COMMON-NEXT: {{[0-9a-f]+}} {{[0-9a-f ]*[1-9a-f]+[0-9a-f ]*}}

# CHECK:      Contents of section __DATA,__la_symbol_ptr:
## Check that this section contains a nonzero pointer. It should point to
## _weak_external_fn, but we don't have a good way of testing the exact value as
## the bytes here are in little-endian order.
# CHECK-NEXT: {{[0-9a-f]+}} {{[0-9a-f ]*[1-9a-f]+[0-9a-f ]*}}

# COMMON-LABEL:      <_main>:
# COMMON-NEXT: movq  [[#]](%rip), %rax  ## 0x[[#%X,WEAK_DY_GOT_ADDR:]]
# COMMON-NEXT: movq  [[#]](%rip), %rax  ## 0x[[#%X,WEAK_EXT_GOT_ADDR:]]
# COMMON-NEXT: leaq  [[#]](%rip), %rax  ## 0x[[#%X,WEAK_INT_GOT_ADDR:]]
# COMMON-NEXT: movq  [[#]](%rip), %rax  ## 0x[[#%X,WEAK_TLV_ADDR:]]
# COMMON-NEXT: movq  [[#]](%rip), %rax  ## 0x[[#%X,WEAK_DY_TLV_ADDR:]]
# COMMON-NEXT: leaq  [[#]](%rip), %rax  ## 0x[[#%X,WEAK_INT_TLV_ADDR:]]
# COMMON-NEXT: callq 0x{{[0-9a-f]*}}
# COMMON-NEXT: callq 0x{{[0-9a-f]*}}
# COMMON-NEXT: callq 0x{{[0-9a-f]*}}

# CHECK-LABEL: Rebase table:
# CHECK:       __DATA        __la_symbol_ptr 0x[[#%x,WEAK_EXT_FN:]]  pointer

# CHECK-LABEL: Bind table:
# CHECK-DAG:   __DATA_CONST  __got           0x[[#WEAK_DY_GOT_ADDR]] pointer 0 libfoo    _weak_dysym_for_gotpcrel
# CHECK-DAG:   __DATA        __la_symbol_ptr 0x[[#%x,WEAK_DY_FN:]]   pointer 0 libfoo    _weak_dysym_fn
# CHECK-DAG:   __DATA        __data          0x[[#%x,WEAK_DY:]]      pointer 0 libfoo    _weak_dysym
# CHECK-DAG:   __DATA        __thread_vars   0x{{[0-9a-f]*}}         pointer 0 libSystem __tlv_bootstrap
# CHECK-DAG:   __DATA        __thread_vars   0x{{[0-9a-f]*}}         pointer 0 libSystem __tlv_bootstrap
# CHECK-DAG:   __DATA        __thread_ptrs   0x[[#WEAK_DY_TLV_ADDR]] pointer 0 libfoo    _weak_dysym_tlv
## Check that we don't have any other bindings
# CHECK-EMPTY:

# CHECK-LABEL: Lazy bind table:
# CHECK-NEXT:  segment section address dylib symbol
## Verify that we have no lazy bindings
# CHECK-EMPTY:

# CHECK-LABEL: Weak bind table:
# CHECK-DAG:   __DATA_CONST __got           0x[[#WEAK_DY_GOT_ADDR]]   pointer 0 _weak_dysym_for_gotpcrel
# CHECK-DAG:   __DATA_CONST __got           0x[[#WEAK_EXT_GOT_ADDR]]  pointer 0 _weak_external_for_gotpcrel
# CHECK-DAG:   __DATA       __data          0x[[#WEAK_DY]]            pointer 0 _weak_dysym
# CHECK-DAG:   __DATA       __thread_ptrs   0x[[#WEAK_TLV_ADDR]]      pointer 0 _weak_tlv
# CHECK-DAG:   __DATA       __thread_ptrs   0x[[#WEAK_DY_TLV_ADDR]]   pointer 0 _weak_dysym_tlv
# CHECK-DAG:   __DATA       __data          0x{{[0-9a-f]*}}           pointer 2 _weak_external
# CHECK-DAG:   __DATA       __la_symbol_ptr 0x[[#WEAK_DY_FN]]         pointer 0 _weak_dysym_fn
# CHECK-DAG:   __DATA       __la_symbol_ptr 0x[[#WEAK_EXT_FN]]        pointer 0 _weak_external_fn
## Check that we don't have any other bindings
# CHECK-EMPTY:

## Weak internal symbols don't get bindings
# RUN: llvm-objdump --macho --bind --lazy-bind --weak-bind %t/test | FileCheck %s --check-prefix=WEAK-INTERNAL
# WEAK-INTERNAL-NOT: _weak_internal
# WEAK-INTERNAL-NOT: _weak_internal_fn
# WEAK-INTERNAL-NOT: _weak_internal_tlv

# CHAINED-LABEL: dyld information:
# CHAINED-NEXT:  segment      section       address                  pointer type  addend dylib      symbol/vm address
# CHAINED-DAG:   __DATA_CONST __got         0x{{[0-9a-f]*}}          {{.*}}  bind  0x0    weak       _weak_external_fn
# CHAINED-DAG:   __DATA_CONST __got         0x{{[0-9a-f]*}}          {{.*}}  bind  0x0    weak       _weak_dysym_fn
# CHAINED-DAG:   __DATA_CONST __got         0x[[#WEAK_EXT_GOT_ADDR]] {{.*}}  bind  0x0    weak       _weak_external_for_gotpcrel
# CHAINED-DAG:   __DATA_CONST __got         0x[[#WEAK_DY_GOT_ADDR]]  {{.*}}  bind  0x0    weak       _weak_dysym_for_gotpcrel
# CHAINED-DAG:   __DATA       __data        0x{{[0-9a-f]*}}          {{.*}}  bind  0x0    weak       _weak_dysym
# CHAINED-DAG:   __DATA       __data        0x{{[0-9a-f]*}}          {{.*}}  bind  0x2    weak       _weak_external
# CHAINED-DAG:   __DATA       __data        0x{{[0-9a-f]*}}          {{.*}}  rebase                  0x[[#%X,WEAK_INT]]
# CHAINED-DAG:   __DATA       __thread_vars 0x{{[0-9a-f]*}}          {{.*}}  bind  0x0    libSystem  __tlv_bootstrap
# CHAINED-DAG:   __DATA       __thread_vars 0x{{[0-9a-f]*}}          {{.*}}  bind  0x0    libSystem  __tlv_bootstrap
# CHAINED-DAG:   __DATA       __thread_ptrs 0x[[#WEAK_DY_TLV_ADDR]]  {{.*}}  bind  0x0    weak       _weak_dysym_tlv
# CHAINED-DAG:   __DATA       __thread_ptrs 0x[[#WEAK_TLV_ADDR]]     {{.*}}  bind  0x0    weak       _weak_tlv
# CHAINED-EMPTY:

#--- libfoo.s

.globl _weak_dysym
.weak_definition _weak_dysym
_weak_dysym:
  .quad 0x1234

.globl _weak_dysym_for_gotpcrel
.weak_definition _weak_dysym_for_gotpcrel
_weak_dysym_for_gotpcrel:
  .quad 0x1234

.globl _weak_dysym_fn
.weak_definition _weak_dysym_fn
_weak_dysym_fn:
  ret

.section __DATA,__thread_vars,thread_local_variables

.globl _weak_dysym_tlv
.weak_definition _weak_dysym_tlv
_weak_dysym_tlv:
  .quad 0x1234

#--- test.s

.globl _main, _weak_external, _weak_external_for_gotpcrel, _weak_external_fn
.weak_definition _weak_external, _weak_external_for_gotpcrel, _weak_external_fn, _weak_internal, _weak_internal_for_gotpcrel, _weak_internal_fn

_main:
  mov _weak_dysym_for_gotpcrel@GOTPCREL(%rip), %rax
  mov _weak_external_for_gotpcrel@GOTPCREL(%rip), %rax
  mov _weak_internal_for_gotpcrel@GOTPCREL(%rip), %rax
  mov _weak_tlv@TLVP(%rip), %rax
  mov _weak_dysym_tlv@TLVP(%rip), %rax
  mov _weak_internal_tlv@TLVP(%rip), %rax
  callq _weak_dysym_fn
  callq _weak_external_fn
  callq _weak_internal_fn
  mov $0, %rax
  ret

_weak_external:
  .quad 0x1234

_weak_external_for_gotpcrel:
  .quad 0x1234

_weak_external_fn:
  ret

_weak_internal:
  .quad 0x1234

_weak_internal_for_gotpcrel:
  .quad 0x1234

_weak_internal_fn:
  ret

.data
  .quad _weak_dysym
  .quad _weak_external + 2
  .quad _weak_internal

.tbss _weak_tlv$tlv$init, 4, 2
.tbss _weak_internal_tlv$tlv$init, 4, 2

.section __DATA,__thread_vars,thread_local_variables
.globl _weak_tlv
.weak_definition  _weak_tlv, _weak_internal_tlv

_weak_tlv:
  .quad __tlv_bootstrap
  .quad 0
  .quad _weak_tlv$tlv$init

_weak_internal_tlv:
  .quad __tlv_bootstrap
  .quad 0
  .quad _weak_internal_tlv$tlv$init