How can I know if an ARM library is using hardfp?

2019-03-11 00:33发布

I don't have access to the build command, I just have the library in my system.

I guess I could build an hardfp executable that links against it and test, but I'm wondering if there's an easier way.

标签: c++ gcc arm
3条回答
做自己的国王
2楼-- · 2019-03-11 00:42

Use readelf.

Here's some example output from one an ARM build of Poco:

$ 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

In the flags section, it will list data about the elf file. These are defined in the ARM ELF Specification, check table 4-2. In my case, this was built with a hard float compiler, so hard-float is listed as a flag.

On a soft float library, the flags line looks like this:

Flags: 0x5000202, has entry point, Version5 EABI, soft-float ABI
查看更多
再贱就再见
3楼-- · 2019-03-11 00:53

Execute readelf -A library.so: if the list of printed tags contains Tag_ABI_VFP_args: VFP registers, then it is a hardfp binary, otherwise assume softfp.

E.g. readelf -A /lib/arm-linux-gnueabihf/libm.so.6 will produce

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

On the other side, readelf -A /lib/arm-linux-gnueabi/libm.so.6 produces

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
查看更多
虎瘦雄心在
4楼-- · 2019-03-11 00:58

Use objdump -d to disassemble, then grep for some floating point commands. I'm not sure whether objdump will produce UAL-compliant assembly, so try old syntax too. It might be even easier to watch for register names rather than command mnemonics, but there could be false positives.

查看更多
登录 后发表回答