public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Frederick Virchanza Gotham <cauldwell.thomas@gmail.com>
To: binutils@sourceware.org
Cc: Michael Matz <matz@suse.de>
Subject: Re: Linker : Make a map of typeinfo to vtable
Date: Thu, 25 Jan 2024 10:17:46 +0000	[thread overview]
Message-ID: <CALtZhhNKzsCEsmkpOhguZ-EN7cDBT6UNYZw=ZffcTvN+dChKyg@mail.gmail.com> (raw)
In-Reply-To: <51e942dd-dbe0-f644-e9bb-0e12fc69f076@suse.de>

On Mon, Jan 22, 2024 at 4:50 PM Michael Matz wrote:
>
> 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()' .


That would be one option, yes it would be possible to edit the source
code for the GNU g++ compiler so that the type '__vmi_class_type_info'
has the vtable pointer appended onto the end of it, and then the
'__vmi_class_type_info::flags' member could have a bit set in it to
indicate the presence of the vtable pointer. There are two drawbacks
to this option though:
    (1) It involves editing the GNU g++ compiler, and I'd rather edit
the linker because then it can be extended easily to other languages
(such as D)
    (2) If we have multiple object files with a weak vtable symbol,
and if some of the weak symbols don't have the vtable pointer
appended, then a symbol missing the vtable pointer might become
'strong'
    (2) It will be necessary to recompile entire programs, whereas if
I edit just the linker, only the final linking step will need to be
redone (which is a big deal if you have been given proprietary object
files and static archives)

So for the time being I'm ploughing on ahead with editing the linker.
Please help me to get this working, here's what I've got so far:

    https://github.com/bminor/binutils-gdb/compare/f11786a1951932217d348f3739e8deb31975a355...healytpk:linker-vtable:master

Inside the file, "ld/ldmain.c", the function 'main' calls 'ldwrite'
which calls 'bfd_final_link'. After 'ldwrite' is called, I am able to
use the pointer "link_info.output_bfd" in order to get a list of all
symbols along with their offsets inside their sections. From this data
I'm able to produce my array which maps typeinfo's to vtables. But
there's one problem -- 'ldwrite' has already been called by the time I
produce my array. So, somehow, I need to call 'bfd_final_link' in
order get the offsets for the vtables inside their section, but then I
need to append my own array onto the end of the section, and then
perform the final link.

Can anybody please point me in the right direction for how to do this?
Can I possibly make a duplicate of the "bfd_link_info" struct and pass
it to "bfd_final_link" so that I can determine the vtable offsets,
then append my array onto the end of the section, and then call
'bfd_final_link' a second time giving it the original "bfd_link_info"
struct? Would something like that work?

  reply	other threads:[~2024-01-25 10:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-19 22:29 Frederick Virchanza Gotham
2024-01-19 22:52 ` Frederick Virchanza Gotham
2024-01-20 19:44   ` Frederick Virchanza Gotham
2024-01-21  3:27     ` Frederick Virchanza Gotham
2024-01-21 22:35       ` Frederick Virchanza Gotham
2024-01-22 16:50 ` Michael Matz
2024-01-25 10:17   ` Frederick Virchanza Gotham [this message]
2024-01-25 23:02     ` Frederick Virchanza Gotham
2024-01-27 10:56       ` Frederick Virchanza Gotham

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CALtZhhNKzsCEsmkpOhguZ-EN7cDBT6UNYZw=ZffcTvN+dChKyg@mail.gmail.com' \
    --to=cauldwell.thomas@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=matz@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).