查看共享库信息,编译器,软硬浮点、依赖库

很多时候,特别是交叉编译环境,经常出现编译版本的差异导致各类问题。这时候需要判断所用共享库是否与目标平台匹配。

./autPlayerTest: error while loading shared libraries: /usr/lib/libbase.so: internal error

此时,我们可以通过readelf来追溯库文件的内容以定位问题,以判断是否共享库与运行平台是否不兼容。
查看该共享库头信息:

arm-linux-gnueabihf-readelf ~/libbase.so -h
ELF 头:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  类别:                              ELF32
  数据:                              2 补码,小端序 (little endian)
  版本:                              1 (current)
  OS/ABI:                            UNIX - System V
  ABI 版本:                          0
  类型:                              DYN (共享目标文件)
  系统架构:                          ARM
  版本:                              0x1
  入口点地址:               0x2f20
  程序头起点:          52 (bytes into file)
  Start of section headers:          149136 (bytes into file)
  标志:             0x5000202, has entry point, Version5 EABI, soft-float ABI
  本头的大小:       52 (字节)
  程序头大小:       32 (字节)
  Number of program headers:         6
  节头大小:         40 (字节)
  节头数量:         37
  字符串表索引节头: 34

对比目标平台库信息:

arm-linux-gnueabihf-readelf ../sdk_lib/libbase.so -h
ELF 头:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  类别:                              ELF32
  数据:                              2 补码,小端序 (little endian)
  版本:                              1 (current)
  OS/ABI:                            UNIX - System V
  ABI 版本:                          0
  类型:                              DYN (共享目标文件)
  系统架构:                          ARM
  版本:                              0x1
  入口点地址:               0x2f20
  程序头起点:          52 (bytes into file)
  Start of section headers:          148972 (bytes into file)
  标志:             0x5000402, has entry point, Version5 EABI, hard-float ABI
  本头的大小:       52 (字节)
  程序头大小:       32 (字节)
  Number of program headers:         6
  节头大小:         40 (字节)
  节头数量:         37
  字符串表索引节头: 34

可以看到两者不同在于 hard-float ABI和soft-float ABI的差别。
我们还可以查看其它信息:

arm-linux-gnueabihf-readelf sdk_disp/libbase.so -a
ELF 头:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  类别:                              ELF32
  数据:                              2 补码,小端序 (little endian)
  版本:                              1 (current)
  OS/ABI:                            UNIX - System V
  ABI 版本:                          0
  类型:                              DYN (共享目标文件)
  系统架构:                          ARM
  版本:                              0x1
  入口点地址:               0x1908
  程序头起点:          52 (bytes into file)
  Start of section headers:          74492 (bytes into file)
  标志:             0x5000402, has entry point, Version5 EABI, hard-float ABI
  本头的大小:       52 (字节)
  程序头大小:       32 (字节)
  Number of program headers:         6
  节头大小:         40 (字节)
  节头数量:         36
  字符串表索引节头: 33

节头:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .note.gnu.build-i NOTE            000000f4 0000f4 000024 00   A  0   0  4
  [ 2] .hash             HASH            00000118 000118 000290 04   A  3   0  4
  [ 3] .dynsym           DYNSYM          000003a8 0003a8 0005f0 10   A  4   3  4
  [ 4] .dynstr           STRTAB          00000998 000998 0009ca 00   A  0   0  1
  [ 5] .gnu.version      VERSYM          00001362 001362 0000be 02   A  3   0  2
  [ 6] .gnu.version_r    VERNEED         00001420 001420 0000a0 00   A  4   4  4
  [ 7] .rel.dyn          REL             000014c0 0014c0 000068 08   A  3   0  4
  [ 8] .rel.plt          REL             00001528 001528 000180 08  AI  3  10  4
  [ 9] .init             PROGBITS        000016a8 0016a8 00000c 00  AX  0   0  4
  [10] .plt              PROGBITS        000016b4 0016b4 000254 04  AX  0   0  4
  [11] .text             PROGBITS        00001908 001908 003f34 00  AX  0   0  4
  [12] .fini             PROGBITS        0000583c 00583c 000008 00  AX  0   0  4
  [13] .rodata           PROGBITS        00005844 005844 000604 00   A  0   0  4
  [14] .ARM.extab        PROGBITS        00005e48 005e48 00013c 00   A  0   0  4
  [15] .ARM.exidx        ARM_EXIDX       00005f84 005f84 0000d8 00  AL 11   0  4
  [16] .eh_frame         PROGBITS        0000605c 00605c 000004 00   A  0   0  4
  [17] .init_array       INIT_ARRAY      00016060 006060 000008 00  WA  0   0  4
  [18] .fini_array       FINI_ARRAY      00016068 006068 000004 00  WA  0   0  4
  [19] .jcr              PROGBITS        0001606c 00606c 000004 00  WA  0   0  4
  [20] .dynamic          DYNAMIC         00016070 006070 000100 08  WA  4   0  4
  [21] .got              PROGBITS        00016170 006170 0000f0 04  WA  0   0  4
  [22] .data             PROGBITS        00016260 006260 000004 00  WA  0   0  4
  [23] .bss              NOBITS          00016264 006264 000050 00  WA  0   0  4
  [24] .comment          PROGBITS        00000000 006264 00002d 01  MS  0   0  1
  [25] .ARM.attributes   ARM_ATTRIBUTES  00000000 006291 000039 00      0   0  1
  [26] .debug_aranges    PROGBITS        00000000 0062d0 0000e8 00      0   0  8
  [27] .debug_info       PROGBITS        00000000 0063b8 0043dd 00      0   0  1
  [28] .debug_abbrev     PROGBITS        00000000 00a795 00084d 00      0   0  1
  [29] .debug_line       PROGBITS        00000000 00afe2 0010f7 00      0   0  1
  [30] .debug_frame      PROGBITS        00000000 00c0dc 000674 00      0   0  4
  [31] .debug_str        PROGBITS        00000000 00c750 0038b2 01  MS  0   0  1
  [32] .debug_ranges     PROGBITS        00000000 010008 000088 00      0   0  8
  [33] .shstrtab         STRTAB          00000000 010090 000156 00      0   0  1
  [34] .symtab           SYMTAB          00000000 0101e8 001110 10     35 181  4
  [35] .strtab           STRTAB          00000000 0112f8 001001 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

There are no section groups in this file.

程序头:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  EXIDX          0x005f84 0x00005f84 0x00005f84 0x000d8 0x000d8 R   0x4
  LOAD           0x000000 0x00000000 0x00000000 0x06060 0x06060 R E 0x10000
  LOAD           0x006060 0x00016060 0x00016060 0x00204 0x00254 RW  0x10000
  DYNAMIC        0x006070 0x00016070 0x00016070 0x00100 0x00100 RW  0x4
  NOTE           0x0000f4 0x000000f4 0x000000f4 0x00024 0x00024 R   0x4
  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0x10

 Section to Segment mapping:
  段节...
   00     .ARM.exidx 
   01     .note.gnu.build-id .hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt .init .plt .text .fini .rodata .ARM.extab .ARM.exidx .eh_frame 
   02     .init_array .fini_array .jcr .dynamic .got .data .bss 
   03     .dynamic 
   04     .note.gnu.build-id 
   05     

Dynamic section at offset 0x6070 contains 28 entries:
  标记        类型                         名称/值
 0x00000001 (NEEDED)                     共享库:[libpthread.so.0]
 0x00000001 (NEEDED)                     共享库:[libstdc++.so.6]
 0x00000001 (NEEDED)                     共享库:[libm.so.6]
 0x00000001 (NEEDED)                     共享库:[libgcc_s.so.1]
 0x00000001 (NEEDED)                     共享库:[libc.so.6]

1.查看共享库编译参数:

  类别:                              ELF32
  数据:                              2 补码,小端序 (little endian)
  版本:                              1 (current)
  OS/ABI:                            UNIX - System V
  ABI 版本:                          0
  类型:                              DYN (共享目标文件)
  系统架构:                          ARM
  版本:                              0x1

2.查看共享库软浮点还是硬浮点:

  标志:             0x5000402, has entry point, Version5 EABI, hard-float ABI

3.参考共享库的依赖库文件:

 0x00000001 (NEEDED)                     共享库:[libpthread.so.0]
 0x00000001 (NEEDED)                     共享库:[libstdc++.so.6]
 0x00000001 (NEEDED)                     共享库:[libm.so.6]
 0x00000001 (NEEDED)                     共享库:[libgcc_s.so.1]
 0x00000001 (NEEDED)                     共享库:[libc.so.6]

4.文件信息:

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_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_VFP_args: VFP registers
  Tag_CPU_unaligned_access: v6
  Tag_MPextension_use: Allowed
  Tag_DIV_use: Allowed in v7-A with integer division extension
  Tag_Virtualization_use: TrustZone and Virtualization Extensions

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值