diff options
author | Daniel Rodríguez Troitiño <danielrodriguez@fb.com> | 2022-11-22 15:12:27 -0800 |
---|---|---|
committer | Daniel Rodríguez Troitiño <danielrodriguez@fb.com> | 2022-11-22 17:44:46 -0800 |
commit | 42ad9bf95fd5cb30e2ab3e017b6718ac6efea1be (patch) | |
tree | 7f860bfb0ae0325ac90754afeb420dd15f7b1283 /llvm/lib/Object/MachOObjectFile.cpp | |
parent | 7218103bcaca36be0287172a91ae2907ca20930c (diff) | |
download | llvm-42ad9bf95fd5cb30e2ab3e017b6718ac6efea1be.zip llvm-42ad9bf95fd5cb30e2ab3e017b6718ac6efea1be.tar.gz llvm-42ad9bf95fd5cb30e2ab3e017b6718ac6efea1be.tar.bz2 |
[MachO] Support exports trie in both LC_DYLD_INFO and LC_DYLD_EXPORTS_TRIE
The exports trie used to be pointed by the information in LC_DYLD_INFO,
but when chained fixups are present, the exports trie is pointed by
LC_DYLD_EXPORTS_TRIE instead.
Modify the Object library to give access to the information pointed by
each of the load commands, and to fallback from one into the other when
the exports are requested.
Modify ObjectYAML to support dumping the export trie when pointed by
LC_DYLD_EXPORTS_TRIE and to parse the existence of a export trie also
when the load command is present.
This is a split of D134250 with improvements on top.
Reviewed By: alexander-shaposhnikov
Differential Revision: https://reviews.llvm.org/D134571
Diffstat (limited to 'llvm/lib/Object/MachOObjectFile.cpp')
-rw-r--r-- | llvm/lib/Object/MachOObjectFile.cpp | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index 20ac343..f3ca2e9 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -1386,6 +1386,11 @@ MachOObjectFile::MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian, *this, Load, I, &DyldChainedFixupsLoadCmd, "LC_DYLD_CHAINED_FIXUPS", Elements, "chained fixups"))) return; + } else if (Load.C.cmd == MachO::LC_DYLD_EXPORTS_TRIE) { + if ((Err = checkLinkeditDataCommand( + *this, Load, I, &DyldExportsTrieLoadCmd, "LC_DYLD_EXPORTS_TRIE", + Elements, "exports trie"))) + return; } else if (Load.C.cmd == MachO::LC_UUID) { if (Load.C.cmdsize != sizeof(MachO::uuid_command)) { Err = malformedError("LC_UUID command " + Twine(I) + " has incorrect " @@ -3225,7 +3230,13 @@ MachOObjectFile::exports(Error &E, ArrayRef<uint8_t> Trie, } iterator_range<export_iterator> MachOObjectFile::exports(Error &Err) const { - return exports(Err, getDyldInfoExportsTrie(), this); + ArrayRef<uint8_t> Trie; + if (DyldInfoLoadCmd) + Trie = getDyldInfoExportsTrie(); + else if (DyldExportsTrieLoadCmd) + Trie = getDyldExportsTrie(); + + return exports(Err, Trie, this); } MachOAbstractFixupEntry::MachOAbstractFixupEntry(Error *E, @@ -4932,6 +4943,20 @@ ArrayRef<uint8_t> MachOObjectFile::getDyldInfoLazyBindOpcodes() const { return makeArrayRef(Ptr, DyldInfo.lazy_bind_size); } +ArrayRef<uint8_t> MachOObjectFile::getDyldInfoExportsTrie() const { + if (!DyldInfoLoadCmd) + return None; + + auto DyldInfoOrErr = + getStructOrErr<MachO::dyld_info_command>(*this, DyldInfoLoadCmd); + if (!DyldInfoOrErr) + return None; + MachO::dyld_info_command DyldInfo = DyldInfoOrErr.get(); + const uint8_t *Ptr = + reinterpret_cast<const uint8_t *>(getPtr(*this, DyldInfo.export_off)); + return makeArrayRef(Ptr, DyldInfo.export_size); +} + Expected<Optional<MachO::linkedit_data_command>> MachOObjectFile::getChainedFixupsLoadCommand() const { // Load the dyld chained fixups load command. @@ -5209,18 +5234,18 @@ MachOObjectFile::getDyldChainedFixupTargets() const { return std::move(Targets); } -ArrayRef<uint8_t> MachOObjectFile::getDyldInfoExportsTrie() const { - if (!DyldInfoLoadCmd) +ArrayRef<uint8_t> MachOObjectFile::getDyldExportsTrie() const { + if (!DyldExportsTrieLoadCmd) return None; - auto DyldInfoOrErr = - getStructOrErr<MachO::dyld_info_command>(*this, DyldInfoLoadCmd); - if (!DyldInfoOrErr) + auto DyldExportsTrieOrError = getStructOrErr<MachO::linkedit_data_command>( + *this, DyldExportsTrieLoadCmd); + if (!DyldExportsTrieOrError) return None; - MachO::dyld_info_command DyldInfo = DyldInfoOrErr.get(); + MachO::linkedit_data_command DyldExportsTrie = DyldExportsTrieOrError.get(); const uint8_t *Ptr = - reinterpret_cast<const uint8_t *>(getPtr(*this, DyldInfo.export_off)); - return makeArrayRef(Ptr, DyldInfo.export_size); + reinterpret_cast<const uint8_t *>(getPtr(*this, DyldExportsTrie.dataoff)); + return makeArrayRef(Ptr, DyldExportsTrie.datasize); } SmallVector<uint64_t> MachOObjectFile::getFunctionStarts() const { |