关于加载器ld-linux-armhf.so.3

关于加载器ld-linux-armhf.so.3

这几天在搞一块am335x的板子,移植完成之后,发现在上面运行程序时候出现

-sh: ./a.out: not found

这个就很奇怪了。
后来发现并不是我的a.out找不到而是板子当前的环境下,缺少加载器。

运行 readelf a.out -a

esc_fei@fei-virtual-machine:~/test/hello$ readelf a.out -a
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:               0x102f1
  Start of program headers:          52 (bytes into file)
  Start of section headers:          5236 (bytes into file)
  Flags:                             0x5000402, has entry point, Version5 EABI, <unknown>
  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:         38
  Section header string table index: 35

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .interp           PROGBITS        00010134 000134 000019 00   A  0   0  1
  [ 2] .note.ABI-tag     NOTE            00010150 000150 000020 00   A  0   0  4
  [ 3] .note.gnu.build-i NOTE            00010170 000170 000024 00   A  0   0  4
  [ 4] .hash             HASH            00010194 000194 000028 04   A  5   0  4
  [ 5] .dynsym           DYNSYM          000101bc 0001bc 000050 10   A  6   1  4
  [ 6] .dynstr           STRTAB          0001020c 00020c 000041 00   A  0   0  1
  [ 7] .gnu.version      VERSYM          0001024e 00024e 00000a 02   A  5   0  2
  [ 8] .gnu.version_r    VERNEED         00010258 000258 000020 00   A  6   1  4
  [ 9] .rel.dyn          REL             00010278 000278 000008 08   A  5   0  4
  [10] .rel.plt          REL             00010280 000280 000020 08   A  5  12  4
  [11] .init             PROGBITS        000102a0 0002a0 00000c 00  AX  0   0  4
  [12] .plt              PROGBITS        000102ac 0002ac 000044 04  AX  0   0  4
  [13] .text             PROGBITS        000102f0 0002f0 00013c 00  AX  0   0  4
  [14] .fini             PROGBITS        0001042c 00042c 000008 00  AX  0   0  4
  [15] .rodata           PROGBITS        00010434 000434 00000c 00   A  0   0  4
  [16] .ARM.exidx        ARM_EXIDX       00010440 000440 000008 00  AL 13   0  4
  [17] .eh_frame         PROGBITS        00010448 000448 000004 00   A  0   0  4
  [18] .init_array       INIT_ARRAY      0002044c 00044c 000004 00  WA  0   0  4
  [19] .fini_array       FINI_ARRAY      00020450 000450 000004 00  WA  0   0  4
  [20] .jcr              PROGBITS        00020454 000454 000004 00  WA  0   0  4
  [21] .dynamic          DYNAMIC         00020458 000458 0000e8 08  WA  6   0  4
  [22] .got              PROGBITS        00020540 000540 000020 04  WA  0   0  4
  [23] .data             PROGBITS        00020560 000560 000008 00  WA  0   0  4
  [24] .bss              NOBITS          00020568 000568 000004 00  WA  0   0  1
  [25] .comment          PROGBITS        00000000 000568 00003a 01  MS  0   0  1
  [26] .ARM.attributes   ARM_ATTRIBUTES  00000000 0005a2 000035 00      0   0  1
  [27] .debug_aranges    PROGBITS        00000000 0005d8 0000b0 00      0   0  8
  [28] .debug_info       PROGBITS        00000000 000688 00042e 00      0   0  1
  [29] .debug_abbrev     PROGBITS        00000000 000ab6 000183 00      0   0  1
  [30] .debug_line       PROGBITS        00000000 000c39 000275 00      0   0  1
  [31] .debug_frame      PROGBITS        00000000 000eb0 000044 00      0   0  4
  [32] .debug_str        PROGBITS        00000000 000ef4 0002f0 01  MS  0   0  1
  [33] .debug_loc        PROGBITS        00000000 0011e4 0000bb 00      0   0  1
  [34] .debug_ranges     PROGBITS        00000000 0012a0 000068 00      0   0  8
  [35] .shstrtab         STRTAB          00000000 001308 00016c 00      0   0  1
  [36] .symtab           SYMTAB          00000000 001a64 000770 10     37  94  4
  [37] .strtab           STRTAB          00000000 0021d4 000529 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.

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  EXIDX          0x000440 0x00010440 0x00010440 0x00008 0x00008 R   0x4
  PHDR           0x000034 0x00010034 0x00010034 0x00100 0x00100 R E 0x4
  INTERP         0x000134 0x00010134 0x00010134 0x00019 0x00019 R   0x1
      [Requesting program interpreter: /lib/ld-linux-armhf.so.3]
  LOAD           0x000000 0x00010000 0x00010000 0x0044c 0x0044c R E 0x10000
  LOAD           0x00044c 0x0002044c 0x0002044c 0x0011c 0x00120 RW  0x10000
  DYNAMIC        0x000458 0x00020458 0x00020458 0x000e8 0x000e8 RW  0x4
  NOTE           0x000150 0x00010150 0x00010150 0x00044 0x00044 R   0x4
  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0x10

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

Dynamic section at offset 0x458 contains 24 entries:
  Tag        Type                         Name/Value
 0x00000001 (NEEDED)                     Shared library: [libc.so.6]
 0x0000000c (INIT)                       0x102a0
 0x0000000d (FINI)                       0x1042c
 0x00000019 (INIT_ARRAY)                 0x2044c
 0x0000001b (INIT_ARRAYSZ)               4 (bytes)
 0x0000001a (FINI_ARRAY)                 0x20450
 0x0000001c (FINI_ARRAYSZ)               4 (bytes)
 0x00000004 (HASH)                       0x10194
 0x00000005 (STRTAB)                     0x1020c
 0x00000006 (SYMTAB)                     0x101bc
 0x0000000a (STRSZ)                      65 (bytes)
 0x0000000b (SYMENT)                     16 (bytes)
 0x00000015 (DEBUG)                      0x0
 0x00000003 (PLTGOT)                     0x20540
 0x00000002 (PLTRELSZ)                   32 (bytes)
 0x00000014 (PLTREL)                     REL
 0x00000017 (JMPREL)                     0x10280
 0x00000011 (REL)                        0x10278
 0x00000012 (RELSZ)                      8 (bytes)
 0x00000013 (RELENT)                     8 (bytes)
 0x6ffffffe (VERNEED)                    0x10258
 0x6fffffff (VERNEEDNUM)                 1
 0x6ffffff0 (VERSYM)                     0x1024e
 0x00000000 (NULL)                       0x0

Relocation section '.rel.dyn' at offset 0x278 contains 1 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
0002055c  00000315 R_ARM_GLOB_DAT    00000000   __gmon_start__

Relocation section '.rel.plt' at offset 0x280 contains 4 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
0002054c  00000116 R_ARM_JUMP_SLOT   00000000   puts
00020550  00000216 R_ARM_JUMP_SLOT   00000000   __libc_start_main
00020554  00000316 R_ARM_JUMP_SLOT   00000000   __gmon_start__
00020558  00000416 R_ARM_JUMP_SLOT   00000000   abort

Unwind table index '.ARM.exidx' at offset 0x440 contains 1 entries:

0x102f0 <_start>: 0x1 [cantunwind]


Symbol table '.dynsym' contains 5 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 00000000     0 FUNC    GLOBAL DEFAULT  UND puts@GLIBC_2.4 (2)
     2: 00000000     0 FUNC    GLOBAL DEFAULT  UND __libc_start_main@GLIBC_2.4 (2)
     3: 00000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__
     4: 00000000     0 FUNC    GLOBAL DEFAULT  UND abort@GLIBC_2.4 (2)

Symbol table '.symtab' contains 119 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 00010134     0 SECTION LOCAL  DEFAULT    1 
     2: 00010150     0 SECTION LOCAL  DEFAULT    2 
     3: 00010170     0 SECTION LOCAL  DEFAULT    3 
     4: 00010194     0 SECTION LOCAL  DEFAULT    4 
     5: 000101bc     0 SECTION LOCAL  DEFAULT    5 
     6: 0001020c     0 SECTION LOCAL  DEFAULT    6 
     7: 0001024e     0 SECTION LOCAL  DEFAULT    7 
     8: 00010258     0 SECTION LOCAL  DEFAULT    8 
     9: 00010278     0 SECTION LOCAL  DEFAULT    9 
    10: 00010280     0 SECTION LOCAL  DEFAULT   10 
    11: 000102a0     0 SECTION LOCAL  DEFAULT   11 
    12: 000102ac     0 SECTION LOCAL  DEFAULT   12 
    13: 000102f0     0 SECTION LOCAL  DEFAULT   13 
    14: 0001042c     0 SECTION LOCAL  DEFAULT   14 
    15: 00010434     0 SECTION LOCAL  DEFAULT   15 
    16: 00010440     0 SECTION LOCAL  DEFAULT   16 
    17: 00010448     0 SECTION LOCAL  DEFAULT   17 
    18: 0002044c     0 SECTION LOCAL  DEFAULT   18 
    19: 00020450     0 SECTION LOCAL  DEFAULT   19 
    20: 00020454     0 SECTION LOCAL  DEFAULT   20 
    21: 00020458     0 SECTION LOCAL  DEFAULT   21 
    22: 00020540     0 SECTION LOCAL  DEFAULT   22 
    23: 00020560     0 SECTION LOCAL  DEFAULT   23 
    24: 00020568     0 SECTION LOCAL  DEFAULT   24 
    25: 00000000     0 SECTION LOCAL  DEFAULT   25 
    26: 00000000     0 SECTION LOCAL  DEFAULT   26 
    27: 00000000     0 SECTION LOCAL  DEFAULT   27 
    28: 00000000     0 SECTION LOCAL  DEFAULT   28 
    29: 00000000     0 SECTION LOCAL  DEFAULT   29 
    30: 00000000     0 SECTION LOCAL  DEFAULT   30 
    31: 00000000     0 SECTION LOCAL  DEFAULT   31 
    32: 00000000     0 SECTION LOCAL  DEFAULT   32 
    33: 00000000     0 SECTION LOCAL  DEFAULT   33 
    34: 00000000     0 SECTION LOCAL  DEFAULT   34 
    35: 00000000     0 FILE    LOCAL  DEFAULT  ABS /home/tcwg-buildslave/wor
    36: 00010150     0 NOTYPE  LOCAL  DEFAULT    2 $d
    37: 00000000     0 FILE    LOCAL  DEFAULT  ABS /home/tcwg-buildslave/wor
    38: 000102f0     0 NOTYPE  LOCAL  DEFAULT   13 $t
    39: 00010440     0 NOTYPE  LOCAL  DEFAULT   16 $d
    40: 00010314     0 NOTYPE  LOCAL  DEFAULT   13 $d
    41: 0000000c     0 NOTYPE  LOCAL  DEFAULT   27 $d
    42: 00000000     0 FILE    LOCAL  DEFAULT  ABS init.c
    43: 00010434     0 NOTYPE  LOCAL  DEFAULT   15 $d
    44: 00000000     0 FILE    LOCAL  DEFAULT  ABS 
    45: 00020560     0 NOTYPE  LOCAL  DEFAULT   23 $d
    46: 00000000     0 FILE    LOCAL  DEFAULT  ABS /home/esc_fei/Project/lie
    47: 00010320     0 NOTYPE  LOCAL  DEFAULT   13 $a
    48: 00010320     0 FUNC    LOCAL  DEFAULT   13 call_weak_fn
    49: 0001033c     0 NOTYPE  LOCAL  DEFAULT   13 $d
    50: 000102a0     0 NOTYPE  LOCAL  DEFAULT   11 $a
    51: 0001042c     0 NOTYPE  LOCAL  DEFAULT   14 $a
    52: 00000044     0 NOTYPE  LOCAL  DEFAULT   27 $d
    53: 00000000     0 FILE    LOCAL  DEFAULT  ABS /home/esc_fei/Project/lie
    54: 000102a8     0 NOTYPE  LOCAL  DEFAULT   11 $a
    55: 00010430     0 NOTYPE  LOCAL  DEFAULT   14 $a
    56: 00000094     0 NOTYPE  LOCAL  DEFAULT   27 $d
    57: 00000000     0 FILE    LOCAL  DEFAULT  ABS crtstuff.c
    58: 00020454     0 OBJECT  LOCAL  DEFAULT   20 __JCR_LIST__
    59: 00010344     0 NOTYPE  LOCAL  DEFAULT   13 $t
    60: 00010345     0 FUNC    LOCAL  DEFAULT   13 deregister_tm_clones
    61: 00010364     0 NOTYPE  LOCAL  DEFAULT   13 $d
    62: 00010368     0 NOTYPE  LOCAL  DEFAULT   13 $t
    63: 00010369     0 FUNC    LOCAL  DEFAULT   13 register_tm_clones
    64: 00020564     0 NOTYPE  LOCAL  DEFAULT   23 $d
    65: 00010395     0 FUNC    LOCAL  DEFAULT   13 __do_global_dtors_aux
    66: 00020568     1 OBJECT  LOCAL  DEFAULT   24 completed.8985
    67: 00020450     0 NOTYPE  LOCAL  DEFAULT   19 $d
    68: 00020450     0 OBJECT  LOCAL  DEFAULT   19 __do_global_dtors_aux_fin
    69: 000103ad     0 FUNC    LOCAL  DEFAULT   13 frame_dummy
    70: 0002044c     0 NOTYPE  LOCAL  DEFAULT   18 $d
    71: 0002044c     0 OBJECT  LOCAL  DEFAULT   18 __frame_dummy_init_array_
    72: 00020568     0 NOTYPE  LOCAL  DEFAULT   24 $d
    73: 00000000     0 FILE    LOCAL  DEFAULT  ABS main.c
    74: 00010438     0 NOTYPE  LOCAL  DEFAULT   15 $d
    75: 000103d0     0 NOTYPE  LOCAL  DEFAULT   13 $t
    76: 00000000     0 FILE    LOCAL  DEFAULT  ABS elf-init.c
    77: 000103e8     0 NOTYPE  LOCAL  DEFAULT   13 $t
    78: 00010420     0 NOTYPE  LOCAL  DEFAULT   13 $d
    79: 00010428     0 NOTYPE  LOCAL  DEFAULT   13 $t
    80: 00000010     0 NOTYPE  LOCAL  DEFAULT   31 $d
    81: 00000000     0 FILE    LOCAL  DEFAULT  ABS crtstuff.c
    82: 00010448     0 NOTYPE  LOCAL  DEFAULT   17 $d
    83: 00010448     0 OBJECT  LOCAL  DEFAULT   17 __FRAME_END__
    84: 00020454     0 NOTYPE  LOCAL  DEFAULT   20 $d
    85: 00020454     0 OBJECT  LOCAL  DEFAULT   20 __JCR_END__
    86: 00000000     0 FILE    LOCAL  DEFAULT  ABS 
    87: 00020450     0 NOTYPE  LOCAL  DEFAULT   18 __init_array_end
    88: 00020458     0 OBJECT  LOCAL  DEFAULT   21 _DYNAMIC
    89: 0002044c     0 NOTYPE  LOCAL  DEFAULT   18 __init_array_start
    90: 00020540     0 OBJECT  LOCAL  DEFAULT   22 _GLOBAL_OFFSET_TABLE_
    91: 000102ac     0 NOTYPE  LOCAL  DEFAULT   12 $a
    92: 000102bc     0 NOTYPE  LOCAL  DEFAULT   12 $d
    93: 000102c0     0 NOTYPE  LOCAL  DEFAULT   12 $a
    94: 00010429     2 FUNC    GLOBAL DEFAULT   13 __libc_csu_fini
    95: 00000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_deregisterTMCloneTab
    96: 00020560     0 NOTYPE  WEAK   DEFAULT   23 data_start
    97: 00020568     0 NOTYPE  GLOBAL DEFAULT   24 __bss_start__
    98: 0002056c     0 NOTYPE  GLOBAL DEFAULT   24 _bss_end__
    99: 00020568     0 NOTYPE  GLOBAL DEFAULT   23 _edata
   100: 0001042c     0 FUNC    GLOBAL DEFAULT   14 _fini
   101: 0002056c     0 NOTYPE  GLOBAL DEFAULT   24 __bss_end__
   102: 00020560     0 NOTYPE  GLOBAL DEFAULT   23 __data_start
   103: 00000000     0 FUNC    GLOBAL DEFAULT  UND puts@@GLIBC_2.4
   104: 00000000     0 FUNC    GLOBAL DEFAULT  UND __libc_start_main@@GLIBC_
   105: 00000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__
   106: 00020564     0 OBJECT  GLOBAL HIDDEN    23 __dso_handle
   107: 00010434     4 OBJECT  GLOBAL DEFAULT   15 _IO_stdin_used
   108: 000103e9    64 FUNC    GLOBAL DEFAULT   13 __libc_csu_init
   109: 0002056c     0 NOTYPE  GLOBAL DEFAULT   24 _end
   110: 000102f1     0 FUNC    GLOBAL DEFAULT   13 _start
   111: 0002056c     0 NOTYPE  GLOBAL DEFAULT   24 __end__
   112: 00020568     0 NOTYPE  GLOBAL DEFAULT   24 __bss_start
   113: 000103d1    22 FUNC    GLOBAL DEFAULT   13 main
   114: 00000000     0 NOTYPE  WEAK   DEFAULT  UND _Jv_RegisterClasses
   115: 00020568     0 OBJECT  GLOBAL HIDDEN    23 __TMC_END__
   116: 00000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_registerTMCloneTable
   117: 00000000     0 FUNC    GLOBAL DEFAULT  UND abort@@GLIBC_2.4
   118: 000102a0     0 FUNC    GLOBAL DEFAULT   11 _init

Histogram for bucket list length (total of 3 buckets):
 Length  Number     % of total  Coverage
      0  0          (  0.0%)
      1  2          ( 66.7%)     50.0%
      2  1          ( 33.3%)    100.0%

Version symbols section '.gnu.version' contains 5 entries:
 Addr: 000000000001024e  Offset: 0x00024e  Link: 5 (.dynsym)
  000:   0 (*local*)       2 (GLIBC_2.4)     2 (GLIBC_2.4)     0 (*local*)    
  004:   2 (GLIBC_2.4)  

Version needs section '.gnu.version_r' contains 1 entries:
 Addr: 0x0000000000010258  Offset: 0x000258  Link: 6 (.dynstr)
  000000: Version: 1  File: libc.so.6  Cnt: 1
  0x0010:   Name: GLIBC_2.4  Flags: none  Version: 2

Notes at offset 0x00000150 with length 0x00000020:
  Owner                 Data size   Description
  GNU                  0x00000010   NT_GNU_ABI_TAG (ABI version tag)
    OS: Linux, ABI: 2.6.16

Notes at offset 0x00000170 with length 0x00000024:
  Owner                 Data size   Description
  GNU                  0x00000014   NT_GNU_BUILD_ID (unique build ID bitstring)
    Build ID: b51634e7c53710594a57b0381c219912f0685bb1
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_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_ABI_VFP_args: VFP registers
  Tag_CPU_unaligned_access: v6

中间出现一行

[Requesting program interpreter: /lib/ld-linux-armhf.so.3]

说明运行该文件需要/lib/ld-linux-armhf.so.3文件。

接下来是两步

  • 在/etc/profile下加入
export LD_LIBRARY_PATH=/lib:$LD_LIBRARY_PATH
  • 在/lib下运行
ln -s ld-2.12.2.so ld-linux-armhf.so.3

然后

root@am335x-evm:/mnt/nfs/test/hello# ./a.out 
hello 

OK!

你可能感兴趣的:(linux)