简体   繁体   English

确定Linux(库或可执行文件)中二进制文件的目标ISA扩展

[英]Determine target ISA extensions of binary file in Linux (library or executable)

We have an issue related to a Java application running under a (rather old) FC3 on an Advantech POS board with a Via C3 processor. 我们遇到了一个与在Advantech POS板上使用Via C3处理器在(相当旧的)FC3下运行的Java应用程序相关的问题。 The java application has several compiled shared libs that are accessed via JNI. java应用程序有几个已编译的共享库,可通过JNI访问。

Via C3 processor is supposed to be i686 compatible. 通过C3处理器应该是i686兼容。 Some time ago after installing Ubuntu 6.10 on a MiniItx board with the same processor, I found out that the previous statement is not 100% true. 前段时间在使用相同处理器的MiniItx主板上安装Ubuntu 6.10之后,我发现之前的声明并非100%正确。 The Ubuntu kernel hanged on startup due to the lack of some specific and optional instructions of the i686 set in the C3 processor. 由于缺少C3处理器中i686设置的一些特定和可选指令,Ubuntu内核在启动时挂起。 These instructions missing in C3 implementation of i686 set are used by default by GCC compiler when using i686 optimizations. 在使用i686优化时,GCC编译器默认使用i686集的C3实现中缺少的这些指令。 The solution, in this case, was to go with an i386 compiled version of Ubuntu distribution. 在这种情况下,解决方案是使用i386编译版本的Ubuntu发行版。

The base problem with the Java application is that the FC3 distribution was installed on the HD by cloning from an image of the HD of another PC, this time an Intel P4. Java应用程序的基本问题是通过克隆另一台PC的HD映像来安装在HD上的FC3发行版,这次是Intel P4。 Afterwards, the distribution needed some hacking to have it running such as replacing some packages (such as the kernel one) with the i386 compiled version. 之后,分发需要一些黑客才能让它运行,比如用i386编译的版本替换一些软件包(例如内核)。

The problem is that after working for a while the system completely hangs without a trace. 问题是,工作一段时间后系统完全挂起而没有任何痕迹。 I am afraid that some i686 code is left somewhere in the system and could be executed randomly at any time (for example after recovering from suspend mode or something like that). 我担心一些i686代码会留在系统中的某个地方,并且可以随时随机执行(例如从暂停模式恢复后或类似的东西)。

My question is: 我的问题是:

  • Is there any tool or way to find out at what specific architecture extensions a binary file (executable or library) requires? 是否有任何工具或方法可以找出二进制文件(可执行文件或库)所需的特定体系结构扩展? file does not give enough information. file没有提供足够的信息。

The unix.linux file command is great for this. unix.linux file命令非常适用于此。 It can generally detect the target architecture and operating system for a given binary (and has been maintained on and off since 1973. wow!) 它通常可以检测给定二进制文件的目标体系结构和操作系统(并且自1973年以来一直保持打开和关闭状态。哇!)

Of course, if you're not running under unix/linux - you're a bit stuck. 当然,如果你没有在unix / linux下运行 - 你有点卡住了。 I'm currently trying to find a java based port that I can call at runtime.. but no such luck. 我目前正在尝试找到一个可以在运行时调用的基于java的端口..但没有这样的运气。

The unix file command gives information like this: unix file命令提供如下信息:

hex: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.4.17, not stripped

More detailed information about the details of the architecture are hinted at with the (unix) objdump -f <fileName> command which returns: 使用(unix) objdump -f <fileName>命令提示有关体系结构详细信息的更多详细信息,该命令返回:

architecture: arm, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x0000876c

This executable was compiled by a gcc cross compiler (compiled on an i86 machine for the ARM processor as a target) 这个可执行文件是由gcc交叉编译器编译的(在i86机器上编译,用于ARM处理器作为目标)

I decide to add one more solution for any, who got here: personally in my case the information provided by the file and objdump wasn't enough, and the grep isn't much of a help -- I resolve my case through the readelf -a -W . 我决定为这里的任何人添加一个解决方案:在我的情况下, file提供的信息和objdump是不够的, grep没有多大帮助 - 我通过readelf -a -W解决了我的情况readelf -a -W

Note, that this gives you pretty much info. 请注意,这可以为您提供相当多的信息。 The arch related information resides in the very beginning and the very end. 拱形相关信息始于最开始和最后。 Here's an example: 这是一个例子:

ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           ARM
  Version:                           0x1
  Entry point address:               0x83f8
  Start of program headers:          52 (bytes into file)
  Start of section headers:          2388 (bytes into file)
  Flags:                             0x5000202, has entry point, Version5 EABI, soft-float ABI
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         8
  Size of section headers:           40 (bytes)
  Number of section headers:         31
  Section header string table index: 28
...
Displaying notes found at file offset 0x00000148 with length 0x00000020:
  Owner                 Data size   Description
  GNU                  0x00000010   NT_GNU_ABI_TAG (ABI version tag)
    OS: Linux, ABI: 2.6.16
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "7-A"
  Tag_CPU_arch: v7
  Tag_CPU_arch_profile: Application
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-2
  Tag_FP_arch: VFPv3
  Tag_Advanced_SIMD_arch: NEONv1
  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_HardFP_use: SP and DP
  Tag_CPU_unaligned_access: v6

I think you need a tool that checks every instruction, to determine exactly which set it belongs to. 我认为你需要一个检查每条指令的工具,以确定它属于哪个集合。 Is there even an offical name for the specific set of instructions implemented by the C3 processor? 是否有C3处理器实现的特定指令集的官方名称? If not, it's even hairier. 如果没有,它甚至更加毛茸茸。

A quick'n'dirty variant might be to do a raw search in the file, if you can determine the bit pattern of the disallowed instructions. 如果您可以确定不允许的指令的位模式,那么quick'n'dirty变体可能是在文件中进行原始搜索。 Just test for them directly, could be done by a simple objdump | grep 只需直接测试它们,就可以通过一个简单的objdump | grep来完成 objdump | grep chain, for instance. 例如, objdump | grep链。

To answer the ambiguity of whether a Via C3 is a i686 class processor: It's not, it's an i586 class processor. 为了回答Via C3是否是i686级处理器的模糊性:它不是,它是i586级处理器。

Cyrix never produced a true 686 class processor, despite their marketing claims with the 6x86MX and MII parts. Cyrix从未生产出真正的686级处理器,尽管他们推销了6x86MX和MII部件。 Among other missing instructions, two important ones they didn't have were CMPXCHG8b and CPUID, which were required to run Windows XP and beyond. 在其他缺失的指令中,他们没有的两个重要指令是CMPXCHG8b和CPUID,它们是运行Windows XP及更高版本所必需的。

National Semiconductor, AMD and VIA have all produced CPU designs based on the Cyrix 5x86/6x86 core (NxP MediaGX, AMD Geode, VIA C3/C7, VIA Corefusion, etc.) which have resulted in oddball designs where you have a 586 class processor with SSE1/2/3 instruction sets. 美国国家半导体,AMD和VIA都生产了基于Cyrix 5x86 / 6x86核心(NxP MediaGX,AMD Geode,VIA C3 / C7,VIA Corefusion等)的CPU设计,这些设计导致了具有586级处理器的古怪设计使用SSE1 / 2/3指令集。

My recommendation if you come across any of the CPUs listed above and it's not for a vintage computer project (ie. Windows 98SE and prior) then run screaming away from it. 我的建议是,如果您遇到上面列出的任何CPU,并且它不适用于老式计算机项目(即Windows 98SE和之前的版本),那么就会尖叫远离它。 You'll be stuck on slow i386/486 Linux or have to recompile all of your software with Cyrix specific optimizations. 您将被困在慢速i386 / 486 Linux上,或者必须使用特定于Cyrix的优化重新编译所有软件。

Expanding upon @Hi-Angel's answer I found an easy way to check the bit width of a static library: 扩展@ Hi-Angel的答案我找到了一种简单的方法来检查静态库的位宽:

readelf -a -W libsomefile.a | grep Class: | sort | uniq

Where libsomefile.a is my static library. libsomefile.a是我的静态库。 Should work for other ELF files as well. 也适用于其他ELF文件。

Quickest thing to find architecture would be to execute: 找到架构最快的方法就是执行:

objdump -f testFile | grep architecture

This works even for binary. 这甚至适用于二进制文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Linux中使用gcc确定文件是二进制可执行文件还是脚本文件 - Determine whether a file is a binary executable file or a script file using gcc in Linux Linux可执行文件作为共享库 - Linux executable file as shared library 如何在Linux终端中运行二进制可执行文件 - How to run a binary executable file in linux terminal 将所有库依赖项包含到可执行文件Linux中 - Include all library dependencies into an executable file Linux 如何将 linux 可执行文件(二进制)转换为 windows exe 文件? - How to convert a linux executable file (binary) to windows exe file? Windows和Linux中二进制文件的C库校验和 - C Library checksum for binary file in windows and linux 如何将jar文件制作为Linux的可执行二进制文件并作为服务运行 - How to make a jar file as executable binary for linux and run as service 内核如何获取在linux下运行的可执行二进制文件? - How does kernel get an executable binary file running under linux? 共享库(.so)与 Linux 可执行文件之间的区别没有扩展名? - Difference between shared library (.so) a Linux executable file without extension? 32 位 linux 可执行文件失败并出现 Exec 格式错误。 二进制文件不可执行 - 32 bit linux executable failing with Exec format error. Binary file not executable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM