ham@Neon.Stanford.EDU (Peter R. Ham) (11/21/89)
I've taken a look at the virtual function tables created by
g++ on the pmax and I have some questions?
What exactly is the layout? I see some pre-amble type
information for each table. Then there are two words of information
for each virtual function: the address of a virtual function and a
"delta" to "fixup" this with. I don't really understand this delta.
I have a test case using multiple inheritance where the
delta is negative. I assume that this means that "this" at some
point had to been offset positively, but I don't see any positive
deltas in any of the other virtual function tables and haven't
been able to generate any. Can "this" only be offset positively
by a cast?
I would appreciate some small example that illustrates
how these deltas are used. Included are the C++ source
and resulting assembly of my example:
class a {
public:
virtual void vf1();
virtual void vf2();
int f1;
int f2;
};
class b {
public:
virtual void vf1();
virtual void vf3();
int f3;
int f4;
};
class c : public b, public a {
public:
virtual void vf1();
int f7;
int f8;
};
class d: public c {
public:
virtual void vf1();
int f5;
int f6;
};
a a1;
b b1;
c c1;
d d1;
void
foo(c x)
{
x.vf1();
}
# .verstamp 2 0
gcc_compiled.:
.globl a1
.data
.align 2
a1:
.space 12
.globl b1
.align 2
b1:
.space 12
.globl c1
.align 2
c1:
.space 32
.globl d1
.align 2
d1:
.space 40
.text
.align 2
.globl foo__FG1c
.ent foo__FG1c
foo__FG1c:
subu $29,8 # saveregs= 8
.frame $30,0,$31
.mask 0xc0000000,-4
sw $31,4($29)
sw $30,0($29)
addiu $30,$29,8 # define fp
addu $2,$0,$30 #movsi $30 -> $2
lw $3,8($30) #movsi 8($30) -> $3
lh $4,8($3) #sign extendhisi2 8($3) -> $4
addiu $29,$29,0xfff0 #subsi3 $29,16 -> $29
addu $4,$2,$4 #addsi3 $2,$4 -> $4
lw $2,12($3) #movsi 12($3) -> $2
jal $31,$2 # call with 16 arguments (reg)
addiu $29,$29,0x10 #addsi3 $29,16 -> $29
addu $8,$0,$30 # don't trust sp?
lw $31,-4($8)
lw $30,-8($8)
addu $29,$0,$8 # sp not trusted here
j $31
.end foo__FG1c
.align 2
.globl __sti__short_c
.ent __sti__short_c
__sti__short_c:
subu $29,8 # saveregs= 8
.frame $30,0,$31
.mask 0x40000000,-4
sw $30,4($29)
addiu $30,$29,8 # define fp
la $3,__vtbl__a #movsi __vtbl__a -> $3
sw $3,a1+8 #movsi $3 -> a1+8
la $3,__vtbl__b #movsi __vtbl__b -> $3
sw $3,b1+8 #movsi $3 -> b1+8
la $2,c1+12 #movsi c1+12(AExp) -> $2
la $3,__vtbl__c$a #movsi __vtbl__c$a -> $3
sw $3,c1+20 #movsi $3 -> c1+20
la $3,__vtbl__c #movsi __vtbl__c -> $3
sw $3,-4($2) #movsi $3 -> -4($2)
la $3,__vtbl__c$a #movsi __vtbl__c$a -> $3
sw $3,d1+20 #movsi $3 -> d1+20
la $2,d1 #movsi d1 -> $2
la $3,__vtbl__d$c #movsi __vtbl__d$c -> $3
sw $3,d1+8 #movsi $3 -> d1+8
la $3,__vtbl__d #movsi __vtbl__d -> $3
sw $3,8($2) #movsi $3 -> 8($2)
addu $8,$0,$30 # don't trust sp?
lw $30,-4($8)
addu $29,$0,$8 # sp not trusted here
j $31
.end __sti__short_c
.data
.align 3
__vtbl__d:
.half 0
.half 0
.word 2
.half 0
.half 0
.word vf1__1d
.half 0
.half 0
.word vf3__1b
.align 3
__vtbl__d$c:
.half 0
.half 0
.word 2
.half 0
.half 0
.word vf1__1d
.half 0
.half 0
.word vf3__1b
.align 3
__vtbl__c:
.half 0
.half 0
.word 2
.half 0
.half 0
.word vf1__1c
.half 0
.half 0
.word vf3__1b
.align 3
__vtbl__c$a:
.half 0
.half 0
.word 2
.half -12
.half 0
.word vf1__1c
.half 0
.half 0
.word vf2__1a
.align 3
__vtbl__b:
.half 0
.half 0
.word 2
.half 0
.half 0
.word vf1__1b
.half 0
.half 0
.word vf3__1b
.align 3
__vtbl__a:
.half 0
.half 0
.word 2
.half 0
.half 0
.word vf1__1a
.half 0
.half 0
.word vf2__1a
--
Peter Ham PO Box 3430 (h)(415) 322-4390
MS Computer Science Student Stanford, CA ham@cs.stanford.edu
Stanford University 94309 (o)(415) 723-2067