[Lldb-commits] [PATCH] D122856: [lldb] Refactor DataBuffer so we can map files as read-only

Pavel Labath via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Mar 31 23:56:45 PDT 2022


labath added a comment.

Yeah, I tried doing this (well, i used `const DataBuffer` to represent read-only data) last time this topic came up, and ran into the same problem. Since there was no pressing need for it, I put the patch away.

I think the best way to fix this is to allow the object file classes to control the way the object file is mapped into memory (during creation). Then the ObjectFileELF could map the the file read-write, and the rest would do it read-only (though I think it's possible we need to relocate COFF files as well, only no one ran into the issue yet). If we wanted to be very fancy, we could check whether the object file needs relocations (basically, does it have any `.rel(a).debug_***` sections) and *then* map the file read-write, but I don't think that's really necessary.

That doesn't directly help with the code in `ObjectFileELF::ApplyRelocations`, since it would still get an object whose static type prohibits writes. However, if we can ensure that the dynamic type of the object is alright, then we can put an appropriate cast there, and put a comment pointing to the place where the object is created.

In llvm the relocations are being applied on-the-fly as the data is being read. That would be another possibility, but it would be a much more intrusive change (and tbh, I can't say I like the llvm model that much). OTOH, it would go a long way towards unifying llvm and lldb object&dwarf readers....


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122856/new/

https://reviews.llvm.org/D122856



More information about the lldb-commits mailing list