public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* differences of memory layout of virtual function table.
@ 2003-11-19  4:53 Susantha Kumara
  0 siblings, 0 replies; 4+ messages in thread
From: Susantha Kumara @ 2003-11-19  4:53 UTC (permalink / raw)
  To: gcc-help; +Cc: Damitha Kumarage

Hi all,

I am writing a C Wrapper mechanism for C++ objects. Here the memory layout
of the virtual table is very important. I am searching for the differences
of memory layouts of the object/virtual pointer table(vtable) with various
compilers (GCC, BC, VC++ etc).

I found that there is a difference of the virtual tables between the GCC
versions 2.96 and 3.2. The difference I found is in the offset for first
virtual function pointer,
	* in GCC 2.96 4th pointer (12-16th bytes) is the pointer to the first
virtual function, whereas
	* in GCC 3.2 3rd pointer (8-12th bytes) is the pointer to the first virtual
function

And in both GCC version I found that the pointer to the virtual destructor
is placed just before the first virtual function pointer. Is this guarenteed
always ?.

Any help for me to figure out how GCC synthesizes an object is greatly
appreciated.

Thanks,

Susantha.


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

* Re: differences of memory layout of virtual function table.
@ 2003-11-22 23:57 Dara Hazeghi
  0 siblings, 0 replies; 4+ messages in thread
From: Dara Hazeghi @ 2003-11-22 23:57 UTC (permalink / raw)
  To: susantha; +Cc: gcc-help

Hi,

regarding layout changes in the vtable, this is
usually documented (for instance
<http://gcc.gnu.org/gcc-3.3/changes.html> and
<http://gcc.gnu.org/gcc-3.4/changes.html>.
Specifically 2.95, 3.0, 3.1 and 3.2 all have changes.
3.4 when it is released may also have changes wrt 3.3.

The option -fdump-class-hierarchy probably helps.

Dara

__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

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

* RE: differences of memory layout of virtual function table.
       [not found] <5.2.1.1.0.20031119064017.014af5d0@iplan-mn.corp.adobe.com>
@ 2003-11-20  6:04 ` Susantha Kumara
  0 siblings, 0 replies; 4+ messages in thread
From: Susantha Kumara @ 2003-11-20  6:04 UTC (permalink / raw)
  To: Eljay Love-Jensen; +Cc: gcc-help, Damitha Kumarage

Hi Eljay,

I find in GCC and VC++ the pointer to the virtual table is the first pointer
of the object. Is there any other known compiler to you that synthesizes a
C++ object a different way ?.

Regarding the Virtual table, offsets and function pointer ordering , I find
its compiler dependant.

>-----Original Message-----
>From: Eljay Love-Jensen [mailto:eljay@adobe.com]
>Sent: Wednesday, November 19, 2003 6:49 PM
>To: Susantha Kumara
>Subject: Re: differences of memory layout of virtual function table.
>
>
>Hi Susantha,
>
>One C++ layout is adding an entry into a map of <addr,vtable> which is then
accessed when fetching the vtable (which includes RTTI).
>

Which compilers do have this way ? Is this when we have virtual base classes
?

>Another one is having the entire C++ vtable precede each object.  (There
are situations where this is preferable.)

Is this preffered for performance reasons or comply with a common standard
with the compilers ?

>
>For GCC in particular, I don't have any specific insight.
>
>But I suspect that what you want to do could better be done by making entry
point static functions that do something like this:
>
>class Foo
>{
>public:
>  virtual int zap(int i, int j);
>  static int Zap(Foo* p, int i, int j);
>};
>
>// Thunk function.
>int Foo::Zap(Foo* p, int i, int j)
>{
>  return p->zap(i, j);
>}
I will try this way and let you know if I succeeds. thanks for the idea.
>
>That's more portable, and can be called from C (albeit with name
mangling... I consider that a different issue and there are means to address
that as well).
>
>Yet another radical alternative is to implement classes as C structs and
hand-cobble the vtable.
This is I think what I do. Here we have to know how each compiler do.

>
>HTH,
>--Eljay
>

Thanks,

Susantha.

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

* RE: differences of memory layout of virtual function table.
       [not found] <3FBBA33A.80006@utmb.edu>
@ 2003-11-20  4:53 ` Susantha Kumara
  0 siblings, 0 replies; 4+ messages in thread
From: Susantha Kumara @ 2003-11-20  4:53 UTC (permalink / raw)
  To: Jacob Smith; +Cc: gcc-help

Hi Jacob,

>-----Original Message-----
>From: Jacob Smith [mailto:jnsmith@utmb.edu]
>Sent: Wednesday, November 19, 2003 11:07 PM
>To: Susantha Kumara
>Subject: Re: differences of memory layout of virtual function table.
>
>
>Virtual tables are never guaranteed for C++; specifically, GCC has been
>known to deliberately break v-table hacks across implementations (you've
>given examples yourself).

Is there any documentation on HOW and WHY gcc does this ?.
Please point me to any such documentation

> There are a number of solutions for converting
>an object to a basic C-type. I'd suggest one of those. If you need more
>help, just post to the list.

Please let me know what they are. But this mechanisms should not have any
runtime overhead
and could be used with most compilers.

>
>-j.
>
>btw, I believe the pointer order for the first offset into the function
>table is dependent upon the number of virtual base classes the class
>has, not some arbitrary number.
>
In our case we dont have any virtual base classes. Anyway knowing how
exactly GCC does this
is very important to me. please give me any links

>Susantha Kumara wrote:
>
>>Hi all,
>>
>>I am writing a C Wrapper mechanism for C++ objects. Here the memory layout
>>of the virtual table is very important. I am searching for the differences
>>of memory layouts of the object/virtual pointer table(vtable) with various
>>compilers (GCC, BC, VC++ etc).
>>
>>I found that there is a difference of the virtual tables between the GCC
>>versions 2.96 and 3.2. The difference I found is in the offset for first
>>virtual function pointer,
>>	* in GCC 2.96 4th pointer (12-16th bytes) is the pointer to the first
>>virtual function, whereas
>>	* in GCC 3.2 3rd pointer (8-12th bytes) is the pointer to the first
virtual
>>function
>>
>>And in both GCC version I found that the pointer to the virtual destructor
>>is placed just before the first virtual function pointer. Is this
guarenteed
>>always ?.
>>
>>Any help for me to figure out how GCC synthesizes an object is greatly
>>appreciated.
>>
>>Thanks,
>>
>>Susantha.
>>
>>
>>
>>
>>
>>
>

Thanks in advance,

Susantha.



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

end of thread, other threads:[~2003-11-22 23:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-19  4:53 differences of memory layout of virtual function table Susantha Kumara
     [not found] <3FBBA33A.80006@utmb.edu>
2003-11-20  4:53 ` Susantha Kumara
     [not found] <5.2.1.1.0.20031119064017.014af5d0@iplan-mn.corp.adobe.com>
2003-11-20  6:04 ` Susantha Kumara
2003-11-22 23:57 Dara Hazeghi

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