handle anonymous mappings on top of ELF files
For various schemes including using hugepages with file-backed mappings such as ELF text segments, the /proc/self/maps file may contain anonymous mmaps for parts of an ELF mapping. This issue covers using adjacent, contiguous file-backed entries to deduce the file that backs the anonymous entries. This is generally only a problem when we attach or we take over late: if we're there from the start we should see a regular mapping followed by an mremap.
Here is a real-world example involving portions of text segments being remapped to be backed by hugepages. Instead of this regular mapping:
00400000-3bff9000 r-xp 00000000 fc:02 13516723 /my/binary
3bff9000-3cf44000 rw-p 3bbf8000 fc:02 13516723 /my/binary
3cf44000-3d709000 rw-p 00000000 00:00 0
We see this when we attach:
00400000-30400000 r-xp 00000000 00:00 0
30400000-31200000 r-xp 30000000 00:27 1392443 /my/binary
31200000-31400000 r-xp 00000000 00:00 0
31400000-39c00000 r-xp 31000000 00:27 1392443 /my/binary
39c00000-39e00000 r-xp 00000000 00:00 0
39e00000-3bff9000 r-xp 39a00000 00:27 1392443 /my/binary
3bff9000-3cf44000 rw-p 3bbf8000 00:27 1392443 /my/binary
3cf44000-3d709000 rw-p 00000000 00:00 0
That leads to numerous asserts, including:
core/unix/memquery.c:155 false && "expected elf header"
core/unix/os.c:8801 executable_start == ma->start