c - readelf 'Align' 列单元

标签 c readelf

我有以下简单的“hello world”程序:

#include <stdio.h>

int main() {
  printf("Hello world.\n");
  return 0;
}

我把它编译成

gcc -static -O0 -g -std=gnu11 -o test_helloworld test_helloworld.c -lpthread

现在,我想通过发出 readelf -l 检查它的内存段并获得以下输出:

Elf file type is EXEC (Executable file)
Entry point 0x400890
There are 6 program headers, starting at offset 64

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000000000 0x0000000000400000 0x0000000000400000
                 0x00000000000c96cf 0x00000000000c96cf  R E    200000
  LOAD           0x00000000000c9eb8 0x00000000006c9eb8 0x00000000006c9eb8
                 0x0000000000001c98 0x00000000000035b0  RW     200000
  NOTE           0x0000000000000190 0x0000000000400190 0x0000000000400190
                 0x0000000000000044 0x0000000000000044  R      4
  TLS            0x00000000000c9eb8 0x00000000006c9eb8 0x00000000006c9eb8
                 0x0000000000000020 0x0000000000000050  R      8
  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000  RW     10
  GNU_RELRO      0x00000000000c9eb8 0x00000000006c9eb8 0x00000000006c9eb8
                 0x0000000000000148 0x0000000000000148  R      1

我对 Align 列感到困惑:这些数字是以字节还是以千字节为单位?我认为对齐应该等于页面大小。为什么我会得到这些数字?

谢谢!

最佳答案

这就是System V Application Binary Interface这是关于 p_align 的:

Values 0 and 1 mean no alignment is required. Otherwise, p_align should be a positive, integral power of 2, and p_vaddr should equal p_offset, modulo p_align.

所以 p_align 不需要等于页面大小。

关于c - readelf 'Align' 列单元,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55411260/

相关文章:

c++ - 生成从可执行文件调用的 c++ 方法列表

c - 错误 : ‘asm’ undeclared (first use in this function)

c - 在C语言中处理多个命令而不是switch语句的正确方法是什么

c++ - 将预处理器宏定义到宏定义行

在 C 中转换结构指针

linux ELF节和头访问权限

linux - 列出 ld 链接器可用的所有符号

linux - 括号中的数字在 readelf 输出中意味着什么?

c++ - 在 Linux 中使用插件的 C++ 程序的最佳实践

c - 将具有结构类型的值传递给 C 中的函数