@@ -30,7 +30,39 @@ using StaticInfixWitness = SWIFT_CC(swift) bool(OpaqueValue *, OpaqueValue *,
30
30
31
31
// Elf indirect symbol references.
32
32
#if defined(__ELF__)
33
- #define INDIRECT_RELREF_GOTPCREL (SYMBOL ) SYMBOL " @GOTPCREL + 1"
33
+ #define INDIRECT_RELREF_GOTPCREL (SYMBOL ) " .Lgot." SYMBOL " - . + 1"
34
+
35
+ // Helper for defining the .type on linux.
36
+ #if defined(__arm__) && !defined(__aarch64__)
37
+ #define TYPE_OBJECT " %object"
38
+ #else
39
+ #define TYPE_OBJECT " @object"
40
+ #endif
41
+
42
+ // Helper to get the pointer sized pointer to symbol and the right alignment.
43
+ #if defined(__x86_64__) || defined(__aarch64__)
44
+ #define POINTER_FOR_GOT (SYMBOL ) \
45
+ " .quad (" SYMBOL " )\n " \
46
+ " .size .Lgot." SYMBOL " , 8\n "
47
+
48
+ #define P2ALIGN_FOR_GOT " .p2align 3\n "
49
+ #else
50
+ #define POINTER_FOR_GOT (SYMBOL ) \
51
+ " .long (" SYMBOl " )\n " \
52
+ " .size .Lgot." SYMBOL " , 4\n "
53
+
54
+ #define P2ALIGN_FOR_GOT " .p2align 2\n "
55
+ #endif
56
+
57
+ // Helper to significantly reduce the amount of code necessary to create got
58
+ // equivalent variables for linux.
59
+ #define GOT_EQUIVALENT (SYMBOL ) \
60
+ __asm ( \
61
+ " .type .Lgot." SYMBOL " , " TYPE_OBJECT " \n " \
62
+ P2ALIGN_FOR_GOT \
63
+ " .Lgot." SYMBOL " :\n " \
64
+ POINTER_FOR_GOT (SYMBOL) \
65
+ );
34
66
#endif
35
67
36
68
// MachO indirect symbol references.
@@ -88,15 +120,22 @@ __asm(
88
120
);
89
121
#endif
90
122
123
+ // Define the got equivalents for the following on linux because some archs
124
+ // support relocations like @GOTPCREL, but others don't.
125
+ #if defined(__ELF__)
126
+ GOT_EQUIVALENT (EQUATABLE_DESCRIPTOR_SYMBOL)
127
+ GOT_EQUIVALENT(EQUATABLE_EE_METHOD_DESCRIPTOR)
128
+ #endif
129
+
91
130
// Define the conformance descriptor for tuple Equatable. We do this in
92
131
// assembly to work around relative reference issues.
93
132
__asm (
94
133
#if defined(__ELF__)
95
- " .type __swift_tupleEquatable_private, @object \n "
134
+ " .type __swift_tupleEquatable_private, " TYPE_OBJECT " \n "
96
135
" .local __swift_tupleEquatable_private\n "
97
136
" .comm __swift_tupleEquatable_private, 128, 16\n "
98
137
" .protected " TUPLE_EQUATABLE_CONF " \n "
99
- " .type " TUPLE_EQUATABLE_CONF " , @object \n "
138
+ " .type " TUPLE_EQUATABLE_CONF " , " TYPE_OBJECT " \n "
100
139
" .section .rodata\n "
101
140
#elif defined(__MACH__)
102
141
" .zerofill __DATA, __bss, __swift_tupleEquatable_private, 128, 4\n "
@@ -225,7 +264,7 @@ __asm(
225
264
__asm (
226
265
#if defined(__ELF__)
227
266
" .hidden \" " TUPLE_COMPARABLE_ASSOCIATEDCONFORMANCE " \"\n "
228
- " .type \" " TUPLE_COMPARABLE_ASSOCIATEDCONFORMANCE " \" , @object \n "
267
+ " .type \" " TUPLE_COMPARABLE_ASSOCIATEDCONFORMANCE " \" , " TYPE_OBJECT " \n "
229
268
" .section swift5_typeref, \" a\"\n "
230
269
" .weak \" " TUPLE_COMPARABLE_ASSOCIATEDCONFORMANCE " \"\n "
231
270
#elif defined(__MACH__)
@@ -251,15 +290,26 @@ __asm(
251
290
#endif
252
291
);
253
292
293
+ // Define the got equivalents for the following on linux because some archs
294
+ // support relocations like @GOTPCREL, but others don't.
295
+ #if defined(__ELF__)
296
+ GOT_EQUIVALENT (COMPARABLE_DESCRIPTOR_SYMBOL)
297
+ GOT_EQUIVALENT(COMPARABLE_BASE_CONFORMANCE_DESCRIPTOR)
298
+ GOT_EQUIVALENT(COMPARABLE_LT_METHOD_DESCRIPTOR)
299
+ GOT_EQUIVALENT(COMPARBALE_LTE_METHOD_DESCRIPTOR)
300
+ GOT_EQUIVALENT(COMPARABLE_GTE_METHOD_DESCRIPTOR)
301
+ GOT_EQUIVALENT(COMPARABLE_GT_METHOD_DESCRIPTOR)
302
+ #endif
303
+
254
304
// Define the conformance descriptor for tuple Comparable. We do this in
255
305
// assembly to work around relative reference issues.
256
306
__asm (
257
307
#if defined(__ELF__)
258
- " .type __swift_tupleComparable_private, @object \n "
308
+ " .type __swift_tupleComparable_private, " TYPE_OBJECT " \n "
259
309
" .local __swift_tupleComparable_private\n "
260
310
" .comm __swift_tupleComparable_private, 128, 16\n "
261
311
" .protected " TUPLE_COMPARABLE_CONF " \n "
262
- " .type " TUPLE_COMPARABLE_CONF " , @object \n "
312
+ " .type " TUPLE_COMPARABLE_CONF " , " TYPE_OBJECT " \n "
263
313
" .section .rodata\n "
264
314
#elif defined(__MACH__)
265
315
" .zerofill __DATA, __bss, __swift_tupleComparable_private, 128, 4\n "
@@ -617,15 +667,25 @@ __asm(
617
667
);
618
668
#endif
619
669
670
+ // Define the got equivalents for the following on linux because some archs
671
+ // support relocations like @GOTPCREL, but others don't.
672
+ #if defined(__ELF__)
673
+ GOT_EQUIVALENT (HASHABLE_DESCRIPTOR_SYMBOL)
674
+ GOT_EQUIVALENT(HASHABLE_BASE_CONFORMANCE_DESCRIPTOR)
675
+ GOT_EQUIVALENT(HASHABLE_HASHVALUE_METHOD_DESCRIPTOR)
676
+ GOT_EQUIVALENT(HASHABLE_HASH_METHOD_DESCRIPTOR)
677
+ GOT_EQUIVALENT(HASHABLE_RAWHASHVALUE_METHOD_DESCRIPTOR)
678
+ #endif
679
+
620
680
// Define the conformance descriptor for tuple Hashable. We do this in
621
681
// assembly to work around relative reference issues.
622
682
__asm (
623
683
#if defined(__ELF__)
624
- " .type __swift_tupleHashable_private, @object \n "
684
+ " .type __swift_tupleHashable_private, " TYPE_OBJECT " \n "
625
685
" .local __swift_tupleHashable_private\n "
626
686
" .comm __swift_tupleHashable_private, 128, 16\n "
627
687
" .protected " TUPLE_HASHABLE_CONF " \n "
628
- " .type " TUPLE_HASHABLE_CONF " , @object \n "
688
+ " .type " TUPLE_HASHABLE_CONF " , " TYPE_OBJECT " \n "
629
689
" .section .rodata\n "
630
690
#elif defined(__MACH__)
631
691
" .zerofill __DATA, __bss, __swift_tupleHashable_private, 128, 4\n "
0 commit comments