Skip to content

Commit 400c4f4

Browse files
committed
runtime: export two symbols used to create static constant arrays.
* `__swiftImmortalRefCount`: The bit pattern of the ref-count field of immortal objects * `__swiftStaticArrayMetadata`: The metadata used for static arrays.
1 parent 3d07dc6 commit 400c4f4

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

stdlib/public/SwiftShims/RefCount.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,13 @@ class RefCountBitsT {
417417
setField(PureSwiftDealloc, value);
418418
}
419419

420+
SWIFT_ALWAYS_INLINE
421+
static constexpr BitsType immortalBits() {
422+
return (BitsType(2) << Offsets::StrongExtraRefCountShift) |
423+
(BitsType(Offsets::IsImmortalMask)) |
424+
(BitsType(1) << Offsets::UseSlowRCShift);
425+
}
426+
420427
SWIFT_ALWAYS_INLINE
421428
RefCountBitsT() = default;
422429

@@ -431,9 +438,7 @@ class RefCountBitsT {
431438
SWIFT_ALWAYS_INLINE
432439
constexpr
433440
RefCountBitsT(Immortal_t immortal)
434-
: bits((BitsType(2) << Offsets::StrongExtraRefCountShift) |
435-
(BitsType(Offsets::IsImmortalMask)) |
436-
(BitsType(1) << Offsets::UseSlowRCShift))
441+
: bits(immortalBits())
437442
{ }
438443

439444
SWIFT_ALWAYS_INLINE

stdlib/public/stubs/GlobalObjects.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,34 @@ swift::_SwiftEmptyArrayStorage swift::_swiftEmptyArrayStorage = {
5353
}
5454
};
5555

56+
__asm__(" .globl __swiftImmortalRefCount\n");
57+
58+
#if __POINTER_WIDTH__ == 64
59+
60+
// TODO: is there a way to avoid hard coding this constant in the inline
61+
// assembly string?
62+
static_assert(swift::InlineRefCountBits::immortalBits() == 0x80000004ffffffffull,
63+
"immortal refcount bits changed: correct the inline asm below");
64+
__asm__(".set __swiftImmortalRefCount, 0x80000004ffffffff\n");
65+
66+
#elif __POINTER_WIDTH__ == 32
67+
68+
// TODO: is there a way to avoid hard coding this constant in the inline
69+
// assembly string?
70+
static_assert(swift::InlineRefCountBits::immortalBits() == 0x800004fful,
71+
"immortal refcount bits changed: correct the inline asm below");
72+
__asm__(".set __swiftImmortalRefCount, 0x800004ff\n");
73+
74+
#else
75+
#error("unsupported pointer width")
76+
#endif
77+
78+
// Static arrays can only contain trivial elements. Therefore we can reuse
79+
// the metadata of the empty array buffer. The important thing is that its
80+
// deinit is a no-op and does not actually destroy any elements.
81+
__asm__(" .globl __swiftStaticArrayMetadata\n");
82+
__asm__(".set __swiftStaticArrayMetadata, _$ss19__EmptyArrayStorageCN\n");
83+
5684
SWIFT_RUNTIME_STDLIB_API
5785
swift::_SwiftEmptyDictionarySingleton swift::_swiftEmptyDictionarySingleton = {
5886
// HeapObject header;

0 commit comments

Comments
 (0)