How Section to Segment mapping is derived from ELF file?
Peng Yu
pengyu.ut@gmail.com
Wed Apr 21 19:03:39 GMT 2021
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?
On Wed, Apr 21, 2021 at 10:59 AM Nick Clifton <nickc@redhat.com> wrote:
>
> Hi Peng,
>
> > How is this relation figured out by readelf? Could anyone help explain
> > the details?
>
> Readelf uses the macro ELF_SECTION_IN_SEGMENT_STRICT to determine if a
> section maps to a specific segment. This macro, defined in
> include/elf/internal.h is quite complex, but essentially it boils to to
> matching section ranges (start address..start address + size) to segment
> ranges. If a section's range is contained within a segment's range,
> then it is considered to be mapped to that segment.
>
> Cheers
> Nick
>
>
--
Regards,
Peng
More information about the Binutils
mailing list