Magic Metadata Symbol In Stubs

I’m currently looking at pushing the storage of the empty Dictionary singleton into rodata, using Array as a reference. Most things are pretty straightforward, except the symbol for the metadata for _EmptyArrayStorage that’s hardcoded in GlobalObjects.cpp:

extern "C" ClassMetadata _TMCs18_EmptyArrayStorage;

How was the _TMCs18 mangle discovered? Does anything need to be done to ensure this is stable? Blindly applying that prefix to the Dictionary class sadly just leads to a linker error. For reference, the current decl for Dictionary is (after gyb expansion):

@objc_non_lazy_realization
internal class _RawNativeDictionaryStorage:
  _SwiftNativeNSDictionary, _NSDictionaryCore

Related: is it completely busted that GlobalObjects.[h/cpp] is blatantly assuming the layout of _EmptyArrayStorage? The doesn’t seem to be any @_fixed_layout annotation on it or its base classes.

I’m currently looking at pushing the storage of the empty Dictionary singleton into rodata, using Array as a reference. Most things are pretty straightforward, except the symbol for the metadata for _EmptyArrayStorage that’s hardcoded in GlobalObjects.cpp:

extern "C" ClassMetadata _TMCs18_EmptyArrayStorage;

How was the _TMCs18 mangle discovered? Does anything need to be done to ensure this is stable? Blindly applying that prefix to the Dictionary class sadly just leads to a linker error. For reference, the current decl for Dictionary is (after gyb expansion):

_T — Swift mangling prefix
M — metadata
C — class
s — ‘Swift’ module
18 — length of ‘_EmptyArrayStorage’

···

On Nov 17, 2016, at 12:36 PM, Alexis via swift-dev <swift-dev@swift.org> wrote:

@objc_non_lazy_realization
internal class _RawNativeDictionaryStorage:
_SwiftNativeNSDictionary, _NSDictionaryCore

Related: is it completely busted that GlobalObjects.[h/cpp] is blatantly assuming the layout of _EmptyArrayStorage? The doesn’t seem to be any @_fixed_layout annotation on it or its base classes.
_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

This is all completely unprincipled code that happens to work by accident today. The C++ code is making blind assumptions about what the Swift compiler happens to do for mangling and class layout today.

-Joe

···

On Nov 17, 2016, at 12:36 PM, Alexis via swift-dev <swift-dev@swift.org> wrote:

I’m currently looking at pushing the storage of the empty Dictionary singleton into rodata, using Array as a reference. Most things are pretty straightforward, except the symbol for the metadata for _EmptyArrayStorage that’s hardcoded in GlobalObjects.cpp:

extern "C" ClassMetadata _TMCs18_EmptyArrayStorage;

How was the _TMCs18 mangle discovered? Does anything need to be done to ensure this is stable? Blindly applying that prefix to the Dictionary class sadly just leads to a linker error. For reference, the current decl for Dictionary is (after gyb expansion):

@objc_non_lazy_realization
internal class _RawNativeDictionaryStorage:
_SwiftNativeNSDictionary, _NSDictionaryCore

Related: is it completely busted that GlobalObjects.[h/cpp] is blatantly assuming the layout of _EmptyArrayStorage? The doesn’t seem to be any @_fixed_layout annotation on it or its base classes.