确定 Linux 中二进制文件的目标 ISA 扩展名(库或可执行文件)
我们遇到了一个与在具有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
unix.linux
file
命令非常适合此操作。 它通常可以检测给定二进制文件的目标体系结构和操作系统(并且自 1973 年以来一直断断续续地维护。哇!)当然,如果您不是在 unix/linux 下运行 - 您就会有点卡住了。 我目前正在尝试找到一个可以在运行时调用的基于java的端口..但没有这样的运气。
unix
file
命令提供如下信息:(unix)
objdump -f
命令暗示有关架构细节的更多详细信息,该命令返回:该可执行文件由 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:More detailed information about the details of the architecture are hinted at with the (unix)
objdump -f <fileName>
command which returns:This executable was compiled by a gcc cross compiler (compiled on an i86 machine for the ARM processor as a target)
就我而言,
file
和objdump
提供的信息还不够,grep
也没有任何帮助。但有效的是:readelf -a -W 。 它输出很多信息。 与拱门相关的信息位于最开始和最后。 例子:
In my case the information provided by
file
andobjdump
wasn't enough, neither wasgrep
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:我认为您需要一个工具来检查每条指令,以准确确定它属于哪一组。 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.要回答 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.
扩展@Hi-Angel的答案,我发现了一种检查静态库位宽度的简单方法:
其中
libsomefile.a
是我的静态库。 也应该适用于其他 ELF 文件。Expanding upon @Hi-Angel's answer I found an easy way to check the bit width of a static library:
Where
libsomefile.a
is my static library. Should work for other ELF files as well.找到架构最快的事情就是执行:
这甚至适用于二进制文件。
Quickest thing to find architecture would be to execute:
This works even for binary.