可执行 C 程序中的段

2023-11-23

我正在阅读有关章节和片段的内容。似乎您可以列出部分和段之间的映射,如下所示。

$ readelf -l test

Elf file type is EXEC (Executable file)
Entry point 0x8048330
There are 9 program headers, starting at offset 52

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  PHDR           0x000034 0x08048034 0x08048034 0x00120 0x00120 R E 0x4
  INTERP         0x000154 0x08048154 0x08048154 0x00013 0x00013 R   0x1
      [Requesting program interpreter: /lib/ld-linux.so.2]
  LOAD           0x000000 0x08048000 0x08048000 0x0065c 0x0065c R E 0x1000
  LOAD           0x000f14 0x08049f14 0x08049f14 0x00104 0x00110 RW  0x1000
  DYNAMIC        0x000f28 0x08049f28 0x08049f28 0x000c8 0x000c8 RW  0x4
  NOTE           0x000168 0x08048168 0x08048168 0x00044 0x00044 R   0x4
  GNU_EH_FRAME   0x000564 0x08048564 0x08048564 0x00034 0x00034 R   0x4
  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0x4
  GNU_RELRO      0x000f14 0x08049f14 0x08049f14 0x000ec 0x000ec R   0x1

 Section to Segment mapping:
  Segment Sections...
   00     
   01     .interp 
   02     .interp .note.ABI-tag .note.gnu.build-id .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt .init .plt .text .fini .rodata .eh_frame_hdr .eh_frame 
   03     .ctors .dtors .jcr .dynamic .got .got.plt .data .bss 
   04     .dynamic 
   05     .note.ABI-tag .note.gnu.build-id 
   06     .eh_frame_hdr 
   07     
   08     .ctors .dtors .jcr .dynamic .got

我的问题,

  1. 我不明白程序头的含义是什么?它们与细分市场有何关系?
  2. 段到段的映射清晰。但有人能说出它的名字吗?我只看到数字。我识别出代码段(03)、数据段(02)和堆栈(07)。

要了解输出readelf它将帮助您理解格式ELF文件。请参考这个文件。

至于如何解释输出readelf this link可能有帮助。

至于你的问题2,这个链接描述了这些段。在该文档中搜索“各个部分保存程序和控制信息:”以查找描述段名称的区域。

该文档对各个部分的描述如下:

各个部分保存程序和控制信息:

   .bss      This section holds uninitialized data that contributes to the
             program's memory image.  By definition, the system initializes the
             data with zeros when the program begins to run.  This section is of
             type SHT_NOBITS.  The attribute types are SHF_ALLOC and SHF_WRITE.

   .comment  This section holds version control information.  This section is of
             type SHT_PROGBITS.  No attribute types are used.

   .ctors    This section holds initialized pointers to the C++ constructor
             functions.  This section is of type SHT_PROGBITS.  The attribute
             types are SHF_ALLOC and SHF_WRITE.

   .data     This section holds initialized data that contribute to the program's
             memory image.  This section is of type SHT_PROGBITS.  The attribute
             types are SHF_ALLOC and SHF_WRITE.

   .data1    This section holds initialized data that contribute to the program's
             memory image.  This section is of type SHT_PROGBITS.  The attribute
             types are SHF_ALLOC and SHF_WRITE.

   .debug    This section holds information for symbolic debugging.  The contents
             are unspecified.  This section is of type SHT_PROGBITS.  No
             attribute types are used.

   .dtors    This section holds initialized pointers to the C++ destructor
             functions.  This section is of type SHT_PROGBITS.  The attribute
             types are SHF_ALLOC and SHF_WRITE.

   .dynamic  This section holds dynamic linking information.  The section's
             attributes will include the SHF_ALLOC bit.  Whether the SHF_WRITE
             bit is set is processor-specific.  This section is of type
             SHT_DYNAMIC.  See the attributes above.

   .dynstr   This section holds strings needed for dynamic linking, most commonly
             the strings that represent the names associated with symbol table
             entries.  This section is of type SHT_STRTAB.  The attribute type
             used is SHF_ALLOC.

   .dynsym   This section holds the dynamic linking symbol table.  This section
             is of type SHT_DYNSYM.  The attribute used is SHF_ALLOC.

   .fini     This section holds executable instructions that contribute to the
             process termination code.  When a program exits normally the system
             arranges to execute the code in this section.  This section is of
             type SHT_PROGBITS.  The attributes used are SHF_ALLOC and
             SHF_EXECINSTR.

   .gnu.version
             This section holds the version symbol table, an array of ElfN_Half
             elements.  This section is of type SHT_GNU_versym.  The attribute
             type used is SHF_ALLOC.

   .gnu.version_d
             This section holds the version symbol definitions, a table of
             ElfN_Verdef structures.  This section is of type SHT_GNU_verdef.
             The attribute type used is SHF_ALLOC.

   .gnu.version_r
             This section holds the version symbol needed elements, a table of
             ElfN_Verneed structures.  This section is of type SHT_GNU_versym.
             The attribute type used is SHF_ALLOC.

   .got      This section holds the global offset table.  This section is of type
             SHT_PROGBITS.  The attributes are processor specific.

   .hash     This section holds a symbol hash table.  This section is of type
             SHT_HASH.  The attribute used is SHF_ALLOC.

   .init     This section holds executable instructions that contribute to the
             process initialization code.  When a program starts to run the
             system arranges to execute the code in this section before calling
             the main program entry point.  This section is of type SHT_PROGBITS.
             The attributes used are SHF_ALLOC and SHF_EXECINSTR.

   .interp   This section holds the pathname of a program interpreter.  If the
             file has a loadable segment that includes the section, the section's
             attributes will include the SHF_ALLOC bit.  Otherwise, that bit will
             be off.  This section is of type SHT_PROGBITS.

   .line     This section holds line number information for symbolic debugging,
             which describes the correspondence between the program source and
             the machine code.  The contents are unspecified.  This section is of
             type SHT_PROGBITS.  No attribute types are used.

   .note     This section holds information in the "Note Section" format.  This
             section is of type SHT_NOTE.  No attribute types are used.  OpenBSD
             native executables usually contain a .note.openbsd.ident section to
             identify themselves, for the kernel to bypass any compatibility ELF
             binary emulation tests when loading the file.

   .note.GNU-stack
             This section is used in Linux object files for declaring stack
             attributes.  This section is of type SHT_PROGBITS.  The only
             attribute used is SHF_EXECINSTR.  This indicates to the GNU linker
             that the object file requires an executable stack.

   .plt      This section holds the procedure linkage table.  This section is of
             type SHT_PROGBITS.  The attributes are processor specific.

   .relNAME  This section holds relocation information as described below.  If
             the file has a loadable segment that includes relocation, the
             section's attributes will include the SHF_ALLOC bit.  Otherwise the
             bit will be off.  By convention, "NAME" is supplied by the section
             to which the relocations apply.  Thus a relocation section for .text
             normally would have the name .rel.text.  This section is of type
             SHT_REL.

   .relaNAME This section holds relocation information as described below.  If
             the file has a loadable segment that includes relocation, the
             section's attributes will include the SHF_ALLOC bit.  Otherwise the
             bit will be off.  By convention, "NAME" is supplied by the section
             to which the relocations apply.  Thus a relocation section for .text
             normally would have the name .rela.text.  This section is of type
             SHT_RELA.

   .rodata   This section holds read-only data that typically contributes to a
             nonwritable segment in the process image.  This section is of type
             SHT_PROGBITS.  The attribute used is SHF_ALLOC.

   .rodata1  This section holds read-only data that typically contributes to a
             nonwritable segment in the process image.  This section is of type
             SHT_PROGBITS.  The attribute used is SHF_ALLOC.

   .shstrtab This section holds section names.  This section is of type
             SHT_STRTAB.  No attribute types are used.

   .strtab   This section holds strings, most commonly the strings that represent
             the names associated with symbol table entries.  If the file has a
             loadable segment that includes the symbol string table, the
             section's attributes will include the SHF_ALLOC bit.  Otherwise the
             bit will be off.  This section is of type SHT_STRTAB.

   .symtab   This section holds a symbol table.  If the file has a loadable
             segment that includes the symbol table, the section's attributes
             will include the SHF_ALLOC bit.  Otherwise the bit will be off.
             This section is of type SHT_SYMTAB.

   .text     This section holds the "text", or executable instructions, of a
             program.  This section is of type SHT_PROGBITS.  The attributes used
             are SHF_ALLOC and SHF_EXECINSTR.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

可执行 C 程序中的段 的相关文章

  • c# 从另一个类中的另一个静态事件引发事件

    需要帮助从另一个班级调用事件 我有已声明事件的课程 public class MxPBaseGridView GridView public event AddNewItemsToPopUpMenuEventHandler AddNewIt
  • 锁定 ASP.NET 应用程序变量

    我在 ASP NET 应用程序中使用第三方 Web 服务 对第 3 方 Web 服务的调用必须同步 但 ASP NET 显然是多线程的 并且可能会发出多个页面请求 从而导致对第 3 方 Web 服务的同时调用 对 Web 服务的调用封装在自
  • 在 ASP.NET MVC 中将模型从视图传递到控制器

    我正在 ASP NET MVC 中开发我的第一个应用程序 但遇到了一个我无法解决的问题 即使在阅读了整个互联网之后也是如此 因此 我有几个使用视图模型创建的视图 它们是报告 这些视图模型是根据用户选择标准填充的 我正在尝试构建一种接受模型并
  • 将下拉列表与字典绑定

    我将字典绑定到下拉列表 举例来说 我的字典中有以下项目 Test1 123 Test2 321 我希望下拉文本采用以下格式 Test1 Count 123 Test2 Count 321 我沿着以下路径走 但没有运气 MyDropDown
  • 全局使用和 .NET Standard 2.0

    我最近意识到我可以使用 C 10 功能文件范围的命名空间在 NET Standard 2 0 项目中也可以通过设置
  • 带有运算符语法的错误消息,但不带有函数语法的错误消息

    为什么我在调用 unary 时收到错误消息 使用运算符语法 如果我用函数语法调用它就可以了 现场演示 https godbolt org z j7AbeQ template
  • while循环中的变量初始化

    我有一个可以分块读取文件的函数 public static DataObject ReadNextFile 数据对象看起来像这样 public DataObject public string Category get set And ot
  • 有什么方法可以重载 C# 中的扩展方法吗?

    我有以下模型模式 public abstract class PARENTCLASS public class CHILD A CLASS PARENTCLASS public static class EXTENSION public s
  • 静态类与类的实例

    我有一个静态类 用于访问我的公共属性 整个应用程序的全局属性 和我在应用程序运行期间使用的方法 例如 我在静态类中设置了一些属性 并且在应用程序运行时我可以从属性中获取值 但我可以使用单例模式创建非静态类并以相同的方式使用它 问题 对于我的
  • 在 C# 中何时使用 ArrayList 而不是 array[]?

    我经常使用一个ArrayList而不是 正常 array 当我使用时 我感觉好像我在作弊 或懒惰 ArrayList 什么时候可以使用ArrayList在数组上 数组是强类型的 并且可以很好地用作参数 如果您知道集合的长度并且它是固定的 则
  • 使用 C# 中的 Google 地图 API 和 SSIS 包获取行驶距离

    更新 找到了谷歌距离矩阵并尝试相应地修改我的代码 我在这里收到无效参数错误 return new GeoLocation dstnc uri ToString catch return new GeoLocation 0 0 https 基
  • 子目录中的头文件(例如 gtk/gtk.h 与 gtk-2.0/gtk/gtk.h)

    我正在尝试使用 GTK 构建一个 hello world 其中包括以下行 include
  • 如何使用递归查找数字中的最小元素 [C]

    好的 所以我正在准备我的 C 考试 当谈到递归时我有点卡住了我是大学一年级的学生 这对我来说似乎有点困难 练习要求在给定的数字中使用递归函数我需要找到最小的元素 例如 52873 是 2 程序需要打印 2 include
  • Xamarin - SignalR 挂在连接上

    我正在尝试将我的 Xamarin 应用程序连接到托管在 Azure 上的 SignalR 后端 我遇到的问题是每次我在 HubConnection 上调用 StartAsync 时 它都会挂起客户端并且请求永远不会完成 我尝试通过应用程序进
  • 如何在 C# 中获取 Json 数组?

    我有一个像这样的 Json 字符串 我想将它加载到 C 数组中 当我尝试这样做时 我收到异常 我的字符串 customerInformation customerId 123 CustomerName Age 39 Gender Male
  • ALTER TABLE ... ADD CONSTRAINT 失败时将事务回滚到保存点

    有没有办法在事务中添加检查约束and如果失败回滚到以前的保存点 而不是回滚整个事务 就我而言 当 ALTER TABLE ADD CONSTRAINT 命令失败时 事务无法回滚到保存点 尝试这样做会引发 InvalidOperationEx
  • 使用 xslt 将 xml 转换为 xsl-fo 时动态创建超链接?

    我想使用 xsl 文件在 PDF 报告中创建标题 如果源文件包含超链接 则应将其呈现为超链接 否则呈现为纯文本 例如 我的 xml 如下所示 a href http google com target blank This is the h
  • Linq.Select() 中的嵌套表达式方法调用

    I use Select i gt new T 每次手动点击数据库后将我的实体对象转换为 DTO 对象 以下是一些示例实体和 DTOS 用户实体 public partial class User public int Id get set
  • Xamarin.Forms UWP 项目中标题栏和选项卡之间令人恼火的空白

    我几乎是新手Xamarin Forms我正在开发一个相当简单的跨平台应用程序 该应用程序在 Android 中显示得足够好 但在 UWP 中却出现了一个愚蠢的空白 该项目由一个 TabbedPage 组成 其中包含 4 个 Navigati
  • “必须声明标量变量”错误[重复]

    这个问题在这里已经有答案了 必须声明标量变量 Id SqlConnection con new SqlConnection connectionstring con Open SqlCommand cmd new SqlCommand cm

随机推荐