目标文件的objdump输出中的标志 [英] Flags in objdump output of object file

查看:269
本文介绍了目标文件的objdump输出中的标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

某些对象文件上有objdump的输出:

There is this output of objdump on some object file:

$ 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

这些标志CONTENTS,ALLOC,LOAD等是什么意思?

What do these flags CONTENTS, ALLOC, LOAD and so on mean?

推荐答案

您将看到目标文件中每个节的ELF节标志,节类型和节标志的组合的解释.

What you see is the interpretation of the combination of ELF segment flags, section type and section flags for each section in the object file.

  • LOAD表示该节位于可加载的段中,即,在创建进程时可以将其内容从文件读取到内存中
  • LOAD means that the section resides in a loadable segment, i.e. its content could be read from the file into memory when a process is created

部分标记在System V应用程序二进制文件的第4章中有详细记录界面,尽管其名称与objdump显示的名称略有不同.

Section flags are well documented in the Chapter 4 of the System V Application Binary Interface, although under slightly different names from what objdump shows.

  • CODE表示该部分包含可执行代码;它由节标题中的SHF_EXECINSTR标志指示
  • DATA表示该部分不可执行,但可写,由SHF_WRITE标志
  • 表示
  • READONLY表示该节既不是可执行文件也不是可写文件,应放置在只读内存页中
  • ALLOC表示该部分占用内存,例如当创建进程时,实际上会分配内存页来保存节的内容,该标志由SHF_ALLOC标志指示.一些部分,例如那些包含调试信息的文件,在正常程序执行期间不会读入内存,也不会标记为ALLOC来节省内存.
  • CODE means that the section contains executable code; it is indicated by the SHF_EXECINSTR flag in the section header
  • DATA means that the section is not executable but is writable, indicated by the presence of the SHF_WRITE flag
  • READONLY means that the section is neither executable nor writtable and should be placed in read-only memory pages
  • ALLOC means that the section occupies memory, e.g. memory pages are actually allocated to hold the section content when a process is created, indicated by the SHF_ALLOC flag. Some sections, e.g. those containing debug information, are not read into memory during normal program execution and are not marked as ALLOC to save memory.

类型为SHT_PROGBITS的部分在文件中具有相应的内容,并显示为CONTENTS.某些部分在文件中没有相应的内容,例如.bss部分,其类型为SHT_NOBITS.

Sections of type SHT_PROGBITS have corresponding content in the file and are shown as CONTENTS. Some sections does not have corresponding content in the file, e.g. the .bss section, which is of type SHT_NOBITS.

.text部分包含程序可执行代码.由于它是SHT_PROGBITS类型,因此显示为CONTENTS.由于该段是ALLOC,因此应为该部分保留内存,并且由于将其内容放置在可LOAD的段中,因此应从文件中加载其内容.程序代码通常是不可修改的,因此该部分位于只读存储器中.它包含要执行的指令,并因此包含CODE标志.

The .text section contains the program executable code. It is show as CONTENTS since it is of type SHT_PROGBITS. Memory should be reserved for this section since it is ALLOC and its contents should be loaded from the file since it is placed in a LOAD-able segment. Program code is generally non-modifiable and hence the section is placed in read-only memory. It contains instructions that are to be executed and hence the CODE flag.

已初始化变量进入.data部分.它们的初始值存储在文件中,并在创建过程时从那里读取.在C/C ++中,这些是适当初始化的全局变量,静态局部变量和C ++静态成员变量,例如static int a = 10;. Fortran将已初始化的SAVE -d变量和COMMON块放置在此处,并使用块DATA语句为其赋予初始值.

Initialised variables with static storage class go into the .data section. Their initial values are stored in the file and read from there as the process is created. In C/C++ these are global variables, static local variables and C++ static member variables that are initialised appropriately, e.g. static int a = 10;. Fortran places initialised SAVE-d variables and COMMON blocks, which are given intiial value with a block DATA statement there.

.bss部分(历史名称, Block Started by Symbol 的缩写)是最简单的部分.它包含具有静态存储类的未初始化变量.它是类型为SHT_NOBITS的部分,在文件中不占空间.内存是ALLOC专用的,但是没有从文件中读取任何内容来预填充内存-它只保留内核内存分配器提供的所有零.

The .bss section (historic name, abbreviation from Block Started by Symbol) is the most simple one. It holds uninitialised variables with static storage class. It is a section of type SHT_NOBITS and takes no space in the file. Memory is ALLOC-ated for it but nothing is read from the file to prepopulate the memory - it just stays all zeroes as delivered by the kernel memory allocator.

常量通常进入.rodata部分(在您的示例中不存在),该部分看起来像.data,但未标记为可写,因此显示为READONLY.

Constants usually go into the .rodata section (not present in your example), which looks like .data but is not marked as writable and is thus shown as READONLY.

这篇关于目标文件的objdump输出中的标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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