确定导致“非法指令"的库.在Pi Zero W(armv6)上,并修复了构建 [英] Determining the library which causes "Illegal instruction" on a Pi Zero W (armv6), and fixing the build

查看:322
本文介绍了确定导致“非法指令"的库.在Pi Zero W(armv6)上,并修复了构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解到Pi Zero的许多编译问题是由于它们使用armv6造成的,而更新的Raspberry Pi(如3 A +和B +)则使用armv7.但是,我不了解如何在导致问题的应用程序中查找有问题的库,以及是否有针对此问题的简单解决方案.

I understand that a lot of compilation issues on the Pi Zeros are due to the fact that they use armv6, whereas the newer Raspberry Pi's like the 3 A+ and B+ use armv7. However, I do not understand how to find the offending library in an application that is causing the issue, and if there is perhaps a simple fix for the problem.

背景:

我正在尝试将应用程序从Linux桌面环境移植到Pi Zero(正在运行armv6).我已成功将其移植到Pi 3 B和B +.也就是说,我编译了代码,并检查它是否产生了正确的输出.

I am trying to port an application from a Linux Desktop environment to the Pi Zero (running armv6). I successfully ported it to the Pi 3 B and B+. That is, I compiled the code, and checked that it is producing the correct output.

但是,Pi Zero实现可以编译,但是在运行时只吐出一条消息:

However, the Pi Zero implementation compiles, but just spits out a single message when run:

Illegal instruction

这很可能是由于某些命令与armv6不兼容,但我无法弄清楚是哪个命令.我首先要确定哪个库是有问题的孩子.请告诉我我将如何诊断.

This is most likely due to some command that is not compatible with armv6, but I cannot figure out which command that is. I would like to start by determining which library is the problem child. Please tell me how I would diagnose that.

其他信息:

我已经检查过编译器不是问题.如何?我编写了一个简单的hello world程序,并为Pi Zero进行了编译:

I have checked that the compiler is not the issue. How? I made a simple hello world program, and compiled it for the Pi Zero:

#include<iostream>

int main(int argc, char *argv[]){
   std::cout << "Hello World!" << std::endl;
   return 0;
}

因此,编译器本身似乎不是问题.

So the compiler itself doesn't seem to be the issue.

更多详细信息:

如果运行readelf -A myapp,我的理解是输出报告该应用程序确实针对armv6进行了编译:

If I run readelf -A myapp, my understanding is that the output is reporting that the app is indeed compiled for armv6:

Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "6"
  Tag_CPU_arch: v6
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-1
  Tag_FP_arch: VFPv2
  Tag_ABI_PCS_wchar_t: 4
  Tag_ABI_FP_rounding: Needed
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_align_preserved: 8-byte, except leaf SP
  Tag_ABI_enum_size: int
  Tag_ABI_VFP_args: VFP registers
  Tag_CPU_unaligned_access: v6

以下是共享库之一的readelf -A:

Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "6"
  Tag_CPU_arch: v6
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-1
  Tag_FP_arch: VFPv4
  Tag_Advanced_SIMD_arch: NEONv1 with Fused-MAC
  Tag_ABI_PCS_wchar_t: 4
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_align_preserved: 8-byte, except leaf SP
  Tag_ABI_enum_size: int
  Tag_ABI_HardFP_use: Deprecated
  Tag_ABI_VFP_args: VFP registers
  Tag_CPU_unaligned_access: v6

推荐答案

要识别诸如Illegal instruction之类的故障,您可以在能够与操作系统的故障处理程序进行交互的调试器下运行该程序.

To identify a fault such as Illegal instruction you can run the program under a debugger capable of interacting with the operating system's fault handler.

在诸如pi的Linux系统上,将为gdb.您可能需要在基于debian的发行版上将其安装为sudo apt-get install gdb

On a Linux system such as the pi, that would be gdb. You may need to install this, on a debian-derived distribution that would be sudo apt-get install gdb

然后运行程序

gdb myprog

或者如果您的程序需要命令行参数

or if your program needs command line arguments

gdb myprog --args some_argument another_argument

一旦gdb启动,键入run,该程序将在接近非法指令的情况下正常执行,这时您将在gdb提示符下转储,并返回一条希望提供信息的错误消息.

Once gdb starts up type run, and the program will execute near normally until it reaches the illegal instruction, at which point you will be dumped back at the gdb prompt with a hopefully informative error message.

您可以使用backtrace之类的命令进行探索,或者程序员具有关联的源list.如果问题出在gdb可以看作是从文件映射的地址,它应该显示给您-您还可以通过gdb命令info files或在/proc/[PID]/maps

There you can explore with commands such as backtrace or if the programmer has associated source, list. If the fault is at an address gdb can see as being mapped as from a file it should show you that - you can also get at the mapping information via the gdb command info files or by looking in /proc/[PID]/maps

如果由于某种原因您无法在gdb下实时运行程序,则可以研究如何为系统启用核心转储,然后将程序和核心转储加载到gdb中以进行事后分析.

If for some reason you can't run the program live under gdb, you can research how to enable core dumps for your system, and then load the program and the core dump into gdb for post-mortem analysis.

根据系统配置,如果在没有调试器的情况下在自己的上运行程序,则可能还会在dmesg的输出或其他系统日志中看到有关故障的信息.

Depending on system configuration, if running the program on its own without a debugger, you may also see information about the fault in the output of dmesg or another system log.

这篇关于确定导致“非法指令"的库.在Pi Zero W(armv6)上,并修复了构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆