Bug#129641: mozilla illegal instruction fault on IA64 (with a fix)
It was suggested that I forward this here, for the benefit of others porting mozilla and any other software that relies on the C++ ABI.
Matt
----- Forwarded message from Matt Chapman <[email protected]> -----
Package: mozilla-browser
Version: 0.9.7-4
Severity: important
Symptoms: Installation of package fails with "Illegal instruction" fault from regxpcom; mozilla dies similarly when executing JavaScript.
This seems to be because in recent versions of g++ - since 3.0.2 according to the ChangeLog - class vtables are arrays of function descriptors (which are (code address, gp value) pairs) rather than arrays of function pointers (which are pointers to function descriptors).
The following fix does the trick for me (it's a little evil, but then this kind of code is necessarily evil :)).
Cheers,
Matt
xpcom/reflect/xptcall/src/md/unix/xptcinvoke_ffi.cpp renamed from xpcom/reflect/xptcall/src/md/unix/xptcinvoke_ffi.old +10 -2
@@ -83,8 +83,9 @@ long offset; /* offset to beginning of object */ unsigned long rtti; /* address of run-time type info */ #endif - void (*methods[1]) (); /* method table (variable length) */ + unsigned long methods[1]; /* method table (variable length) */ } *vtable = *(struct vtable **) that; + void (*method)(); ffi_type **arg_types; void **args; ffi_status status;
@@ -102,6 +103,13 @@ if (status != FFI_OK) return NS_ERROR_INVALID_ARG; - ffi_call (&cif, vtable->methods[methodIndex], &result, args); +/* As of g++ 3.0.2, IA64 vtables contain function descriptors - [email protected] */ +#if defined(__ia64) && __GNUC__ >= 3 && !(__GNUC__ = 3 && __GNUC_MINOR__ = 0 && __GNUC_PATCHLEVEL__ < 2) + method = (void (*)())&vtable->methods[2*methodIndex]; +#else + method = (void (*)())vtable->methods[methodIndex]; +#endif + + ffi_call (&cif, method, &result, args); return result; }
----- End forwarded message -----
Quoted 4 lines
This seems to be because in recent versions of g++ - since 3.0.2 according to the ChangeLog - class vtables are arrays of function descriptors (which are (code address, gp value) pairs) rather than arrays of function pointers (which are pointers to function descriptors).
This change was required by the C++ ABI. If was always the intent to do things this way, it just took a while to get around to it because there was more compiler work than people available to do it.
Jim