Skip to content

Commit b78da2d

Browse files
committed
[Runtime] Add stubs for indirect symbols on armv7/s, add missing newlines for ELF directives, fix compile crash for arm64e
1 parent 7a6ea99 commit b78da2d

File tree

1 file changed

+83
-17
lines changed

1 file changed

+83
-17
lines changed

stdlib/public/runtime/BuiltinProtocolConformances.cpp

Lines changed: 83 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ using StaticInfixWitness = SWIFT_CC(swift) bool(OpaqueValue *, OpaqueValue *,
3333
#elif defined(__MACH__)
3434
#if defined(__aarch64__)
3535
#define INDIRECT_RELREF_GOTPCREL(SYMBOL) SYMBOL "@GOT - . + 1"
36+
#elif defined(__arm__)
37+
// Darwin doesn't support @GOT like syntax for 32 bit ARM.
38+
#define INDIRECT_RELREF_GOTPCREL(SYMBOL) "L" SYMBOL "$non_lazy_ptr - . + 1"
3639
#else
3740
#define INDIRECT_RELREF_GOTPCREL(SYMBOL) SYMBOL "@GOTPCREL + 5"
3841
#endif
@@ -42,6 +45,22 @@ using StaticInfixWitness = SWIFT_CC(swift) bool(OpaqueValue *, OpaqueValue *,
4245
// Tuple Equatable Conformance
4346
//===----------------------------------------------------------------------===//
4447

48+
// For 32 bit ARM (specifically armv7 and armv7s for iphoneos), emit non-lazy
49+
// pointer stubs to indirectly reference. Darwin doesn't support @GOT syntax for
50+
// ARM.
51+
#if defined(__MACH__) && defined(__arm__) && !defined(__aarch64__)
52+
__asm(
53+
" .section __DATA, __nl_symbol_ptr, non_lazy_symbol_pointers\n"
54+
" .p2align 2\n"
55+
"L" EQUATABLE_DESCRIPTOR_SYMBOL "$non_lazy_ptr:\n"
56+
" .indirect_symbol " EQUATABLE_DESCRIPTOR_SYMBOL "\n"
57+
" .long 0\n"
58+
"L" EQUATABLE_EE_METHOD_DESCRIPTOR "$non_lazy_ptr:\n"
59+
" .indirect_symbol " EQUATABLE_EE_METHOD_DESCRIPTOR "\n"
60+
" .long 0\n"
61+
);
62+
#endif
63+
4564
// Define the conformance descriptor for tuple Equatable. We do this in
4665
// assembly to work around relative reference issues.
4766
__asm(
@@ -137,14 +156,42 @@ bool swift::_swift_tupleEquatable_equals(OpaqueValue *tuple1,
137156
// Tuple Comparable Conformance
138157
//===----------------------------------------------------------------------===//
139158

159+
// For 32 bit ARM (specifically armv7 and armv7s for iphoneos), emit non-lazy
160+
// pointer stubs to indirectly reference. Darwin doesn't support @GOT syntax for
161+
// ARM.
162+
#if defined(__MACH__) && defined(__arm__) && !defined(__aarch64__)
163+
__asm(
164+
" .section __DATA, __nl_symbol_ptr, non_lazy_symbol_pointers\n"
165+
" .p2align 2\n"
166+
"L" COMPARABLE_DESCRIPTOR_SYMBOL "$non_lazy_ptr:\n"
167+
" .indirect_symbol " COMPARABLE_DESCRIPTOR_SYMBOL "\n"
168+
" .long 0\n"
169+
"L" COMPARABLE_BASE_CONFORMANCE_DESCRIPTOR "$non_lazy_ptr:\n"
170+
" .indirect_symbol " COMPARABLE_BASE_CONFORMANCE_DESCRIPTOR "\n"
171+
" .long 0\n"
172+
"L" COMPARABLE_LT_METHOD_DESCRIPTOR "$non_lazy_ptr:\n"
173+
" .indirect_symbol " COMPARABLE_LT_METHOD_DESCRIPTOR "\n"
174+
" .long 0\n"
175+
"L" COMPARBALE_LTE_METHOD_DESCRIPTOR "$non_lazy_ptr:\n"
176+
" .indirect_symbol " COMPARBALE_LTE_METHOD_DESCRIPTOR "\n"
177+
" .long 0\n"
178+
"L" COMPARABLE_GTE_METHOD_DESCRIPTOR "$non_lazy_ptr:\n"
179+
" .indirect_symbol " COMPARABLE_GTE_METHOD_DESCRIPTOR "\n"
180+
" .long 0\n"
181+
"L" COMPARABLE_GT_METHOD_DESCRIPTOR "$non_lazy_ptr:\n"
182+
" .indirect_symbol " COMPARABLE_GT_METHOD_DESCRIPTOR "\n"
183+
" .long 0\n"
184+
);
185+
#endif
186+
140187
// Define the associated conformance structure for tuple Comparable. We do this
141188
// in assembly to work around relative reference issues.
142189
__asm(
143190
#if defined(__ELF__)
144191
" .hidden \"" TUPLE_COMPARABLE_ASSOCIATEDCONFORMANCE "\"\n"
145192
" .type \"" TUPLE_COMPARABLE_ASSOCIATEDCONFORMANCE "\", @object\n"
146-
" .section swift5_typeref, \"a\""
147-
" .weak \"" TUPLE_COMPARABLE_ASSOCIATEDCONFORMANCE "\""
193+
" .section swift5_typeref, \"a\"\n"
194+
" .weak \"" TUPLE_COMPARABLE_ASSOCIATEDCONFORMANCE "\"\n"
148195
#elif defined(__MACH__)
149196
" .private_extern \"" TUPLE_COMPARABLE_ASSOCIATEDCONFORMANCE "\"\n"
150197
" .section __TEXT, __swift5_typeref\n"
@@ -497,6 +544,31 @@ bool swift::_swift_tupleComparable_greaterThan(OpaqueValue *tuple1,
497544
// Tuple Hashable Conformance
498545
//===----------------------------------------------------------------------===//
499546

547+
// For 32 bit ARM (specifically armv7 and armv7s for iphoneos), emit non-lazy
548+
// pointer stubs to indirectly reference. Darwin doesn't support @GOT syntax for
549+
// ARM.
550+
#if defined(__MACH__) && defined(__arm__) && !defined(__aarch64__)
551+
__asm(
552+
" .section __DATA, __nl_symbol_ptr, non_lazy_symbol_pointers\n"
553+
" .p2align 2\n"
554+
"L" HASHABLE_DESCRIPTOR_SYMBOL "$non_lazy_ptr:\n"
555+
" .indirect_symbol " HASHABLE_DESCRIPTOR_SYMBOL "\n"
556+
" .long 0\n"
557+
"L" HASHABLE_BASE_CONFORMANCE_DESCRIPTOR "$non_lazy_ptr:\n"
558+
" .indirect_symbol " HASHABLE_BASE_CONFORMANCE_DESCRIPTOR "\n"
559+
" .long 0\n"
560+
"L" HASHABLE_HASHVALUE_METHOD_DESCRIPTOR "$non_lazy_ptr:\n"
561+
" .indirect_symbol " HASHABLE_HASHVALUE_METHOD_DESCRIPTOR "\n"
562+
" .long 0\n"
563+
"L" HASHABLE_HASH_METHOD_DESCRIPTOR "$non_lazy_ptr:\n"
564+
" .indirect_symbol " HASHABLE_HASH_METHOD_DESCRIPTOR "\n"
565+
" .long 0\n"
566+
"L" HASHABLE_RAWHASHVALUE_METHOD_DESCRIPTOR "$non_lazy_ptr:\n"
567+
" .indirect_symbol " HASHABLE_RAWHASHVALUE_METHOD_DESCRIPTOR "\n"
568+
" .long 0\n"
569+
);
570+
#endif
571+
500572
// Define the conformance descriptor for tuple Hashable. We do this in
501573
// assembly to work around relative reference issues.
502574
__asm(
@@ -570,22 +642,19 @@ __asm(
570642
#endif
571643
);
572644

573-
// These are all function values that we reinterpret later.
574-
extern void *SWIFT_HASHVALUE_FUNC;
575-
extern void *SWIFT_HASHER_COMBINE_FUNC;
645+
extern "C" SWIFT_CC(swift)
646+
intptr_t SWIFT_HASHVALUE_FUNC(OpaqueValue *value, Metadata *Self,
647+
void *witnessTable);
576648

577-
using HashValueFn = SWIFT_CC(swift) intptr_t(OpaqueValue *value, Metadata *Self,
578-
void *witnessTable);
579-
using HasherCombineFn = SWIFT_CC(swift) void(OpaqueValue *value,
580-
const Metadata *Self,
581-
const WitnessTable *witnessTable,
582-
SWIFT_CONTEXT OpaqueValue *hasher);
649+
extern "C" SWIFT_CC(swift)
650+
void SWIFT_HASHER_COMBINE_FUNC(OpaqueValue *value, const Metadata *Self,
651+
const WitnessTable *witnessTable,
652+
SWIFT_CONTEXT OpaqueValue *hasher);
583653

584654
SWIFT_RUNTIME_EXPORT SWIFT_CC(swift)
585655
intptr_t _swift_tupleHashable_hashValue(SWIFT_CONTEXT OpaqueValue *tuple,
586656
Metadata *Self, void *witnessTable) {
587-
auto _hashValue = reinterpret_cast<HashValueFn *>(&SWIFT_HASHVALUE_FUNC);
588-
return _hashValue(tuple, Self, witnessTable);
657+
return SWIFT_HASHVALUE_FUNC(tuple, Self, witnessTable);
589658
}
590659

591660
SWIFT_RUNTIME_EXPORT SWIFT_CC(swift)
@@ -606,11 +675,8 @@ void _swift_tupleHashable_hash(OpaqueValue *hasher,
606675
auto value = reinterpret_cast<OpaqueValue *>(
607676
reinterpret_cast<char *>(tuple) + elt.Offset);
608677

609-
auto hasherCombine =
610-
reinterpret_cast<HasherCombineFn *>(&SWIFT_HASHER_COMBINE_FUNC);
611-
612678
// Call the combine function on the hasher for this element value and we're
613679
// done!
614-
hasherCombine(value, elt.Type, conformance, hasher);
680+
SWIFT_HASHER_COMBINE_FUNC(value, elt.Type, conformance, hasher);
615681
}
616682
}

0 commit comments

Comments
 (0)