Why do we mmap data that is already mmapped?
The basic strategy for backtrace symbolication on Linux:
- We use a combination of
dl_iterate_phdrand opening/proc/self/mapsto learn about what memory objects are loaded - We obtain a bunch of filenames for these memory objects, their dynamic libraries
- We then later mmap these filenames into memory.
- ...WAIT A TICK?!?
...why do we map things into memory that we almost certainly know are already in-memory objects?
we probably have to occasionally map something anyways, but it seems we shouldn't need to always? anyway, would be happy to have your insight into this bout of madness, or a correction if I am wrong, @bjorn3 or @philipc
I had the same question when I was working on Android support (sorry if this is an unwanted comment).
AFAICT, it's because the sections containing the symbol tables and DWARF debug info aren't (normally) mapped, so it's needed for symbolication to work properly. But I'm not totally sure.
The debugging information is in parts of the file that aren't mapped into memory. (e.g for ELF, it isn't in a PT_LOAD segment).
Huh, okay!
Thank you for the answer! We should probably write it down somewhere if it regularly puzzles both contributors and maintainers, then we can close this issue...