LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 858|回复: 0

请教:关于elf文件的program headers

[复制链接]
发表于 2010-4-21 09:25:00 | 显示全部楼层 |阅读模式
尝试为专用的MIPS platform上写个小程序helloword,最后生成bin文件。但总是无法在实际机器上运行。readelf输出如下:

ELF Header:
  Magic:   7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF32
  Data:                              2's complement, big endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           SUNPLUS S+Core
  Version:                           0x1
  Entry point address:               0x8000f000
  Start of program headers:          52 (bytes into file)
  Start of section headers:          264 (bytes into file)
  Flags:                             0x20001101
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         2
  Size of section headers:           40 (bytes)
  Number of section headers:         5
  Section header string table index: 4

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES *** Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        8000f000 000080 000040 00 WAX  0   0 16
  [ 2] .data             PROGBITS        8000f040 0000c0 000010 00  WA  0   0 16
  [ 3] .reginfo          LOPROC+6        8000f050 0000d0 000018 18   A  0   0  4
  [ 4] .shstrtab         STRTAB          00000000 0000e8 000020 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), 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  *** Align
  LOPROC+0       0x0000d0 0x8000f050 0x8000f050 0x00018 0x00018 R   0x4
  LOAD           0x000000 0x8000ef80 0x8000ef80 0x000d0 0x000d0 RWE 0x10

Section to Segment mapping:
  Segment Sections...
   00     .reginfo
   01     .text .data

There is no dynamic section in this file.

There are no relocations in this file.

There are no unwind sections in this file.

No version information found in this file.


但根据提供的原始bin文件,其readelf结果如下:
ELF Header:
  Magic:   7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF32
  Data:                              2's complement, big endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           SUNPLUS S+Core
  Version:                           0x1
  Entry point address:               0x80008000
  Start of program headers:          52 (bytes into file)
  Start of section headers:          216 (bytes into file)
  Flags:                             0x20001101
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         1
  Size of section headers:           40 (bytes)
  Number of section headers:         5
  Section header string table index: 4

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES *** Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        80008000 000054 00003c 00 WAX  0   0  4
  [ 2] .reginfo          LOPROC+6        00400000 0000a0 000018 01      0   0  4
  [ 3] .data             PROGBITS        8000803c 000090 000010 00  WA  0   0  4
  [ 4] .shstrtab         STRTAB          00000000 0000b8 000020 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), 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  *** Align
  LOAD           0x000054 0x80008000 0x80008000 0x0004c 0x0004c RWE 0x4

Section to Segment mapping:
  Segment Sections...
   00     .text .data

There is no dynamic section in this file.

There are no relocations in this file.

There are no unwind sections in this file.

No version information found in this file.

因此有如下几个问题请教:
1、ld如何设置连接参数(或自定义ldscript?),以便生成只有一个program header的elf文件?也就是去掉“  LOPROC+0       0x0000d0 0x8000f050 0x8000f050 0x00018 0x00018 R   0x4”这些东西。
2、如何修改elf header中的flags?是ld连接时、还是在objcopy时?
3、section header中的align怎么修改呢?如何定义为4?我自己生成的是16。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表