“非法指令”交叉编译 Qt 4.7 时
我已经在这个问题上苦苦挣扎了一个多星期了,但仍然找不到解决方案...
我正在尝试为 ARM 设备交叉编译 Qt 4.7 嵌入式开源版本。构建过程本身可以顺利完成,但生成的二进制文件似乎包含处理器无法理解的指令。
- 构建主机是 i386 上的 Debian 5 (Etch)(在虚拟 PC 上运行)
- 该设备是带有 ARM 处理器的 Trimble Nomad 手持设备 (查看完整的cpuinfo和内核配置)
- 我使用原来的构建专为该设备制作的工具链,并且迄今为止运行良好(甚至可以成功构建 Gnash ) - 请参阅编译器设置和版本
- 我正在使用基于的自定义
qmake.conf
linux-arm-gnueabi-g++
并进行了调整以使用正确的工具链 - 在此处查看源代码 - 通过将
-msoft-float -D__GCC_FLOAT_NOT_NEEDED
添加到编译器标志,我有了部分改进,但我仍然得到在某些情况下出现“非法指令”错误(但至少这是一个很大的改进) - 二进制文件本身基本上可以工作,但在某些情况下,程序会因“非法指令”而崩溃“ 错误。我相信在进行图形处理时某些浮点操作期间会发生这种情况。
- 添加
-mcpu=xscale
、-march=armv4
、-O0
、-march=armv4
、-mtune=arm920t
(并非全部同时)没有任何帮助。 - 使用
--debug
标志构建 Qt 似乎可以解决所有问题,但添加-O2
标志会重新引入这些问题。奇怪的是,-O0
设置 without --debug 没有没有帮助。 - 可以看到编译
configure
和make
输出 据说它们是编译器的错误警告 。 - Qt 4.7.2 中一定有一些变化,因为早期版本(4.7.1、4.7.0)确实运行良好。
configure
设置:
./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 \
-nomake examples \
-nomake tools \
-nomake demos \
-nomake translations \
-opensource \
-qt-mouse-tslib \
-qt-libjpeg \
-qt-gif
崩溃前的 strace:
$ LD_LIBRARY_PATH=. QT_QWS_FONTDIR=$PWD/fonts QT_PLUGIN_PATH=$PWD/plugins QWS_MOUSE_PROTO=tslib:/dev/input/touchscreen0 strace ./digitalclock -qws test.htm
...
lseek(15, 0, SEEK_END) = 16998
write(15, "\t\n\f\0\367\t", 6) = 6
write(15, "\0\0+\234\325\343\306{\3\0\0\0\0J\370\377\351\301\336\377"..., 120) = 120
lseek(15, 0, SEEK_END) = 17124
write(15, "\10\10\10\0\371\10", 6) = 6
write(15, "\0\6j\251\260\201\27\0\2\276\377\351\334\377\346\32K\377"..., 64) = 64
lseek(15, 0, SEEK_END) = 17194
write(15, "\7\10\10\0\371\7", 6) = 6
write(15, "\0\4c\245\263\224 \0\1\271\377\367\315\356P\0I\377\364"..., 64) = 64
lseek(15, 0, SEEK_END) = 17264
write(15, "\10\n\10\1\366\10", 6) = 6
write(15, "\37 \3\0\0\0\0\0\374\377\34\0\0\0\0\0\374\377\34\0\0\0"..., 80) = 80
fcntl64(15, F_SETLK, {type=F_UNLCK, whence=SEEK_SET, start=0, len=0}) = 0
lseek(15, 0, SEEK_END) = 17350
mremap(0x415f5000, 16552, 17350, MREMAP_MAYMOVE) = 0x415f5000
--- SIGILL (Illegal instruction) @ 0 (0) ---
rt_sigaction(SIGILL, {SIG_DFL}, {0x401b7d34, [ILL], SA_RESTART|0x4000000}, 8) = 0
socket_subcall(0x1f8004, 0, 0x100, 0, 0, 0x18844, 0x18840, 0x12c) = 0
ioctl(12, KDSKBMODE, 0x2) = 0
ioctl(12, SNDCTL_TMR_START or TCSETS, {B38400 -opost -isig -icanon -echo ...}) = 0
close(12) = 0
ioctl(10, KDSETMODE, 0x1) = 0
write(10, "\33[9;15]\33[?33h\33[?25h\33[?0c\0", 25) = 25
close(10) = 0
statfs64(umovestr: Input/output error
0x6d4f, 27983, {???}) = 0
sigreturn() = ? (mask now [ILL ABRT BUS FPE USR1 SEGV USR2 PIPE STKFLT CHLD CONT STOP TTOU URG XCPU VTALRM PROF WINCH IO PWR RTMIN])
--- SIGILL (Illegal instruction) @ 0 (0) ---
+++ killed by SIGILL +++
Process 27983 detached
崩溃的 gdb 回溯(我缺少调试符号,因为使用调试信息编译可以解决问题):
(gdb) run -qws
Starting program: /home/.qt-test2/digitalclock -qws
Program received signal SIGILL, Illegal instruction.
0x4130268c in __sigsetjmp () from /lib/libc.so.6
(gdb) bt
#0 0x4130268c in __sigsetjmp () from /lib/libc.so.6
#1 0x4046ee5c in ?? () from ./libQtGui.so.4
(gdb)
请注意,设备预装了 Qtopia 4.3,供应商可以'也不能解释我的构建的问题。
更新
在 Igor Skochinsky 的帮助下,我可以找到导致 SIGILL 的确切汇编指令。由于某种原因,该指令在导致错误之前运行正常 47 次。请参阅下面的 gdb
输出(请注意,我根本不熟悉 ARM 汇编器):
$ LD_LIBRARY_PATH=. QT_QWS_FONTDIR=$PWD/fonts QT_PLUGIN_PATH=$PWD/plugins QWS_MOUSE_PROTO=tslib:/dev/input/touchscreen0 gdb ./digitalclock
GNU gdb 6.6
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "arm-angstrom-linux-gnueabi"...
Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) start -qws
Breakpoint 1 at 0xaa58: file main.cpp, line 47.
Starting program: /home/.qt-test2/digitalclock -qws
[Thread debugging using libthread_db enabled]
[New Thread 1073870720 (LWP 2799)]
[Switching to Thread 1073870720 (LWP 2799)]
main (argc=2, argv=0xbea17d04) at main.cpp:47
47 main.cpp: No such file or directory.
in main.cpp
(gdb) display/i $pc
1: x/i $pc 0xaa58 <main+24>: sub r3, r11, #28 ; 0x1c
(gdb) display/x $r2
2: /x $r2 = 0xbea17d10
(gdb) display/x $f2
3: /x $f2 = 0x0
(gdb) b *0x41302684
Breakpoint 2 at 0x41302684
(gdb) continue
Continuing.
---> no problem here:
Breakpoint 2, 0x41302684 in __sigsetjmp () from /lib/libc.so.6
3: /x $f2 = 0x0
2: /x $r2 = 0x293
1: x/i $pc 0x41302684 <__sigsetjmp+52>: beq 0x413026a0 <Lno_iwmmxt>
(gdb) si
0x41302688 in __sigsetjmp () from /lib/libc.so.6
3: /x $f2 = 0x0
2: /x $r2 = 0x293
1: x/i $pc 0x41302688 <__sigsetjmp+56>: stfp f2, [r12], #8
(gdb) si
0x4130268c in __sigsetjmp () from /lib/libc.so.6
3: /x $f2 = 0x0
2: /x $r2 = 0x293
1: x/i $pc 0x4130268c <__sigsetjmp+60>: stfp f3, [r12], #8
(gdb) si
0x41302690 in __sigsetjmp () from /lib/libc.so.6
3: /x $f2 = 0x0
2: /x $r2 = 0x293
1: x/i $pc 0x41302690 <__sigsetjmp+64>: stfp f4, [r12], #8
(gdb) continue
Continuing.
Breakpoint 2, 0x41302684 in __sigsetjmp () from /lib/libc.so.6
3: /x $f2 = 0x0
2: /x $r2 = 0x293
1: x/i $pc 0x41302684 <__sigsetjmp+52>: beq 0x413026a0 <Lno_iwmmxt>
(gdb) continue 46
Will ignore next 45 crossings of breakpoint 2. Continuing.
---> __sigsetjmp still working fine, but then:
Breakpoint 2, 0x41302684 in __sigsetjmp () from /lib/libc.so.6
3: /x $f2 = 0x0
2: /x $r2 = 0x293
1: x/i $pc 0x41302684 <__sigsetjmp+52>: beq 0x413026a0 <Lno_iwmmxt>
(gdb) si
0x41302688 in __sigsetjmp () from /lib/libc.so.6
3: /x $f2 = 0x0
2: /x $r2 = 0x293
1: x/i $pc 0x41302688 <__sigsetjmp+56>: stfp f2, [r12], #8
(gdb) si
Program received signal SIGILL, Illegal instruction.
0x4130268c in __sigsetjmp () from /lib/libc.so.6
3: /x $f2 = 0x0
2: /x $r2 = 0x293
1: x/i $pc 0x4130268c <__sigsetjmp+60>: stfp f3, [r12], #8
有什么建议我下一步可以尝试吗?
I'm struggling with this problem for more than a week now, and still can't find a solution...
I'm trying to cross-compile Qt 4.7 embedded open-source version for an ARM device. The build process itself completes without problems, but the generated binaries seem to contain instructions that the processor does not understand.
- Build host is Debian 5 (Etch) on i386 (running on a virtual PC)
- The device is a Trimble Nomad handheld with an ARM processor (see full cpuinfo and kernel configuration)
- I use the original build toolchain that was made for the device and that worked fine to date (even could build Gnash successfully) - see compiler settings and version
- I'm using a custom
qmake.conf
based onlinux-arm-gnueabi-g++
and adapted to use the correct toolchain - see source code here - I had a partial improvement by adding
-msoft-float -D__GCC_FLOAT_NOT_NEEDED
to the compiler flags but I still get "Illegal instruction" errors in some situations (but at least this was a big improvement) - The binaries themselves basically work, but in certain situations the program crashes with the "Illegal instruction" error. I believe this happens during certain floating point operations while doing graphics stuff.
- Adding
-mcpu=xscale
,-march=armv4
,-O0
,-march=armv4
,-mtune=arm920t
(not all at the same time) did not help in any way. - Building Qt with the
--debug
flag appears to resolve all problems but adding the-O2
flag reintroduces them. Strangely the-O0
setting without --debug does not help. - The compilete
configure
andmake
output can be seen here. There are lots of alignment warnings but they are said to be false warnings of the compiler. - there must have been some change in Qt 4.7.2 because earlier versions (4.7.1, 4.7.0) do run fine.
configure
settings:
./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 \
-nomake examples \
-nomake tools \
-nomake demos \
-nomake translations \
-opensource \
-qt-mouse-tslib \
-qt-libjpeg \
-qt-gif
strace before the crash:
$ LD_LIBRARY_PATH=. QT_QWS_FONTDIR=$PWD/fonts QT_PLUGIN_PATH=$PWD/plugins QWS_MOUSE_PROTO=tslib:/dev/input/touchscreen0 strace ./digitalclock -qws test.htm
...
lseek(15, 0, SEEK_END) = 16998
write(15, "\t\n\f\0\367\t", 6) = 6
write(15, "\0\0+\234\325\343\306{\3\0\0\0\0J\370\377\351\301\336\377"..., 120) = 120
lseek(15, 0, SEEK_END) = 17124
write(15, "\10\10\10\0\371\10", 6) = 6
write(15, "\0\6j\251\260\201\27\0\2\276\377\351\334\377\346\32K\377"..., 64) = 64
lseek(15, 0, SEEK_END) = 17194
write(15, "\7\10\10\0\371\7", 6) = 6
write(15, "\0\4c\245\263\224 \0\1\271\377\367\315\356P\0I\377\364"..., 64) = 64
lseek(15, 0, SEEK_END) = 17264
write(15, "\10\n\10\1\366\10", 6) = 6
write(15, "\37 \3\0\0\0\0\0\374\377\34\0\0\0\0\0\374\377\34\0\0\0"..., 80) = 80
fcntl64(15, F_SETLK, {type=F_UNLCK, whence=SEEK_SET, start=0, len=0}) = 0
lseek(15, 0, SEEK_END) = 17350
mremap(0x415f5000, 16552, 17350, MREMAP_MAYMOVE) = 0x415f5000
--- SIGILL (Illegal instruction) @ 0 (0) ---
rt_sigaction(SIGILL, {SIG_DFL}, {0x401b7d34, [ILL], SA_RESTART|0x4000000}, 8) = 0
socket_subcall(0x1f8004, 0, 0x100, 0, 0, 0x18844, 0x18840, 0x12c) = 0
ioctl(12, KDSKBMODE, 0x2) = 0
ioctl(12, SNDCTL_TMR_START or TCSETS, {B38400 -opost -isig -icanon -echo ...}) = 0
close(12) = 0
ioctl(10, KDSETMODE, 0x1) = 0
write(10, "\33[9;15]\33[?33h\33[?25h\33[?0c\0", 25) = 25
close(10) = 0
statfs64(umovestr: Input/output error
0x6d4f, 27983, {???}) = 0
sigreturn() = ? (mask now [ILL ABRT BUS FPE USR1 SEGV USR2 PIPE STKFLT CHLD CONT STOP TTOU URG XCPU VTALRM PROF WINCH IO PWR RTMIN])
--- SIGILL (Illegal instruction) @ 0 (0) ---
+++ killed by SIGILL +++
Process 27983 detached
gdb backtrace of the crash (I'm missing debug symbols since compiling with debug information resolves the problem):
(gdb) run -qws
Starting program: /home/.qt-test2/digitalclock -qws
Program received signal SIGILL, Illegal instruction.
0x4130268c in __sigsetjmp () from /lib/libc.so.6
(gdb) bt
#0 0x4130268c in __sigsetjmp () from /lib/libc.so.6
#1 0x4046ee5c in ?? () from ./libQtGui.so.4
(gdb)
Note the device comes with Qtopia 4.3 preinstalled and the vendor can't explain the problem with my build either.
Update
With help from Igor Skochinsky I could find the exact assembler instruction that is causing the SIGILL. For some reason the instruction works fine for 47 times before causing the error. See gdb
output below (note I'm not familiar with ARM assembler at all ):
$ LD_LIBRARY_PATH=. QT_QWS_FONTDIR=$PWD/fonts QT_PLUGIN_PATH=$PWD/plugins QWS_MOUSE_PROTO=tslib:/dev/input/touchscreen0 gdb ./digitalclock
GNU gdb 6.6
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "arm-angstrom-linux-gnueabi"...
Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) start -qws
Breakpoint 1 at 0xaa58: file main.cpp, line 47.
Starting program: /home/.qt-test2/digitalclock -qws
[Thread debugging using libthread_db enabled]
[New Thread 1073870720 (LWP 2799)]
[Switching to Thread 1073870720 (LWP 2799)]
main (argc=2, argv=0xbea17d04) at main.cpp:47
47 main.cpp: No such file or directory.
in main.cpp
(gdb) display/i $pc
1: x/i $pc 0xaa58 <main+24>: sub r3, r11, #28 ; 0x1c
(gdb) display/x $r2
2: /x $r2 = 0xbea17d10
(gdb) display/x $f2
3: /x $f2 = 0x0
(gdb) b *0x41302684
Breakpoint 2 at 0x41302684
(gdb) continue
Continuing.
---> no problem here:
Breakpoint 2, 0x41302684 in __sigsetjmp () from /lib/libc.so.6
3: /x $f2 = 0x0
2: /x $r2 = 0x293
1: x/i $pc 0x41302684 <__sigsetjmp+52>: beq 0x413026a0 <Lno_iwmmxt>
(gdb) si
0x41302688 in __sigsetjmp () from /lib/libc.so.6
3: /x $f2 = 0x0
2: /x $r2 = 0x293
1: x/i $pc 0x41302688 <__sigsetjmp+56>: stfp f2, [r12], #8
(gdb) si
0x4130268c in __sigsetjmp () from /lib/libc.so.6
3: /x $f2 = 0x0
2: /x $r2 = 0x293
1: x/i $pc 0x4130268c <__sigsetjmp+60>: stfp f3, [r12], #8
(gdb) si
0x41302690 in __sigsetjmp () from /lib/libc.so.6
3: /x $f2 = 0x0
2: /x $r2 = 0x293
1: x/i $pc 0x41302690 <__sigsetjmp+64>: stfp f4, [r12], #8
(gdb) continue
Continuing.
Breakpoint 2, 0x41302684 in __sigsetjmp () from /lib/libc.so.6
3: /x $f2 = 0x0
2: /x $r2 = 0x293
1: x/i $pc 0x41302684 <__sigsetjmp+52>: beq 0x413026a0 <Lno_iwmmxt>
(gdb) continue 46
Will ignore next 45 crossings of breakpoint 2. Continuing.
---> __sigsetjmp still working fine, but then:
Breakpoint 2, 0x41302684 in __sigsetjmp () from /lib/libc.so.6
3: /x $f2 = 0x0
2: /x $r2 = 0x293
1: x/i $pc 0x41302684 <__sigsetjmp+52>: beq 0x413026a0 <Lno_iwmmxt>
(gdb) si
0x41302688 in __sigsetjmp () from /lib/libc.so.6
3: /x $f2 = 0x0
2: /x $r2 = 0x293
1: x/i $pc 0x41302688 <__sigsetjmp+56>: stfp f2, [r12], #8
(gdb) si
Program received signal SIGILL, Illegal instruction.
0x4130268c in __sigsetjmp () from /lib/libc.so.6
3: /x $f2 = 0x0
2: /x $r2 = 0x293
1: x/i $pc 0x4130268c <__sigsetjmp+60>: stfp f3, [r12], #8
Any suggestions what I could try next?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
发布的反汇编非常有趣。
该代码检查 fpscr 中的位 9,如果设置,则尝试保存寄存器 f2-f7。那些是什么?我从未在最近的处理器中见过它们,但我认为这些是 FPA(“浮点加速器”)寄存器,在一些旧内核中实现,并在 VFP 出现之前用于软 FP。
所以,我认为会发生以下情况:
在 FPA 支持下,可能是
错误。
意思是“启用 FPA”或其他什么
类似
FPSCR 的第 9 位(DZE = 除法
通过零异常启用位)不是
设置,这样他们就不会尝试保存 FPA
寄存器。然而,它被设置在
发布版本。
我在这里看到两个选项:
更新:我错了。 gdb 反汇编让我很困惑。我发现setjmp.S 的来源,这是相关部分:
所以,它试图存储 WMMXt 寄存器,而不是 FPA。 但是,这里有一个错误。它使用 r2 临时存储 fpscr,但是会覆盖 a3 中先前加载的 hwcap 值(a3 是 r2 的 APCS 名称)。也许作者打算使用a2,而不是r2,或者这两个部分可能是由不同的人完成的。无论哪种情况,Qt 的发布版本都会以某种方式更改 FPSCR(很可能由内核模拟)并触发存储 iwmmxt regs 的代码。
但这还不是故事的全部。 hwcaps 您粘贴的声称CPU确实支持iWMMXt,所以我不确定为什么这些指令会带来麻烦。也许报告的 PC 值在某种程度上是错误的。我认为您应该尝试在 __sigsetjmp 上放置断点并通过指令(stepi)逐步执行它,以查看它到底在哪里崩溃。
The posted disassembly is quite interesting.
The code checks for bit 9 in fpscr, and, if set, tries to save registers f2-f7. What are those? I've never seen them in recent processors, but I think those are FPA ("Floating Point Accelerator") registers, implemented in a few old cores, and used for soft FP before VFP appeared.
So, here's what I think happens:
with FPA support, probably by
mistake.
meant "FPA enabled" or something
similar
the bit 9 of FPSCR (DZE = Division
by Zero exception enable bit) is not
set, so they don't try to save FPA
registers. However, it gets set in
the release version.
I see here two options:
Update: I was wrong. The gdb disassembly confused me. I found the source of setjmp.S, here's the relevant part:
So, it's trying to store WMMXt registers, not FPA. However, there is a bug here. It's using r2 to temporarily store fpscr, but that ovewrites the previously loaded hwcap value in a3 (a3 is the APCS name for r2). Maybe the author meant to use a2, not r2, or maybe the two parts were done by different people. In either case, somehow the release version of Qt changes FPSCR (which is most likely emulated by the kernel) and the code storing iwmmxt regs is triggered.
Still, that's not the whole story. The hwcaps you pasted claim that the CPU does support iWMMXt, so I'm not sure why those instructions would be giving trouble. Maybe the reported PC value is wrong somehow. I think you should try putting breakpoint on __sigsetjmp and stepping through it by instruction (stepi), to see where exactly it crashes.
您好,几天前我遇到了类似的问题...但是我在 VMware 播放器(不是 ARM 设备)中的 Slackware Linux 上运行 Qt Creator 5.7。
安装成功后,我无法启动 Qt Creator。我尝试使用以下终端命令
/opt/Qt5.7.0/Tools/QtCreator/bin/qtcreator
运行 Qt Creator,但它给了我一个错误非法指令
。在 Google 上呆了几个小时后,我尝试使用此终端命令
/opt/Qt5.7.0/Tools/QtCreator/bin/qtcreator -noload Welcome
运行 Qt Creator,这对我有用。希望这对某人有帮助。抱歉回复晚了。
Hello I had similar problem few days ago... But I run Qt Creator 5.7 on my Slackware Linux in VMware player (not ARM device).
After successful installation I could not start Qt Creator. I tried to run Qt Creator with the following terminal command
/opt/Qt5.7.0/Tools/QtCreator/bin/qtcreator
and it gave me an errorIllegal instruction
.After few hours spent with Google, I tried to run Qt Creator with this terminal commands
/opt/Qt5.7.0/Tools/QtCreator/bin/qtcreator -noload Welcome
and this worked for me.Hope this helps someone. Sorry for late response.