Skip to content

Commit b985817

Browse files
committed
[Runtime] Add Native Windows support for builtin conformances
Force C name mangling for Windows
1 parent 48ea837 commit b985817

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

stdlib/public/runtime/BuiltinProtocolConformances.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ using StaticInfixWitness = SWIFT_CC(swift) bool(OpaqueValue *, OpaqueValue *,
5656
// MachO doesn't support @GOT like relocations for 32 bit x86.
5757
#define INDIRECT_RELREF_GOTPCREL(SYMBOL) "L" SYMBOL "$non_lazy_ptr - . + 1"
5858
#endif
59+
#endif
5960

61+
// Windows native indirect symbol references.
62+
#if defined(_WIN32)
63+
#define INDIRECT_RELREF_GOTPCREL(SYMBOL) "__imp_" SYMBOL " - . + 1"
6064
#endif
6165

6266
//===----------------------------------------------------------------------===//
@@ -97,6 +101,10 @@ __asm(
97101
#elif defined(__MACH__)
98102
" .zerofill __DATA, __bss, __swift_tupleEquatable_private, 128, 4\n"
99103
" .section __TEXT, __const\n"
104+
#elif defined(_WIN32)
105+
" .lcomm __swift_tupleEquatable_private, 128, 16\n"
106+
" .section .rdata, \"dr\"\n"
107+
#pragma comment(linker, "/EXPORT:_swift_tupleEquatable_conf,DATA")
100108
#endif
101109
" .globl " TUPLE_EQUATABLE_CONF "\n"
102110
" .p2align 2\n"
@@ -135,7 +143,7 @@ __asm(
135143
#endif
136144
);
137145

138-
extern const ProtocolConformanceDescriptor _swift_tupleEquatable_conf;
146+
extern "C" const ProtocolConformanceDescriptor _swift_tupleEquatable_conf;
139147

140148
SWIFT_RUNTIME_EXPORT SWIFT_CC(swift)
141149
bool swift::_swift_tupleEquatable_equals(OpaqueValue *tuple1,
@@ -225,6 +233,9 @@ __asm(
225233
" .section __TEXT, __swift5_typeref\n"
226234
" .globl \"" TUPLE_COMPARABLE_ASSOCIATEDCONFORMANCE "\"\n"
227235
" .weak_definition \"" TUPLE_COMPARABLE_ASSOCIATEDCONFORMANCE "\"\n"
236+
#elif defined(_WIN32)
237+
" .section .sw5tyrf$B, \"dr\", discard, \"" TUPLE_COMPARABLE_ASSOCIATEDCONFORMANCE "\"\n"
238+
" .globl \"" TUPLE_COMPARABLE_ASSOCIATEDCONFORMANCE "\"\n"
228239
#endif
229240
" .p2align 1\n"
230241
"\"" TUPLE_COMPARABLE_ASSOCIATEDCONFORMANCE "\":\n"
@@ -253,6 +264,10 @@ __asm(
253264
#elif defined(__MACH__)
254265
" .zerofill __DATA, __bss, __swift_tupleComparable_private, 128, 4\n"
255266
" .section __TEXT, __const\n"
267+
#elif defined(_WIN32)
268+
" .lcomm __swift_tupleComparable_private, 128, 16\n"
269+
" .section .rdata, \"dr\"\n"
270+
#pragma comment(linker, "/EXPORT:_swift_tupleComparable_conf,DATA")
256271
#endif
257272
" .globl " TUPLE_COMPARABLE_CONF "\n"
258273
" .p2align 2\n"
@@ -615,6 +630,10 @@ __asm(
615630
#elif defined(__MACH__)
616631
" .zerofill __DATA, __bss, __swift_tupleHashable_private, 128, 4\n"
617632
" .section __TEXT, __const\n"
633+
#elif defined(_WIN32)
634+
" .lcomm __swift_tupleHashable_private, 128, 16\n"
635+
" .section .rdata, \"dr\"\n"
636+
#pragma comment(linker, "/EXPORT:_swift_tupleHashable_conf,DATA")
618637
#endif
619638
" .globl " TUPLE_HASHABLE_CONF "\n"
620639
" .p2align 2\n"

stdlib/public/runtime/ProtocolConformance.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,9 @@ searchInConformanceCache(const Metadata *type,
376376
return {false, nullptr};
377377
}
378378

379-
extern const ProtocolDescriptor EQUATABLE_DESCRIPTOR;
380-
extern const ProtocolDescriptor COMPARABLE_DESCRIPTOR;
381-
extern const ProtocolDescriptor HASHABLE_DESCRIPTOR;
379+
extern "C" const ProtocolDescriptor EQUATABLE_DESCRIPTOR;
380+
extern "C" const ProtocolDescriptor COMPARABLE_DESCRIPTOR;
381+
extern "C" const ProtocolDescriptor HASHABLE_DESCRIPTOR;
382382

383383
static bool tupleConformsToProtocol(const Metadata *type,
384384
const ProtocolDescriptor *protocol) {
@@ -401,9 +401,9 @@ static bool tupleConformsToProtocol(const Metadata *type,
401401
return true;
402402
}
403403

404-
extern const ProtocolConformanceDescriptor _swift_tupleEquatable_conf;
405-
extern const ProtocolConformanceDescriptor _swift_tupleComparable_conf;
406-
extern const ProtocolConformanceDescriptor _swift_tupleHashable_conf;
404+
extern "C" const ProtocolConformanceDescriptor _swift_tupleEquatable_conf;
405+
extern "C" const ProtocolConformanceDescriptor _swift_tupleComparable_conf;
406+
extern "C" const ProtocolConformanceDescriptor _swift_tupleHashable_conf;
407407

408408
static const ProtocolConformanceDescriptor *getTupleConformanceDescriptor(
409409
const ProtocolDescriptor *protocol) {

test/IRGen/builtin_conformances.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s
22

3-
// CHECK-LABEL: @_swift_tupleEquatable_conf = external global %swift.protocol_conformance_descriptor
4-
// CHECK-LABEL: @_swift_tupleComparable_conf = external global %swift.protocol_conformance_descriptor
5-
// CHECK-LABEL: @_swift_tupleHashable_conf = external global %swift.protocol_conformance_descriptor
3+
// CHECK-LABEL: @_swift_tupleEquatable_conf = external{{( dllimport)?}} global %swift.protocol_conformance_descriptor
4+
// CHECK-LABEL: @_swift_tupleComparable_conf = external{{( dllimport)?}} global %swift.protocol_conformance_descriptor
5+
// CHECK-LABEL: @_swift_tupleHashable_conf = external{{( dllimport)?}} global %swift.protocol_conformance_descriptor
66

77
struct Wrapper<T> {
88
let value: T

0 commit comments

Comments
 (0)