3

I have the following simple "hello world" program:

#include <stdio.h>

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

I compile it as

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

Now, I want check its memory segment by issuing readelf -l and obtain the following output:

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

I got confused by Align column: are those number in bytes or kilobytes? I thought align should be equal to the page size. Why am I getting those number?

Thanks!

xxks-kkk
  • 2,336
  • 3
  • 28
  • 48

1 Answers1

-1

This is what System V Application Binary Interface says this about 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.

So p_align doesn't need to be equal to the page size.