PDA

View Full Version : segment fault with any QT GUI program



earth
14th December 2010, 03:07
Hi,all:
Now,I cross-compile QT 4.6.0 for arm(LPC3250),and now I meet a strange segment fault when I try to run a GUI program (even "hello world").
Here is my hello.cpp:

#include<QtGui>
int main(int argc,char * argv[])
{
QApplication app(argc,argv);
QLabel label("hello world\n");
label.show();
return app.exec();
}
When I gdb the core file,I got this:

#0 0x407a327c in qt_getFreetypeData () at text/qfontengine_ft.cpp:142
#1 0x407a530c in qt_getFreetype () at text/qfontengine_ft.cpp:156
#2 0x40656a0c in QFontDatabasePrivate::addTTFile (this=0x155e8, file=...,
fontData=...) at text/qfontdatabase.cpp:779
#3 0x40659054 in initializeDb () at text/qfontdatabase_qws.cpp:362
#4 0x4065d320 in qt_qws_init_fontdb () at text/qfontdatabase_qws.cpp:506
#5 0x401c4d58 in QWSServerPrivate::initServer (this=0x15d38, flags=0)
at embedded/qwindowsystem_qws.cpp:1422
#6 0x401c5254 in QWSServer::QWSServer (this=0x13948, flags=0, parent=0x0)
at embedded/qwindowsystem_qws.cpp:1301
#7 0x401c5434 in QWSServer::startup (flags=0)
at embedded/qwindowsystem_qws.cpp:4067
#8 0x40321cc4 in qt_init (priv=0x12b58, type=2)
at kernel/qapplication_qws.cpp:2303
#9 0x402365d8 in QApplicationPrivate::construct (this=0x12b58)
at kernel/qapplication.cpp:768
#10 0x402378cc in QApplication::QApplication (this=0xbefebdcc,
argc=@0xbefebdb0, argv=0xbefebe64, _internal=263680)
at kernel/qapplication.cpp:690
#11 0x00008a30 in main (argc=1, argv=0xbefebe64) at hello.cpp:4
It seems the segment fault occurred in qt_getFreetypeData () at text/qfontengine_ft.cpp:142
And then,I add printf in qt_getFreetypeData () at text/qfontengine_ft.cpp:142 to see why it's segment fault.
The original qt_getFreetypeData () is like that:

QtFreetypeData *qt_getFreetypeData()
{
QtFreetypeData *&freetypeData = theFreetypeData()->localData();
if (!freetypeData)
freetypeData = new QtFreetypeData;
return freetypeData;
}
After modified qt_getFreetypeData () is like that:

QtFreetypeData *qt_getFreetypeData()
{
QtFreetypeData *&freetypeData = theFreetypeData()->localData();
if (!freetypeData)
{
printf("%s\n",__func__);
freetypeData = new QtFreetypeData;
}
return freetypeData;
}
After rebuild all,I still got a segment fault.But this time when I gdb core, I got this:

#0 0x4061a768 in QFontCache::instance () at text/qfont.cpp:2589
#1 0x40620014 in QFontPrivate::engineForScript (this=0x36f08, script=0)
at text/qfont.cpp:264
#2 0x40646920 in QFontMetrics::height (this=0xbe8291f8)
at text/qfontmetrics.cpp:329
#3 0x4090deb4 in QPlastiqueStyle::pixelMetric (this=0x37088,
metric=QStyle::PM_TitleBarHeight, option=0xbe8291d8, widget=0x0)
at styles/qplastiquestyle.cpp:5611
#4 0x401f0060 in QDecorationStyled::titleBarHeight (this=0x36810,
widget=0xbe829db8) at embedded/qdecorationstyled_qws.cpp:84
#5 0x401eb8d8 in QDecorationDefault::region (this=0x36810,
widget=0xbe829db8, rect=..., decorationRegion=2147483647)
at embedded/qdecorationdefault_qws.cpp:421
#6 0x401ef9f0 in QDecorationStyled::region (this=0x36810,
widget=0xbe829db8, rect=..., decorationRegion=2147483647)
at embedded/qdecorationstyled_qws.cpp:298
#7 0x4033694c in QWidgetPrivate::create_sys (this=0x33e40, window=0,
initializeWindow=true) at kernel/qwidget_qws.cpp:222
#8 0x402d95ec in QWidget::create (this=0xbe829db8, window=0,
initializeWindow=true, destroyOldWindow=true) at kernel/qwidget.cpp:1318
#9 0x402db47c in QWidget::setVisible (this=0xbe829db8, visible=true)
at kernel/qwidget.cpp:7329
#10 0x00008c74 in QWidget::show (this=0xbe829db8)
at ../qt-lib/include/QtGui/qwidget.h:481
#11 0x00008ae8 in main (argc=1, argv=0xbe829e64) at hello.cpp:6
It seems that,when I add the printf in qt_getFreetypeData () at text/qfontengine_ft.cpp:142,
It did not meet a segment fault in qt_getFreetypeData (),but meet segment fault after.

Now the strange thing is:
Not add printf in qt_getFreetypeData (),segment fault occurred in main->QApplication app(argc,argv)->...->qt_getFreetypeData () at text/qfontengine_ft.cpp:142
Add printf in qt_getFreetypeData (), segment fault occurred in main->label.show()->QFontCache::instance () at text/qfont.cpp:2589

I guess it is cause by Compiler optimization.
So instead of add printf, I add memory barrier in qt_getFreetypeData () to avoid wrong optimization.
Now the qt_getFreetypeData() is like this:

QtFreetypeData *qt_getFreetypeData()
{
QtFreetypeData *&freetypeData = theFreetypeData()->localData();
if (!freetypeData)
{
// printf("%s\n",__func__);
__asm__ __volatile__("":::"memory");
freetypeData = new QtFreetypeData;
}
return freetypeData;
}
But it is useless,it still occur segment fault in qt_getFreetypeData.

Then,I check the QFontCache::instance () at text/qfont.cpp:2589 because it cause the other segment fault.
And I found that the instance() is similar to qt_getFreetypeData().
The instance() is like this:

QFontCache *QFontCache::instance()
{
QFontCache *&fontCache = theFontCache()->localData();
if (!fontCache)
fontCache = new QFontCache;
return fontCache;
}
So I add printf() in instance too,like this:

QFontCache *QFontCache::instance()
{
QFontCache *&fontCache = theFontCache()->localData();
if (!fontCache)
{
printf("%s\n",__func__);
fontCache = new QFontCache;
}
return fontCache;
}
After add printf() in both qt_getFreetypeData() and instance(),rebuild all,no segment fault occur and i can see "hello world" on my board.
Now I want to know how can I solve segment fault without adding printf()?

This thread is so long ,thanks for read it.

Environment:

Host OS is fedora 10.

cross-compiler:

[ljp@localhost hello]$ arm-vfp-linux-gnu-gcc -v
Using built-in specs.
Target: arm-vfp-linux-gnu
Configured with: /home/usb10132/ct1/bin/targets/src/gcc-4.3.2/configure --build=i386-build_redhat-linux-gnu --host=i386-build_redhat-linux-gnu --target=arm-vfp-linux-gnu --prefix=/home/usb10132/x-tools/arm-vfp-linux-gnu --with-sysroot=/home/usb10132/x-tools/arm-vfp-linux-gnu/arm-vfp-linux-gnu/sys-root --enable-languages=c,c++ --disable-multilib --with-arch=armv5te --with-abi=atpcs --with-cpu=arm926ej-s --with-fpu=vfp --with-float=soft --with-gmp=/home/usb10132/x-tools/arm-vfp-linux-gnu --with-mpfr=/home/usb10132/x-tools/arm-vfp-linux-gnu --with-pkgversion=crosstool-NG-1.3.1 --enable-__cxa_atexit --with-local-prefix=/home/usb10132/x-tools/arm-vfp-linux-gnu/arm-vfp-linux-gnu/sys-root --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-c99 --enable-long-long --enable-target-optspace
Thread model: posix
gcc version 4.3.2 (crosstool-NG-1.3.1)


qmake.conf:

#
# qmake configuration for building with arm-linux-g++
#

include(../../common/g++.conf)
include(../../common/linux.conf)
include(../../common/qws.conf)

# modifications to g++.conf
QMAKE_CC = arm-vfp-linux-gnu-gcc
QMAKE_CXX = arm-vfp-linux-gnu-g++
QMAKE_LINK = arm-vfp-linux-gnu-g++
QMAKE_LINK_SHLIB = arm-vfp-linux-gnu-g++

# modifications to linux.conf
QMAKE_AR = arm-vfp-linux-gnu-ar cqs
QMAKE_OBJCOPY = arm-vfp-linux-gnu-objcopy
QMAKE_STRIP = arm-vfp-linux-gnu-strip

load(qt_config)

QT configure script

./configure -embedded arm -xplatform qws/linux-m3250 -prefix /home/ljp/qt-lib\
-qt-mouse-tslib -I/home/ljp/tslib-lib/include -L/home/ljp/tslib-lib/lib\
-nomake examples -nomake demos -no-webkit \
-no-exceptions -debug -qt-zlib \
-no-largefile -no-accessibility -no-stl -no-qt3support -no-xmlpatterns -no-phonon -no-phonon-backend \
-no-multimedia -no-javascript-jit -no-openssl -nomake docs -nomake translations -nomake tools -no-nis \
-no-pch -no-libtiff -no-xcursor -no-xfixes -no-xrandr -no-xrender -no-xkb -no-sm -no-xinerama -no-xshape \
-optimized-qmake -no-opengl -no-separate-debug-info -no-qvfb -qt-gfx-linuxfb -no-gfx-qvfb -no-kbd-qvfb \
-opensource -confirm-license -no-scripttools -no-cups -no-mouse-qvfb

I build hello like this :
qmake -project
qmake
make

Target board is LPC3250,it has a VFP.

I have read the thread:
http://www.qtcentre.org/threads/23230-ARM-Platform-Segfaults-with-quot-release-quot-Qt-but-works-great-with-quot-debug-quot-Qt-!
And do what it said(except change the compiler),but all useless.
can anyone help me?
Thanks again.

earth
20th December 2010, 02:57
Hi all,now I found another things:
when I add

char ch[]={'a','b'};
instead of printf(),
The GUI program works too.
Any one know why?

Nathael
22nd March 2011, 15:00
Hi, I got the same symptoms !

I'll try your solution, but did you find a better solution, or an explanation for this problem ?

Processor is ARM926EJ-S rev 5 (v5l) (arm9 iMX233), and I have the same problem on another arm9 : ARM920T rev 0 (v4l) (Samsung S3C2442B)

I'm using gcc from emdebian ([...] --target=arm-linux-gnueabi [...] gcc version 4.4.5 (Debian 4.4.5-8))

I will try adding
QMAKE_CFLAGS += -march=armv5te
QMAKE_CXXFLAGS += -march=armv5te
to my specs, as the same binaries are running just fine on an armv6 (arm11 - iMX353)

(compilation of Qt libs running right now ...)

Nathael
22nd March 2011, 23:29
Back, and with a much better solution: sitch to Qt 4.7.2 !

First, I found some interesting info there :
QTBUG-14804 (http://bugreports.qt.nokia.com/browse/QTBUG-14804?page=com.atlassian.jira.plugin.system.issuet abpanels%3Aall-tabpanel)
and there :
QTBUG-13441 (http://bugreports.qt.nokia.com/browse/QTBUG-13441)

I seems that the freetype implementation embedded in Qt has problems with ARM9 cores.

But I tried to use -system-freetype in configure with no success.
But the bug reports also mentioned that the problems where in 4.7.0 and 4.7.1, but not 4.7.2.
So I tried 4.7.2, and I have no more segfault.

If you're interrested in the reasons behind the segfaults, look at the bugreports and the solution, I did not have time for this.

+++
have fun !