什么是“ Algn”? objdump的输出中2 ** 2和2 ** 0的平均值? [英] What does an "Algn" of 2**2 and 2**0 mean in the output of objdump?

查看:324
本文介绍了什么是“ Algn”? objdump的输出中2 ** 2和2 ** 0的平均值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的文件中这意味着什么? 2 ** 2 2 ** 0



<课前= lang-none prettyprint-override> $ objdump -h main.o

main.o:文件格式elf32-i386

节:
Idx名称大小VMA LMA关闭文件Algn
0 .text 0000000b 00000000 00000000 00000034 2 ** 2
目录,ALLOC,加载,READONLY,代码
1 .data 00000000 00000000 00000000 00000040 2 ** 2
目录,ALLOC,加载,数据
2 .bss 00000000 00000000 00000000 00000040 2 ** 2
ALLOC
3 .note.GNU堆栈00000000 00000000 00000000 00000040 2 ** 0
目录,只读,代码


解决方案

我认为 2 ** 2 表示2 2 或4字节对齐,而 2 ** 0 表示无(一个字节)对齐。



此值来自 sh_addralign 的领域ELF节头。 ELF规范状态(强调我的意思):


sh_addralign 有些节有地址对齐约束。例如,如果某节包含
双字,则系统必须确保整个节的双字对齐。
也就是说,sh_addr的值必须与
sh_addralign的值取模等于0。当前,仅允许0和2的正整数幂。
值0和1表示该节没有对齐约束。


Ray Toal ,因为对齐方式必须是2的幂,所以 objdump 会将这个值表示为2的幂,而 2 ** x 表示法。



请注意,在某些语言中,例如 Python FORTRAN ** 是幂或幂运算符。






查看 objdump.c ,我们看到:

 静态void 
dump_section_header(bfd * abfd,asection * section,
void *忽略了ATTRIBUTE_UNUSED)
{
// ...
printf(%08lx 2 ** %u,(无符号长整数)section-> filepos,
bfd_get_section_alignment(abfd,section));

objdump.h

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

其中 bfd alignment_power 成员是:

  / *本节的对齐要求为2-
的指数,例如3对齐2 ^ 3(或8)。 * /

unsigned int alignment_power;





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

解决方案

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;


这篇关于什么是“ Algn”? objdump的输出中2 ** 2和2 ** 0的平均值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆