Subject: vtable format
To: None <port-alpha@NetBSD.org>
From: Shin'ichiro TAYA <taya@NetBSD.org>
List: tech-toolchain
Date: 08/13/2004 00:31:13
Hi,
I finally managed to run mozilla on -current/alpha.
It is required to call method of a C++ object specified by position
number in vtable.

e.g.
from mozilla/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_linux_alpha.cpp

    /*
     * Call the virtual function with the constructed stack frame.
     */
    "bis $16,$16,$1\n\t"    /* load "this" */
    "ldq $2,16($15)\n\t"    /* load "methodIndex" */
    "ldq $1,0($1)\n\t"      /* load vtable */
    "s8addq $2,16,$2\n\t"   /* vtable index = "methodIndex" * 8 + 16 */
    "addq $1,$2,$1\n\t"
    "ldq $27,0($1)\n\t"     /* load address of function */
    "jsr $26,($27),0\n\t"   /* call virtual function */
    "ldgp $29,0($26)\n\t"


Below is an example to vtable.

_ZTV16InvokeTestTarget:
	.quad	0
	.quad	0
	.quad	_ZN16InvokeTestTarget14QueryInterfaceERK4nsIDPPv
	.quad	_ZN16InvokeTestTarget6AddRefEv
	.quad	_ZN16InvokeTestTarget7ReleaseEv
	.quad	_ZN16InvokeTestTarget10AddTwoIntsEiiPi
	.quad	_ZN16InvokeTestTarget11MultTwoIntsEiiPi
	.quad	_ZN16InvokeTestTarget9AddTwoLLsEllPl
	.quad	_ZN16InvokeTestTarget10MultTwoLLsEllPl
	.quad	_ZN16InvokeTestTarget11AddManyIntsEiiiiiiiiiiPi
	.quad	_ZN16InvokeTestTarget12AddTwoFloatsEffPf
	.quad	_ZN16InvokeTestTarget14AddManyDoublesEddddddddddPd
	.quad	_ZN16InvokeTestTarget13AddManyFloatsEffffffffffPf
	.quad	_ZN16InvokeTestTarget17AddManyManyFloatsEffffffffffffffffffffPf
	.quad	_ZN16InvokeTestTarget12AddMixedIntsEliliiliiliPl
	.quad	_ZN16InvokeTestTarget13AddMixedInts2EilillillilPl
	.quad	_ZN16InvokeTestTarget14AddMixedFloatsEffddffddfdfPd
	.quad	_ZN16InvokeTestTarget14PassTwoStringsEPKcS1_PPc

Above assember code add 16bytes everytime.
I assume this is to skip first two '0'.

But I build the code on NetBSD-current(gcc-3.3) and traced the code
and vtable points to first non 0 entry of vtable.
_ZN16InvokeTestTarget14QueryInterfaceERK4nsIDPPv for the above example.
So no need to add 16bytes.

My question is:
(1)When did this change occur?
Between gcc-2.95 and gcc-3.X?

(2)Then, does this patch make sense?

diff -u /mnt/local/src/mozilla-1.7rc3/mozilla/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_linux_alpha.cpp ./xptcinvoke_linux_alpha.cpp
--- /mnt/local/src/mozilla-1.7rc3/mozilla/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_linux_alpha.cpp	2001-09-29 05:12:51.000000000 +0900
+++ ./xptcinvoke_linux_alpha.cpp	2004-08-13 00:06:53.000000000 +0900
@@ -163,7 +163,11 @@
     "bis $16,$16,$1\n\t"    /* load "this" */
     "ldq $2,16($15)\n\t"    /* load "methodIndex" */
     "ldq $1,0($1)\n\t"      /* load vtable */
+#if defined(__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100 /* G++ V3 ABI */
+    "s8addq $2,0,$2\n\t"   /* vtable index = "methodIndex" * 8 */
+#else /* G++2.95 ABI */
     "s8addq $2,16,$2\n\t"   /* vtable index = "methodIndex" * 8 + 16 */
+#endif
     "addq $1,$2,$1\n\t"
     "ldq $27,0($1)\n\t"     /* load address of function */
     "jsr $26,($27),0\n\t"   /* call virtual function */

(3)Is this NetBSD specific change or gcc specific?
In another word, is this patch usefull for linux or FreeBSD?
I mean this file(xptcinvoke_linux_alpha.cpp) is shared between NetBSD,
linuxa and FreeBSD, can I submit patch to mozilla.org? or should I
create new file like xptcinvoke_netbsd_alpha.cpp?

---
Sorry for my poor english.
Regrds,
taya