public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Getting a pointer to a vtable
@ 2012-03-26 10:08 Mike Hommey
  2012-03-26 20:49 ` Ian Lance Taylor
  0 siblings, 1 reply; 6+ messages in thread
From: Mike Hommey @ 2012-03-26 10:08 UTC (permalink / raw)
  To: gcc-help

Hi,

Essentially, I would like to do something like:

void *bar = (void *)_ZTV3foo;

Except I only know "foo", and it may be namespaced. So is there some way
to have g++ do the mangling with a macro or something else?

Cheers,

Mike

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Getting a pointer to a vtable
  2012-03-26 10:08 Getting a pointer to a vtable Mike Hommey
@ 2012-03-26 20:49 ` Ian Lance Taylor
  2012-03-26 20:55   ` Mike Hommey
  0 siblings, 1 reply; 6+ messages in thread
From: Ian Lance Taylor @ 2012-03-26 20:49 UTC (permalink / raw)
  To: Mike Hommey; +Cc: gcc-help

Mike Hommey <mh@glandium.org> writes:

> Essentially, I would like to do something like:
>
> void *bar = (void *)_ZTV3foo;
>
> Except I only know "foo", and it may be namespaced. So is there some way
> to have g++ do the mangling with a macro or something else?

There is no macro that does mangling, no.

Why not simply

void *bar = &foo;

?

Ian

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Getting a pointer to a vtable
  2012-03-26 20:49 ` Ian Lance Taylor
@ 2012-03-26 20:55   ` Mike Hommey
  2012-03-26 21:22     ` Ian Lance Taylor
  2012-03-26 21:48     ` Ángel González
  0 siblings, 2 replies; 6+ messages in thread
From: Mike Hommey @ 2012-03-26 20:55 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-help

On Mon, Mar 26, 2012 at 01:48:45PM -0700, Ian Lance Taylor wrote:
> Mike Hommey <mh@glandium.org> writes:
> 
> > Essentially, I would like to do something like:
> >
> > void *bar = (void *)_ZTV3foo;
> >
> > Except I only know "foo", and it may be namespaced. So is there some way
> > to have g++ do the mangling with a macro or something else?
> 
> There is no macro that does mangling, no.
> 
> Why not simply
> 
> void *bar = &foo;

I want a pointer to the vtable.

Mike

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Getting a pointer to a vtable
  2012-03-26 20:55   ` Mike Hommey
@ 2012-03-26 21:22     ` Ian Lance Taylor
  2012-03-27  6:42       ` Mike Hommey
  2012-03-26 21:48     ` Ángel González
  1 sibling, 1 reply; 6+ messages in thread
From: Ian Lance Taylor @ 2012-03-26 21:22 UTC (permalink / raw)
  To: Mike Hommey; +Cc: gcc-help

Mike Hommey <mh@glandium.org> writes:

> On Mon, Mar 26, 2012 at 01:48:45PM -0700, Ian Lance Taylor wrote:
>> Mike Hommey <mh@glandium.org> writes:
>> 
>> > Essentially, I would like to do something like:
>> >
>> > void *bar = (void *)_ZTV3foo;
>> >
>> > Except I only know "foo", and it may be namespaced. So is there some way
>> > to have g++ do the mangling with a macro or something else?
>> 
>> There is no macro that does mangling, no.
>> 
>> Why not simply
>> 
>> void *bar = &foo;
>
> I want a pointer to the vtable.

Oh, right, missed that.  If you have an instance of the type, you could
use pointer manipulation and the C++ ABI
(http://codesourcery.com/cxx-abi/).  But there isn't any direct way to
get that pointer, or the name of the vtable.

Ian

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Getting a pointer to a vtable
  2012-03-26 20:55   ` Mike Hommey
  2012-03-26 21:22     ` Ian Lance Taylor
@ 2012-03-26 21:48     ` Ángel González
  1 sibling, 0 replies; 6+ messages in thread
From: Ángel González @ 2012-03-26 21:48 UTC (permalink / raw)
  To: Mike Hommey; +Cc: Ian Lance Taylor, gcc-help

On 26/03/12 22:55, Mike Hommey wrote:
> On Mon, Mar 26, 2012 at 01:48:45PM -0700, Ian Lance Taylor wrote:
>> There is no macro that does mangling, no.
>>
>> Why not simply
>>
>> void *bar = &foo;
> I want a pointer to the vtable.
>
> Mike
Isn't the vtable stored as the first class 'member'?
So  struct VtableFoo** v = (struct VtableFoo**)&foo; _would_ work
(abusing the internals...).

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Getting a pointer to a vtable
  2012-03-26 21:22     ` Ian Lance Taylor
@ 2012-03-27  6:42       ` Mike Hommey
  0 siblings, 0 replies; 6+ messages in thread
From: Mike Hommey @ 2012-03-27  6:42 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-help

On Mon, Mar 26, 2012 at 02:22:09PM -0700, Ian Lance Taylor wrote:
> Mike Hommey <mh@glandium.org> writes:
> 
> > On Mon, Mar 26, 2012 at 01:48:45PM -0700, Ian Lance Taylor wrote:
> >> Mike Hommey <mh@glandium.org> writes:
> >> 
> >> > Essentially, I would like to do something like:
> >> >
> >> > void *bar = (void *)_ZTV3foo;
> >> >
> >> > Except I only know "foo", and it may be namespaced. So is there some way
> >> > to have g++ do the mangling with a macro or something else?
> >> 
> >> There is no macro that does mangling, no.
> >> 
> >> Why not simply
> >> 
> >> void *bar = &foo;
> >
> > I want a pointer to the vtable.
> 
> Oh, right, missed that.  If you have an instance of the type, you could
> use pointer manipulation and the C++ ABI
> (http://codesourcery.com/cxx-abi/).  But there isn't any direct way to
> get that pointer, or the name of the vtable.

Except I want to avoid having an instance of the type in the first
place, because gcc is being unuseful creating static initializers to
just copy the vtable pointer, while clang or msvc just do relocations.

Mike

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-03-27  6:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-26 10:08 Getting a pointer to a vtable Mike Hommey
2012-03-26 20:49 ` Ian Lance Taylor
2012-03-26 20:55   ` Mike Hommey
2012-03-26 21:22     ` Ian Lance Taylor
2012-03-27  6:42       ` Mike Hommey
2012-03-26 21:48     ` Ángel González

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).