backtrace-rs icon indicating copy to clipboard operation
backtrace-rs copied to clipboard

Why do we mmap data that is already mmapped?

Open workingjubilee opened this issue 1 year ago • 5 comments

The basic strategy for backtrace symbolication on Linux:

  • We use a combination of dl_iterate_phdr and opening /proc/self/maps to 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?

workingjubilee avatar Sep 09 '24 03:09 workingjubilee

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

workingjubilee avatar Sep 09 '24 03:09 workingjubilee

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.

sudoBash418 avatar Sep 09 '24 04:09 sudoBash418

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).

philipc avatar Sep 09 '24 04:09 philipc

Huh, okay!

workingjubilee avatar Sep 09 '24 05:09 workingjubilee

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...

workingjubilee avatar Sep 09 '24 05:09 workingjubilee