What does an “Algn” of 2**2 and 2**0 mean in the output of objdump?

匿名 (未验证) 提交于 2019-12-03 01:34:02

问题:

What does this mean in below file? 2**2 and 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 

回答1:

I would assume that 2**2 means 22, or 4 byte alignment, while 2**0 means no (one byte) alignment.

This value comes from the sh_addralign field of the ELF section header. The ELF specification states (emphasis mine):

sh_addralign Some sections have address alignment constraints. For example, 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 0, modulo the value of sh_addralign. Currently, only 0 and positive integral powers of two are allowed. Values 0 and 1 mean the section has no alignment constraints.

As Ray Toal mentioned, since the alignment must be a power of two, it only makes sense that objdump would express this value as a power of two with the 2**x notation.

Note that in some languages, like Python and FORTRAN, ** is a power or exponentiation operator.


Looking at objdump.c, we see:

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)); 

And in objdump.h:

#define bfd_get_section_alignment(bfd, ptr) ((ptr)->alignment_power + 0) 

where the alignment_power member of bfd is:

/* The alignment requirement of the section, as an exponent of 2 -    e.g., 3 aligns to 2^3 (or 8). */  unsigned int alignment_power; 



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!