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

发布于 2024-07-07 18:26:12 字数 683 浏览 7 评论 0原文

我们遇到了一个与在具有 Via C3 处理器的 Advantech POS 板上(相当旧的)FC3 下运行的 Java 应用程序相关的问题。 java 应用程序有几个已编译的共享库,可以通过 JNI 访问它们。

Via C3 处理器应该与 i686 兼容。 前段时间在具有相同处理器的MiniItx板上安装Ubuntu 6.10后,我发现之前的说法并不是100%正确。 由于缺少 C3 处理器中 i686 集的一些特定和可选指令,Ubuntu 内核在启动时挂起。 在使用 i686 优化时,GCC 编译器默认使用 i686 集的 C3 实现中缺少的这些指令。 在这种情况下,解决方案是使用 Ubuntu 发行版的 i386 编译版本。

Java 应用程序的基本问题是 FC3 发行版是通过从另一台 PC(这次是 Intel P4)的 HD 映像克隆来安装在 HD 上的。 之后,该发行版需要进行一些修改才能使其运行,例如用 i386 编译版本替换一些软件包(例如内核软件包)。

问题是,工作一段时间后,系统完全挂起,没有任何痕迹。 我担心某些 i686 代码会留在系统中的某个位置,并且可以随时随机执行(例如从挂起模式恢复后或类似的情况)。

我的问题是:

  • 是否有任何工具或方法可以找出二进制文件(可执行文件或库)需要哪些特定的体系结构扩展? file 没有提供足够的信息。

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. The java application has several compiled shared libs that are accessed via JNI.

Via C3 processor is supposed to be i686 compatible. 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. The Ubuntu kernel hanged on startup due to the lack of some specific and optional instructions of the i686 set in the C3 processor. These instructions missing in C3 implementation of i686 set are used by default by GCC compiler when using i686 optimizations. The solution, in this case, was to go with an i386 compiled version of Ubuntu distribution.

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. 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.

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).

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

故事和酒 2024-07-14 18:26:12

unix.linux file 命令非常适合此操作。 它通常可以检测给定二进制文件的目标体系结构和操作系统(并且自 1973 年以来一直断断续续地维护。哇!)

当然,如果您不是在 unix/linux 下运行 - 您就会有点卡住了。 我目前正在尝试找到一个可以在运行时调用的基于java的端口..但没有这样的运气。

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

(unix) objdump -f 命令暗示有关架构细节的更多详细信息,该命令返回:

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

该可执行文件由 gcc 交叉编译器编译(在 i86 机器上以 ARM 处理器为目标编译)

The unix.linux file command is great for this. It can generally detect the target architecture and operating system for a given binary (and has been maintained on and off since 1973. wow!)

Of course, if you're not running under unix/linux - you're a bit stuck. I'm currently trying to find a java based port that I can call at runtime.. but no such luck.

The unix file command gives information like this:

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:

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)

べ映画 2024-07-14 18:26:12

就我而言,fileobjdump 提供的信息还不够,grep 也没有任何帮助。

但有效的是:readelf -a -W 。 它输出很多信息。 与拱门相关的信息位于最开始和最后。 例子:

λ readelf -aW ./my_binary
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

In my case the information provided by file and objdump wasn't enough, neither was grep of any help.

What worked though is: readelf -a -W. It outputs a lot of info. The arch related information resides in the very beginning and the very end. Example:

λ readelf -aW ./my_binary
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
撩人痒 2024-07-14 18:26:12

我认为您需要一个工具来检查每条指令,以准确确定它属于哪一组。 C3 处理器实现的特定指令集是否有正式名称? 如果没有的话,它的毛就更多了。

如果您可以确定不允许的指令的位模式,则一种快速的变体可能是在文件中进行原始搜索。 只需直接测试它们即可通过简单的 objdump | 来完成 例如,grep 链。

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? 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. Just test for them directly, could be done by a simple objdump | grep chain, for instance.

影子的影子 2024-07-14 18:26:12

要回答 Via C3 是否是 i686 级处理器的歧义:不是,它是 i586 级处理器。

尽管 Cyrix 声称拥有 6x86MX 和 MII 部件,但他们从未生产过真正的 686 级处理器。 在其他缺失的指令中,他们没有的两个重要指令是 CMPXCHG8b 和 CPUID,这是运行 Windows XP 及更高版本所必需的。

National Semiconductor、AMD 和 VIA 都生产了基于 Cyrix 5x86/6x86 内核(NxP MediaGX、AMD Geode、VIA C3/C7、VIA Corefusion 等)的 CPU 设计,这些设计导致了 586 级处理器的奇怪设计具有SSE1/2/3指令集。

我的建议是,如果您遇到上面列出的任何 CPU,并且它不适合老式计算机项目(即 Windows 98SE 及更早版本),那么请立即远离它。 您将被困在缓慢的 i386/486 Linux 上,或者必须使用 Cyrix 特定的优化重新编译所有软件。

To answer the ambiguity of whether a Via C3 is a i686 class processor: It's not, it's an i586 class processor.

Cyrix never produced a true 686 class processor, despite their marketing claims with the 6x86MX and MII parts. Among other missing instructions, two important ones they didn't have were CMPXCHG8b and CPUID, which were required to run Windows XP and beyond.

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.

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. You'll be stuck on slow i386/486 Linux or have to recompile all of your software with Cyrix specific optimizations.

橘寄 2024-07-14 18:26:12

扩展@Hi-Angel的答案,我发现了一种检查静态库位宽度的简单方法:

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

其中libsomefile.a是我的静态库。 也应该适用于其他 ELF 文件。

Expanding upon @Hi-Angel's answer I found an easy way to check the bit width of a static library:

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

Where libsomefile.a is my static library. Should work for other ELF files as well.

半边脸i 2024-07-14 18:26:12

找到架构最快的事情就是执行:

objdump -f testFile | grep architecture

这甚至适用于二进制文件。

Quickest thing to find architecture would be to execute:

objdump -f testFile | grep architecture

This works even for binary.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文