I'm having a hard time trying to understand the following excerpt from ELF spec that discusses how base address is determined:
An executable or shared object file's base address is calculated during execution from three values: the virtual memory load address, the maximum page size, and the lowest virtual address of a program's loadable segment. To compute the base address, one determines the memory address associated with the lowest p_vaddr value for a PT_LOAD segment. This address is truncated to the nearest multiple of the maximum page size. The corresponding p_vaddr value itself is also truncated to the nearest multiple of the maximum page size. The base address is the difference between the truncated memory address and the truncated p_vaddr value.
1.
What does
memory address associated with the lowest p_vaddr value
mean? Do they simply mean the virtual address of the lowest p_vaddr struct element, as in:
int i = 1;
int *p = &i;
printf("i == %p\n", i);
?
2.
If ELF is mapped in memory like this:
ELF Header
..
Program Header Table
..
p_vaddr of the first Elf32_Phdr -> mapped at 0x80000000, points to 0x80000100
p_vaddr of the second Elf32_Phdr
...
first loadable segment -> mapped to 0x80000100
Is the base address 0x80000100 - 0x80000000 = 0x100?
User contributions licensed under CC BY-SA 3.0