Skip to content

Commit ba3e67b

Browse files
committed
Work Around _swiftStaticArrayMetadata Alias Breakage
The alias defined here with the `.set` directive doesn't actually define a symbolic alias that the linker respects in all cases. The resulting standard library dylib _does_ contain a reference to the aliased symbol with the correct value, but the resulting variable is not actually considered relocatable by the linker. Thus, its value may not always get fixed up properly. Work around this by dropping the alias for now - directly use the type metadata for Swift.__EmptyArrayStorage instead. rdar://100288247
1 parent fa3c951 commit ba3e67b

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

lib/IRGen/GenConstant.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,11 @@ llvm::Constant *irgen::emitConstantObject(IRGenModule &IGM, ObjectInst *OI,
288288
IGM.swiftImmortalRefCount = var;
289289
}
290290
if (!IGM.swiftStaticArrayMetadata) {
291+
// HACK: This should be an alias to this symbol rather than a direct
292+
// reference.
291293
auto *var = new llvm::GlobalVariable(IGM.Module, IGM.TypeMetadataStructTy,
292294
/*constant*/ true, llvm::GlobalValue::ExternalLinkage,
293-
/*initializer*/ nullptr, "_swiftStaticArrayMetadata");
295+
/*initializer*/ nullptr, "$ss19__EmptyArrayStorageCN");
294296
IGM.swiftStaticArrayMetadata = var;
295297
}
296298
elts[0] = llvm::ConstantStruct::get(ObjectHeaderTy, {

stdlib/public/stubs/GlobalObjects.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,6 @@ __asm__(" .globl __swiftImmortalRefCount\n");
8585
#error("unsupported pointer width")
8686
#endif
8787

88-
// Static arrays can only contain trivial elements. Therefore we can reuse
89-
// the metadata of the empty array buffer. The important thing is that its
90-
// deinit is a no-op and does not actually destroy any elements.
91-
__asm__(" .globl __swiftStaticArrayMetadata\n");
92-
__asm__(".set __swiftStaticArrayMetadata, _$ss19__EmptyArrayStorageCN\n");
93-
9488
#endif
9589

9690
SWIFT_RUNTIME_STDLIB_API

0 commit comments

Comments
 (0)