Linker : Make a map of typeinfo to vtable

Michael Matz matz@suse.de
Mon Jan 22 16:50:33 GMT 2024


Hello,

On Fri, 19 Jan 2024, Frederick Virchanza Gotham wrote:

> So I want to edit the source code for the GNU linker in order to add two
> new symbols to every binary:
> 
>     (1) __map_typeinfohash_vtable
>     (2) __map_typeinfohash_vtable_size
> 
> The first one is an array mapping the hashes of type_info's to vtable
> pointers. The second one is the number of elements in the array. The array
> would look something like the following in C++:
> 
>     pair<size_t, void const*> const g_vtables[] = {
>          { typeid(MyClass).hash_code(), &_ZTI7MyClass },
>          { typeid(YourClass).hash_code(), &_ZTI9YourClass },
>     };

When you want to get from typeinfo to vtable pointer, why not just add 
that pointer directly into the typeinfo?  A hashtable is quite a 
roundabout way to implement 'typeid(Type).vtable()' .

As you're proposing your general idea on a mailing list for new features 
of C++, that seems like a more sensible design than hacking the linker.


Ciao,
Michael.


More information about the Binutils mailing list