"Illegal instruction" when cross-compiling Qt 4.7.2+
-
I'm trying to cross compile Qt embedded 4.7 for a Linux ARM device (Trimble Nomad) for a few days. While it was pretty easy to get a successful build I had the problem that running the binaries on the device lead to "Invalid instruction" errors with some (but not all!) demos. It helped a lot to add
-msoft-float -D__GCC_FLOAT_NOT_NEEDED
to the compiler flags in qmake.conf but the "Invalid instruction" still appeared with some examples.Strangely, when building Qt with the -debug flag everything is fine and I don't get any problems anymore, even if I "strip" the binaries. All Qt programs are running fine.
So I guess that the option does more than add some debug symbols in the binaries. Can anybody explain me how it affects the build?
I could live with -debug on, but I need to avoid any potentially negative impact on performance.
Full configure settings below (i386; Debian Lenny Host):
./configure
-embedded arm
-xplatform qws/linux-arm-angstrom-gnueabi-g++
-debug
-no-largefile
-no-multimedia
-no-audio-backend
-no-phonon
-no-phonon-backend
-webkit
-javascript-jit
-no-xshape
-no-xvideo
-no-xsync
-no-xinerama
-no-xcursor
-no-xfixes
-no-xrandr
-no-xrender
-no-xinput
-no-xkb
-no-opengl
-nomake docs
-opensource
-qt-mouse-tslib
-qt-libjpeg
-qt-gifMy qmake.conf can be seen here: http://pastebin.com/D3RECiUj
-
With -release the code is compiled with (typically) the -O2 option passed to the compiler command line. The gcc docs will tell you exactly which optimisations this allows the compiler to apply. Without checking I think it implies things like limited loop unrolling, inlining of functions, some instruction reordering.
It is more likely that the -march, -mtune, or -mcpu options in the mkspec are not quite right for your cpu or that your cross-toolchain is broken in some way. Are you able to build and run optimised code without Qt using your cross-toolchain?
-
[quote author="ZapB" date="1302290525"]With -release the code is compiled with (typically) the -O2 option passed to the compiler command line. [/quote]
You're right, adding the -O2 flag reintroduces the "Illegal instruction" error. Strangely, using -O0 in -release mode does not avoid the error, so -debug must do some more changes.
[quote author="ZapB" date="1302290525"]It is more likely that the -march, -mtune, or -mcpu options in the mkspec are not quite right for your cpu or that your cross-toolchain is broken in some way. [/quote]
I tried -mcpu=xscale, -march=armv4, -mtune=arm920t (and non-conflicting combinations) but it didn't change anything. As said, only "-msoft-float" helped so far.
Perhaps you have some concrete suggestions for compiler settings I should try? You can see the cpuinfo here: http://pastebin.com/NS5CyEpQ
Compiler version and settings: http://pastebin.com/jbEjYMwT[quote author="ZapB" date="1302290525"]Are you able to build and run optimised code without Qt using your cross-toolchain?[/quote]
I'm using the toolchain for quite a while now without problems. Even Gnash (the OS flash player written in C++) had never any problems with -O2, although it had been built on a different host (but identical toolchain). The toolchain was made by the hardware vendor and they say that they had no problems building Qtopia 4.3. I usually don't need to specify any special compiler settings.
Any suggestions?
-
Difficult to say who is to blame here.
It may be a Qt bug (trying to utilize certain ARM intrisics on a unsupported CPU), or a toolchain problem. You should try to build a minimal testcase that shows the problem, then it would be quite easy to check where it is coming from.
-
I am not able to build a minimal testcase since I don't know what the problem is. I tried with floating point operations but they all run fine. I just know that at least the little example program "digitalclock" from the Qt source fails every time with Qt 4.7.2+.
It think the problem must be in some Qt optimizations that do not work with my CPU. I do not have any problems with Qt 4.7.0 or 4.7.1 but I get the same identical errors in Qt 4.7.2 and 4.7.3, so obviously it is related to some change between 4.7.1 and 4.7.2.
Looking at the diff of src/gui/painting/qdrawhelper.cpp I can see QT_HAVE_NEON checks all over the place. What is this? Also there are other ARM- and MMX-related changes to that file. Could one of them be the cause of my problem?
See full diff between 4.7.1 and 4.7.2 here:
http://indunet.it/temp/qt7-problem/qdrawhelper-471-472-diff.htm or
http://indunet.it/temp/qt7-problem/qdrawhelper-471-472-diff.patchUnfortunately I am not so familiar whether with ARM assembly nor with the Qt defines.
I would be glad if you could give me some hint..
PS: There is also a discussion at Stackoverflow with lots of details to my problem: http://stackoverflow.com/questions/5621393/illegal-instruction-when-cross-compiling-qt-4-7