我有以下简单的“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/