在ELF可执行二进制文件中分段映射的不正确部分

时间:2012-07-25 21:15:37

标签: linux-kernel linux-device-driver elf

我正在使用readelf命令分析ELF文件。我查看了程序标题和节标题,但发现并非所有节都被映射到一个段。我提供了readelf输出的一部分:

Section Headers:
[Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
[ 0]                   NULL            00000000 000000 000000 00      0   0  0
[ 1] ddr_data_nc_wt    NOBITS          70001800 0000b4 000000 00   W  0   0  1
[ 2] ddr_data_c_wb     NOBITS          70001800 0000b4 000000 00   W  0   0  1
[ 3] ddr_text_c        NOBITS          70001800 0000b4 000000 00   X  0   0  1
[ 4] m2_textboot_c     LOPROC+0        b0000000 0000c0 0023cc 00  AX  0 2952790016  2
[ 5] m2_text_c         LOPROC+0        38000000 002490 004d22 00  AX  0 2952799232 16
[ 6] m2_data_c_wb      LOPROC+5        70000000 0071c0 0006a8 00  WA  0 2952819200  2
[ 7] data_boot_c       LOPROC+5        20000000 007870 000100 00  WA  0 2953019392  4

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  Flg Align
LOAD           0x0000c0 0xb0000000 0xb0000000 0x023cc 0x023cc R E 0x2
LOAD           0x002490 0xb0002400 0xb0002400 0x04d22 0x04d22 R E 0x10
LOAD           0x0071c0 0xb0007200 0xb0007200 0x006a8 0x017a8 RW  0x2
LOAD           0x007870 0xb0038000 0xb0038000 0x00100 0x08000 RW  0x4

Section to Segment mapping:
Segment Sections...
  00     m2_textboot_c
  01
  02
  03

There is no dynamic section in this file.

There are no relocations in this file.

There are no unwind sections in this file.

我发现只有m2_textboot_c部分被映射到Segment 00,但没有提到其他部分的映射位置。能否请您告诉我可能出现的问题以及应该做些什么?

另外,我想知道是否有任何使用节头而不是程序头将ELF二进制文件加载到处理器上的机制。我遇到的每个在线帮助都使用程序头加载二进制文件。

2 个答案:

答案 0 :(得分:0)

  

我发现只有m2_textboot_c部分被映射到Segment 00,但没有提到其他部分的映射位置

您可能使用“自定义”链接描述文件链接了此ELF图像。 那个脚本控制着段到段的映射,它(显然)不能完成你想要的其他部分。

答案 1 :(得分:0)

我猜想readelf通过查看虚拟地址对节地址到段进行了反向映射。您的段跨越了虚拟地址空间0xb0000000-0xb0040000,并且该地址空间中唯一包含的部分确实是m2_textboot_c。

请记住,您可能应该将m2_text_c和m2_data_c_wb部分分别重新映射到0xb0002400和0xb0007200,以便它们与第二和第三代码段匹配。