Skip to content

Commit cb67bda

Browse files
committed
[Runtime] Define got equivalents for Linux for BuiltinProtocolConformances
1 parent 96c1e47 commit cb67bda

File tree

1 file changed

+68
-8
lines changed

1 file changed

+68
-8
lines changed

stdlib/public/runtime/BuiltinProtocolConformances.cpp

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,39 @@ using StaticInfixWitness = SWIFT_CC(swift) bool(OpaqueValue *, OpaqueValue *,
3030

3131
// Elf indirect symbol references.
3232
#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+
);
3466
#endif
3567

3668
// MachO indirect symbol references.
@@ -88,15 +120,22 @@ __asm(
88120
);
89121
#endif
90122

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+
91130
// Define the conformance descriptor for tuple Equatable. We do this in
92131
// assembly to work around relative reference issues.
93132
__asm(
94133
#if defined(__ELF__)
95-
" .type __swift_tupleEquatable_private, @object\n"
134+
" .type __swift_tupleEquatable_private, " TYPE_OBJECT "\n"
96135
" .local __swift_tupleEquatable_private\n"
97136
" .comm __swift_tupleEquatable_private, 128, 16\n"
98137
" .protected " TUPLE_EQUATABLE_CONF "\n"
99-
" .type " TUPLE_EQUATABLE_CONF ", @object\n"
138+
" .type " TUPLE_EQUATABLE_CONF ", " TYPE_OBJECT "\n"
100139
" .section .rodata\n"
101140
#elif defined(__MACH__)
102141
" .zerofill __DATA, __bss, __swift_tupleEquatable_private, 128, 4\n"
@@ -225,7 +264,7 @@ __asm(
225264
__asm(
226265
#if defined(__ELF__)
227266
" .hidden \"" TUPLE_COMPARABLE_ASSOCIATEDCONFORMANCE "\"\n"
228-
" .type \"" TUPLE_COMPARABLE_ASSOCIATEDCONFORMANCE "\", @object\n"
267+
" .type \"" TUPLE_COMPARABLE_ASSOCIATEDCONFORMANCE "\", " TYPE_OBJECT "\n"
229268
" .section swift5_typeref, \"a\"\n"
230269
" .weak \"" TUPLE_COMPARABLE_ASSOCIATEDCONFORMANCE "\"\n"
231270
#elif defined(__MACH__)
@@ -251,15 +290,26 @@ __asm(
251290
#endif
252291
);
253292

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+
254304
// Define the conformance descriptor for tuple Comparable. We do this in
255305
// assembly to work around relative reference issues.
256306
__asm(
257307
#if defined(__ELF__)
258-
" .type __swift_tupleComparable_private, @object\n"
308+
" .type __swift_tupleComparable_private, " TYPE_OBJECT "\n"
259309
" .local __swift_tupleComparable_private\n"
260310
" .comm __swift_tupleComparable_private, 128, 16\n"
261311
" .protected " TUPLE_COMPARABLE_CONF "\n"
262-
" .type " TUPLE_COMPARABLE_CONF ", @object\n"
312+
" .type " TUPLE_COMPARABLE_CONF ", " TYPE_OBJECT "\n"
263313
" .section .rodata\n"
264314
#elif defined(__MACH__)
265315
" .zerofill __DATA, __bss, __swift_tupleComparable_private, 128, 4\n"
@@ -617,15 +667,25 @@ __asm(
617667
);
618668
#endif
619669

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+
620680
// Define the conformance descriptor for tuple Hashable. We do this in
621681
// assembly to work around relative reference issues.
622682
__asm(
623683
#if defined(__ELF__)
624-
" .type __swift_tupleHashable_private, @object\n"
684+
" .type __swift_tupleHashable_private, " TYPE_OBJECT "\n"
625685
" .local __swift_tupleHashable_private\n"
626686
" .comm __swift_tupleHashable_private, 128, 16\n"
627687
" .protected " TUPLE_HASHABLE_CONF "\n"
628-
" .type " TUPLE_HASHABLE_CONF ", @object\n"
688+
" .type " TUPLE_HASHABLE_CONF ", " TYPE_OBJECT "\n"
629689
" .section .rodata\n"
630690
#elif defined(__MACH__)
631691
" .zerofill __DATA, __bss, __swift_tupleHashable_private, 128, 4\n"

0 commit comments

Comments
 (0)