MochiLibraries / Biohazrd

A framework for automatically generating binding wrappers for C/C++ libraries
MIT License
59 stars 8 forks source link

Query Clang for the which vTable entry is the 0th entry #49

Open PathogenDavid opened 3 years ago

PathogenDavid commented 3 years ago

Things like the RTTI pointer are stored in the vTable before the entry where the vTable pointer points. Right now we just assume the vTable pointer points to the first occurrence of a function pointer in the table. This is probably fine, but in the interest of correctness we should figure out where this information is hidden within Clang.

If I remember right, -fdump-vtable-layouts points it out for the Microsoft ABI but not Linux. I think I investigated how it was determining it but it was non-trivial and I decided to make an assumption for now instead.

Note that right now CSharpLibraryGenerator is what is handling this assumption. Ideally this should be encoded in TranslatedVTable instead.

PathogenDavid commented 3 years ago

In the Itanium ABI, this entry is called the address point. The logic we use for determining the 0th entry lines up with the Itanium spec (0th entry is first function pointer.) (Reference)

PathogenDavid commented 3 years ago

VTableLayout contains an AddressPoints map. This is probably what we need.

This issue is closely related to https://github.com/InfectedLibraries/Biohazrd/issues/112