这在下面的文件中意味着什么?2**2和2**0
$ objdump -h main.o
main.o: file format elf32-i386
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 0000000b 00000000 00000000 00000034 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .data 00000000 00000000 00000000 00000040 2**2
CONTENTS, ALLOC, LOAD, DATA
2 .bss 00000000 00000000 00000000 00000040 2**2
ALLOC
3 .note.GNU-stack 00000000 00000000 00000000 00000040 2**0
CONTENTS, READONLY, CODE
Run Code Online (Sandbox Code Playgroud)
我认为这2**2意味着2 2或4字节对齐,而2**0意味着没有(一个字节)对齐.
该值来自sh_addralignELF节标题的字段.在ELF规范国家(重点煤矿):
sh_addralign某些部分具有地址对齐约束.例如,如果某个部分包含双字,则系统必须确保整个部分的双字对齐.也就是说,sh_addr的值必须与0一致,以sh_addralign的值为模.目前,只允许0和2的正整数幂. 值0和1表示该部分没有对齐约束.
正如Ray Toal所提到的,由于对齐必须是2的幂,所以只有objdump用2**x符号表示这个值为2的幂才有意义.
请注意,在某些语言中,如Python和FORTRAN,**是幂或取幂运算符.
看objdump.c,我们看到:
static void
dump_section_header (bfd *abfd, asection *section,
void *ignored ATTRIBUTE_UNUSED)
{
// ...
printf (" %08lx 2**%u", (unsigned long) section->filepos,
bfd_get_section_alignment (abfd, section));
Run Code Online (Sandbox Code Playgroud)
并在objdump.h:
#define bfd_get_section_alignment(bfd, ptr) ((ptr)->alignment_power + 0)
Run Code Online (Sandbox Code Playgroud)
其alignment_power成员bfd是:
/* The alignment requirement of the section, as an exponent of 2 -
e.g., 3 aligns to 2^3 (or 8). */
unsigned int alignment_power;
Run Code Online (Sandbox Code Playgroud)