加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 在objdump的输出中,2 ** 2和2 ** 0的“Algn”是什么意思?

发布时间:2020-12-16 09:50:29 所属栏目:百科 来源:网络整理
导读:这在下面的文件中意味着什么? 2 ** 2和2 ** 0 $objdump -h main.omain.o: file format elf32-i386Sections:Idx Name Size VMA LMA File off Algn 0 .text 0000000b 00000000 00000000 00000034 2**2 CONTENTS,ALLOC,LOAD,READONLY,CODE 1 .data 00000000 00
这在下面的文件中意味着什么? 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,DATA
  2 .bss          00000000  00000000  00000000  00000040  2**2
                  ALLOC
  3 .note.GNU-stack 00000000  00000000  00000000  00000040  2**0
                  CONTENTS,CODE

解决方法

我假设2 ** 2表示22或4字节对齐,而2 ** 0表示没有(一个字节)对齐.

此值来自ELF节标题的sh_addralign字段. ELF specification州(强调我的):

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.

作为Ray Toal mentioned,由于对齐必须是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));

并在objdump.h

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

bfd的alignment_power成员是:

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

unsigned int alignment_power;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读