The r-xp , r--p and rw-p mappings are just regions that need different permissions.
Mystery mapping ---p is the result of virtual memory offsets of sections described in the ELF file that do not necessarily correspond to physical offsets in the file (there may be an addition for alignment).
i.e. The ELF file itself might look like this:
| .... sections .... | .... more sections .... |
... but we describe a memory layout that looks like this:
| .... sections .... | gap | .... more sections .... |
(You can see this with objdump -h or readelf -e .)
So, the general principle is that ld.so needs to allocate enough memory for everything:
| |
... then we make one mapping for the first part:
| .... sections .... | |
... and then do a second display to get the second part in the right place:
| .... sections .... | | .... more sections .... |
Then it protects the βholeβ remaining in the virtual address space. This is the mysterious display you see:
| .... sections .... |XXXXXXXXXXXXX| .... more sections .... |
I believe that the hole is protected and not freed for reuse - so that everything is simple: this ensures that each library has only one range of virtual addresses that belongs to it and to no one else.
source share