Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 1 | //===- MachOReader.cpp ------------------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 127252b | 2019-02-11 08:25:19 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "MachOReader.h" |
| 10 | #include "../llvm-objcopy.h" |
| 11 | #include "Object.h" |
| 12 | #include "llvm/BinaryFormat/MachO.h" |
| 13 | #include "llvm/Object/MachO.h" |
| 14 | #include <memory> |
| 15 | |
| 16 | namespace llvm { |
| 17 | namespace objcopy { |
| 18 | namespace macho { |
| 19 | |
| 20 | void MachOReader::readHeader(Object &O) const { |
| 21 | O.Header.Magic = MachOObj.getHeader().magic; |
| 22 | O.Header.CPUType = MachOObj.getHeader().cputype; |
| 23 | O.Header.CPUSubType = MachOObj.getHeader().cpusubtype; |
| 24 | O.Header.FileType = MachOObj.getHeader().filetype; |
| 25 | O.Header.NCmds = MachOObj.getHeader().ncmds; |
| 26 | O.Header.SizeOfCmds = MachOObj.getHeader().sizeofcmds; |
| 27 | O.Header.Flags = MachOObj.getHeader().flags; |
| 28 | } |
| 29 | |
| 30 | template <typename SectionType> |
Alexander Shaposhnikov | f34fdbc | 2020-04-22 14:26:28 -0700 | [diff] [blame] | 31 | Section constructSectionCommon(SectionType Sec, uint32_t Index) { |
Seiya Nuta | 9e119ad | 2019-12-16 14:05:06 +0900 | [diff] [blame] | 32 | StringRef SegName(Sec.segname, strnlen(Sec.segname, sizeof(Sec.segname))); |
| 33 | StringRef SectName(Sec.sectname, strnlen(Sec.sectname, sizeof(Sec.sectname))); |
| 34 | Section S(SegName, SectName); |
Alexander Shaposhnikov | f34fdbc | 2020-04-22 14:26:28 -0700 | [diff] [blame] | 35 | S.Index = Index; |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 36 | S.Addr = Sec.addr; |
| 37 | S.Size = Sec.size; |
| 38 | S.Offset = Sec.offset; |
| 39 | S.Align = Sec.align; |
| 40 | S.RelOff = Sec.reloff; |
| 41 | S.NReloc = Sec.nreloc; |
| 42 | S.Flags = Sec.flags; |
| 43 | S.Reserved1 = Sec.reserved1; |
| 44 | S.Reserved2 = Sec.reserved2; |
| 45 | S.Reserved3 = 0; |
| 46 | return S; |
| 47 | } |
| 48 | |
Alexander Shaposhnikov | f34fdbc | 2020-04-22 14:26:28 -0700 | [diff] [blame] | 49 | template <typename SectionType> |
| 50 | Section constructSection(SectionType Sec, uint32_t Index); |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 51 | |
Alexander Shaposhnikov | f34fdbc | 2020-04-22 14:26:28 -0700 | [diff] [blame] | 52 | template <> Section constructSection(MachO::section Sec, uint32_t Index) { |
| 53 | return constructSectionCommon(Sec, Index); |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Alexander Shaposhnikov | f34fdbc | 2020-04-22 14:26:28 -0700 | [diff] [blame] | 56 | template <> Section constructSection(MachO::section_64 Sec, uint32_t Index) { |
| 57 | Section S = constructSectionCommon(Sec, Index); |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 58 | S.Reserved3 = Sec.reserved3; |
| 59 | return S; |
| 60 | } |
| 61 | |
| 62 | // TODO: get rid of reportError and make MachOReader return Expected<> instead. |
| 63 | template <typename SectionType, typename SegmentType> |
Alexander Shaposhnikov | dc046c7 | 2020-02-21 13:18:36 -0800 | [diff] [blame] | 64 | std::vector<std::unique_ptr<Section>> |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 65 | extractSections(const object::MachOObjectFile::LoadCommandInfo &LoadCmd, |
| 66 | const object::MachOObjectFile &MachOObj, |
Alexander Shaposhnikov | f34fdbc | 2020-04-22 14:26:28 -0700 | [diff] [blame] | 67 | uint32_t &NextSectionIndex) { |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 68 | auto End = LoadCmd.Ptr + LoadCmd.C.cmdsize; |
| 69 | const SectionType *Curr = |
| 70 | reinterpret_cast<const SectionType *>(LoadCmd.Ptr + sizeof(SegmentType)); |
Alexander Shaposhnikov | dc046c7 | 2020-02-21 13:18:36 -0800 | [diff] [blame] | 71 | std::vector<std::unique_ptr<Section>> Sections; |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 72 | for (; reinterpret_cast<const void *>(Curr) < End; Curr++) { |
| 73 | if (MachOObj.isLittleEndian() != sys::IsLittleEndianHost) { |
| 74 | SectionType Sec; |
| 75 | memcpy((void *)&Sec, Curr, sizeof(SectionType)); |
| 76 | MachO::swapStruct(Sec); |
Alexander Shaposhnikov | f34fdbc | 2020-04-22 14:26:28 -0700 | [diff] [blame] | 77 | Sections.push_back( |
| 78 | std::make_unique<Section>(constructSection(Sec, NextSectionIndex))); |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 79 | } else { |
Alexander Shaposhnikov | f34fdbc | 2020-04-22 14:26:28 -0700 | [diff] [blame] | 80 | Sections.push_back( |
| 81 | std::make_unique<Section>(constructSection(*Curr, NextSectionIndex))); |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Alexander Shaposhnikov | dc046c7 | 2020-02-21 13:18:36 -0800 | [diff] [blame] | 84 | Section &S = *Sections.back(); |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 85 | |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 86 | Expected<object::SectionRef> SecRef = |
| 87 | MachOObj.getSection(NextSectionIndex++); |
| 88 | if (!SecRef) |
| 89 | reportError(MachOObj.getFileName(), SecRef.takeError()); |
| 90 | |
Fangrui Song | e1cb2c0 | 2019-05-14 04:22:51 +0000 | [diff] [blame] | 91 | if (Expected<ArrayRef<uint8_t>> E = |
| 92 | MachOObj.getSectionContents(SecRef->getRawDataRefImpl())) |
| 93 | S.Content = |
| 94 | StringRef(reinterpret_cast<const char *>(E->data()), E->size()); |
| 95 | else |
| 96 | reportError(MachOObj.getFileName(), E.takeError()); |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 97 | |
| 98 | S.Relocations.reserve(S.NReloc); |
| 99 | for (auto RI = MachOObj.section_rel_begin(SecRef->getRawDataRefImpl()), |
| 100 | RE = MachOObj.section_rel_end(SecRef->getRawDataRefImpl()); |
Seiya Nuta | f923d9b | 2019-06-21 00:21:50 +0000 | [diff] [blame] | 101 | RI != RE; ++RI) { |
| 102 | RelocationInfo R; |
| 103 | R.Symbol = nullptr; // We'll fill this field later. |
| 104 | R.Info = MachOObj.getRelocation(RI->getRawDataRefImpl()); |
Seiya Nuta | 323b89f | 2019-06-24 23:39:01 +0000 | [diff] [blame] | 105 | R.Scattered = MachOObj.isRelocationScattered(R.Info); |
Alexander Shaposhnikov | 0db3a5a | 2020-04-26 22:39:50 -0700 | [diff] [blame] | 106 | R.Extern = !R.Scattered && MachOObj.getPlainRelocationExternal(R.Info); |
Seiya Nuta | f923d9b | 2019-06-21 00:21:50 +0000 | [diff] [blame] | 107 | S.Relocations.push_back(R); |
| 108 | } |
| 109 | |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 110 | assert(S.NReloc == S.Relocations.size() && |
| 111 | "Incorrect number of relocations"); |
| 112 | } |
| 113 | return Sections; |
| 114 | } |
| 115 | |
| 116 | void MachOReader::readLoadCommands(Object &O) const { |
| 117 | // For MachO sections indices start from 1. |
Alexander Shaposhnikov | f34fdbc | 2020-04-22 14:26:28 -0700 | [diff] [blame] | 118 | uint32_t NextSectionIndex = 1; |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 119 | for (auto LoadCmd : MachOObj.load_commands()) { |
| 120 | LoadCommand LC; |
| 121 | switch (LoadCmd.C.cmd) { |
| 122 | case MachO::LC_SEGMENT: |
| 123 | LC.Sections = extractSections<MachO::section, MachO::segment_command>( |
| 124 | LoadCmd, MachOObj, NextSectionIndex); |
| 125 | break; |
| 126 | case MachO::LC_SEGMENT_64: |
| 127 | LC.Sections = |
| 128 | extractSections<MachO::section_64, MachO::segment_command_64>( |
| 129 | LoadCmd, MachOObj, NextSectionIndex); |
| 130 | break; |
| 131 | case MachO::LC_SYMTAB: |
| 132 | O.SymTabCommandIndex = O.LoadCommands.size(); |
| 133 | break; |
Seiya Nuta | 552bcb8 | 2019-08-19 21:05:31 +0000 | [diff] [blame] | 134 | case MachO::LC_DYSYMTAB: |
| 135 | O.DySymTabCommandIndex = O.LoadCommands.size(); |
| 136 | break; |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 137 | case MachO::LC_DYLD_INFO: |
| 138 | case MachO::LC_DYLD_INFO_ONLY: |
| 139 | O.DyLdInfoCommandIndex = O.LoadCommands.size(); |
| 140 | break; |
Seiya Nuta | 552bcb8 | 2019-08-19 21:05:31 +0000 | [diff] [blame] | 141 | case MachO::LC_DATA_IN_CODE: |
| 142 | O.DataInCodeCommandIndex = O.LoadCommands.size(); |
| 143 | break; |
| 144 | case MachO::LC_FUNCTION_STARTS: |
| 145 | O.FunctionStartsCommandIndex = O.LoadCommands.size(); |
| 146 | break; |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 147 | } |
| 148 | #define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \ |
| 149 | case MachO::LCName: \ |
| 150 | memcpy((void *)&(LC.MachOLoadCommand.LCStruct##_data), LoadCmd.Ptr, \ |
| 151 | sizeof(MachO::LCStruct)); \ |
| 152 | if (MachOObj.isLittleEndian() != sys::IsLittleEndianHost) \ |
| 153 | MachO::swapStruct(LC.MachOLoadCommand.LCStruct##_data); \ |
Alexander Shaposhnikov | c54959c | 2019-11-19 23:30:52 -0800 | [diff] [blame] | 154 | if (LoadCmd.C.cmdsize > sizeof(MachO::LCStruct)) \ |
| 155 | LC.Payload = ArrayRef<uint8_t>( \ |
| 156 | reinterpret_cast<uint8_t *>(const_cast<char *>(LoadCmd.Ptr)) + \ |
| 157 | sizeof(MachO::LCStruct), \ |
| 158 | LoadCmd.C.cmdsize - sizeof(MachO::LCStruct)); \ |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 159 | break; |
| 160 | |
| 161 | switch (LoadCmd.C.cmd) { |
| 162 | default: |
| 163 | memcpy((void *)&(LC.MachOLoadCommand.load_command_data), LoadCmd.Ptr, |
| 164 | sizeof(MachO::load_command)); |
| 165 | if (MachOObj.isLittleEndian() != sys::IsLittleEndianHost) |
| 166 | MachO::swapStruct(LC.MachOLoadCommand.load_command_data); |
Alexander Shaposhnikov | c54959c | 2019-11-19 23:30:52 -0800 | [diff] [blame] | 167 | if (LoadCmd.C.cmdsize > sizeof(MachO::load_command)) |
| 168 | LC.Payload = ArrayRef<uint8_t>( |
| 169 | reinterpret_cast<uint8_t *>(const_cast<char *>(LoadCmd.Ptr)) + |
| 170 | sizeof(MachO::load_command), |
| 171 | LoadCmd.C.cmdsize - sizeof(MachO::load_command)); |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 172 | break; |
| 173 | #include "llvm/BinaryFormat/MachO.def" |
| 174 | } |
| 175 | O.LoadCommands.push_back(std::move(LC)); |
| 176 | } |
| 177 | } |
| 178 | |
Seiya Nuta | f923d9b | 2019-06-21 00:21:50 +0000 | [diff] [blame] | 179 | template <typename nlist_t> |
| 180 | SymbolEntry constructSymbolEntry(StringRef StrTable, const nlist_t &nlist) { |
| 181 | assert(nlist.n_strx < StrTable.size() && |
| 182 | "n_strx exceeds the size of the string table"); |
| 183 | SymbolEntry SE; |
| 184 | SE.Name = StringRef(StrTable.data() + nlist.n_strx).str(); |
| 185 | SE.n_type = nlist.n_type; |
| 186 | SE.n_sect = nlist.n_sect; |
| 187 | SE.n_desc = nlist.n_desc; |
| 188 | SE.n_value = nlist.n_value; |
| 189 | return SE; |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | void MachOReader::readSymbolTable(Object &O) const { |
Seiya Nuta | f923d9b | 2019-06-21 00:21:50 +0000 | [diff] [blame] | 193 | StringRef StrTable = MachOObj.getStringTableData(); |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 194 | for (auto Symbol : MachOObj.symbols()) { |
Seiya Nuta | f923d9b | 2019-06-21 00:21:50 +0000 | [diff] [blame] | 195 | SymbolEntry SE = |
| 196 | (MachOObj.is64Bit() |
Alexander Shaposhnikov | f34fdbc | 2020-04-22 14:26:28 -0700 | [diff] [blame] | 197 | ? constructSymbolEntry(StrTable, MachOObj.getSymbol64TableEntry( |
| 198 | Symbol.getRawDataRefImpl())) |
| 199 | : constructSymbolEntry(StrTable, MachOObj.getSymbolTableEntry( |
| 200 | Symbol.getRawDataRefImpl()))); |
Seiya Nuta | f923d9b | 2019-06-21 00:21:50 +0000 | [diff] [blame] | 201 | |
Jonas Devlieghere | 0eaee54 | 2019-08-15 15:54:37 +0000 | [diff] [blame] | 202 | O.SymTable.Symbols.push_back(std::make_unique<SymbolEntry>(SE)); |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 203 | } |
Clement Courbet | be16b80 | 2019-02-04 10:24:42 +0000 | [diff] [blame] | 204 | } |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 205 | |
Seiya Nuta | f923d9b | 2019-06-21 00:21:50 +0000 | [diff] [blame] | 206 | void MachOReader::setSymbolInRelocationInfo(Object &O) const { |
Alexander Shaposhnikov | 0db3a5a | 2020-04-26 22:39:50 -0700 | [diff] [blame] | 207 | std::vector<const Section *> Sections; |
| 208 | for (auto &LC : O.LoadCommands) |
| 209 | for (std::unique_ptr<Section> &Sec : LC.Sections) |
| 210 | Sections.push_back(Sec.get()); |
| 211 | |
Alexander Shaposhnikov | dc046c7 | 2020-02-21 13:18:36 -0800 | [diff] [blame] | 212 | for (LoadCommand &LC : O.LoadCommands) |
| 213 | for (std::unique_ptr<Section> &Sec : LC.Sections) |
| 214 | for (auto &Reloc : Sec->Relocations) |
Alexander Shaposhnikov | 0db3a5a | 2020-04-26 22:39:50 -0700 | [diff] [blame] | 215 | if (!Reloc.Scattered) { |
| 216 | const uint32_t SymbolNum = |
| 217 | Reloc.getPlainRelocationSymbolNum(MachOObj.isLittleEndian()); |
| 218 | if (Reloc.Extern) { |
| 219 | Reloc.Symbol = O.SymTable.getSymbolByIndex(SymbolNum); |
| 220 | } else { |
| 221 | // FIXME: Refactor error handling in MachOReader and report an error |
| 222 | // if we encounter an invalid relocation. |
| 223 | assert(SymbolNum >= 1 && SymbolNum <= Sections.size() && |
| 224 | "Invalid section index."); |
Alexander Shaposhnikov | 29c6f5c | 2020-04-27 18:20:01 -0700 | [diff] [blame] | 225 | Reloc.Sec = Sections[SymbolNum - 1]; |
Alexander Shaposhnikov | 0db3a5a | 2020-04-26 22:39:50 -0700 | [diff] [blame] | 226 | } |
| 227 | } |
Clement Courbet | be16b80 | 2019-02-04 10:24:42 +0000 | [diff] [blame] | 228 | } |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 229 | |
| 230 | void MachOReader::readRebaseInfo(Object &O) const { |
| 231 | O.Rebases.Opcodes = MachOObj.getDyldInfoRebaseOpcodes(); |
| 232 | } |
| 233 | |
| 234 | void MachOReader::readBindInfo(Object &O) const { |
| 235 | O.Binds.Opcodes = MachOObj.getDyldInfoBindOpcodes(); |
| 236 | } |
| 237 | |
| 238 | void MachOReader::readWeakBindInfo(Object &O) const { |
| 239 | O.WeakBinds.Opcodes = MachOObj.getDyldInfoWeakBindOpcodes(); |
| 240 | } |
| 241 | |
| 242 | void MachOReader::readLazyBindInfo(Object &O) const { |
| 243 | O.LazyBinds.Opcodes = MachOObj.getDyldInfoLazyBindOpcodes(); |
| 244 | } |
| 245 | |
| 246 | void MachOReader::readExportInfo(Object &O) const { |
| 247 | O.Exports.Trie = MachOObj.getDyldInfoExportsTrie(); |
| 248 | } |
| 249 | |
Seiya Nuta | 552bcb8 | 2019-08-19 21:05:31 +0000 | [diff] [blame] | 250 | void MachOReader::readDataInCodeData(Object &O) const { |
| 251 | if (!O.DataInCodeCommandIndex) |
| 252 | return; |
| 253 | const MachO::linkedit_data_command &LDC = |
| 254 | O.LoadCommands[*O.DataInCodeCommandIndex] |
| 255 | .MachOLoadCommand.linkedit_data_command_data; |
| 256 | |
| 257 | O.DataInCode.Data = arrayRefFromStringRef( |
| 258 | MachOObj.getData().substr(LDC.dataoff, LDC.datasize)); |
| 259 | } |
| 260 | |
| 261 | void MachOReader::readFunctionStartsData(Object &O) const { |
| 262 | if (!O.FunctionStartsCommandIndex) |
| 263 | return; |
| 264 | const MachO::linkedit_data_command &LDC = |
| 265 | O.LoadCommands[*O.FunctionStartsCommandIndex] |
| 266 | .MachOLoadCommand.linkedit_data_command_data; |
| 267 | |
| 268 | O.FunctionStarts.Data = arrayRefFromStringRef( |
| 269 | MachOObj.getData().substr(LDC.dataoff, LDC.datasize)); |
| 270 | } |
| 271 | |
| 272 | void MachOReader::readIndirectSymbolTable(Object &O) const { |
| 273 | MachO::dysymtab_command DySymTab = MachOObj.getDysymtabLoadCommand(); |
Seiya Nuta | 1e589f6 | 2019-10-30 15:12:17 +0900 | [diff] [blame] | 274 | constexpr uint32_t AbsOrLocalMask = |
| 275 | MachO::INDIRECT_SYMBOL_LOCAL | MachO::INDIRECT_SYMBOL_ABS; |
| 276 | for (uint32_t i = 0; i < DySymTab.nindirectsyms; ++i) { |
| 277 | uint32_t Index = MachOObj.getIndirectSymbolTableEntry(DySymTab, i); |
| 278 | if ((Index & AbsOrLocalMask) != 0) |
| 279 | O.IndirectSymTable.Symbols.emplace_back(Index, None); |
| 280 | else |
| 281 | O.IndirectSymTable.Symbols.emplace_back( |
| 282 | Index, O.SymTable.getSymbolByIndex(Index)); |
| 283 | } |
Seiya Nuta | 552bcb8 | 2019-08-19 21:05:31 +0000 | [diff] [blame] | 284 | } |
| 285 | |
Alexander Shaposhnikov | 842a8cc | 2020-05-26 16:49:56 -0700 | [diff] [blame] | 286 | void MachOReader::readSwiftVersion(Object &O) const { |
| 287 | struct ObjCImageInfo { |
| 288 | uint32_t Version; |
| 289 | uint32_t Flags; |
| 290 | } ImageInfo; |
| 291 | |
| 292 | for (const LoadCommand &LC : O.LoadCommands) |
| 293 | for (const std::unique_ptr<Section> &Sec : LC.Sections) |
| 294 | if (Sec->Sectname == "__objc_imageinfo" && |
| 295 | (Sec->Segname == "__DATA" || Sec->Segname == "__DATA_CONST" || |
| 296 | Sec->Segname == "__DATA_DIRTY") && |
| 297 | Sec->Content.size() >= sizeof(ObjCImageInfo)) { |
| 298 | memcpy(&ImageInfo, Sec->Content.data(), sizeof(ObjCImageInfo)); |
| 299 | if (MachOObj.isLittleEndian() != sys::IsLittleEndianHost) { |
| 300 | sys::swapByteOrder(ImageInfo.Version); |
| 301 | sys::swapByteOrder(ImageInfo.Flags); |
| 302 | } |
| 303 | O.SwiftVersion = (ImageInfo.Flags >> 8) & 0xff; |
| 304 | return; |
| 305 | } |
| 306 | } |
| 307 | |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 308 | std::unique_ptr<Object> MachOReader::create() const { |
Jonas Devlieghere | 0eaee54 | 2019-08-15 15:54:37 +0000 | [diff] [blame] | 309 | auto Obj = std::make_unique<Object>(); |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 310 | readHeader(*Obj); |
| 311 | readLoadCommands(*Obj); |
| 312 | readSymbolTable(*Obj); |
Seiya Nuta | f923d9b | 2019-06-21 00:21:50 +0000 | [diff] [blame] | 313 | setSymbolInRelocationInfo(*Obj); |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 314 | readRebaseInfo(*Obj); |
| 315 | readBindInfo(*Obj); |
| 316 | readWeakBindInfo(*Obj); |
| 317 | readLazyBindInfo(*Obj); |
| 318 | readExportInfo(*Obj); |
Seiya Nuta | 552bcb8 | 2019-08-19 21:05:31 +0000 | [diff] [blame] | 319 | readDataInCodeData(*Obj); |
| 320 | readFunctionStartsData(*Obj); |
| 321 | readIndirectSymbolTable(*Obj); |
Alexander Shaposhnikov | 842a8cc | 2020-05-26 16:49:56 -0700 | [diff] [blame] | 322 | readSwiftVersion(*Obj); |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 323 | return Obj; |
| 324 | } |
| 325 | |
| 326 | } // end namespace macho |
| 327 | } // end namespace objcopy |
| 328 | } // end namespace llvm |