How Section to Segment mapping is derived from ELF file?

Ian Lance Taylor iant@google.com
Wed Apr 21 19:09:18 GMT 2021


On Wed, Apr 21, 2021 at 12:03 PM Peng Yu via Binutils
<binutils@sourceware.org> wrote:
>
> It is indeed hard to understand that macro.
>
> There are two addresses in the program header.
>
> https://github.com/lattera/glibc/blob/master/elf/elf.h#L690
>
> Elf64_Addr p_vaddr; /* Segment virtual address */
> Elf64_Addr p_paddr; /* Segment physical address */
>
> One address in the section header.
>
> https://github.com/lattera/glibc/blob/master/elf/elf.h#L398
> Elf64_Addr sh_addr; /* Section virtual addr at execution */
>
> So it is the virtual addresses in both headers used for the comparison?
>
> Another thing that is confusing to me is when ASLR is effective, the
> addresses are not fixed each time the program runs. So how these
> addresses are the same as the addresses used by the program when the
> program runs?

Unless I misunderstand what you are asking, ASLR is irrelevant here.
ASLR effectively applies a constant offset to both section addresses
and segment addresses, so it doesn't affect the mapping of sections to
segments.

Ian


More information about the Binutils mailing list