1
[Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
[ 1] .text             PROGBITS        00000000 000034 00002a 00  AX  0   0  4

如上,段从 0x34 地址开始,但其 Al 为 4,所以不能被 2**4 整除。

我的意思是:0x34 % 16 != 0。所以我想问一下为什么 .text 段的地址不是从 16 的整数倍开始。

4

1 回答 1

1

节标题结构如下所示:

typedef struct {
   uint32_t   sh_name;
   uint32_t   sh_type;
   uint32_t   sh_flags;
   Elf32_Addr sh_addr;
   Elf32_Off  sh_offset;
   uint32_t   sh_size;
   uint32_t   sh_link;
   uint32_t   sh_info;
   uint32_t   sh_addralign;
   uint32_t   sh_entsize;
} Elf32_Shdr;

因此,您在Al列下看到的是sh_addralign. 让我们看一下elf 手册页中对该成员的描述:

sh_addralign
             Some sections have address alignment constraints.  If a
             section holds a doubleword, the system must ensure
             doubleword alignment for the entire section.  That is, the
             value of sh_addr must be congruent to zero, modulo the
             value of sh_addralign.  Only zero and positive integral
             powers of two are allowed.  Values of zero or one mean the
             section has no alignment constraints.

TL;DR:列中显示的对齐约束Al是 for Addr(在您的情况下对齐,因为它为零),而不是 for Off。换句话说,它是图像在内存中加载的地址的对齐约束,而不是图像在 ELF 文件中的存储位置。

于 2013-05-24T06:31:59.670 回答