c - ELF中Program header和Section Header的区别

标签 c arm gnu elf linker-scripts

Q1 ELF中Program header和Section Header有什么区别?

Q1.1 segment 和 section 有什么区别?

我相信 pheaders 只指向部分。

Q2。文件头和程序头有什么区别?

根据 GNU ld 链接描述文件,Using Id: The GNU Linker :

PHDRS
{
name type [ FILEHDR ] [ PHDRS ] [ AT ( address ) ]
[ FLAGS ( flags ) ] ;
}

You may use the FILEHDR and PHDRS keywords appear after the program header type to further describe the contents of the segment. The FILEHDR keyword means that the segment should include the ELF file header. The PHDRS keyword means that the segment should include the ELF program headers themselves.

这有点令人困惑。

最佳答案

Executable & Linkable Format wikipage 有一张很好的图片来解释 ELF,以及它的程序头和节头之间的区别。另见 elf(5)

[初始] 程序头定义段(在 address spaceprocess 中运行该 ELF 可执行文件)投影在 virtual memory 中(可执行的观点)在 execve(2)时间。 [final] 部分标题定义部分(可链接的观点,ld(1) 等...)。每个部分都属于一个段(并且在执行时可能可见,也可能不可见 - 即映射到内存中)。 ELF文件头告诉程序头表和节头表在哪里。

也可以使用 objdump(1)readelf(1)探索 Linux 系统上现有的几个 ELF 文件(可执行文件、共享对象、可链接对象)。

莱文的 Linkers & Loaders书中有一章对此进行了详细解释。

还有 Drepper 的论文 How to Write Shared Libraries也有一些很好的解释。

关于c - ELF中Program header和Section Header的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23379880/

相关文章:

docker - K8S-Docker-ARM Unbutu 64位-QEMU:未捕获的目标信号11(分段故障)-内核已转储

windows - gnuwin32 inetutils 包去了哪里?

c - 文件如何包含空字节?

c - 如何从 GET HTTP 请求中仅获取消息正文?

floating-point - 利用 -mfloat-abi=hard 和 -mfpu=vfp/neon Codesourcery Lite 2013.05-24

c - 如何修复 ".c:6: undefined reference to ' printf'

linux - Gnu 时间和格式化输出

C - 应用于矩阵的函数指针。段错误

c - 如何读取我用 C 语言创建的文本文件

c - 对 `main' 和 _sbrk 的 undefined reference - 自己的静态库中的启动代码