[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Sheflug] Qt GUI library problem and Gnu c++ compiler and vtable pointer alignment
I'm currently trying to track down an error in the Qt4.5 GUI libraries
which is causing a SIGBUS error on my embedded linux project.
I've think I've tracked this down to one line of code in the library and
this may also be relevant to the following...
https://lists.ubuntu.com/archives/kubuntu-bugs/2009-March/069503.html
This however is a more general query about C++, virtual functions and
vtables. Trouble is I'm still on page 1 of the C++ tutorial.
My understanding is that a class containing virtual functions contains a
table of pointers to the implementations of those functions to support
dynamic linking. This table is populated by the compiler as required by
any derived classes.
An instance of the derived class then contains a pointer to the relevant
'vtable' as its first item, and we use an index into the table to call
the function.
If so, then the following code should display a list of the addresses of
implementations of those virtual functions for the current object...
[code]
int * vtable = ((int*)*(int*)this);
for (unsigned int i = 0; i < 0x60; i++) {
printf("vt[%x] = %p\n", i, (int*)*(vtable+i));
}
[/code]
When I run this on my failing Qt object on my target (32-bit) hardware,
the results show some (a few) addresses in the table aligned to a 16-bit
rather than a 32-bit boundary. Suspiciously, one of these entries (say
vt[n]) corresponds to the nth virtual function in the class definition
which just happens to be called from the line of code in the Qt GUI
library which is giving me some grief (QCommonStyle::drawPrimitive()).
This may or may not be relevant to the SIGBUS error - but on my current
understanding it could well be responsible - fixing it is another matter.
Is the above interpretation of vtables correct or is the situation more
complex than this? I've seen a few bits of information on the web about
g++ not always obeying machine alignment rules.
I'd also like to confirm that the addresses listed by the above code are
indeed those of the relevant class methods, but my C++ experience is, as
I say, very basic and I can't seem to take the address of the functions
by name - the compiler throws a wobbler when I try to do this. I really
want to know where the drawPrimitive() function for the current object
is located in memory - and I can't build Qt with debugging symbols.
Regards to all
Bob
--
Robert E B Holland CEng FIET
Bradwell IT Solutions Ltd
Registered in England & Wales No: 2564938
Registered office: Throapham House, Oldcotes Road, Throapham Sheffield
S25 2QS
Phone: 01909 568630 Fax: 01909 567825
Skype: rebholland
Web: http://www.bradwell.net/
All information or opinions expressed in this message and/or any
attachments are those of the author and are not necessarily those of
Bradwell IT Solutions Ltd.
Copyright: Any distribution, use or reproduction without the sender's
prior consent is unauthorised and strictly prohibited.
Confidentiality: This email and its attachments are intended for the
exclusive use of the addressee(s) and may be confidential. If you have
received this message in error, you must take no action on them nor must
you copy or show them to anyone. Please reply to this email immediately
highlighting the error and delete this message from your computer.
Security: Email is not a secure medium. We advise that you understand
and accept this lack of security when emailing us.
Viruses: Bradwell IT Solutions Ltd accepts no responsibility for loss or
damage arising from the use of this email including damage by virus.
*** For luxury bed and breakfast accommodation in South Yorkshire visit
http://www.throapham-house.co.uk ***
_______________________________________________
Sheffield Linux User's Group
http://sheflug.org.uk/mailman/listinfo/sheflug_sheflug.org.uk
FAQ at: http://www.sheflug.org.uk/mailfaq.html
GNU - The Choice of a Complete Generation