[英]How can the offset of a segment Off not divisible by the alignment Al in an ELF file?
[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的整数倍开始的。
节标题结构如下所示:
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
列中显示的对齐约束是针对Addr
(因为您的情况是零,因此已对齐),而不适用于Off
。 换句话说,它是图像在内存中加载地址的对齐约束,而不是图像存储在ELF文件中的对齐约束。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.