Fix item vtable usage on Windows

The item tree is intended to be initialized with pointers to the item
vtables, which are implemented using data relocation records that
resolve to the symbols exported by the sixtyfps_cpp shared library.

On windows, according to

    https://docs.microsoft.com/en-us/cpp/c-language/rules-and-limitations-for-dllimport-dllexport?view=msvc-160

such data relocations are not supported, so this patch implements the
fallback through getter functions.
This commit is contained in:
Simon Hausmann 2021-05-10 16:24:13 +02:00 committed by Simon Hausmann
parent 4198513832
commit 28701d2f90
5 changed files with 30 additions and 5 deletions

View file

@ -205,9 +205,21 @@ inline vtable::Layout drop_in_place(ComponentRef component)
}
template<typename VTableType>
constexpr inline const VTableType *get_vtable(const VTableType *vtable_symbol)
constexpr inline const VTableType *get_vtable(const VTableType *vtable_symbol,
const VTableType *(*getter)())
{
// On Windows cross-dll data relocations are not supported:
// https://docs.microsoft.com/en-us/cpp/c-language/rules-and-limitations-for-dllimport-dllexport?view=msvc-160
// so we have a relocation to a function that returns the address we seek. That
// relocation will be resolved to the locally linked stub library, the implementation of
// which will be patched.
#if defined(_WIN32) || defined(_WIN64)
(void)vtable_symbol;
return getter();
#else
(void)getter;
return vtable_symbol;
#endif
}
template<typename T>