[swift-dev] Making the value witness table reference relative
Joe Groff
jgroff at apple.com
Wed Jan 27 13:25:20 CST 2016
I have a patch in the works that makes the nominal type descriptor and parent metadata references in type metadata relative:
https://github.com/apple/swift/compare/master...jckarter:relative-from-metadata
After this, the only remaining relocation in concrete value type metadata is for the value witness table. We should be able to make the value witness table reference relative too with little codegen cost: on x86, loading from the table can be done from an Index(%metadata, %relative_vwtable) address in the same code size as Index(%absolute_vwtable); on ARMv7/8, it takes an extra add, though that add can be hoisted and performed once per-type within a function. That seems like me like an acceptable cost to be able to make most concrete value types' metadata read-only. However, dynamic linkers don't generally support relative relocations at load time, so we'd lose the ability for compiler-emitted metadata to refer to standard value witness tables provided by the runtime for common layouts, at least not without some runtime instantiation work. (Same-shaped types within the same module could of course still share value witnesses.) Classes already require instantiation work (at least on Darwin, to interact with the ObjC runtime), so we could set up the relative reference to the runtime's common value witness table for classes during that instantiation. Generic metadata is similarly runtime-instantiated. Would we be willing to forgo runtime-provided value witness tables for concrete value types, or to introduce instantiation overhead on them?
-Joe
More information about the swift-dev
mailing list