diff options
author | Jason Molenda <jmolenda@apple.com> | 2024-11-28 10:31:57 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-28 10:31:57 -0800 |
commit | 448ac7d3418a31d35b462440c8bf644287efac8a (patch) | |
tree | 0b37fc05437dc6919c1d314925a2db604c239c15 /lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp | |
parent | 611ccfcae9842a1356195189d5595ef1684e3df4 (diff) | |
download | llvm-448ac7d3418a31d35b462440c8bf644287efac8a.zip llvm-448ac7d3418a31d35b462440c8bf644287efac8a.tar.gz llvm-448ac7d3418a31d35b462440c8bf644287efac8a.tar.bz2 |
[lldb][Mach-O] Handle shared cache binaries correctly (#117832)
The Mach-O load commands have an LC_SYMTAB / struct symtab_command which
represents the offset of the symbol table (nlist records) and string
table for this binary. In a mach-o binary on disk, these are file
offsets. If a mach-o binary is loaded in memory with all segments
consecutive, the `symoff` and `stroff` are the offsets from the TEXT
segment (aka the mach-o header) virtual address to the virtual address
of the start of these tables.
However, if a Mach-O binary is a part of the shared cache, then the
segments will be separated -- they will have different slide values. And
it is possible for the LINKEDIT segment to be greater than 4GB away from
the TEXT segment in the virtual address space, so these 32-bit offsets
cannot express the offset from TEXT segment to these tables.
Create separate uint64_t variables to track the offset to the symbol
table and string table, instead of reusing the 32-bit ones in the
symtab_command structure.
rdar://140432279
Diffstat (limited to 'lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp')
-rw-r--r-- | lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index 079fd90..4aa85a9 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -2235,11 +2235,11 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) { LLDB_LOG(log, "Parsing symbol table for {0}", file_name); Progress progress("Parsing symbol table", file_name); - llvm::MachO::symtab_command symtab_load_command = {0, 0, 0, 0, 0, 0}; llvm::MachO::linkedit_data_command function_starts_load_command = {0, 0, 0, 0}; llvm::MachO::linkedit_data_command exports_trie_load_command = {0, 0, 0, 0}; llvm::MachO::dyld_info_command dyld_info = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; llvm::MachO::dysymtab_command dysymtab = m_dysymtab; + SymtabCommandLargeOffsets symtab_load_command; // The data element of type bool indicates that this entry is thumb // code. typedef AddressDataArray<lldb::addr_t, bool, 100> FunctionStarts; @@ -2276,12 +2276,20 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) { // Watch for the symbol table load command switch (lc.cmd) { case LC_SYMTAB: + // struct symtab_command { + // uint32_t cmd; /* LC_SYMTAB */ + // uint32_t cmdsize; /* sizeof(struct symtab_command) */ + // uint32_t symoff; /* symbol table offset */ + // uint32_t nsyms; /* number of symbol table entries */ + // uint32_t stroff; /* string table offset */ + // uint32_t strsize; /* string table size in bytes */ + // }; symtab_load_command.cmd = lc.cmd; symtab_load_command.cmdsize = lc.cmdsize; - // Read in the rest of the symtab load command - if (m_data.GetU32(&offset, &symtab_load_command.symoff, 4) == - nullptr) // fill in symoff, nsyms, stroff, strsize fields - return; + symtab_load_command.symoff = m_data.GetU32(&offset); + symtab_load_command.nsyms = m_data.GetU32(&offset); + symtab_load_command.stroff = m_data.GetU32(&offset); + symtab_load_command.strsize = m_data.GetU32(&offset); break; case LC_DYLD_INFO: |