Skip to content

Exports load command #3149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2231,6 +2231,7 @@ size_t ObjectFileMachO::ParseSymtab() {

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};
// The data element of type bool indicates that this entry is thumb
// code.
Expand Down Expand Up @@ -2308,11 +2309,19 @@ size_t ObjectFileMachO::ParseSymtab() {
}
} break;

case LC_DYLD_EXPORTS_TRIE:
exports_trie_load_command.cmd = lc.cmd;
exports_trie_load_command.cmdsize = lc.cmdsize;
if (m_data.GetU32(&offset, &exports_trie_load_command.dataoff, 2) ==
nullptr) // fill in offset and size fields
memset(&exports_trie_load_command, 0,
sizeof(exports_trie_load_command));
break;
case LC_FUNCTION_STARTS:
function_starts_load_command.cmd = lc.cmd;
function_starts_load_command.cmdsize = lc.cmdsize;
if (m_data.GetU32(&offset, &function_starts_load_command.dataoff, 2) ==
nullptr) // fill in symoff, nsyms, stroff, strsize fields
nullptr) // fill in data offset and size fields
memset(&function_starts_load_command, 0,
sizeof(function_starts_load_command));
break;
Expand Down Expand Up @@ -2456,16 +2465,24 @@ size_t ObjectFileMachO::ParseSymtab() {
dyld_info.export_off += linkedit_slide;
m_dysymtab.indirectsymoff += linkedit_slide;
function_starts_load_command.dataoff += linkedit_slide;
exports_trie_load_command.dataoff += linkedit_slide;
}

nlist_data.SetData(m_data, symtab_load_command.symoff,
nlist_data_byte_size);
strtab_data.SetData(m_data, symtab_load_command.stroff,
strtab_data_byte_size);

// We shouldn't have exports data from both the LC_DYLD_INFO command
// AND the LC_DYLD_EXPORTS_TRIE command in the same binary:
lldbassert(!((dyld_info.export_size > 0)
&& (exports_trie_load_command.datasize > 0)));
if (dyld_info.export_size > 0) {
dyld_trie_data.SetData(m_data, dyld_info.export_off,
dyld_info.export_size);
} else if (exports_trie_load_command.datasize > 0) {
dyld_trie_data.SetData(m_data, exports_trie_load_command.dataoff,
exports_trie_load_command.datasize);
}

if (m_dysymtab.nindirectsyms != 0) {
Expand Down
2 changes: 2 additions & 0 deletions llvm/include/llvm/BinaryFormat/MachO.def
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ HANDLE_LOAD_COMMAND(LC_VERSION_MIN_TVOS, 0x0000002Fu, version_min_command)
HANDLE_LOAD_COMMAND(LC_VERSION_MIN_WATCHOS, 0x00000030u, version_min_command)
HANDLE_LOAD_COMMAND(LC_NOTE, 0x00000031u, note_command)
HANDLE_LOAD_COMMAND(LC_BUILD_VERSION, 0x00000032u, build_version_command)
HANDLE_LOAD_COMMAND(LC_DYLD_EXPORTS_TRIE, 0x80000033u, linkedit_data_command)
HANDLE_LOAD_COMMAND(LC_DYLD_CHAINED_FIXUPS, 0x80000034u, linkedit_data_command)

#endif

Expand Down