C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Allow conversion of memfunc pointers to func pointers

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Fri, 19 Jan 2024 13:32:10 +0000
On Friday, January 19, 2024, Frederick Virchanza Gotham wrote:
>
>
> I'm tempted to do what Arthur did and fork the GNU linker, try to make a
> list of all the vtables and all the type_info's, and then create the
> aforementioned sorted map in order to implement 'void const
> *std::get_polymorphic_facilitator(type_info const &)'.
>



I think 'binutils-gdb' is what I need to alter:

    https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git

I would edit the linker to create two new linker symbols:

    (1) __map_typeinfohash_vtable
    (2) __map_typeinfohash_vtable_size

The first one is the array mapping the hashes of type_info's to vtables.
The second one is the number of elements in the map.

Then I would fork libstdc++ to edit the <typeinfo> standard header file to
add the following inline function:

    inline void const *get_polymorphic_facilitator(type_info const &ti)
    {
        pair<size_t,void const*> *const p = __map_typeinfohash_vtable;

        pair<size_t,void const*> const *const q = p +
__map_typeinfohash_vtable_size;

        return lower_bound( p, q, ti.hash_code(), OnlyCompareFirst()
)->second;
    }

I've never edited a compiler before so this could be an interesting
experience.

Received on 2024-01-19 13:32:12