[Lldb-commits] [lldb] [LLDB] Impove ObjectFileELF's .dynamic parsing and usage. (PR #101237)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Wed Jul 31 05:04:31 PDT 2024
================
@@ -2550,6 +2550,21 @@ ModuleSP Process::ReadModuleFromMemory(const FileSpec &file_spec,
}
ModuleSP module_sp(new Module(file_spec, ArchSpec()));
if (module_sp) {
+ if (size_to_read == 0) {
+ // Default to 8192 in case we can't find a memory region.
+ size_to_read = 0x2000;
+ MemoryRegionInfo range_info;
+ Status error(GetMemoryRegionInfo(header_addr, range_info));
+ if (error.Success()) {
+ // We found a memory region, set the range of bytes ro read to read to
+ // the end of the memory region. This should be enough to contain the
+ // file header and important bits.
+ const auto &range = range_info.GetRange();
----------------
labath wrote:
Depending on how the file is linked (`-z noseparate-code`) the first region could end up containing all of the code in the binary (and so be arbitrarily big), it might not be a good idea to read all of it. What's the reason for this change? Could that be a separate patch as well? (I think we can test DT_DYNAMIC parsing without actually loading the file from memory)
For reference, this is what I get with a hello world binary built like this:
```
$ clang++ -o /tmp/a.out -x c++ - -static <<<"int main(){}" -Wl,-z,noseparate-code && llvm-readelf -e /tmp/a.out | grep -e LOAD -B 1
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x000000 0x0000000000400000 0x0000000000400000 0x09caf6 0x09caf6 R E 0x1000
LOAD 0x09ceb0 0x000000000049deb0 0x000000000049deb0 0x005b58 0x00b2b8 RW 0x1000
```
https://github.com/llvm/llvm-project/pull/101237
More information about the lldb-commits
mailing list