如何确定 ARM 库是否使用硬件浮点运算(hardfp)?

22

我没有访问构建命令的权限,只有这个库在我的系统中。

我猜我可以构建一个链接到它的hardfp可执行文件并进行测试,但我想知道是否有更简单的方法。


1
我会尝试反汇编库并查找相应的hardfp指令。这些指令的存在或缺失是一个很好的指标。 - Ali
3个回答

22

执行 readelf -A library.so 命令:如果输出的标签列表中包含 Tag_ABI_VFP_args: VFP registers,则它是一个 hardfp 二进制文件;否则假设它是 softfp

例如,readelf -A /lib/arm-linux-gnueabihf/libm.so.6 将产生以下输出:

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-D16
  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: SP and DP
  Tag_ABI_VFP_args: VFP registers
  Tag_ABI_optimization_goals: Aggressive Speed
  Tag_CPU_unaligned_access: v6

另一方面,readelf -A /lib/arm-linux-gnueabi/libm.so.6 生成:

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-D16
  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_optimization_goals: Aggressive Speed
  Tag_CPU_unaligned_access: v6

1
你能告诉我为什么这个命令在我的 AMD64 Linux 系统上没有产生任何输出吗? - enedil
该库不适用于ARM,或者该库适用于旧的ARM ABI(OABI),或者您的readelf不支持解析ARM EABI属性。 - Marat Dukhan
2
AMD64 ELF未定义特定于架构的属性部分。 - Marat Dukhan
这个解决方案适用于静态库吗?编译到库存档中的目标代码也算作 ELF 文件并具有这些属性吗? - Spidey
1
@Spidey 我认为你需要提取一个存档成员(目标文件)才能使用这种方法。 - Marat Dukhan
显示剩余3条评论

8

使用readelf命令。

以下是Poco ARM版本的示例输出:

$ readelf libPocoFoundation.so -h
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:                              DYN (Shared object file)
  Machine:                           ARM
  Version:                           0x1
  Entry point address:               0x61e50
  Start of program headers:          52 (bytes into file)
  Start of section headers:          1078048 (bytes into file)
  Flags:                             0x5000402, has entry point, Version5 EABI, hard-float ABI
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         7
  Size of section headers:           40 (bytes)
  Number of section headers:         28
  Section header string table index: 27

在标志部分,它将列出有关elf文件的数据。这些定义在ARM ELF规范中,请查看表4-2。在我的情况下,使用硬浮点编译器构建,因此硬浮点被列为标志。
在软浮点库上,标志行如下:
Flags: 0x5000202, has entry point, Version5 EABI, soft-float ABI

3
hardfp/softfp标志是最近才加入的,只有最新的工具链支持它们。旧的工具链只在EABI属性部分指示浮点ABI。 - Marat Dukhan
引用自参考文档:EF_ARM_ABI_FLOAT_HARD(0x00000400)(ABI版本5及更高版本):在可执行文件头中设置(e_type = ET_EXEC或ET_DYN),以表示可执行文件构建时符合硬件浮点过程调用标准。与旧版(版本5之前)gcc兼容,可用作EF_ARM_VFP_FLOAT。 - undefined

-2
使用objdump -d进行反汇编,然后grep一些浮点命令。我不确定objdump是否会生成符合UAL的汇编语言,因此也可以尝试旧语法。观察寄存器名称可能比命令助记符更容易,但可能会有误报。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接