Benjamin Kramer | 0b8b771 | 2011-09-19 17:56:04 +0000 | [diff] [blame] | 1 | // |
Chandler Carruth | 6b54768 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 2 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 3 | // See https://llvm.org/LICENSE.txt for license information. |
| 4 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Benjamin Kramer | 0b8b771 | 2011-09-19 17:56:04 +0000 | [diff] [blame] | 5 | // |
| 6 | //===----------------------------------------------------------------------===// |
| 7 | |
Benjamin Kramer | 00e08fc | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 8 | #ifndef LLVM_TOOLS_LLVM_OBJDUMP_LLVM_OBJDUMP_H |
| 9 | #define LLVM_TOOLS_LLVM_OBJDUMP_LLVM_OBJDUMP_H |
Benjamin Kramer | 0b8b771 | 2011-09-19 17:56:04 +0000 | [diff] [blame] | 10 | |
Igor Laevsky | 2557480 | 2016-01-26 15:09:42 +0000 | [diff] [blame] | 11 | #include "llvm/DebugInfo/DIContext.h" |
Benjamin Kramer | 0b8b771 | 2011-09-19 17:56:04 +0000 | [diff] [blame] | 12 | #include "llvm/Support/CommandLine.h" |
Davide Italiano | ec0fb28 | 2015-12-29 13:41:02 +0000 | [diff] [blame] | 13 | #include "llvm/Support/Compiler.h" |
Benjamin Kramer | 0b8b771 | 2011-09-19 17:56:04 +0000 | [diff] [blame] | 14 | #include "llvm/Support/DataTypes.h" |
Kevin Enderby | 77be094 | 2016-05-17 17:10:12 +0000 | [diff] [blame] | 15 | #include "llvm/Object/Archive.h" |
Benjamin Kramer | 0b8b771 | 2011-09-19 17:56:04 +0000 | [diff] [blame] | 16 | |
| 17 | namespace llvm { |
Mehdi Amini | f6071e1 | 2016-04-18 09:17:29 +0000 | [diff] [blame] | 18 | class StringRef; |
| 19 | |
Michael J. Spencer | eef7b62 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 20 | namespace object { |
George Rimar | 605942e | 2019-01-18 11:33:26 +0000 | [diff] [blame] | 21 | class COFFObjectFile; |
| 22 | class COFFImportFile; |
| 23 | class ELFObjectFileBase; |
George Rimar | 4771873 | 2019-01-28 14:11:35 +0000 | [diff] [blame] | 24 | class ELFSectionRef; |
George Rimar | 605942e | 2019-01-18 11:33:26 +0000 | [diff] [blame] | 25 | class MachOObjectFile; |
| 26 | class MachOUniversalBinary; |
| 27 | class ObjectFile; |
| 28 | class Archive; |
| 29 | class RelocationRef; |
Michael J. Spencer | eef7b62 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 30 | } |
Michael J. Spencer | eef7b62 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 31 | |
Benjamin Kramer | 0b8b771 | 2011-09-19 17:56:04 +0000 | [diff] [blame] | 32 | extern cl::opt<std::string> TripleName; |
| 33 | extern cl::opt<std::string> ArchName; |
Kevin Enderby | 75d423f | 2014-08-06 23:24:41 +0000 | [diff] [blame] | 34 | extern cl::opt<std::string> MCPU; |
| 35 | extern cl::list<std::string> MAttrs; |
Colin LeMahieu | 154b3f0 | 2015-07-29 19:08:10 +0000 | [diff] [blame] | 36 | extern cl::list<std::string> FilterSections; |
Fangrui Song | 84e5dbf | 2018-06-27 20:45:11 +0000 | [diff] [blame] | 37 | extern cl::opt<bool> AllHeaders; |
Zachary Turner | c04ae04 | 2018-08-20 22:18:21 +0000 | [diff] [blame] | 38 | extern cl::opt<bool> Demangle; |
Colin LeMahieu | edbf9d7 | 2015-07-29 15:45:39 +0000 | [diff] [blame] | 39 | extern cl::opt<bool> Disassemble; |
Colin LeMahieu | ea80502 | 2015-07-23 20:58:49 +0000 | [diff] [blame] | 40 | extern cl::opt<bool> DisassembleAll; |
Kevin Enderby | e793862 | 2014-09-24 23:08:22 +0000 | [diff] [blame] | 41 | extern cl::opt<bool> NoShowRawInsn; |
Saleem Abdulrasool | 5bbd189 | 2017-02-08 18:11:31 +0000 | [diff] [blame] | 42 | extern cl::opt<bool> NoLeadingAddr; |
Kevin Enderby | 60e9ca4 | 2015-01-07 21:02:18 +0000 | [diff] [blame] | 43 | extern cl::opt<bool> PrivateHeaders; |
Paul Semel | d069a21 | 2018-07-04 15:25:03 +0000 | [diff] [blame] | 44 | extern cl::opt<bool> FileHeaders; |
Kevin Enderby | f3e6026 | 2016-01-13 00:25:36 +0000 | [diff] [blame] | 45 | extern cl::opt<bool> FirstPrivateHeader; |
Kevin Enderby | 60e9ca4 | 2015-01-07 21:02:18 +0000 | [diff] [blame] | 46 | extern cl::opt<bool> ExportsTrie; |
| 47 | extern cl::opt<bool> Rebase; |
| 48 | extern cl::opt<bool> Bind; |
| 49 | extern cl::opt<bool> LazyBind; |
| 50 | extern cl::opt<bool> WeakBind; |
Adrian Prantl | 54a2768 | 2015-07-08 02:04:15 +0000 | [diff] [blame] | 51 | extern cl::opt<bool> RawClangAST; |
Kevin Enderby | 6248d1b | 2015-01-09 19:22:37 +0000 | [diff] [blame] | 52 | extern cl::opt<bool> UniversalHeaders; |
Kevin Enderby | cdfe54f | 2015-01-15 23:19:11 +0000 | [diff] [blame] | 53 | extern cl::opt<bool> ArchiveHeaders; |
Kevin Enderby | bcbb869 | 2015-01-22 18:55:27 +0000 | [diff] [blame] | 54 | extern cl::opt<bool> IndirectSymbols; |
Kevin Enderby | 66e2ddc | 2015-01-23 18:52:17 +0000 | [diff] [blame] | 55 | extern cl::opt<bool> DataInCode; |
Kevin Enderby | a167fe1 | 2015-01-27 21:28:24 +0000 | [diff] [blame] | 56 | extern cl::opt<bool> LinkOptHints; |
Kevin Enderby | 8284f0f | 2015-03-11 22:06:32 +0000 | [diff] [blame] | 57 | extern cl::opt<bool> InfoPlist; |
Kevin Enderby | 6250724 | 2015-03-16 20:08:09 +0000 | [diff] [blame] | 58 | extern cl::opt<bool> DylibsUsed; |
| 59 | extern cl::opt<bool> DylibId; |
Kevin Enderby | 95d8155 | 2015-04-01 20:57:01 +0000 | [diff] [blame] | 60 | extern cl::opt<bool> ObjcMetaData; |
Kevin Enderby | 73cd697d | 2015-03-17 17:10:57 +0000 | [diff] [blame] | 61 | extern cl::opt<std::string> DisSymName; |
Kevin Enderby | 300c79d | 2015-03-13 17:56:32 +0000 | [diff] [blame] | 62 | extern cl::opt<bool> NonVerbose; |
Kevin Enderby | c97fb73 | 2015-01-20 21:47:46 +0000 | [diff] [blame] | 63 | extern cl::opt<bool> Relocations; |
Paul Semel | 3fc70658 | 2018-06-07 13:30:55 +0000 | [diff] [blame] | 64 | extern cl::opt<bool> DynamicRelocations; |
Kevin Enderby | c97fb73 | 2015-01-20 21:47:46 +0000 | [diff] [blame] | 65 | extern cl::opt<bool> SectionHeaders; |
| 66 | extern cl::opt<bool> SectionContents; |
| 67 | extern cl::opt<bool> SymbolTable; |
| 68 | extern cl::opt<bool> UnwindInfo; |
Colin LeMahieu | 8cc8dbc | 2015-06-07 21:07:17 +0000 | [diff] [blame] | 69 | extern cl::opt<bool> PrintImmHex; |
Igor Laevsky | 2557480 | 2016-01-26 15:09:42 +0000 | [diff] [blame] | 70 | extern cl::opt<DIDumpType> DwarfDumpType; |
Benjamin Kramer | 0b8b771 | 2011-09-19 17:56:04 +0000 | [diff] [blame] | 71 | |
George Rimar | 605942e | 2019-01-18 11:33:26 +0000 | [diff] [blame] | 72 | typedef std::function<bool(llvm::object::SectionRef const &)> FilterPredicate; |
| 73 | |
| 74 | class SectionFilterIterator { |
| 75 | public: |
| 76 | SectionFilterIterator(FilterPredicate P, |
| 77 | llvm::object::section_iterator const &I, |
| 78 | llvm::object::section_iterator const &E) |
| 79 | : Predicate(std::move(P)), Iterator(I), End(E) { |
| 80 | ScanPredicate(); |
| 81 | } |
| 82 | const llvm::object::SectionRef &operator*() const { return *Iterator; } |
| 83 | SectionFilterIterator &operator++() { |
| 84 | ++Iterator; |
| 85 | ScanPredicate(); |
| 86 | return *this; |
| 87 | } |
| 88 | bool operator!=(SectionFilterIterator const &Other) const { |
| 89 | return Iterator != Other.Iterator; |
| 90 | } |
| 91 | |
| 92 | private: |
| 93 | void ScanPredicate() { |
| 94 | while (Iterator != End && !Predicate(*Iterator)) { |
| 95 | ++Iterator; |
| 96 | } |
| 97 | } |
| 98 | FilterPredicate Predicate; |
| 99 | llvm::object::section_iterator Iterator; |
| 100 | llvm::object::section_iterator End; |
| 101 | }; |
| 102 | |
| 103 | class SectionFilter { |
| 104 | public: |
| 105 | SectionFilter(FilterPredicate P, llvm::object::ObjectFile const &O) |
| 106 | : Predicate(std::move(P)), Object(O) {} |
| 107 | SectionFilterIterator begin() { |
| 108 | return SectionFilterIterator(Predicate, Object.section_begin(), |
| 109 | Object.section_end()); |
| 110 | } |
| 111 | SectionFilterIterator end() { |
| 112 | return SectionFilterIterator(Predicate, Object.section_end(), |
| 113 | Object.section_end()); |
| 114 | } |
| 115 | |
| 116 | private: |
| 117 | FilterPredicate Predicate; |
| 118 | llvm::object::ObjectFile const &Object; |
| 119 | }; |
| 120 | |
Benjamin Kramer | 0b8b771 | 2011-09-19 17:56:04 +0000 | [diff] [blame] | 121 | // Various helper functions. |
George Rimar | 605942e | 2019-01-18 11:33:26 +0000 | [diff] [blame] | 122 | SectionFilter ToolSectionFilter(llvm::object::ObjectFile const &O); |
| 123 | |
| 124 | std::error_code |
| 125 | getELFRelocationValueString(const object::ELFObjectFileBase *Obj, |
| 126 | const object::RelocationRef &Rel, |
| 127 | llvm::SmallVectorImpl<char> &Result); |
| 128 | std::error_code |
| 129 | getCOFFRelocationValueString(const object::COFFObjectFile *Obj, |
| 130 | const object::RelocationRef &Rel, |
| 131 | llvm::SmallVectorImpl<char> &Result); |
| 132 | std::error_code |
| 133 | getWasmRelocationValueString(const object::WasmObjectFile *Obj, |
| 134 | const object::RelocationRef &RelRef, |
| 135 | llvm::SmallVectorImpl<char> &Result); |
| 136 | std::error_code |
| 137 | getMachORelocationValueString(const object::MachOObjectFile *Obj, |
| 138 | const object::RelocationRef &RelRef, |
| 139 | llvm::SmallVectorImpl<char> &Result); |
| 140 | |
George Rimar | 4771873 | 2019-01-28 14:11:35 +0000 | [diff] [blame] | 141 | uint64_t getELFSectionLMA(const object::ELFSectionRef& Sec); |
| 142 | |
Davide Italiano | 281c1b0 | 2015-08-05 07:18:31 +0000 | [diff] [blame] | 143 | void error(std::error_code ec); |
George Rimar | 45d116d | 2019-01-15 09:19:18 +0000 | [diff] [blame] | 144 | bool isRelocAddressLess(object::RelocationRef A, object::RelocationRef B); |
| 145 | void parseInputMachO(StringRef Filename); |
| 146 | void parseInputMachO(object::MachOUniversalBinary *UB); |
| 147 | void printCOFFUnwindInfo(const object::COFFObjectFile *O); |
| 148 | void printMachOUnwindInfo(const object::MachOObjectFile *O); |
| 149 | void printMachOExportsTrie(const object::MachOObjectFile *O); |
| 150 | void printMachORebaseTable(object::MachOObjectFile *O); |
| 151 | void printMachOBindTable(object::MachOObjectFile *O); |
| 152 | void printMachOLazyBindTable(object::MachOObjectFile *O); |
| 153 | void printMachOWeakBindTable(object::MachOObjectFile *O); |
| 154 | void printELFFileHeader(const object::ObjectFile *O); |
Paul Semel | 05d358b | 2018-07-25 11:09:20 +0000 | [diff] [blame] | 155 | void printELFDynamicSection(const object::ObjectFile *Obj); |
George Rimar | 45d116d | 2019-01-15 09:19:18 +0000 | [diff] [blame] | 156 | void printCOFFFileHeader(const object::ObjectFile *O); |
| 157 | void printCOFFSymbolTable(const object::COFFImportFile *I); |
| 158 | void printCOFFSymbolTable(const object::COFFObjectFile *O); |
| 159 | void printMachOFileHeader(const object::ObjectFile *O); |
| 160 | void printMachOLoadCommands(const object::ObjectFile *O); |
| 161 | void printWasmFileHeader(const object::ObjectFile *O); |
| 162 | void printExportsTrie(const object::ObjectFile *O); |
| 163 | void printRebaseTable(object::ObjectFile *O); |
| 164 | void printBindTable(object::ObjectFile *O); |
| 165 | void printLazyBindTable(object::ObjectFile *O); |
| 166 | void printWeakBindTable(object::ObjectFile *O); |
| 167 | void printRawClangAST(const object::ObjectFile *O); |
| 168 | void printRelocations(const object::ObjectFile *O); |
| 169 | void printDynamicRelocations(const object::ObjectFile *O); |
| 170 | void printSectionHeaders(const object::ObjectFile *O); |
| 171 | void printSectionContents(const object::ObjectFile *O); |
| 172 | void printSymbolTable(const object::ObjectFile *O, StringRef ArchiveName, |
Kevin Enderby | e9ddf3a | 2016-05-31 20:35:34 +0000 | [diff] [blame] | 173 | StringRef ArchitectureName = StringRef()); |
Paul Semel | baea3f0 | 2018-07-18 16:39:21 +0000 | [diff] [blame] | 174 | void warn(StringRef Message); |
Kevin Enderby | c827f2c | 2016-06-28 23:16:13 +0000 | [diff] [blame] | 175 | LLVM_ATTRIBUTE_NORETURN void error(Twine Message); |
Kevin Enderby | fbd189d | 2016-11-16 22:17:38 +0000 | [diff] [blame] | 176 | LLVM_ATTRIBUTE_NORETURN void report_error(StringRef File, Twine Message); |
Davide Italiano | ec0fb28 | 2015-12-29 13:41:02 +0000 | [diff] [blame] | 177 | LLVM_ATTRIBUTE_NORETURN void report_error(StringRef File, std::error_code EC); |
Kevin Enderby | c6bf9be | 2016-04-06 22:14:09 +0000 | [diff] [blame] | 178 | LLVM_ATTRIBUTE_NORETURN void report_error(StringRef File, llvm::Error E); |
Kevin Enderby | 77be094 | 2016-05-17 17:10:12 +0000 | [diff] [blame] | 179 | LLVM_ATTRIBUTE_NORETURN void report_error(StringRef FileName, |
| 180 | StringRef ArchiveName, |
Kevin Enderby | e9ddf3a | 2016-05-31 20:35:34 +0000 | [diff] [blame] | 181 | llvm::Error E, |
| 182 | StringRef ArchitectureName |
| 183 | = StringRef()); |
Kevin Enderby | 77be094 | 2016-05-17 17:10:12 +0000 | [diff] [blame] | 184 | LLVM_ATTRIBUTE_NORETURN void report_error(StringRef ArchiveName, |
| 185 | const object::Archive::Child &C, |
Kevin Enderby | e9ddf3a | 2016-05-31 20:35:34 +0000 | [diff] [blame] | 186 | llvm::Error E, |
| 187 | StringRef ArchitectureName |
| 188 | = StringRef()); |
Benjamin Kramer | 0b8b771 | 2011-09-19 17:56:04 +0000 | [diff] [blame] | 189 | |
Rui Ueyama | a6610ee | 2013-09-27 21:04:00 +0000 | [diff] [blame] | 190 | } // end namespace llvm |
Benjamin Kramer | 0b8b771 | 2011-09-19 17:56:04 +0000 | [diff] [blame] | 191 | |
| 192 | #endif |