aboutsummaryrefslogtreecommitdiff
path: root/tools/llvm-objcopy/MachO/MachOReader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/llvm-objcopy/MachO/MachOReader.cpp')
-rw-r--r--tools/llvm-objcopy/MachO/MachOReader.cpp45
1 files changed, 43 insertions, 2 deletions
diff --git a/tools/llvm-objcopy/MachO/MachOReader.cpp b/tools/llvm-objcopy/MachO/MachOReader.cpp
index d31293034608..b48a0d8952d0 100644
--- a/tools/llvm-objcopy/MachO/MachOReader.cpp
+++ b/tools/llvm-objcopy/MachO/MachOReader.cpp
@@ -129,10 +129,19 @@ void MachOReader::readLoadCommands(Object &O) const {
case MachO::LC_SYMTAB:
O.SymTabCommandIndex = O.LoadCommands.size();
break;
+ case MachO::LC_DYSYMTAB:
+ O.DySymTabCommandIndex = O.LoadCommands.size();
+ break;
case MachO::LC_DYLD_INFO:
case MachO::LC_DYLD_INFO_ONLY:
O.DyLdInfoCommandIndex = O.LoadCommands.size();
break;
+ case MachO::LC_DATA_IN_CODE:
+ O.DataInCodeCommandIndex = O.LoadCommands.size();
+ break;
+ case MachO::LC_FUNCTION_STARTS:
+ O.FunctionStartsCommandIndex = O.LoadCommands.size();
+ break;
}
#define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \
case MachO::LCName: \
@@ -188,7 +197,7 @@ void MachOReader::readSymbolTable(Object &O) const {
StrTable,
MachOObj.getSymbolTableEntry(Symbol.getRawDataRefImpl())));
- O.SymTable.Symbols.push_back(llvm::make_unique<SymbolEntry>(SE));
+ O.SymTable.Symbols.push_back(std::make_unique<SymbolEntry>(SE));
}
}
@@ -222,8 +231,37 @@ void MachOReader::readExportInfo(Object &O) const {
O.Exports.Trie = MachOObj.getDyldInfoExportsTrie();
}
+void MachOReader::readDataInCodeData(Object &O) const {
+ if (!O.DataInCodeCommandIndex)
+ return;
+ const MachO::linkedit_data_command &LDC =
+ O.LoadCommands[*O.DataInCodeCommandIndex]
+ .MachOLoadCommand.linkedit_data_command_data;
+
+ O.DataInCode.Data = arrayRefFromStringRef(
+ MachOObj.getData().substr(LDC.dataoff, LDC.datasize));
+}
+
+void MachOReader::readFunctionStartsData(Object &O) const {
+ if (!O.FunctionStartsCommandIndex)
+ return;
+ const MachO::linkedit_data_command &LDC =
+ O.LoadCommands[*O.FunctionStartsCommandIndex]
+ .MachOLoadCommand.linkedit_data_command_data;
+
+ O.FunctionStarts.Data = arrayRefFromStringRef(
+ MachOObj.getData().substr(LDC.dataoff, LDC.datasize));
+}
+
+void MachOReader::readIndirectSymbolTable(Object &O) const {
+ MachO::dysymtab_command DySymTab = MachOObj.getDysymtabLoadCommand();
+ for (uint32_t i = 0; i < DySymTab.nindirectsyms; ++i)
+ O.IndirectSymTable.Symbols.push_back(
+ MachOObj.getIndirectSymbolTableEntry(DySymTab, i));
+}
+
std::unique_ptr<Object> MachOReader::create() const {
- auto Obj = llvm::make_unique<Object>();
+ auto Obj = std::make_unique<Object>();
readHeader(*Obj);
readLoadCommands(*Obj);
readSymbolTable(*Obj);
@@ -233,6 +271,9 @@ std::unique_ptr<Object> MachOReader::create() const {
readWeakBindInfo(*Obj);
readLazyBindInfo(*Obj);
readExportInfo(*Obj);
+ readDataInCodeData(*Obj);
+ readFunctionStartsData(*Obj);
+ readIndirectSymbolTable(*Obj);
return Obj;
}