Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 1 | //===- ELFDumper.cpp - ELF-specific dumper --------------------------------===// |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// |
| 10 | /// \file |
| 11 | /// \brief This file implements the ELF-specific dumper for llvm-readobj. |
| 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 15 | #include "ARMEHABIPrinter.h" |
| 16 | #include "Error.h" |
| 17 | #include "ObjDumper.h" |
| 18 | #include "StackMapPrinter.h" |
Zachary Turner | 88bb163 | 2016-05-03 00:28:04 +0000 | [diff] [blame] | 19 | #include "llvm-readobj.h" |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/ArrayRef.h" |
George Rimar | 762abff6 | 2017-09-16 14:29:51 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/DenseMap.h" |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/Optional.h" |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/PointerIntPair.h" |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/SmallString.h" |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/SmallVector.h" |
| 26 | #include "llvm/ADT/STLExtras.h" |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/StringExtras.h" |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 28 | #include "llvm/ADT/StringRef.h" |
| 29 | #include "llvm/ADT/Twine.h" |
| 30 | #include "llvm/BinaryFormat/ELF.h" |
| 31 | #include "llvm/Object/ELF.h" |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 32 | #include "llvm/Object/ELFObjectFile.h" |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 33 | #include "llvm/Object/ELFTypes.h" |
| 34 | #include "llvm/Object/Error.h" |
| 35 | #include "llvm/Object/ObjectFile.h" |
| 36 | #include "llvm/Object/StackMapParser.h" |
Konstantin Zhuravlyov | b3c605d | 2017-10-14 18:21:42 +0000 | [diff] [blame] | 37 | #include "llvm/Support/AMDGPUMetadata.h" |
Sam Parker | 34315ee | 2017-01-13 10:50:01 +0000 | [diff] [blame] | 38 | #include "llvm/Support/ARMAttributeParser.h" |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 39 | #include "llvm/Support/ARMBuildAttributes.h" |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 40 | #include "llvm/Support/Casting.h" |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 41 | #include "llvm/Support/Compiler.h" |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 42 | #include "llvm/Support/Endian.h" |
| 43 | #include "llvm/Support/ErrorHandling.h" |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 44 | #include "llvm/Support/Format.h" |
Zachary Turner | 88bb163 | 2016-05-03 00:28:04 +0000 | [diff] [blame] | 45 | #include "llvm/Support/FormattedStream.h" |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 46 | #include "llvm/Support/MathExtras.h" |
| 47 | #include "llvm/Support/MipsABIFlags.h" |
Zachary Turner | 88bb163 | 2016-05-03 00:28:04 +0000 | [diff] [blame] | 48 | #include "llvm/Support/ScopedPrinter.h" |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 49 | #include "llvm/Support/raw_ostream.h" |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 50 | #include <algorithm> |
| 51 | #include <cinttypes> |
| 52 | #include <cstddef> |
| 53 | #include <cstdint> |
| 54 | #include <cstdlib> |
| 55 | #include <iterator> |
| 56 | #include <memory> |
| 57 | #include <string> |
| 58 | #include <system_error> |
| 59 | #include <vector> |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 60 | |
| 61 | using namespace llvm; |
| 62 | using namespace llvm::object; |
| 63 | using namespace ELF; |
| 64 | |
| 65 | #define LLVM_READOBJ_ENUM_CASE(ns, enum) \ |
| 66 | case ns::enum: return #enum; |
| 67 | |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 68 | #define ENUM_ENT(enum, altName) \ |
| 69 | { #enum, altName, ELF::enum } |
| 70 | |
| 71 | #define ENUM_ENT_1(enum) \ |
| 72 | { #enum, #enum, ELF::enum } |
| 73 | |
Hemant Kulkarni | 7d564ba | 2016-03-28 17:20:23 +0000 | [diff] [blame] | 74 | #define LLVM_READOBJ_PHDR_ENUM(ns, enum) \ |
| 75 | case ns::enum: \ |
| 76 | return std::string(#enum).substr(3); |
| 77 | |
Hemant Kulkarni | 206ba84 | 2016-03-09 19:16:13 +0000 | [diff] [blame] | 78 | #define TYPEDEF_ELF_TYPES(ELFT) \ |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 79 | using ELFO = ELFFile<ELFT>; \ |
| 80 | using Elf_Shdr = typename ELFO::Elf_Shdr; \ |
| 81 | using Elf_Sym = typename ELFO::Elf_Sym; \ |
| 82 | using Elf_Dyn = typename ELFO::Elf_Dyn; \ |
| 83 | using Elf_Dyn_Range = typename ELFO::Elf_Dyn_Range; \ |
| 84 | using Elf_Rel = typename ELFO::Elf_Rel; \ |
| 85 | using Elf_Rela = typename ELFO::Elf_Rela; \ |
| 86 | using Elf_Rel_Range = typename ELFO::Elf_Rel_Range; \ |
| 87 | using Elf_Rela_Range = typename ELFO::Elf_Rela_Range; \ |
| 88 | using Elf_Phdr = typename ELFO::Elf_Phdr; \ |
| 89 | using Elf_Half = typename ELFO::Elf_Half; \ |
| 90 | using Elf_Ehdr = typename ELFO::Elf_Ehdr; \ |
| 91 | using Elf_Word = typename ELFO::Elf_Word; \ |
| 92 | using Elf_Hash = typename ELFO::Elf_Hash; \ |
| 93 | using Elf_GnuHash = typename ELFO::Elf_GnuHash; \ |
| 94 | using Elf_Sym_Range = typename ELFO::Elf_Sym_Range; \ |
| 95 | using Elf_Versym = typename ELFO::Elf_Versym; \ |
| 96 | using Elf_Verneed = typename ELFO::Elf_Verneed; \ |
| 97 | using Elf_Vernaux = typename ELFO::Elf_Vernaux; \ |
| 98 | using Elf_Verdef = typename ELFO::Elf_Verdef; \ |
| 99 | using Elf_Verdaux = typename ELFO::Elf_Verdaux; \ |
| 100 | using uintX_t = typename ELFO::uintX_t; |
Hemant Kulkarni | 206ba84 | 2016-03-09 19:16:13 +0000 | [diff] [blame] | 101 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 102 | namespace { |
| 103 | |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 104 | template <class ELFT> class DumpStyle; |
| 105 | |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 106 | /// Represents a contiguous uniform range in the file. We cannot just create a |
| 107 | /// range directly because when creating one of these from the .dynamic table |
| 108 | /// the size, entity size and virtual address are different entries in arbitrary |
| 109 | /// order (DT_REL, DT_RELSZ, DT_RELENT for example). |
Rafael Espindola | 65a6fd8 | 2016-02-16 14:27:33 +0000 | [diff] [blame] | 110 | struct DynRegionInfo { |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 111 | DynRegionInfo() = default; |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 112 | DynRegionInfo(const void *A, uint64_t S, uint64_t ES) |
| 113 | : Addr(A), Size(S), EntSize(ES) {} |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 114 | |
Rafael Espindola | 65a6fd8 | 2016-02-16 14:27:33 +0000 | [diff] [blame] | 115 | /// \brief Address in current address space. |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 116 | const void *Addr = nullptr; |
Rafael Espindola | 65a6fd8 | 2016-02-16 14:27:33 +0000 | [diff] [blame] | 117 | /// \brief Size in bytes of the region. |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 118 | uint64_t Size = 0; |
Rafael Espindola | 65a6fd8 | 2016-02-16 14:27:33 +0000 | [diff] [blame] | 119 | /// \brief Size of each entity in the region. |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 120 | uint64_t EntSize = 0; |
Rafael Espindola | c70aeda | 2016-02-16 14:50:39 +0000 | [diff] [blame] | 121 | |
Rafael Espindola | aafcf75 | 2016-04-05 14:47:22 +0000 | [diff] [blame] | 122 | template <typename Type> ArrayRef<Type> getAsArrayRef() const { |
Rafael Espindola | c70aeda | 2016-02-16 14:50:39 +0000 | [diff] [blame] | 123 | const Type *Start = reinterpret_cast<const Type *>(Addr); |
Rafael Espindola | 944f655 | 2016-02-16 15:16:00 +0000 | [diff] [blame] | 124 | if (!Start) |
| 125 | return {Start, Start}; |
Rafael Espindola | c70aeda | 2016-02-16 14:50:39 +0000 | [diff] [blame] | 126 | if (EntSize != sizeof(Type) || Size % EntSize) |
| 127 | reportError("Invalid entity size"); |
| 128 | return {Start, Start + (Size / EntSize)}; |
| 129 | } |
Rafael Espindola | 65a6fd8 | 2016-02-16 14:27:33 +0000 | [diff] [blame] | 130 | }; |
| 131 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 132 | template<typename ELFT> |
| 133 | class ELFDumper : public ObjDumper { |
| 134 | public: |
Zachary Turner | 88bb163 | 2016-05-03 00:28:04 +0000 | [diff] [blame] | 135 | ELFDumper(const ELFFile<ELFT> *Obj, ScopedPrinter &Writer); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 136 | |
| 137 | void printFileHeaders() override; |
| 138 | void printSections() override; |
| 139 | void printRelocations() override; |
| 140 | void printDynamicRelocations() override; |
| 141 | void printSymbols() override; |
| 142 | void printDynamicSymbols() override; |
| 143 | void printUnwindInfo() override; |
| 144 | |
| 145 | void printDynamicTable() override; |
| 146 | void printNeededLibraries() override; |
| 147 | void printProgramHeaders() override; |
| 148 | void printHashTable() override; |
| 149 | void printGnuHashTable() override; |
| 150 | void printLoadName() override; |
| 151 | void printVersionInfo() override; |
Hemant Kulkarni | ab4a46f | 2016-01-26 19:46:39 +0000 | [diff] [blame] | 152 | void printGroupSections() override; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 153 | |
| 154 | void printAttributes() override; |
| 155 | void printMipsPLTGOT() override; |
| 156 | void printMipsABIFlags() override; |
| 157 | void printMipsReginfo() override; |
Simon Atanasyan | 8a71b53 | 2016-05-04 05:58:57 +0000 | [diff] [blame] | 158 | void printMipsOptions() override; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 159 | |
| 160 | void printStackMap() const override; |
| 161 | |
Hemant Kulkarni | 9b1b7f0 | 2016-04-11 17:15:30 +0000 | [diff] [blame] | 162 | void printHashHistogram() override; |
| 163 | |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 164 | void printNotes() override; |
| 165 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 166 | private: |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 167 | std::unique_ptr<DumpStyle<ELFT>> ELFDumperStyle; |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 168 | |
Rafael Espindola | 6bc2990 | 2016-10-06 14:07:26 +0000 | [diff] [blame] | 169 | TYPEDEF_ELF_TYPES(ELFT) |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 170 | |
Rafael Espindola | e17c3f3 | 2016-02-17 16:48:00 +0000 | [diff] [blame] | 171 | DynRegionInfo checkDRI(DynRegionInfo DRI) { |
| 172 | if (DRI.Addr < Obj->base() || |
| 173 | (const uint8_t *)DRI.Addr + DRI.Size > Obj->base() + Obj->getBufSize()) |
| 174 | error(llvm::object::object_error::parse_failed); |
| 175 | return DRI; |
| 176 | } |
| 177 | |
| 178 | DynRegionInfo createDRIFrom(const Elf_Phdr *P, uintX_t EntSize) { |
| 179 | return checkDRI({Obj->base() + P->p_offset, P->p_filesz, EntSize}); |
| 180 | } |
| 181 | |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 182 | DynRegionInfo createDRIFrom(const Elf_Shdr *S) { |
Rafael Espindola | e17c3f3 | 2016-02-17 16:48:00 +0000 | [diff] [blame] | 183 | return checkDRI({Obj->base() + S->sh_offset, S->sh_size, S->sh_entsize}); |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Michael J. Spencer | 60d82b2 | 2016-02-11 04:59:37 +0000 | [diff] [blame] | 186 | void parseDynamicTable(ArrayRef<const Elf_Phdr *> LoadSegments); |
| 187 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 188 | void printValue(uint64_t Type, uint64_t Value); |
| 189 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 190 | StringRef getDynamicString(uint64_t Offset) const; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 191 | StringRef getSymbolVersion(StringRef StrTab, const Elf_Sym *symb, |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 192 | bool &IsDefault) const; |
| 193 | void LoadVersionMap() const; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 194 | void LoadVersionNeeds(const Elf_Shdr *ec) const; |
| 195 | void LoadVersionDefs(const Elf_Shdr *sec) const; |
| 196 | |
| 197 | const ELFO *Obj; |
Simon Atanasyan | 72155c3 | 2016-01-16 22:40:09 +0000 | [diff] [blame] | 198 | DynRegionInfo DynRelRegion; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 199 | DynRegionInfo DynRelaRegion; |
Rafael Espindola | 944f655 | 2016-02-16 15:16:00 +0000 | [diff] [blame] | 200 | DynRegionInfo DynPLTRelRegion; |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 201 | DynRegionInfo DynSymRegion; |
Rafael Espindola | e17c3f3 | 2016-02-17 16:48:00 +0000 | [diff] [blame] | 202 | DynRegionInfo DynamicTable; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 203 | StringRef DynamicStringTable; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 204 | StringRef SOName; |
| 205 | const Elf_Hash *HashTable = nullptr; |
| 206 | const Elf_GnuHash *GnuHashTable = nullptr; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 207 | const Elf_Shdr *DotSymtabSec = nullptr; |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 208 | StringRef DynSymtabName; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 209 | ArrayRef<Elf_Word> ShndxTable; |
| 210 | |
| 211 | const Elf_Shdr *dot_gnu_version_sec = nullptr; // .gnu.version |
| 212 | const Elf_Shdr *dot_gnu_version_r_sec = nullptr; // .gnu.version_r |
| 213 | const Elf_Shdr *dot_gnu_version_d_sec = nullptr; // .gnu.version_d |
| 214 | |
| 215 | // Records for each version index the corresponding Verdef or Vernaux entry. |
| 216 | // This is filled the first time LoadVersionMap() is called. |
| 217 | class VersionMapEntry : public PointerIntPair<const void *, 1> { |
| 218 | public: |
| 219 | // If the integer is 0, this is an Elf_Verdef*. |
| 220 | // If the integer is 1, this is an Elf_Vernaux*. |
| 221 | VersionMapEntry() : PointerIntPair<const void *, 1>(nullptr, 0) {} |
| 222 | VersionMapEntry(const Elf_Verdef *verdef) |
| 223 | : PointerIntPair<const void *, 1>(verdef, 0) {} |
| 224 | VersionMapEntry(const Elf_Vernaux *vernaux) |
| 225 | : PointerIntPair<const void *, 1>(vernaux, 1) {} |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 226 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 227 | bool isNull() const { return getPointer() == nullptr; } |
| 228 | bool isVerdef() const { return !isNull() && getInt() == 0; } |
| 229 | bool isVernaux() const { return !isNull() && getInt() == 1; } |
| 230 | const Elf_Verdef *getVerdef() const { |
| 231 | return isVerdef() ? (const Elf_Verdef *)getPointer() : nullptr; |
| 232 | } |
| 233 | const Elf_Vernaux *getVernaux() const { |
| 234 | return isVernaux() ? (const Elf_Vernaux *)getPointer() : nullptr; |
| 235 | } |
| 236 | }; |
| 237 | mutable SmallVector<VersionMapEntry, 16> VersionMap; |
| 238 | |
| 239 | public: |
| 240 | Elf_Dyn_Range dynamic_table() const { |
Rafael Espindola | aafcf75 | 2016-04-05 14:47:22 +0000 | [diff] [blame] | 241 | return DynamicTable.getAsArrayRef<Elf_Dyn>(); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 244 | Elf_Sym_Range dynamic_symbols() const { |
Rafael Espindola | aafcf75 | 2016-04-05 14:47:22 +0000 | [diff] [blame] | 245 | return DynSymRegion.getAsArrayRef<Elf_Sym>(); |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 246 | } |
| 247 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 248 | Elf_Rel_Range dyn_rels() const; |
| 249 | Elf_Rela_Range dyn_relas() const; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 250 | std::string getFullSymbolName(const Elf_Sym *Symbol, StringRef StrTable, |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 251 | bool IsDynamic) const; |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 252 | |
| 253 | void printSymbolsHelper(bool IsDynamic) const; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 254 | const Elf_Shdr *getDotSymtabSec() const { return DotSymtabSec; } |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 255 | ArrayRef<Elf_Word> getShndxTable() const { return ShndxTable; } |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 256 | StringRef getDynamicStringTable() const { return DynamicStringTable; } |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 257 | const DynRegionInfo &getDynRelRegion() const { return DynRelRegion; } |
| 258 | const DynRegionInfo &getDynRelaRegion() const { return DynRelaRegion; } |
| 259 | const DynRegionInfo &getDynPLTRelRegion() const { return DynPLTRelRegion; } |
Hemant Kulkarni | 9b1b7f0 | 2016-04-11 17:15:30 +0000 | [diff] [blame] | 260 | const Elf_Hash *getHashTable() const { return HashTable; } |
| 261 | const Elf_GnuHash *getGnuHashTable() const { return GnuHashTable; } |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 262 | }; |
| 263 | |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 264 | template <class ELFT> |
| 265 | void ELFDumper<ELFT>::printSymbolsHelper(bool IsDynamic) const { |
| 266 | StringRef StrTable, SymtabName; |
| 267 | size_t Entries = 0; |
| 268 | Elf_Sym_Range Syms(nullptr, nullptr); |
| 269 | if (IsDynamic) { |
| 270 | StrTable = DynamicStringTable; |
| 271 | Syms = dynamic_symbols(); |
| 272 | SymtabName = DynSymtabName; |
| 273 | if (DynSymRegion.Addr) |
| 274 | Entries = DynSymRegion.Size / DynSymRegion.EntSize; |
| 275 | } else { |
| 276 | if (!DotSymtabSec) |
| 277 | return; |
| 278 | StrTable = unwrapOrError(Obj->getStringTableForSymtab(*DotSymtabSec)); |
Rafael Espindola | 9ea6834 | 2016-11-03 13:43:30 +0000 | [diff] [blame] | 279 | Syms = unwrapOrError(Obj->symbols(DotSymtabSec)); |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 280 | SymtabName = unwrapOrError(Obj->getSectionName(DotSymtabSec)); |
| 281 | Entries = DotSymtabSec->getEntityCount(); |
| 282 | } |
| 283 | if (Syms.begin() == Syms.end()) |
| 284 | return; |
| 285 | ELFDumperStyle->printSymtabMessage(Obj, SymtabName, Entries); |
| 286 | for (const auto &Sym : Syms) |
| 287 | ELFDumperStyle->printSymbol(Obj, &Sym, Syms.begin(), StrTable, IsDynamic); |
| 288 | } |
| 289 | |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 290 | template <typename ELFT> class DumpStyle { |
| 291 | public: |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 292 | using Elf_Shdr = typename ELFFile<ELFT>::Elf_Shdr; |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 293 | using Elf_Sym = typename ELFFile<ELFT>::Elf_Sym; |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 294 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 295 | DumpStyle(ELFDumper<ELFT> *Dumper) : Dumper(Dumper) {} |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 296 | virtual ~DumpStyle() = default; |
| 297 | |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 298 | virtual void printFileHeaders(const ELFFile<ELFT> *Obj) = 0; |
Hemant Kulkarni | 206ba84 | 2016-03-09 19:16:13 +0000 | [diff] [blame] | 299 | virtual void printGroupSections(const ELFFile<ELFT> *Obj) = 0; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 300 | virtual void printRelocations(const ELFFile<ELFT> *Obj) = 0; |
| 301 | virtual void printSections(const ELFFile<ELFT> *Obj) = 0; |
| 302 | virtual void printSymbols(const ELFFile<ELFT> *Obj) = 0; |
| 303 | virtual void printDynamicSymbols(const ELFFile<ELFT> *Obj) = 0; |
| 304 | virtual void printDynamicRelocations(const ELFFile<ELFT> *Obj) = 0; |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 305 | virtual void printSymtabMessage(const ELFFile<ELFT> *obj, StringRef Name, |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 306 | size_t Offset) {} |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 307 | virtual void printSymbol(const ELFFile<ELFT> *Obj, const Elf_Sym *Symbol, |
| 308 | const Elf_Sym *FirstSym, StringRef StrTable, |
| 309 | bool IsDynamic) = 0; |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 310 | virtual void printProgramHeaders(const ELFFile<ELFT> *Obj) = 0; |
Hemant Kulkarni | 9b1b7f0 | 2016-04-11 17:15:30 +0000 | [diff] [blame] | 311 | virtual void printHashHistogram(const ELFFile<ELFT> *Obj) = 0; |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 312 | virtual void printNotes(const ELFFile<ELFT> *Obj) = 0; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 313 | const ELFDumper<ELFT> *dumper() const { return Dumper; } |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 314 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 315 | private: |
| 316 | const ELFDumper<ELFT> *Dumper; |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 317 | }; |
| 318 | |
| 319 | template <typename ELFT> class GNUStyle : public DumpStyle<ELFT> { |
| 320 | formatted_raw_ostream OS; |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 321 | |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 322 | public: |
Hemant Kulkarni | 206ba84 | 2016-03-09 19:16:13 +0000 | [diff] [blame] | 323 | TYPEDEF_ELF_TYPES(ELFT) |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 324 | |
Zachary Turner | 88bb163 | 2016-05-03 00:28:04 +0000 | [diff] [blame] | 325 | GNUStyle(ScopedPrinter &W, ELFDumper<ELFT> *Dumper) |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 326 | : DumpStyle<ELFT>(Dumper), OS(W.getOStream()) {} |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 327 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 328 | void printFileHeaders(const ELFO *Obj) override; |
Hemant Kulkarni | 206ba84 | 2016-03-09 19:16:13 +0000 | [diff] [blame] | 329 | void printGroupSections(const ELFFile<ELFT> *Obj) override; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 330 | void printRelocations(const ELFO *Obj) override; |
| 331 | void printSections(const ELFO *Obj) override; |
| 332 | void printSymbols(const ELFO *Obj) override; |
| 333 | void printDynamicSymbols(const ELFO *Obj) override; |
| 334 | void printDynamicRelocations(const ELFO *Obj) override; |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 335 | void printSymtabMessage(const ELFO *Obj, StringRef Name, |
| 336 | size_t Offset) override; |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 337 | void printProgramHeaders(const ELFO *Obj) override; |
Hemant Kulkarni | 9b1b7f0 | 2016-04-11 17:15:30 +0000 | [diff] [blame] | 338 | void printHashHistogram(const ELFFile<ELFT> *Obj) override; |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 339 | void printNotes(const ELFFile<ELFT> *Obj) override; |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 340 | |
| 341 | private: |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 342 | struct Field { |
| 343 | StringRef Str; |
| 344 | unsigned Column; |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 345 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 346 | Field(StringRef S, unsigned Col) : Str(S), Column(Col) {} |
| 347 | Field(unsigned Col) : Str(""), Column(Col) {} |
| 348 | }; |
| 349 | |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 350 | template <typename T, typename TEnum> |
| 351 | std::string printEnum(T Value, ArrayRef<EnumEntry<TEnum>> EnumValues) { |
| 352 | for (const auto &EnumItem : EnumValues) |
| 353 | if (EnumItem.Value == Value) |
| 354 | return EnumItem.AltName; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 355 | return to_hexString(Value, false); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 356 | } |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 357 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 358 | formatted_raw_ostream &printField(struct Field F) { |
| 359 | if (F.Column != 0) |
| 360 | OS.PadToColumn(F.Column); |
| 361 | OS << F.Str; |
| 362 | OS.flush(); |
| 363 | return OS; |
| 364 | } |
Hemant Kulkarni | a6ee9fd | 2016-11-23 18:04:23 +0000 | [diff] [blame] | 365 | void printHashedSymbol(const ELFO *Obj, const Elf_Sym *FirstSym, uint32_t Sym, |
| 366 | StringRef StrTable, uint32_t Bucket); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 367 | void printRelocation(const ELFO *Obj, const Elf_Shdr *SymTab, |
| 368 | const Elf_Rela &R, bool IsRela); |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 369 | void printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, const Elf_Sym *First, |
| 370 | StringRef StrTable, bool IsDynamic) override; |
| 371 | std::string getSymbolSectionNdx(const ELFO *Obj, const Elf_Sym *Symbol, |
| 372 | const Elf_Sym *FirstSym); |
Hemant Kulkarni | a79c798 | 2016-03-29 02:41:49 +0000 | [diff] [blame] | 373 | void printDynamicRelocation(const ELFO *Obj, Elf_Rela R, bool IsRela); |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 374 | bool checkTLSSections(const Elf_Phdr &Phdr, const Elf_Shdr &Sec); |
| 375 | bool checkoffsets(const Elf_Phdr &Phdr, const Elf_Shdr &Sec); |
| 376 | bool checkVMA(const Elf_Phdr &Phdr, const Elf_Shdr &Sec); |
| 377 | bool checkPTDynamic(const Elf_Phdr &Phdr, const Elf_Shdr &Sec); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 378 | }; |
| 379 | |
| 380 | template <typename ELFT> class LLVMStyle : public DumpStyle<ELFT> { |
| 381 | public: |
Hemant Kulkarni | 206ba84 | 2016-03-09 19:16:13 +0000 | [diff] [blame] | 382 | TYPEDEF_ELF_TYPES(ELFT) |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 383 | |
Zachary Turner | 88bb163 | 2016-05-03 00:28:04 +0000 | [diff] [blame] | 384 | LLVMStyle(ScopedPrinter &W, ELFDumper<ELFT> *Dumper) |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 385 | : DumpStyle<ELFT>(Dumper), W(W) {} |
| 386 | |
| 387 | void printFileHeaders(const ELFO *Obj) override; |
Hemant Kulkarni | 206ba84 | 2016-03-09 19:16:13 +0000 | [diff] [blame] | 388 | void printGroupSections(const ELFFile<ELFT> *Obj) override; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 389 | void printRelocations(const ELFO *Obj) override; |
| 390 | void printRelocations(const Elf_Shdr *Sec, const ELFO *Obj); |
| 391 | void printSections(const ELFO *Obj) override; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 392 | void printSymbols(const ELFO *Obj) override; |
| 393 | void printDynamicSymbols(const ELFO *Obj) override; |
| 394 | void printDynamicRelocations(const ELFO *Obj) override; |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 395 | void printProgramHeaders(const ELFO *Obj) override; |
Hemant Kulkarni | 9b1b7f0 | 2016-04-11 17:15:30 +0000 | [diff] [blame] | 396 | void printHashHistogram(const ELFFile<ELFT> *Obj) override; |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 397 | void printNotes(const ELFFile<ELFT> *Obj) override; |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 398 | |
| 399 | private: |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 400 | void printRelocation(const ELFO *Obj, Elf_Rela Rel, const Elf_Shdr *SymTab); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 401 | void printDynamicRelocation(const ELFO *Obj, Elf_Rela Rel); |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 402 | void printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, const Elf_Sym *First, |
| 403 | StringRef StrTable, bool IsDynamic) override; |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 404 | |
Zachary Turner | 88bb163 | 2016-05-03 00:28:04 +0000 | [diff] [blame] | 405 | ScopedPrinter &W; |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 406 | }; |
| 407 | |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 408 | } // end anonymous namespace |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 409 | |
| 410 | namespace llvm { |
| 411 | |
| 412 | template <class ELFT> |
| 413 | static std::error_code createELFDumper(const ELFFile<ELFT> *Obj, |
Zachary Turner | 88bb163 | 2016-05-03 00:28:04 +0000 | [diff] [blame] | 414 | ScopedPrinter &Writer, |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 415 | std::unique_ptr<ObjDumper> &Result) { |
| 416 | Result.reset(new ELFDumper<ELFT>(Obj, Writer)); |
| 417 | return readobj_error::success; |
| 418 | } |
| 419 | |
| 420 | std::error_code createELFDumper(const object::ObjectFile *Obj, |
Zachary Turner | 88bb163 | 2016-05-03 00:28:04 +0000 | [diff] [blame] | 421 | ScopedPrinter &Writer, |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 422 | std::unique_ptr<ObjDumper> &Result) { |
| 423 | // Little-endian 32-bit |
| 424 | if (const ELF32LEObjectFile *ELFObj = dyn_cast<ELF32LEObjectFile>(Obj)) |
| 425 | return createELFDumper(ELFObj->getELFFile(), Writer, Result); |
| 426 | |
| 427 | // Big-endian 32-bit |
| 428 | if (const ELF32BEObjectFile *ELFObj = dyn_cast<ELF32BEObjectFile>(Obj)) |
| 429 | return createELFDumper(ELFObj->getELFFile(), Writer, Result); |
| 430 | |
| 431 | // Little-endian 64-bit |
| 432 | if (const ELF64LEObjectFile *ELFObj = dyn_cast<ELF64LEObjectFile>(Obj)) |
| 433 | return createELFDumper(ELFObj->getELFFile(), Writer, Result); |
| 434 | |
| 435 | // Big-endian 64-bit |
| 436 | if (const ELF64BEObjectFile *ELFObj = dyn_cast<ELF64BEObjectFile>(Obj)) |
| 437 | return createELFDumper(ELFObj->getELFFile(), Writer, Result); |
| 438 | |
| 439 | return readobj_error::unsupported_obj_file_format; |
| 440 | } |
| 441 | |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 442 | } // end namespace llvm |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 443 | |
| 444 | // Iterate through the versions needed section, and place each Elf_Vernaux |
| 445 | // in the VersionMap according to its index. |
| 446 | template <class ELFT> |
| 447 | void ELFDumper<ELFT>::LoadVersionNeeds(const Elf_Shdr *sec) const { |
| 448 | unsigned vn_size = sec->sh_size; // Size of section in bytes |
| 449 | unsigned vn_count = sec->sh_info; // Number of Verneed entries |
| 450 | const char *sec_start = (const char *)Obj->base() + sec->sh_offset; |
| 451 | const char *sec_end = sec_start + vn_size; |
| 452 | // The first Verneed entry is at the start of the section. |
| 453 | const char *p = sec_start; |
| 454 | for (unsigned i = 0; i < vn_count; i++) { |
| 455 | if (p + sizeof(Elf_Verneed) > sec_end) |
| 456 | report_fatal_error("Section ended unexpectedly while scanning " |
| 457 | "version needed records."); |
| 458 | const Elf_Verneed *vn = reinterpret_cast<const Elf_Verneed *>(p); |
| 459 | if (vn->vn_version != ELF::VER_NEED_CURRENT) |
| 460 | report_fatal_error("Unexpected verneed version"); |
| 461 | // Iterate through the Vernaux entries |
| 462 | const char *paux = p + vn->vn_aux; |
| 463 | for (unsigned j = 0; j < vn->vn_cnt; j++) { |
| 464 | if (paux + sizeof(Elf_Vernaux) > sec_end) |
| 465 | report_fatal_error("Section ended unexpected while scanning auxiliary " |
| 466 | "version needed records."); |
| 467 | const Elf_Vernaux *vna = reinterpret_cast<const Elf_Vernaux *>(paux); |
| 468 | size_t index = vna->vna_other & ELF::VERSYM_VERSION; |
| 469 | if (index >= VersionMap.size()) |
| 470 | VersionMap.resize(index + 1); |
| 471 | VersionMap[index] = VersionMapEntry(vna); |
| 472 | paux += vna->vna_next; |
| 473 | } |
| 474 | p += vn->vn_next; |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | // Iterate through the version definitions, and place each Elf_Verdef |
| 479 | // in the VersionMap according to its index. |
| 480 | template <class ELFT> |
| 481 | void ELFDumper<ELFT>::LoadVersionDefs(const Elf_Shdr *sec) const { |
| 482 | unsigned vd_size = sec->sh_size; // Size of section in bytes |
| 483 | unsigned vd_count = sec->sh_info; // Number of Verdef entries |
| 484 | const char *sec_start = (const char *)Obj->base() + sec->sh_offset; |
| 485 | const char *sec_end = sec_start + vd_size; |
| 486 | // The first Verdef entry is at the start of the section. |
| 487 | const char *p = sec_start; |
| 488 | for (unsigned i = 0; i < vd_count; i++) { |
| 489 | if (p + sizeof(Elf_Verdef) > sec_end) |
| 490 | report_fatal_error("Section ended unexpectedly while scanning " |
| 491 | "version definitions."); |
| 492 | const Elf_Verdef *vd = reinterpret_cast<const Elf_Verdef *>(p); |
| 493 | if (vd->vd_version != ELF::VER_DEF_CURRENT) |
| 494 | report_fatal_error("Unexpected verdef version"); |
| 495 | size_t index = vd->vd_ndx & ELF::VERSYM_VERSION; |
| 496 | if (index >= VersionMap.size()) |
| 497 | VersionMap.resize(index + 1); |
| 498 | VersionMap[index] = VersionMapEntry(vd); |
| 499 | p += vd->vd_next; |
| 500 | } |
| 501 | } |
| 502 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 503 | template <class ELFT> void ELFDumper<ELFT>::LoadVersionMap() const { |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 504 | // If there is no dynamic symtab or version table, there is nothing to do. |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 505 | if (!DynSymRegion.Addr || !dot_gnu_version_sec) |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 506 | return; |
| 507 | |
| 508 | // Has the VersionMap already been loaded? |
| 509 | if (VersionMap.size() > 0) |
| 510 | return; |
| 511 | |
| 512 | // The first two version indexes are reserved. |
| 513 | // Index 0 is LOCAL, index 1 is GLOBAL. |
| 514 | VersionMap.push_back(VersionMapEntry()); |
| 515 | VersionMap.push_back(VersionMapEntry()); |
| 516 | |
| 517 | if (dot_gnu_version_d_sec) |
| 518 | LoadVersionDefs(dot_gnu_version_d_sec); |
| 519 | |
| 520 | if (dot_gnu_version_r_sec) |
| 521 | LoadVersionNeeds(dot_gnu_version_r_sec); |
| 522 | } |
| 523 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 524 | template <typename ELFO, class ELFT> |
Zachary Turner | 88bb163 | 2016-05-03 00:28:04 +0000 | [diff] [blame] | 525 | static void printVersionSymbolSection(ELFDumper<ELFT> *Dumper, const ELFO *Obj, |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 526 | const typename ELFO::Elf_Shdr *Sec, |
Zachary Turner | 88bb163 | 2016-05-03 00:28:04 +0000 | [diff] [blame] | 527 | ScopedPrinter &W) { |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 528 | DictScope SS(W, "Version symbols"); |
| 529 | if (!Sec) |
| 530 | return; |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 531 | StringRef Name = unwrapOrError(Obj->getSectionName(Sec)); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 532 | W.printNumber("Section Name", Name, Sec->sh_name); |
| 533 | W.printHex("Address", Sec->sh_addr); |
| 534 | W.printHex("Offset", Sec->sh_offset); |
| 535 | W.printNumber("Link", Sec->sh_link); |
| 536 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 537 | const uint8_t *P = (const uint8_t *)Obj->base() + Sec->sh_offset; |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 538 | StringRef StrTable = Dumper->getDynamicStringTable(); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 539 | |
| 540 | // Same number of entries in the dynamic symbol table (DT_SYMTAB). |
| 541 | ListScope Syms(W, "Symbols"); |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 542 | for (const typename ELFO::Elf_Sym &Sym : Dumper->dynamic_symbols()) { |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 543 | DictScope S(W, "Symbol"); |
| 544 | std::string FullSymbolName = |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 545 | Dumper->getFullSymbolName(&Sym, StrTable, true /* IsDynamic */); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 546 | W.printNumber("Version", *P); |
| 547 | W.printString("Name", FullSymbolName); |
| 548 | P += sizeof(typename ELFO::Elf_Half); |
| 549 | } |
| 550 | } |
| 551 | |
George Rimar | cd36e18 | 2016-06-07 11:04:49 +0000 | [diff] [blame] | 552 | static const EnumEntry<unsigned> SymVersionFlags[] = { |
| 553 | {"Base", "BASE", VER_FLG_BASE}, |
| 554 | {"Weak", "WEAK", VER_FLG_WEAK}, |
| 555 | {"Info", "INFO", VER_FLG_INFO}}; |
| 556 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 557 | template <typename ELFO, class ELFT> |
| 558 | static void printVersionDefinitionSection(ELFDumper<ELFT> *Dumper, |
| 559 | const ELFO *Obj, |
| 560 | const typename ELFO::Elf_Shdr *Sec, |
Zachary Turner | 88bb163 | 2016-05-03 00:28:04 +0000 | [diff] [blame] | 561 | ScopedPrinter &W) { |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 562 | using VerDef = typename ELFO::Elf_Verdef; |
| 563 | using VerdAux = typename ELFO::Elf_Verdaux; |
George Rimar | ff8b539 | 2016-06-22 13:43:38 +0000 | [diff] [blame] | 564 | |
| 565 | DictScope SD(W, "SHT_GNU_verdef"); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 566 | if (!Sec) |
| 567 | return; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 568 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 569 | // The number of entries in the section SHT_GNU_verdef |
| 570 | // is determined by DT_VERDEFNUM tag. |
George Rimar | ff8b539 | 2016-06-22 13:43:38 +0000 | [diff] [blame] | 571 | unsigned VerDefsNum = 0; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 572 | for (const typename ELFO::Elf_Dyn &Dyn : Dumper->dynamic_table()) { |
| 573 | if (Dyn.d_tag == DT_VERDEFNUM) |
George Rimar | ff8b539 | 2016-06-22 13:43:38 +0000 | [diff] [blame] | 574 | VerDefsNum = Dyn.d_un.d_val; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 575 | } |
| 576 | const uint8_t *SecStartAddress = |
| 577 | (const uint8_t *)Obj->base() + Sec->sh_offset; |
| 578 | const uint8_t *SecEndAddress = SecStartAddress + Sec->sh_size; |
| 579 | const uint8_t *P = SecStartAddress; |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 580 | const typename ELFO::Elf_Shdr *StrTab = |
| 581 | unwrapOrError(Obj->getSection(Sec->sh_link)); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 582 | |
George Rimar | ff8b539 | 2016-06-22 13:43:38 +0000 | [diff] [blame] | 583 | while (VerDefsNum--) { |
| 584 | if (P + sizeof(VerDef) > SecEndAddress) |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 585 | report_fatal_error("invalid offset in the section"); |
George Rimar | ff8b539 | 2016-06-22 13:43:38 +0000 | [diff] [blame] | 586 | |
| 587 | auto *VD = reinterpret_cast<const VerDef *>(P); |
| 588 | DictScope Def(W, "Definition"); |
| 589 | W.printNumber("Version", VD->vd_version); |
| 590 | W.printEnum("Flags", VD->vd_flags, makeArrayRef(SymVersionFlags)); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 591 | W.printNumber("Index", VD->vd_ndx); |
Davide Italiano | 22b3ad86 | 2016-05-02 02:30:18 +0000 | [diff] [blame] | 592 | W.printNumber("Hash", VD->vd_hash); |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 593 | W.printString("Name", |
| 594 | StringRef((const char *)(Obj->base() + StrTab->sh_offset + |
| 595 | VD->getAux()->vda_name))); |
George Rimar | ff8b539 | 2016-06-22 13:43:38 +0000 | [diff] [blame] | 596 | if (!VD->vd_cnt) |
| 597 | report_fatal_error("at least one definition string must exist"); |
| 598 | if (VD->vd_cnt > 2) |
| 599 | report_fatal_error("more than one predecessor is not expected"); |
| 600 | |
| 601 | if (VD->vd_cnt == 2) { |
| 602 | const uint8_t *PAux = P + VD->vd_aux + VD->getAux()->vda_next; |
| 603 | const VerdAux *Aux = reinterpret_cast<const VerdAux *>(PAux); |
| 604 | W.printString("Predecessor", |
| 605 | StringRef((const char *)(Obj->base() + StrTab->sh_offset + |
| 606 | Aux->vda_name))); |
| 607 | } |
| 608 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 609 | P += VD->vd_next; |
| 610 | } |
| 611 | } |
| 612 | |
George Rimar | cd36e18 | 2016-06-07 11:04:49 +0000 | [diff] [blame] | 613 | template <typename ELFO, class ELFT> |
| 614 | static void printVersionDependencySection(ELFDumper<ELFT> *Dumper, |
| 615 | const ELFO *Obj, |
| 616 | const typename ELFO::Elf_Shdr *Sec, |
| 617 | ScopedPrinter &W) { |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 618 | using VerNeed = typename ELFO::Elf_Verneed; |
| 619 | using VernAux = typename ELFO::Elf_Vernaux; |
George Rimar | cd36e18 | 2016-06-07 11:04:49 +0000 | [diff] [blame] | 620 | |
| 621 | DictScope SD(W, "SHT_GNU_verneed"); |
| 622 | if (!Sec) |
| 623 | return; |
| 624 | |
| 625 | unsigned VerNeedNum = 0; |
| 626 | for (const typename ELFO::Elf_Dyn &Dyn : Dumper->dynamic_table()) |
| 627 | if (Dyn.d_tag == DT_VERNEEDNUM) |
| 628 | VerNeedNum = Dyn.d_un.d_val; |
| 629 | |
| 630 | const uint8_t *SecData = (const uint8_t *)Obj->base() + Sec->sh_offset; |
| 631 | const typename ELFO::Elf_Shdr *StrTab = |
| 632 | unwrapOrError(Obj->getSection(Sec->sh_link)); |
| 633 | |
| 634 | const uint8_t *P = SecData; |
| 635 | for (unsigned I = 0; I < VerNeedNum; ++I) { |
| 636 | const VerNeed *Need = reinterpret_cast<const VerNeed *>(P); |
| 637 | DictScope Entry(W, "Dependency"); |
| 638 | W.printNumber("Version", Need->vn_version); |
| 639 | W.printNumber("Count", Need->vn_cnt); |
| 640 | W.printString("FileName", |
| 641 | StringRef((const char *)(Obj->base() + StrTab->sh_offset + |
| 642 | Need->vn_file))); |
| 643 | |
| 644 | const uint8_t *PAux = P + Need->vn_aux; |
| 645 | for (unsigned J = 0; J < Need->vn_cnt; ++J) { |
| 646 | const VernAux *Aux = reinterpret_cast<const VernAux *>(PAux); |
| 647 | DictScope Entry(W, "Entry"); |
| 648 | W.printNumber("Hash", Aux->vna_hash); |
| 649 | W.printEnum("Flags", Aux->vna_flags, makeArrayRef(SymVersionFlags)); |
| 650 | W.printNumber("Index", Aux->vna_other); |
| 651 | W.printString("Name", |
| 652 | StringRef((const char *)(Obj->base() + StrTab->sh_offset + |
| 653 | Aux->vna_name))); |
| 654 | PAux += Aux->vna_next; |
| 655 | } |
| 656 | P += Need->vn_next; |
| 657 | } |
| 658 | } |
| 659 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 660 | template <typename ELFT> void ELFDumper<ELFT>::printVersionInfo() { |
| 661 | // Dump version symbol section. |
| 662 | printVersionSymbolSection(this, Obj, dot_gnu_version_sec, W); |
| 663 | |
| 664 | // Dump version definition section. |
| 665 | printVersionDefinitionSection(this, Obj, dot_gnu_version_d_sec, W); |
George Rimar | cd36e18 | 2016-06-07 11:04:49 +0000 | [diff] [blame] | 666 | |
| 667 | // Dump version dependency section. |
| 668 | printVersionDependencySection(this, Obj, dot_gnu_version_r_sec, W); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | template <typename ELFT> |
| 672 | StringRef ELFDumper<ELFT>::getSymbolVersion(StringRef StrTab, |
| 673 | const Elf_Sym *symb, |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 674 | bool &IsDefault) const { |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 675 | // This is a dynamic symbol. Look in the GNU symbol version table. |
| 676 | if (!dot_gnu_version_sec) { |
| 677 | // No version table. |
| 678 | IsDefault = false; |
| 679 | return StringRef(""); |
| 680 | } |
| 681 | |
| 682 | // Determine the position in the symbol table of this entry. |
| 683 | size_t entry_index = (reinterpret_cast<uintptr_t>(symb) - |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 684 | reinterpret_cast<uintptr_t>(DynSymRegion.Addr)) / |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 685 | sizeof(Elf_Sym); |
| 686 | |
| 687 | // Get the corresponding version index entry |
Rafael Espindola | ed1395a | 2016-11-03 18:05:33 +0000 | [diff] [blame] | 688 | const Elf_Versym *vs = unwrapOrError( |
| 689 | Obj->template getEntry<Elf_Versym>(dot_gnu_version_sec, entry_index)); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 690 | size_t version_index = vs->vs_index & ELF::VERSYM_VERSION; |
| 691 | |
| 692 | // Special markers for unversioned symbols. |
| 693 | if (version_index == ELF::VER_NDX_LOCAL || |
| 694 | version_index == ELF::VER_NDX_GLOBAL) { |
| 695 | IsDefault = false; |
| 696 | return StringRef(""); |
| 697 | } |
| 698 | |
| 699 | // Lookup this symbol in the version table |
| 700 | LoadVersionMap(); |
| 701 | if (version_index >= VersionMap.size() || VersionMap[version_index].isNull()) |
| 702 | reportError("Invalid version entry"); |
| 703 | const VersionMapEntry &entry = VersionMap[version_index]; |
| 704 | |
| 705 | // Get the version name string |
| 706 | size_t name_offset; |
| 707 | if (entry.isVerdef()) { |
| 708 | // The first Verdaux entry holds the name. |
| 709 | name_offset = entry.getVerdef()->getAux()->vda_name; |
| 710 | IsDefault = !(vs->vs_index & ELF::VERSYM_HIDDEN); |
| 711 | } else { |
| 712 | name_offset = entry.getVernaux()->vna_name; |
| 713 | IsDefault = false; |
| 714 | } |
| 715 | if (name_offset >= StrTab.size()) |
| 716 | reportError("Invalid string offset"); |
| 717 | return StringRef(StrTab.data() + name_offset); |
| 718 | } |
| 719 | |
| 720 | template <typename ELFT> |
| 721 | std::string ELFDumper<ELFT>::getFullSymbolName(const Elf_Sym *Symbol, |
| 722 | StringRef StrTable, |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 723 | bool IsDynamic) const { |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 724 | StringRef SymbolName = unwrapOrError(Symbol->getName(StrTable)); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 725 | if (!IsDynamic) |
| 726 | return SymbolName; |
| 727 | |
| 728 | std::string FullSymbolName(SymbolName); |
| 729 | |
| 730 | bool IsDefault; |
| 731 | StringRef Version = getSymbolVersion(StrTable, &*Symbol, IsDefault); |
| 732 | FullSymbolName += (IsDefault ? "@@" : "@"); |
| 733 | FullSymbolName += Version; |
| 734 | return FullSymbolName; |
| 735 | } |
| 736 | |
Rafael Espindola | 714c295 | 2016-11-03 14:41:17 +0000 | [diff] [blame] | 737 | template <typename ELFT> |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 738 | static void |
Rafael Espindola | 714c295 | 2016-11-03 14:41:17 +0000 | [diff] [blame] | 739 | getSectionNameIndex(const ELFFile<ELFT> &Obj, const typename ELFT::Sym *Symbol, |
| 740 | const typename ELFT::Sym *FirstSym, |
| 741 | ArrayRef<typename ELFT::Word> ShndxTable, |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 742 | StringRef &SectionName, unsigned &SectionIndex) { |
| 743 | SectionIndex = Symbol->st_shndx; |
| 744 | if (Symbol->isUndefined()) |
| 745 | SectionName = "Undefined"; |
| 746 | else if (Symbol->isProcessorSpecific()) |
| 747 | SectionName = "Processor Specific"; |
| 748 | else if (Symbol->isOSSpecific()) |
| 749 | SectionName = "Operating System Specific"; |
| 750 | else if (Symbol->isAbsolute()) |
| 751 | SectionName = "Absolute"; |
| 752 | else if (Symbol->isCommon()) |
| 753 | SectionName = "Common"; |
| 754 | else if (Symbol->isReserved() && SectionIndex != SHN_XINDEX) |
| 755 | SectionName = "Reserved"; |
| 756 | else { |
| 757 | if (SectionIndex == SHN_XINDEX) |
Rafael Espindola | 714c295 | 2016-11-03 14:41:17 +0000 | [diff] [blame] | 758 | SectionIndex = unwrapOrError(object::getExtendedSymbolTableIndex<ELFT>( |
| 759 | Symbol, FirstSym, ShndxTable)); |
| 760 | const typename ELFT::Shdr *Sec = |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 761 | unwrapOrError(Obj.getSection(SectionIndex)); |
| 762 | SectionName = unwrapOrError(Obj.getSectionName(Sec)); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 763 | } |
| 764 | } |
| 765 | |
| 766 | template <class ELFO> |
Simon Atanasyan | cb1175c | 2016-02-09 18:45:35 +0000 | [diff] [blame] | 767 | static const typename ELFO::Elf_Shdr * |
| 768 | findNotEmptySectionByAddress(const ELFO *Obj, uint64_t Addr) { |
Rafael Espindola | 25be8c8 | 2016-11-02 14:10:57 +0000 | [diff] [blame] | 769 | for (const auto &Shdr : unwrapOrError(Obj->sections())) |
Simon Atanasyan | cb1175c | 2016-02-09 18:45:35 +0000 | [diff] [blame] | 770 | if (Shdr.sh_addr == Addr && Shdr.sh_size > 0) |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 771 | return &Shdr; |
| 772 | return nullptr; |
| 773 | } |
| 774 | |
| 775 | template <class ELFO> |
| 776 | static const typename ELFO::Elf_Shdr *findSectionByName(const ELFO &Obj, |
| 777 | StringRef Name) { |
Rafael Espindola | 25be8c8 | 2016-11-02 14:10:57 +0000 | [diff] [blame] | 778 | for (const auto &Shdr : unwrapOrError(Obj.sections())) { |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 779 | if (Name == unwrapOrError(Obj.getSectionName(&Shdr))) |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 780 | return &Shdr; |
| 781 | } |
| 782 | return nullptr; |
| 783 | } |
| 784 | |
| 785 | static const EnumEntry<unsigned> ElfClass[] = { |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 786 | {"None", "none", ELF::ELFCLASSNONE}, |
| 787 | {"32-bit", "ELF32", ELF::ELFCLASS32}, |
| 788 | {"64-bit", "ELF64", ELF::ELFCLASS64}, |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 789 | }; |
| 790 | |
| 791 | static const EnumEntry<unsigned> ElfDataEncoding[] = { |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 792 | {"None", "none", ELF::ELFDATANONE}, |
| 793 | {"LittleEndian", "2's complement, little endian", ELF::ELFDATA2LSB}, |
| 794 | {"BigEndian", "2's complement, big endian", ELF::ELFDATA2MSB}, |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 795 | }; |
| 796 | |
| 797 | static const EnumEntry<unsigned> ElfObjectFileType[] = { |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 798 | {"None", "NONE (none)", ELF::ET_NONE}, |
| 799 | {"Relocatable", "REL (Relocatable file)", ELF::ET_REL}, |
| 800 | {"Executable", "EXEC (Executable file)", ELF::ET_EXEC}, |
| 801 | {"SharedObject", "DYN (Shared object file)", ELF::ET_DYN}, |
| 802 | {"Core", "CORE (Core file)", ELF::ET_CORE}, |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 803 | }; |
| 804 | |
| 805 | static const EnumEntry<unsigned> ElfOSABI[] = { |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 806 | {"SystemV", "UNIX - System V", ELF::ELFOSABI_NONE}, |
| 807 | {"HPUX", "UNIX - HP-UX", ELF::ELFOSABI_HPUX}, |
| 808 | {"NetBSD", "UNIX - NetBSD", ELF::ELFOSABI_NETBSD}, |
| 809 | {"GNU/Linux", "UNIX - GNU", ELF::ELFOSABI_LINUX}, |
| 810 | {"GNU/Hurd", "GNU/Hurd", ELF::ELFOSABI_HURD}, |
| 811 | {"Solaris", "UNIX - Solaris", ELF::ELFOSABI_SOLARIS}, |
| 812 | {"AIX", "UNIX - AIX", ELF::ELFOSABI_AIX}, |
| 813 | {"IRIX", "UNIX - IRIX", ELF::ELFOSABI_IRIX}, |
| 814 | {"FreeBSD", "UNIX - FreeBSD", ELF::ELFOSABI_FREEBSD}, |
| 815 | {"TRU64", "UNIX - TRU64", ELF::ELFOSABI_TRU64}, |
| 816 | {"Modesto", "Novell - Modesto", ELF::ELFOSABI_MODESTO}, |
| 817 | {"OpenBSD", "UNIX - OpenBSD", ELF::ELFOSABI_OPENBSD}, |
| 818 | {"OpenVMS", "VMS - OpenVMS", ELF::ELFOSABI_OPENVMS}, |
| 819 | {"NSK", "HP - Non-Stop Kernel", ELF::ELFOSABI_NSK}, |
| 820 | {"AROS", "AROS", ELF::ELFOSABI_AROS}, |
| 821 | {"FenixOS", "FenixOS", ELF::ELFOSABI_FENIXOS}, |
| 822 | {"CloudABI", "CloudABI", ELF::ELFOSABI_CLOUDABI}, |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 823 | {"Standalone", "Standalone App", ELF::ELFOSABI_STANDALONE} |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 824 | }; |
| 825 | |
Konstantin Zhuravlyov | 121125f | 2017-10-02 20:49:58 +0000 | [diff] [blame] | 826 | static const EnumEntry<unsigned> AMDGPUElfOSABI[] = { |
Konstantin Zhuravlyov | 0aa94d3 | 2017-10-03 21:14:14 +0000 | [diff] [blame] | 827 | {"AMDGPU_HSA", "AMDGPU - HSA", ELF::ELFOSABI_AMDGPU_HSA}, |
| 828 | {"AMDGPU_PAL", "AMDGPU - PAL", ELF::ELFOSABI_AMDGPU_PAL}, |
| 829 | {"AMDGPU_MESA3D", "AMDGPU - MESA3D", ELF::ELFOSABI_AMDGPU_MESA3D} |
Konstantin Zhuravlyov | 121125f | 2017-10-02 20:49:58 +0000 | [diff] [blame] | 830 | }; |
| 831 | |
| 832 | static const EnumEntry<unsigned> ARMElfOSABI[] = { |
| 833 | {"ARM", "ARM", ELF::ELFOSABI_ARM} |
| 834 | }; |
| 835 | |
| 836 | static const EnumEntry<unsigned> C6000ElfOSABI[] = { |
| 837 | {"C6000_ELFABI", "Bare-metal C6000", ELF::ELFOSABI_C6000_ELFABI}, |
| 838 | {"C6000_LINUX", "Linux C6000", ELF::ELFOSABI_C6000_LINUX} |
| 839 | }; |
| 840 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 841 | static const EnumEntry<unsigned> ElfMachineType[] = { |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 842 | ENUM_ENT(EM_NONE, "None"), |
| 843 | ENUM_ENT(EM_M32, "WE32100"), |
| 844 | ENUM_ENT(EM_SPARC, "Sparc"), |
| 845 | ENUM_ENT(EM_386, "Intel 80386"), |
| 846 | ENUM_ENT(EM_68K, "MC68000"), |
| 847 | ENUM_ENT(EM_88K, "MC88000"), |
| 848 | ENUM_ENT(EM_IAMCU, "EM_IAMCU"), |
| 849 | ENUM_ENT(EM_860, "Intel 80860"), |
| 850 | ENUM_ENT(EM_MIPS, "MIPS R3000"), |
| 851 | ENUM_ENT(EM_S370, "IBM System/370"), |
| 852 | ENUM_ENT(EM_MIPS_RS3_LE, "MIPS R3000 little-endian"), |
| 853 | ENUM_ENT(EM_PARISC, "HPPA"), |
| 854 | ENUM_ENT(EM_VPP500, "Fujitsu VPP500"), |
| 855 | ENUM_ENT(EM_SPARC32PLUS, "Sparc v8+"), |
| 856 | ENUM_ENT(EM_960, "Intel 80960"), |
| 857 | ENUM_ENT(EM_PPC, "PowerPC"), |
| 858 | ENUM_ENT(EM_PPC64, "PowerPC64"), |
| 859 | ENUM_ENT(EM_S390, "IBM S/390"), |
| 860 | ENUM_ENT(EM_SPU, "SPU"), |
| 861 | ENUM_ENT(EM_V800, "NEC V800 series"), |
| 862 | ENUM_ENT(EM_FR20, "Fujistsu FR20"), |
| 863 | ENUM_ENT(EM_RH32, "TRW RH-32"), |
| 864 | ENUM_ENT(EM_RCE, "Motorola RCE"), |
| 865 | ENUM_ENT(EM_ARM, "ARM"), |
| 866 | ENUM_ENT(EM_ALPHA, "EM_ALPHA"), |
| 867 | ENUM_ENT(EM_SH, "Hitachi SH"), |
| 868 | ENUM_ENT(EM_SPARCV9, "Sparc v9"), |
| 869 | ENUM_ENT(EM_TRICORE, "Siemens Tricore"), |
| 870 | ENUM_ENT(EM_ARC, "ARC"), |
| 871 | ENUM_ENT(EM_H8_300, "Hitachi H8/300"), |
| 872 | ENUM_ENT(EM_H8_300H, "Hitachi H8/300H"), |
| 873 | ENUM_ENT(EM_H8S, "Hitachi H8S"), |
| 874 | ENUM_ENT(EM_H8_500, "Hitachi H8/500"), |
| 875 | ENUM_ENT(EM_IA_64, "Intel IA-64"), |
| 876 | ENUM_ENT(EM_MIPS_X, "Stanford MIPS-X"), |
| 877 | ENUM_ENT(EM_COLDFIRE, "Motorola Coldfire"), |
| 878 | ENUM_ENT(EM_68HC12, "Motorola MC68HC12 Microcontroller"), |
| 879 | ENUM_ENT(EM_MMA, "Fujitsu Multimedia Accelerator"), |
| 880 | ENUM_ENT(EM_PCP, "Siemens PCP"), |
| 881 | ENUM_ENT(EM_NCPU, "Sony nCPU embedded RISC processor"), |
| 882 | ENUM_ENT(EM_NDR1, "Denso NDR1 microprocesspr"), |
| 883 | ENUM_ENT(EM_STARCORE, "Motorola Star*Core processor"), |
| 884 | ENUM_ENT(EM_ME16, "Toyota ME16 processor"), |
| 885 | ENUM_ENT(EM_ST100, "STMicroelectronics ST100 processor"), |
| 886 | ENUM_ENT(EM_TINYJ, "Advanced Logic Corp. TinyJ embedded processor"), |
| 887 | ENUM_ENT(EM_X86_64, "Advanced Micro Devices X86-64"), |
| 888 | ENUM_ENT(EM_PDSP, "Sony DSP processor"), |
| 889 | ENUM_ENT(EM_PDP10, "Digital Equipment Corp. PDP-10"), |
| 890 | ENUM_ENT(EM_PDP11, "Digital Equipment Corp. PDP-11"), |
| 891 | ENUM_ENT(EM_FX66, "Siemens FX66 microcontroller"), |
| 892 | ENUM_ENT(EM_ST9PLUS, "STMicroelectronics ST9+ 8/16 bit microcontroller"), |
| 893 | ENUM_ENT(EM_ST7, "STMicroelectronics ST7 8-bit microcontroller"), |
| 894 | ENUM_ENT(EM_68HC16, "Motorola MC68HC16 Microcontroller"), |
| 895 | ENUM_ENT(EM_68HC11, "Motorola MC68HC11 Microcontroller"), |
| 896 | ENUM_ENT(EM_68HC08, "Motorola MC68HC08 Microcontroller"), |
| 897 | ENUM_ENT(EM_68HC05, "Motorola MC68HC05 Microcontroller"), |
| 898 | ENUM_ENT(EM_SVX, "Silicon Graphics SVx"), |
| 899 | ENUM_ENT(EM_ST19, "STMicroelectronics ST19 8-bit microcontroller"), |
| 900 | ENUM_ENT(EM_VAX, "Digital VAX"), |
| 901 | ENUM_ENT(EM_CRIS, "Axis Communications 32-bit embedded processor"), |
| 902 | ENUM_ENT(EM_JAVELIN, "Infineon Technologies 32-bit embedded cpu"), |
| 903 | ENUM_ENT(EM_FIREPATH, "Element 14 64-bit DSP processor"), |
| 904 | ENUM_ENT(EM_ZSP, "LSI Logic's 16-bit DSP processor"), |
| 905 | ENUM_ENT(EM_MMIX, "Donald Knuth's educational 64-bit processor"), |
| 906 | ENUM_ENT(EM_HUANY, "Harvard Universitys's machine-independent object format"), |
| 907 | ENUM_ENT(EM_PRISM, "Vitesse Prism"), |
| 908 | ENUM_ENT(EM_AVR, "Atmel AVR 8-bit microcontroller"), |
| 909 | ENUM_ENT(EM_FR30, "Fujitsu FR30"), |
| 910 | ENUM_ENT(EM_D10V, "Mitsubishi D10V"), |
| 911 | ENUM_ENT(EM_D30V, "Mitsubishi D30V"), |
| 912 | ENUM_ENT(EM_V850, "NEC v850"), |
| 913 | ENUM_ENT(EM_M32R, "Renesas M32R (formerly Mitsubishi M32r)"), |
| 914 | ENUM_ENT(EM_MN10300, "Matsushita MN10300"), |
| 915 | ENUM_ENT(EM_MN10200, "Matsushita MN10200"), |
| 916 | ENUM_ENT(EM_PJ, "picoJava"), |
| 917 | ENUM_ENT(EM_OPENRISC, "OpenRISC 32-bit embedded processor"), |
| 918 | ENUM_ENT(EM_ARC_COMPACT, "EM_ARC_COMPACT"), |
| 919 | ENUM_ENT(EM_XTENSA, "Tensilica Xtensa Processor"), |
| 920 | ENUM_ENT(EM_VIDEOCORE, "Alphamosaic VideoCore processor"), |
| 921 | ENUM_ENT(EM_TMM_GPP, "Thompson Multimedia General Purpose Processor"), |
| 922 | ENUM_ENT(EM_NS32K, "National Semiconductor 32000 series"), |
| 923 | ENUM_ENT(EM_TPC, "Tenor Network TPC processor"), |
| 924 | ENUM_ENT(EM_SNP1K, "EM_SNP1K"), |
| 925 | ENUM_ENT(EM_ST200, "STMicroelectronics ST200 microcontroller"), |
| 926 | ENUM_ENT(EM_IP2K, "Ubicom IP2xxx 8-bit microcontrollers"), |
| 927 | ENUM_ENT(EM_MAX, "MAX Processor"), |
| 928 | ENUM_ENT(EM_CR, "National Semiconductor CompactRISC"), |
| 929 | ENUM_ENT(EM_F2MC16, "Fujitsu F2MC16"), |
| 930 | ENUM_ENT(EM_MSP430, "Texas Instruments msp430 microcontroller"), |
| 931 | ENUM_ENT(EM_BLACKFIN, "Analog Devices Blackfin"), |
| 932 | ENUM_ENT(EM_SE_C33, "S1C33 Family of Seiko Epson processors"), |
| 933 | ENUM_ENT(EM_SEP, "Sharp embedded microprocessor"), |
| 934 | ENUM_ENT(EM_ARCA, "Arca RISC microprocessor"), |
| 935 | ENUM_ENT(EM_UNICORE, "Unicore"), |
| 936 | ENUM_ENT(EM_EXCESS, "eXcess 16/32/64-bit configurable embedded CPU"), |
| 937 | ENUM_ENT(EM_DXP, "Icera Semiconductor Inc. Deep Execution Processor"), |
| 938 | ENUM_ENT(EM_ALTERA_NIOS2, "Altera Nios"), |
| 939 | ENUM_ENT(EM_CRX, "National Semiconductor CRX microprocessor"), |
| 940 | ENUM_ENT(EM_XGATE, "Motorola XGATE embedded processor"), |
| 941 | ENUM_ENT(EM_C166, "Infineon Technologies xc16x"), |
| 942 | ENUM_ENT(EM_M16C, "Renesas M16C"), |
| 943 | ENUM_ENT(EM_DSPIC30F, "Microchip Technology dsPIC30F Digital Signal Controller"), |
| 944 | ENUM_ENT(EM_CE, "Freescale Communication Engine RISC core"), |
| 945 | ENUM_ENT(EM_M32C, "Renesas M32C"), |
| 946 | ENUM_ENT(EM_TSK3000, "Altium TSK3000 core"), |
| 947 | ENUM_ENT(EM_RS08, "Freescale RS08 embedded processor"), |
| 948 | ENUM_ENT(EM_SHARC, "EM_SHARC"), |
| 949 | ENUM_ENT(EM_ECOG2, "Cyan Technology eCOG2 microprocessor"), |
| 950 | ENUM_ENT(EM_SCORE7, "SUNPLUS S+Core"), |
| 951 | ENUM_ENT(EM_DSP24, "New Japan Radio (NJR) 24-bit DSP Processor"), |
| 952 | ENUM_ENT(EM_VIDEOCORE3, "Broadcom VideoCore III processor"), |
| 953 | ENUM_ENT(EM_LATTICEMICO32, "Lattice Mico32"), |
| 954 | ENUM_ENT(EM_SE_C17, "Seiko Epson C17 family"), |
| 955 | ENUM_ENT(EM_TI_C6000, "Texas Instruments TMS320C6000 DSP family"), |
| 956 | ENUM_ENT(EM_TI_C2000, "Texas Instruments TMS320C2000 DSP family"), |
| 957 | ENUM_ENT(EM_TI_C5500, "Texas Instruments TMS320C55x DSP family"), |
| 958 | ENUM_ENT(EM_MMDSP_PLUS, "STMicroelectronics 64bit VLIW Data Signal Processor"), |
| 959 | ENUM_ENT(EM_CYPRESS_M8C, "Cypress M8C microprocessor"), |
| 960 | ENUM_ENT(EM_R32C, "Renesas R32C series microprocessors"), |
| 961 | ENUM_ENT(EM_TRIMEDIA, "NXP Semiconductors TriMedia architecture family"), |
| 962 | ENUM_ENT(EM_HEXAGON, "Qualcomm Hexagon"), |
| 963 | ENUM_ENT(EM_8051, "Intel 8051 and variants"), |
| 964 | ENUM_ENT(EM_STXP7X, "STMicroelectronics STxP7x family"), |
| 965 | ENUM_ENT(EM_NDS32, "Andes Technology compact code size embedded RISC processor family"), |
| 966 | ENUM_ENT(EM_ECOG1, "Cyan Technology eCOG1 microprocessor"), |
| 967 | ENUM_ENT(EM_ECOG1X, "Cyan Technology eCOG1X family"), |
| 968 | ENUM_ENT(EM_MAXQ30, "Dallas Semiconductor MAXQ30 Core microcontrollers"), |
| 969 | ENUM_ENT(EM_XIMO16, "New Japan Radio (NJR) 16-bit DSP Processor"), |
| 970 | ENUM_ENT(EM_MANIK, "M2000 Reconfigurable RISC Microprocessor"), |
| 971 | ENUM_ENT(EM_CRAYNV2, "Cray Inc. NV2 vector architecture"), |
| 972 | ENUM_ENT(EM_RX, "Renesas RX"), |
| 973 | ENUM_ENT(EM_METAG, "Imagination Technologies Meta processor architecture"), |
| 974 | ENUM_ENT(EM_MCST_ELBRUS, "MCST Elbrus general purpose hardware architecture"), |
| 975 | ENUM_ENT(EM_ECOG16, "Cyan Technology eCOG16 family"), |
| 976 | ENUM_ENT(EM_CR16, "Xilinx MicroBlaze"), |
| 977 | ENUM_ENT(EM_ETPU, "Freescale Extended Time Processing Unit"), |
| 978 | ENUM_ENT(EM_SLE9X, "Infineon Technologies SLE9X core"), |
| 979 | ENUM_ENT(EM_L10M, "EM_L10M"), |
| 980 | ENUM_ENT(EM_K10M, "EM_K10M"), |
| 981 | ENUM_ENT(EM_AARCH64, "AArch64"), |
Dylan McKay | dffaaa3 | 2017-09-27 22:39:37 +0000 | [diff] [blame] | 982 | ENUM_ENT(EM_AVR32, "Atmel Corporation 32-bit microprocessor family"), |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 983 | ENUM_ENT(EM_STM8, "STMicroeletronics STM8 8-bit microcontroller"), |
| 984 | ENUM_ENT(EM_TILE64, "Tilera TILE64 multicore architecture family"), |
| 985 | ENUM_ENT(EM_TILEPRO, "Tilera TILEPro multicore architecture family"), |
| 986 | ENUM_ENT(EM_CUDA, "NVIDIA CUDA architecture"), |
| 987 | ENUM_ENT(EM_TILEGX, "Tilera TILE-Gx multicore architecture family"), |
| 988 | ENUM_ENT(EM_CLOUDSHIELD, "EM_CLOUDSHIELD"), |
| 989 | ENUM_ENT(EM_COREA_1ST, "EM_COREA_1ST"), |
| 990 | ENUM_ENT(EM_COREA_2ND, "EM_COREA_2ND"), |
| 991 | ENUM_ENT(EM_ARC_COMPACT2, "EM_ARC_COMPACT2"), |
| 992 | ENUM_ENT(EM_OPEN8, "EM_OPEN8"), |
| 993 | ENUM_ENT(EM_RL78, "Renesas RL78"), |
| 994 | ENUM_ENT(EM_VIDEOCORE5, "Broadcom VideoCore V processor"), |
| 995 | ENUM_ENT(EM_78KOR, "EM_78KOR"), |
| 996 | ENUM_ENT(EM_56800EX, "EM_56800EX"), |
| 997 | ENUM_ENT(EM_AMDGPU, "EM_AMDGPU"), |
Alex Bradbury | 1524f62 | 2016-11-01 16:59:37 +0000 | [diff] [blame] | 998 | ENUM_ENT(EM_RISCV, "RISC-V"), |
Jacques Pienaar | ea9f25a | 2016-03-01 21:21:42 +0000 | [diff] [blame] | 999 | ENUM_ENT(EM_WEBASSEMBLY, "EM_WEBASSEMBLY"), |
| 1000 | ENUM_ENT(EM_LANAI, "EM_LANAI"), |
Alexei Starovoitov | cfb51f5 | 2016-07-15 22:27:55 +0000 | [diff] [blame] | 1001 | ENUM_ENT(EM_BPF, "EM_BPF"), |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1002 | }; |
| 1003 | |
| 1004 | static const EnumEntry<unsigned> ElfSymbolBindings[] = { |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 1005 | {"Local", "LOCAL", ELF::STB_LOCAL}, |
| 1006 | {"Global", "GLOBAL", ELF::STB_GLOBAL}, |
| 1007 | {"Weak", "WEAK", ELF::STB_WEAK}, |
| 1008 | {"Unique", "UNIQUE", ELF::STB_GNU_UNIQUE}}; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1009 | |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 1010 | static const EnumEntry<unsigned> ElfSymbolVisibilities[] = { |
| 1011 | {"DEFAULT", "DEFAULT", ELF::STV_DEFAULT}, |
| 1012 | {"INTERNAL", "INTERNAL", ELF::STV_INTERNAL}, |
| 1013 | {"HIDDEN", "HIDDEN", ELF::STV_HIDDEN}, |
| 1014 | {"PROTECTED", "PROTECTED", ELF::STV_PROTECTED}}; |
| 1015 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1016 | static const EnumEntry<unsigned> ElfSymbolTypes[] = { |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 1017 | {"None", "NOTYPE", ELF::STT_NOTYPE}, |
| 1018 | {"Object", "OBJECT", ELF::STT_OBJECT}, |
| 1019 | {"Function", "FUNC", ELF::STT_FUNC}, |
| 1020 | {"Section", "SECTION", ELF::STT_SECTION}, |
| 1021 | {"File", "FILE", ELF::STT_FILE}, |
| 1022 | {"Common", "COMMON", ELF::STT_COMMON}, |
| 1023 | {"TLS", "TLS", ELF::STT_TLS}, |
| 1024 | {"GNU_IFunc", "IFUNC", ELF::STT_GNU_IFUNC}}; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1025 | |
| 1026 | static const EnumEntry<unsigned> AMDGPUSymbolTypes[] = { |
Konstantin Zhuravlyov | 5b0bf2ff | 2017-06-05 21:33:40 +0000 | [diff] [blame] | 1027 | { "AMDGPU_HSA_KERNEL", ELF::STT_AMDGPU_HSA_KERNEL } |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1028 | }; |
| 1029 | |
Hemant Kulkarni | ab4a46f | 2016-01-26 19:46:39 +0000 | [diff] [blame] | 1030 | static const char *getGroupType(uint32_t Flag) { |
| 1031 | if (Flag & ELF::GRP_COMDAT) |
| 1032 | return "COMDAT"; |
| 1033 | else |
| 1034 | return "(unknown)"; |
| 1035 | } |
| 1036 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1037 | static const EnumEntry<unsigned> ElfSectionFlags[] = { |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 1038 | ENUM_ENT(SHF_WRITE, "W"), |
| 1039 | ENUM_ENT(SHF_ALLOC, "A"), |
| 1040 | ENUM_ENT(SHF_EXCLUDE, "E"), |
| 1041 | ENUM_ENT(SHF_EXECINSTR, "X"), |
| 1042 | ENUM_ENT(SHF_MERGE, "M"), |
| 1043 | ENUM_ENT(SHF_STRINGS, "S"), |
| 1044 | ENUM_ENT(SHF_INFO_LINK, "I"), |
| 1045 | ENUM_ENT(SHF_LINK_ORDER, "L"), |
| 1046 | ENUM_ENT(SHF_OS_NONCONFORMING, "o"), |
| 1047 | ENUM_ENT(SHF_GROUP, "G"), |
| 1048 | ENUM_ENT(SHF_TLS, "T"), |
Hemant Kulkarni | 04ac3d7 | 2016-05-12 19:58:52 +0000 | [diff] [blame] | 1049 | ENUM_ENT(SHF_MASKOS, "o"), |
| 1050 | ENUM_ENT(SHF_MASKPROC, "p"), |
George Rimar | c13c59a | 2016-05-21 10:16:58 +0000 | [diff] [blame] | 1051 | ENUM_ENT_1(SHF_COMPRESSED), |
| 1052 | }; |
| 1053 | |
| 1054 | static const EnumEntry<unsigned> ElfXCoreSectionFlags[] = { |
| 1055 | LLVM_READOBJ_ENUM_ENT(ELF, XCORE_SHF_CP_SECTION), |
| 1056 | LLVM_READOBJ_ENUM_ENT(ELF, XCORE_SHF_DP_SECTION) |
Simon Atanasyan | 2d0d853 | 2016-01-20 19:15:18 +0000 | [diff] [blame] | 1057 | }; |
| 1058 | |
Prakhar Bahuguna | 52a7dd7 | 2016-12-15 07:59:08 +0000 | [diff] [blame] | 1059 | static const EnumEntry<unsigned> ElfARMSectionFlags[] = { |
| 1060 | LLVM_READOBJ_ENUM_ENT(ELF, SHF_ARM_PURECODE) |
| 1061 | }; |
| 1062 | |
Simon Atanasyan | 2d0d853 | 2016-01-20 19:15:18 +0000 | [diff] [blame] | 1063 | static const EnumEntry<unsigned> ElfHexagonSectionFlags[] = { |
| 1064 | LLVM_READOBJ_ENUM_ENT(ELF, SHF_HEX_GPREL) |
| 1065 | }; |
| 1066 | |
| 1067 | static const EnumEntry<unsigned> ElfMipsSectionFlags[] = { |
| 1068 | LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_NODUPES), |
| 1069 | LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_NAMES ), |
| 1070 | LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_LOCAL ), |
| 1071 | LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_NOSTRIP), |
| 1072 | LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_GPREL ), |
| 1073 | LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_MERGE ), |
| 1074 | LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_ADDR ), |
| 1075 | LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_STRING ) |
| 1076 | }; |
| 1077 | |
| 1078 | static const EnumEntry<unsigned> ElfX86_64SectionFlags[] = { |
| 1079 | LLVM_READOBJ_ENUM_ENT(ELF, SHF_X86_64_LARGE) |
| 1080 | }; |
| 1081 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 1082 | static std::string getGNUFlags(uint64_t Flags) { |
| 1083 | std::string Str; |
| 1084 | for (auto Entry : ElfSectionFlags) { |
| 1085 | uint64_t Flag = Entry.Value & Flags; |
| 1086 | Flags &= ~Entry.Value; |
| 1087 | switch (Flag) { |
| 1088 | case ELF::SHF_WRITE: |
| 1089 | case ELF::SHF_ALLOC: |
| 1090 | case ELF::SHF_EXECINSTR: |
| 1091 | case ELF::SHF_MERGE: |
| 1092 | case ELF::SHF_STRINGS: |
| 1093 | case ELF::SHF_INFO_LINK: |
| 1094 | case ELF::SHF_LINK_ORDER: |
| 1095 | case ELF::SHF_OS_NONCONFORMING: |
| 1096 | case ELF::SHF_GROUP: |
| 1097 | case ELF::SHF_TLS: |
| 1098 | case ELF::SHF_EXCLUDE: |
| 1099 | Str += Entry.AltName; |
| 1100 | break; |
| 1101 | default: |
Hemant Kulkarni | 04ac3d7 | 2016-05-12 19:58:52 +0000 | [diff] [blame] | 1102 | if (Flag & ELF::SHF_MASKOS) |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 1103 | Str += "o"; |
Hemant Kulkarni | 04ac3d7 | 2016-05-12 19:58:52 +0000 | [diff] [blame] | 1104 | else if (Flag & ELF::SHF_MASKPROC) |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 1105 | Str += "p"; |
| 1106 | else if (Flag) |
| 1107 | Str += "x"; |
| 1108 | } |
| 1109 | } |
| 1110 | return Str; |
| 1111 | } |
| 1112 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1113 | static const char *getElfSegmentType(unsigned Arch, unsigned Type) { |
| 1114 | // Check potentially overlapped processor-specific |
| 1115 | // program header type. |
| 1116 | switch (Arch) { |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1117 | case ELF::EM_ARM: |
| 1118 | switch (Type) { |
| 1119 | LLVM_READOBJ_ENUM_CASE(ELF, PT_ARM_EXIDX); |
| 1120 | } |
| 1121 | case ELF::EM_MIPS: |
| 1122 | case ELF::EM_MIPS_RS3_LE: |
| 1123 | switch (Type) { |
| 1124 | LLVM_READOBJ_ENUM_CASE(ELF, PT_MIPS_REGINFO); |
| 1125 | LLVM_READOBJ_ENUM_CASE(ELF, PT_MIPS_RTPROC); |
| 1126 | LLVM_READOBJ_ENUM_CASE(ELF, PT_MIPS_OPTIONS); |
| 1127 | LLVM_READOBJ_ENUM_CASE(ELF, PT_MIPS_ABIFLAGS); |
| 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | switch (Type) { |
| 1132 | LLVM_READOBJ_ENUM_CASE(ELF, PT_NULL ); |
| 1133 | LLVM_READOBJ_ENUM_CASE(ELF, PT_LOAD ); |
| 1134 | LLVM_READOBJ_ENUM_CASE(ELF, PT_DYNAMIC); |
| 1135 | LLVM_READOBJ_ENUM_CASE(ELF, PT_INTERP ); |
| 1136 | LLVM_READOBJ_ENUM_CASE(ELF, PT_NOTE ); |
| 1137 | LLVM_READOBJ_ENUM_CASE(ELF, PT_SHLIB ); |
| 1138 | LLVM_READOBJ_ENUM_CASE(ELF, PT_PHDR ); |
| 1139 | LLVM_READOBJ_ENUM_CASE(ELF, PT_TLS ); |
| 1140 | |
| 1141 | LLVM_READOBJ_ENUM_CASE(ELF, PT_GNU_EH_FRAME); |
| 1142 | LLVM_READOBJ_ENUM_CASE(ELF, PT_SUNW_UNWIND); |
| 1143 | |
| 1144 | LLVM_READOBJ_ENUM_CASE(ELF, PT_GNU_STACK); |
| 1145 | LLVM_READOBJ_ENUM_CASE(ELF, PT_GNU_RELRO); |
George Rimar | bcfcb9e | 2016-10-18 10:54:56 +0000 | [diff] [blame] | 1146 | |
| 1147 | LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_RANDOMIZE); |
| 1148 | LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_WXNEEDED); |
George Rimar | 114d335 | 2016-12-06 17:55:52 +0000 | [diff] [blame] | 1149 | LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_BOOTDATA); |
George Rimar | bcfcb9e | 2016-10-18 10:54:56 +0000 | [diff] [blame] | 1150 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1151 | default: return ""; |
| 1152 | } |
| 1153 | } |
| 1154 | |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 1155 | static std::string getElfPtType(unsigned Arch, unsigned Type) { |
| 1156 | switch (Type) { |
Hemant Kulkarni | 7d564ba | 2016-03-28 17:20:23 +0000 | [diff] [blame] | 1157 | LLVM_READOBJ_PHDR_ENUM(ELF, PT_NULL) |
| 1158 | LLVM_READOBJ_PHDR_ENUM(ELF, PT_LOAD) |
| 1159 | LLVM_READOBJ_PHDR_ENUM(ELF, PT_DYNAMIC) |
| 1160 | LLVM_READOBJ_PHDR_ENUM(ELF, PT_INTERP) |
| 1161 | LLVM_READOBJ_PHDR_ENUM(ELF, PT_NOTE) |
| 1162 | LLVM_READOBJ_PHDR_ENUM(ELF, PT_SHLIB) |
| 1163 | LLVM_READOBJ_PHDR_ENUM(ELF, PT_PHDR) |
| 1164 | LLVM_READOBJ_PHDR_ENUM(ELF, PT_TLS) |
| 1165 | LLVM_READOBJ_PHDR_ENUM(ELF, PT_GNU_EH_FRAME) |
| 1166 | LLVM_READOBJ_PHDR_ENUM(ELF, PT_SUNW_UNWIND) |
| 1167 | LLVM_READOBJ_PHDR_ENUM(ELF, PT_GNU_STACK) |
| 1168 | LLVM_READOBJ_PHDR_ENUM(ELF, PT_GNU_RELRO) |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 1169 | default: |
| 1170 | // All machine specific PT_* types |
| 1171 | switch (Arch) { |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 1172 | case ELF::EM_ARM: |
| 1173 | if (Type == ELF::PT_ARM_EXIDX) |
| 1174 | return "EXIDX"; |
| 1175 | return ""; |
| 1176 | case ELF::EM_MIPS: |
| 1177 | case ELF::EM_MIPS_RS3_LE: |
| 1178 | switch (Type) { |
| 1179 | case PT_MIPS_REGINFO: |
| 1180 | return "REGINFO"; |
| 1181 | case PT_MIPS_RTPROC: |
| 1182 | return "RTPROC"; |
| 1183 | case PT_MIPS_OPTIONS: |
| 1184 | return "OPTIONS"; |
| 1185 | case PT_MIPS_ABIFLAGS: |
| 1186 | return "ABIFLAGS"; |
| 1187 | } |
| 1188 | return ""; |
| 1189 | } |
| 1190 | } |
| 1191 | return std::string("<unknown>: ") + to_string(format_hex(Type, 1)); |
| 1192 | } |
| 1193 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1194 | static const EnumEntry<unsigned> ElfSegmentFlags[] = { |
| 1195 | LLVM_READOBJ_ENUM_ENT(ELF, PF_X), |
| 1196 | LLVM_READOBJ_ENUM_ENT(ELF, PF_W), |
| 1197 | LLVM_READOBJ_ENUM_ENT(ELF, PF_R) |
| 1198 | }; |
| 1199 | |
| 1200 | static const EnumEntry<unsigned> ElfHeaderMipsFlags[] = { |
| 1201 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_NOREORDER), |
| 1202 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_PIC), |
| 1203 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_CPIC), |
| 1204 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ABI2), |
| 1205 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_32BITMODE), |
| 1206 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_FP64), |
| 1207 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_NAN2008), |
| 1208 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ABI_O32), |
| 1209 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ABI_O64), |
| 1210 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ABI_EABI32), |
| 1211 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ABI_EABI64), |
| 1212 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_3900), |
| 1213 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_4010), |
| 1214 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_4100), |
| 1215 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_4650), |
| 1216 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_4120), |
| 1217 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_4111), |
| 1218 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_SB1), |
| 1219 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_OCTEON), |
| 1220 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_XLR), |
| 1221 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_OCTEON2), |
| 1222 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_OCTEON3), |
| 1223 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_5400), |
| 1224 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_5900), |
| 1225 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_5500), |
| 1226 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_9000), |
| 1227 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_LS2E), |
| 1228 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_LS2F), |
| 1229 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_LS3A), |
| 1230 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MICROMIPS), |
| 1231 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_ASE_M16), |
| 1232 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_ASE_MDMX), |
| 1233 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_1), |
| 1234 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_2), |
| 1235 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_3), |
| 1236 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_4), |
| 1237 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_5), |
| 1238 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_32), |
| 1239 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_64), |
| 1240 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_32R2), |
| 1241 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_64R2), |
| 1242 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_32R6), |
| 1243 | LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_64R6) |
| 1244 | }; |
| 1245 | |
Konstantin Zhuravlyov | aa0835a | 2017-10-05 16:19:18 +0000 | [diff] [blame] | 1246 | static const EnumEntry<unsigned> ElfHeaderAMDGPUFlags[] = { |
| 1247 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_ARCH_NONE), |
| 1248 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_ARCH_R600), |
| 1249 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_ARCH_GCN) |
| 1250 | }; |
| 1251 | |
Alex Bradbury | bb89b2b | 2017-10-03 08:41:59 +0000 | [diff] [blame] | 1252 | static const EnumEntry<unsigned> ElfHeaderRISCVFlags[] = { |
| 1253 | LLVM_READOBJ_ENUM_ENT(ELF, EF_RISCV_RVC), |
| 1254 | LLVM_READOBJ_ENUM_ENT(ELF, EF_RISCV_FLOAT_ABI_SINGLE), |
| 1255 | LLVM_READOBJ_ENUM_ENT(ELF, EF_RISCV_FLOAT_ABI_DOUBLE), |
| 1256 | LLVM_READOBJ_ENUM_ENT(ELF, EF_RISCV_FLOAT_ABI_QUAD), |
| 1257 | LLVM_READOBJ_ENUM_ENT(ELF, EF_RISCV_RVE) |
| 1258 | }; |
| 1259 | |
Simon Atanasyan | b7807a0 | 2016-03-24 16:10:37 +0000 | [diff] [blame] | 1260 | static const EnumEntry<unsigned> ElfSymOtherFlags[] = { |
| 1261 | LLVM_READOBJ_ENUM_ENT(ELF, STV_INTERNAL), |
| 1262 | LLVM_READOBJ_ENUM_ENT(ELF, STV_HIDDEN), |
| 1263 | LLVM_READOBJ_ENUM_ENT(ELF, STV_PROTECTED) |
| 1264 | }; |
| 1265 | |
| 1266 | static const EnumEntry<unsigned> ElfMipsSymOtherFlags[] = { |
| 1267 | LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_OPTIONAL), |
| 1268 | LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_PLT), |
| 1269 | LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_PIC), |
| 1270 | LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_MICROMIPS) |
| 1271 | }; |
| 1272 | |
| 1273 | static const EnumEntry<unsigned> ElfMips16SymOtherFlags[] = { |
| 1274 | LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_OPTIONAL), |
| 1275 | LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_PLT), |
| 1276 | LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_MIPS16) |
| 1277 | }; |
| 1278 | |
Simon Atanasyan | 8a71b53 | 2016-05-04 05:58:57 +0000 | [diff] [blame] | 1279 | static const char *getElfMipsOptionsOdkType(unsigned Odk) { |
| 1280 | switch (Odk) { |
| 1281 | LLVM_READOBJ_ENUM_CASE(ELF, ODK_NULL); |
| 1282 | LLVM_READOBJ_ENUM_CASE(ELF, ODK_REGINFO); |
| 1283 | LLVM_READOBJ_ENUM_CASE(ELF, ODK_EXCEPTIONS); |
| 1284 | LLVM_READOBJ_ENUM_CASE(ELF, ODK_PAD); |
| 1285 | LLVM_READOBJ_ENUM_CASE(ELF, ODK_HWPATCH); |
| 1286 | LLVM_READOBJ_ENUM_CASE(ELF, ODK_FILL); |
| 1287 | LLVM_READOBJ_ENUM_CASE(ELF, ODK_TAGS); |
| 1288 | LLVM_READOBJ_ENUM_CASE(ELF, ODK_HWAND); |
| 1289 | LLVM_READOBJ_ENUM_CASE(ELF, ODK_HWOR); |
| 1290 | LLVM_READOBJ_ENUM_CASE(ELF, ODK_GP_GROUP); |
| 1291 | LLVM_READOBJ_ENUM_CASE(ELF, ODK_IDENT); |
| 1292 | LLVM_READOBJ_ENUM_CASE(ELF, ODK_PAGESIZE); |
| 1293 | default: |
| 1294 | return "Unknown"; |
| 1295 | } |
| 1296 | } |
| 1297 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1298 | template <typename ELFT> |
Zachary Turner | 88bb163 | 2016-05-03 00:28:04 +0000 | [diff] [blame] | 1299 | ELFDumper<ELFT>::ELFDumper(const ELFFile<ELFT> *Obj, ScopedPrinter &Writer) |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1300 | : ObjDumper(Writer), Obj(Obj) { |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1301 | SmallVector<const Elf_Phdr *, 4> LoadSegments; |
Rafael Espindola | 6a49497 | 2016-11-03 17:28:33 +0000 | [diff] [blame] | 1302 | for (const Elf_Phdr &Phdr : unwrapOrError(Obj->program_headers())) { |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1303 | if (Phdr.p_type == ELF::PT_DYNAMIC) { |
Rafael Espindola | e17c3f3 | 2016-02-17 16:48:00 +0000 | [diff] [blame] | 1304 | DynamicTable = createDRIFrom(&Phdr, sizeof(Elf_Dyn)); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1305 | continue; |
| 1306 | } |
| 1307 | if (Phdr.p_type != ELF::PT_LOAD || Phdr.p_filesz == 0) |
| 1308 | continue; |
| 1309 | LoadSegments.push_back(&Phdr); |
| 1310 | } |
| 1311 | |
Rafael Espindola | 25be8c8 | 2016-11-02 14:10:57 +0000 | [diff] [blame] | 1312 | for (const Elf_Shdr &Sec : unwrapOrError(Obj->sections())) { |
Michael J. Spencer | 37304f1 | 2016-02-11 04:59:26 +0000 | [diff] [blame] | 1313 | switch (Sec.sh_type) { |
Michael J. Spencer | 94f060c | 2016-02-11 04:59:32 +0000 | [diff] [blame] | 1314 | case ELF::SHT_SYMTAB: |
| 1315 | if (DotSymtabSec != nullptr) |
Saleem Abdulrasool | 46ee733 | 2017-09-29 02:45:44 +0000 | [diff] [blame] | 1316 | reportError("Multiple SHT_SYMTAB"); |
Michael J. Spencer | 94f060c | 2016-02-11 04:59:32 +0000 | [diff] [blame] | 1317 | DotSymtabSec = &Sec; |
| 1318 | break; |
| 1319 | case ELF::SHT_DYNSYM: |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 1320 | if (DynSymRegion.Size) |
Saleem Abdulrasool | 46ee733 | 2017-09-29 02:45:44 +0000 | [diff] [blame] | 1321 | reportError("Multiple SHT_DYNSYM"); |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 1322 | DynSymRegion = createDRIFrom(&Sec); |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 1323 | // This is only used (if Elf_Shdr present)for naming section in GNU style |
| 1324 | DynSymtabName = unwrapOrError(Obj->getSectionName(&Sec)); |
Michael J. Spencer | 94f060c | 2016-02-11 04:59:32 +0000 | [diff] [blame] | 1325 | break; |
Michael J. Spencer | 1c793ef | 2016-02-17 22:30:41 +0000 | [diff] [blame] | 1326 | case ELF::SHT_SYMTAB_SHNDX: |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 1327 | ShndxTable = unwrapOrError(Obj->getSHNDXTable(Sec)); |
Michael J. Spencer | 94f060c | 2016-02-11 04:59:32 +0000 | [diff] [blame] | 1328 | break; |
Michael J. Spencer | 37304f1 | 2016-02-11 04:59:26 +0000 | [diff] [blame] | 1329 | case ELF::SHT_GNU_versym: |
| 1330 | if (dot_gnu_version_sec != nullptr) |
| 1331 | reportError("Multiple SHT_GNU_versym"); |
| 1332 | dot_gnu_version_sec = &Sec; |
| 1333 | break; |
| 1334 | case ELF::SHT_GNU_verdef: |
| 1335 | if (dot_gnu_version_d_sec != nullptr) |
| 1336 | reportError("Multiple SHT_GNU_verdef"); |
| 1337 | dot_gnu_version_d_sec = &Sec; |
| 1338 | break; |
| 1339 | case ELF::SHT_GNU_verneed: |
| 1340 | if (dot_gnu_version_r_sec != nullptr) |
Saleem Abdulrasool | 46ee733 | 2017-09-29 02:45:44 +0000 | [diff] [blame] | 1341 | reportError("Multiple SHT_GNU_verneed"); |
Michael J. Spencer | 37304f1 | 2016-02-11 04:59:26 +0000 | [diff] [blame] | 1342 | dot_gnu_version_r_sec = &Sec; |
| 1343 | break; |
Michael J. Spencer | 37304f1 | 2016-02-11 04:59:26 +0000 | [diff] [blame] | 1344 | } |
| 1345 | } |
| 1346 | |
Michael J. Spencer | 60d82b2 | 2016-02-11 04:59:37 +0000 | [diff] [blame] | 1347 | parseDynamicTable(LoadSegments); |
| 1348 | |
| 1349 | if (opts::Output == opts::GNU) |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 1350 | ELFDumperStyle.reset(new GNUStyle<ELFT>(Writer, this)); |
Michael J. Spencer | 60d82b2 | 2016-02-11 04:59:37 +0000 | [diff] [blame] | 1351 | else |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 1352 | ELFDumperStyle.reset(new LLVMStyle<ELFT>(Writer, this)); |
Michael J. Spencer | 60d82b2 | 2016-02-11 04:59:37 +0000 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | template <typename ELFT> |
| 1356 | void ELFDumper<ELFT>::parseDynamicTable( |
| 1357 | ArrayRef<const Elf_Phdr *> LoadSegments) { |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1358 | auto toMappedAddr = [&](uint64_t VAddr) -> const uint8_t * { |
Michael J. Spencer | 60d82b2 | 2016-02-11 04:59:37 +0000 | [diff] [blame] | 1359 | const Elf_Phdr *const *I = std::upper_bound( |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1360 | LoadSegments.begin(), LoadSegments.end(), VAddr, compareAddr<ELFT>); |
| 1361 | if (I == LoadSegments.begin()) |
Rafael Espindola | 6009db6 | 2016-02-16 14:17:48 +0000 | [diff] [blame] | 1362 | report_fatal_error("Virtual address is not in any segment"); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1363 | --I; |
| 1364 | const Elf_Phdr &Phdr = **I; |
| 1365 | uint64_t Delta = VAddr - Phdr.p_vaddr; |
| 1366 | if (Delta >= Phdr.p_filesz) |
Rafael Espindola | 6009db6 | 2016-02-16 14:17:48 +0000 | [diff] [blame] | 1367 | report_fatal_error("Virtual address is not in any segment"); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1368 | return Obj->base() + Phdr.p_offset + Delta; |
| 1369 | }; |
| 1370 | |
| 1371 | uint64_t SONameOffset = 0; |
| 1372 | const char *StringTableBegin = nullptr; |
| 1373 | uint64_t StringTableSize = 0; |
| 1374 | for (const Elf_Dyn &Dyn : dynamic_table()) { |
| 1375 | switch (Dyn.d_tag) { |
| 1376 | case ELF::DT_HASH: |
| 1377 | HashTable = |
| 1378 | reinterpret_cast<const Elf_Hash *>(toMappedAddr(Dyn.getPtr())); |
| 1379 | break; |
| 1380 | case ELF::DT_GNU_HASH: |
| 1381 | GnuHashTable = |
| 1382 | reinterpret_cast<const Elf_GnuHash *>(toMappedAddr(Dyn.getPtr())); |
| 1383 | break; |
Michael J. Spencer | 94f060c | 2016-02-11 04:59:32 +0000 | [diff] [blame] | 1384 | case ELF::DT_STRTAB: |
| 1385 | StringTableBegin = (const char *)toMappedAddr(Dyn.getPtr()); |
Simon Atanasyan | 72155c3 | 2016-01-16 22:40:09 +0000 | [diff] [blame] | 1386 | break; |
Michael J. Spencer | 94f060c | 2016-02-11 04:59:32 +0000 | [diff] [blame] | 1387 | case ELF::DT_STRSZ: |
| 1388 | StringTableSize = Dyn.getVal(); |
Simon Atanasyan | 72155c3 | 2016-01-16 22:40:09 +0000 | [diff] [blame] | 1389 | break; |
Michael J. Spencer | 94f060c | 2016-02-11 04:59:32 +0000 | [diff] [blame] | 1390 | case ELF::DT_SYMTAB: |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 1391 | DynSymRegion.Addr = toMappedAddr(Dyn.getPtr()); |
| 1392 | DynSymRegion.EntSize = sizeof(Elf_Sym); |
Simon Atanasyan | 72155c3 | 2016-01-16 22:40:09 +0000 | [diff] [blame] | 1393 | break; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1394 | case ELF::DT_RELA: |
| 1395 | DynRelaRegion.Addr = toMappedAddr(Dyn.getPtr()); |
| 1396 | break; |
| 1397 | case ELF::DT_RELASZ: |
| 1398 | DynRelaRegion.Size = Dyn.getVal(); |
| 1399 | break; |
| 1400 | case ELF::DT_RELAENT: |
| 1401 | DynRelaRegion.EntSize = Dyn.getVal(); |
| 1402 | break; |
| 1403 | case ELF::DT_SONAME: |
| 1404 | SONameOffset = Dyn.getVal(); |
| 1405 | break; |
Michael J. Spencer | 94f060c | 2016-02-11 04:59:32 +0000 | [diff] [blame] | 1406 | case ELF::DT_REL: |
| 1407 | DynRelRegion.Addr = toMappedAddr(Dyn.getPtr()); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1408 | break; |
Michael J. Spencer | 94f060c | 2016-02-11 04:59:32 +0000 | [diff] [blame] | 1409 | case ELF::DT_RELSZ: |
| 1410 | DynRelRegion.Size = Dyn.getVal(); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1411 | break; |
Michael J. Spencer | 94f060c | 2016-02-11 04:59:32 +0000 | [diff] [blame] | 1412 | case ELF::DT_RELENT: |
| 1413 | DynRelRegion.EntSize = Dyn.getVal(); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1414 | break; |
Rafael Espindola | 944f655 | 2016-02-16 15:16:00 +0000 | [diff] [blame] | 1415 | case ELF::DT_PLTREL: |
| 1416 | if (Dyn.getVal() == DT_REL) |
| 1417 | DynPLTRelRegion.EntSize = sizeof(Elf_Rel); |
| 1418 | else if (Dyn.getVal() == DT_RELA) |
| 1419 | DynPLTRelRegion.EntSize = sizeof(Elf_Rela); |
| 1420 | else |
| 1421 | reportError(Twine("unknown DT_PLTREL value of ") + |
| 1422 | Twine((uint64_t)Dyn.getVal())); |
| 1423 | break; |
| 1424 | case ELF::DT_JMPREL: |
| 1425 | DynPLTRelRegion.Addr = toMappedAddr(Dyn.getPtr()); |
| 1426 | break; |
| 1427 | case ELF::DT_PLTRELSZ: |
| 1428 | DynPLTRelRegion.Size = Dyn.getVal(); |
| 1429 | break; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1430 | } |
| 1431 | } |
| 1432 | if (StringTableBegin) |
| 1433 | DynamicStringTable = StringRef(StringTableBegin, StringTableSize); |
| 1434 | if (SONameOffset) |
| 1435 | SOName = getDynamicString(SONameOffset); |
Rafael Espindola | 6009db6 | 2016-02-16 14:17:48 +0000 | [diff] [blame] | 1436 | } |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1437 | |
Rafael Espindola | 6009db6 | 2016-02-16 14:17:48 +0000 | [diff] [blame] | 1438 | template <typename ELFT> |
Simon Atanasyan | 72155c3 | 2016-01-16 22:40:09 +0000 | [diff] [blame] | 1439 | typename ELFDumper<ELFT>::Elf_Rel_Range ELFDumper<ELFT>::dyn_rels() const { |
Rafael Espindola | aafcf75 | 2016-04-05 14:47:22 +0000 | [diff] [blame] | 1440 | return DynRelRegion.getAsArrayRef<Elf_Rel>(); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | template <typename ELFT> |
| 1444 | typename ELFDumper<ELFT>::Elf_Rela_Range ELFDumper<ELFT>::dyn_relas() const { |
Rafael Espindola | aafcf75 | 2016-04-05 14:47:22 +0000 | [diff] [blame] | 1445 | return DynRelaRegion.getAsArrayRef<Elf_Rela>(); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | template<class ELFT> |
| 1449 | void ELFDumper<ELFT>::printFileHeaders() { |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 1450 | ELFDumperStyle->printFileHeaders(Obj); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1451 | } |
| 1452 | |
| 1453 | template<class ELFT> |
| 1454 | void ELFDumper<ELFT>::printSections() { |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 1455 | ELFDumperStyle->printSections(Obj); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | template<class ELFT> |
| 1459 | void ELFDumper<ELFT>::printRelocations() { |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 1460 | ELFDumperStyle->printRelocations(Obj); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1461 | } |
| 1462 | |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 1463 | template <class ELFT> void ELFDumper<ELFT>::printProgramHeaders() { |
| 1464 | ELFDumperStyle->printProgramHeaders(Obj); |
| 1465 | } |
| 1466 | |
Simon Atanasyan | 72155c3 | 2016-01-16 22:40:09 +0000 | [diff] [blame] | 1467 | template <class ELFT> void ELFDumper<ELFT>::printDynamicRelocations() { |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 1468 | ELFDumperStyle->printDynamicRelocations(Obj); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1469 | } |
| 1470 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1471 | template<class ELFT> |
| 1472 | void ELFDumper<ELFT>::printSymbols() { |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 1473 | ELFDumperStyle->printSymbols(Obj); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | template<class ELFT> |
| 1477 | void ELFDumper<ELFT>::printDynamicSymbols() { |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 1478 | ELFDumperStyle->printDynamicSymbols(Obj); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1479 | } |
| 1480 | |
Hemant Kulkarni | 9b1b7f0 | 2016-04-11 17:15:30 +0000 | [diff] [blame] | 1481 | template <class ELFT> void ELFDumper<ELFT>::printHashHistogram() { |
| 1482 | ELFDumperStyle->printHashHistogram(Obj); |
| 1483 | } |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 1484 | |
| 1485 | template <class ELFT> void ELFDumper<ELFT>::printNotes() { |
| 1486 | ELFDumperStyle->printNotes(Obj); |
| 1487 | } |
| 1488 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1489 | #define LLVM_READOBJ_TYPE_CASE(name) \ |
| 1490 | case DT_##name: return #name |
| 1491 | |
Hemant Kulkarni | e60b294 | 2016-12-27 19:59:29 +0000 | [diff] [blame] | 1492 | static const char *getTypeString(unsigned Arch, uint64_t Type) { |
| 1493 | switch (Arch) { |
| 1494 | case EM_HEXAGON: |
| 1495 | switch (Type) { |
| 1496 | LLVM_READOBJ_TYPE_CASE(HEXAGON_SYMSZ); |
| 1497 | LLVM_READOBJ_TYPE_CASE(HEXAGON_VER); |
| 1498 | LLVM_READOBJ_TYPE_CASE(HEXAGON_PLT); |
| 1499 | } |
| 1500 | case EM_MIPS: |
| 1501 | switch (Type) { |
| 1502 | LLVM_READOBJ_TYPE_CASE(MIPS_RLD_MAP_REL); |
| 1503 | LLVM_READOBJ_TYPE_CASE(MIPS_RLD_VERSION); |
| 1504 | LLVM_READOBJ_TYPE_CASE(MIPS_FLAGS); |
| 1505 | LLVM_READOBJ_TYPE_CASE(MIPS_BASE_ADDRESS); |
| 1506 | LLVM_READOBJ_TYPE_CASE(MIPS_LOCAL_GOTNO); |
| 1507 | LLVM_READOBJ_TYPE_CASE(MIPS_SYMTABNO); |
| 1508 | LLVM_READOBJ_TYPE_CASE(MIPS_UNREFEXTNO); |
| 1509 | LLVM_READOBJ_TYPE_CASE(MIPS_GOTSYM); |
| 1510 | LLVM_READOBJ_TYPE_CASE(MIPS_RLD_MAP); |
| 1511 | LLVM_READOBJ_TYPE_CASE(MIPS_PLTGOT); |
| 1512 | LLVM_READOBJ_TYPE_CASE(MIPS_OPTIONS); |
| 1513 | } |
| 1514 | } |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1515 | switch (Type) { |
| 1516 | LLVM_READOBJ_TYPE_CASE(BIND_NOW); |
| 1517 | LLVM_READOBJ_TYPE_CASE(DEBUG); |
| 1518 | LLVM_READOBJ_TYPE_CASE(FINI); |
| 1519 | LLVM_READOBJ_TYPE_CASE(FINI_ARRAY); |
| 1520 | LLVM_READOBJ_TYPE_CASE(FINI_ARRAYSZ); |
| 1521 | LLVM_READOBJ_TYPE_CASE(FLAGS); |
| 1522 | LLVM_READOBJ_TYPE_CASE(FLAGS_1); |
| 1523 | LLVM_READOBJ_TYPE_CASE(HASH); |
| 1524 | LLVM_READOBJ_TYPE_CASE(INIT); |
| 1525 | LLVM_READOBJ_TYPE_CASE(INIT_ARRAY); |
| 1526 | LLVM_READOBJ_TYPE_CASE(INIT_ARRAYSZ); |
| 1527 | LLVM_READOBJ_TYPE_CASE(PREINIT_ARRAY); |
| 1528 | LLVM_READOBJ_TYPE_CASE(PREINIT_ARRAYSZ); |
| 1529 | LLVM_READOBJ_TYPE_CASE(JMPREL); |
| 1530 | LLVM_READOBJ_TYPE_CASE(NEEDED); |
| 1531 | LLVM_READOBJ_TYPE_CASE(NULL); |
| 1532 | LLVM_READOBJ_TYPE_CASE(PLTGOT); |
| 1533 | LLVM_READOBJ_TYPE_CASE(PLTREL); |
| 1534 | LLVM_READOBJ_TYPE_CASE(PLTRELSZ); |
| 1535 | LLVM_READOBJ_TYPE_CASE(REL); |
| 1536 | LLVM_READOBJ_TYPE_CASE(RELA); |
| 1537 | LLVM_READOBJ_TYPE_CASE(RELENT); |
| 1538 | LLVM_READOBJ_TYPE_CASE(RELSZ); |
| 1539 | LLVM_READOBJ_TYPE_CASE(RELAENT); |
| 1540 | LLVM_READOBJ_TYPE_CASE(RELASZ); |
| 1541 | LLVM_READOBJ_TYPE_CASE(RPATH); |
| 1542 | LLVM_READOBJ_TYPE_CASE(RUNPATH); |
| 1543 | LLVM_READOBJ_TYPE_CASE(SONAME); |
| 1544 | LLVM_READOBJ_TYPE_CASE(STRSZ); |
| 1545 | LLVM_READOBJ_TYPE_CASE(STRTAB); |
| 1546 | LLVM_READOBJ_TYPE_CASE(SYMBOLIC); |
| 1547 | LLVM_READOBJ_TYPE_CASE(SYMENT); |
| 1548 | LLVM_READOBJ_TYPE_CASE(SYMTAB); |
| 1549 | LLVM_READOBJ_TYPE_CASE(TEXTREL); |
| 1550 | LLVM_READOBJ_TYPE_CASE(VERDEF); |
| 1551 | LLVM_READOBJ_TYPE_CASE(VERDEFNUM); |
| 1552 | LLVM_READOBJ_TYPE_CASE(VERNEED); |
| 1553 | LLVM_READOBJ_TYPE_CASE(VERNEEDNUM); |
George Rimar | e05fcec | 2016-01-16 10:38:32 +0000 | [diff] [blame] | 1554 | LLVM_READOBJ_TYPE_CASE(VERSYM); |
Davide Italiano | 8c50367 | 2016-01-16 06:06:36 +0000 | [diff] [blame] | 1555 | LLVM_READOBJ_TYPE_CASE(RELACOUNT); |
George Rimar | e05fcec | 2016-01-16 10:38:32 +0000 | [diff] [blame] | 1556 | LLVM_READOBJ_TYPE_CASE(RELCOUNT); |
| 1557 | LLVM_READOBJ_TYPE_CASE(GNU_HASH); |
| 1558 | LLVM_READOBJ_TYPE_CASE(TLSDESC_PLT); |
| 1559 | LLVM_READOBJ_TYPE_CASE(TLSDESC_GOT); |
George Rimar | d8a4eca | 2016-09-02 07:35:19 +0000 | [diff] [blame] | 1560 | LLVM_READOBJ_TYPE_CASE(AUXILIARY); |
George Rimar | efd3ffb | 2017-07-14 16:00:16 +0000 | [diff] [blame] | 1561 | LLVM_READOBJ_TYPE_CASE(FILTER); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1562 | default: return "unknown"; |
| 1563 | } |
| 1564 | } |
| 1565 | |
| 1566 | #undef LLVM_READOBJ_TYPE_CASE |
| 1567 | |
| 1568 | #define LLVM_READOBJ_DT_FLAG_ENT(prefix, enum) \ |
| 1569 | { #enum, prefix##_##enum } |
| 1570 | |
| 1571 | static const EnumEntry<unsigned> ElfDynamicDTFlags[] = { |
| 1572 | LLVM_READOBJ_DT_FLAG_ENT(DF, ORIGIN), |
| 1573 | LLVM_READOBJ_DT_FLAG_ENT(DF, SYMBOLIC), |
| 1574 | LLVM_READOBJ_DT_FLAG_ENT(DF, TEXTREL), |
| 1575 | LLVM_READOBJ_DT_FLAG_ENT(DF, BIND_NOW), |
| 1576 | LLVM_READOBJ_DT_FLAG_ENT(DF, STATIC_TLS) |
| 1577 | }; |
| 1578 | |
| 1579 | static const EnumEntry<unsigned> ElfDynamicDTFlags1[] = { |
| 1580 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, NOW), |
| 1581 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, GLOBAL), |
| 1582 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, GROUP), |
| 1583 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, NODELETE), |
| 1584 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, LOADFLTR), |
| 1585 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, INITFIRST), |
| 1586 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, NOOPEN), |
| 1587 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, ORIGIN), |
| 1588 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, DIRECT), |
| 1589 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, TRANS), |
| 1590 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, INTERPOSE), |
| 1591 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, NODEFLIB), |
| 1592 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, NODUMP), |
| 1593 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, CONFALT), |
| 1594 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, ENDFILTEE), |
| 1595 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, DISPRELDNE), |
| 1596 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, NODIRECT), |
| 1597 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, IGNMULDEF), |
| 1598 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, NOKSYMS), |
| 1599 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, NOHDR), |
| 1600 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, EDITED), |
| 1601 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, NORELOC), |
| 1602 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, SYMINTPOSE), |
| 1603 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, GLOBAUDIT), |
| 1604 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, SINGLETON) |
| 1605 | }; |
| 1606 | |
| 1607 | static const EnumEntry<unsigned> ElfDynamicDTMipsFlags[] = { |
| 1608 | LLVM_READOBJ_DT_FLAG_ENT(RHF, NONE), |
| 1609 | LLVM_READOBJ_DT_FLAG_ENT(RHF, QUICKSTART), |
| 1610 | LLVM_READOBJ_DT_FLAG_ENT(RHF, NOTPOT), |
| 1611 | LLVM_READOBJ_DT_FLAG_ENT(RHS, NO_LIBRARY_REPLACEMENT), |
| 1612 | LLVM_READOBJ_DT_FLAG_ENT(RHF, NO_MOVE), |
| 1613 | LLVM_READOBJ_DT_FLAG_ENT(RHF, SGI_ONLY), |
| 1614 | LLVM_READOBJ_DT_FLAG_ENT(RHF, GUARANTEE_INIT), |
| 1615 | LLVM_READOBJ_DT_FLAG_ENT(RHF, DELTA_C_PLUS_PLUS), |
| 1616 | LLVM_READOBJ_DT_FLAG_ENT(RHF, GUARANTEE_START_INIT), |
| 1617 | LLVM_READOBJ_DT_FLAG_ENT(RHF, PIXIE), |
| 1618 | LLVM_READOBJ_DT_FLAG_ENT(RHF, DEFAULT_DELAY_LOAD), |
| 1619 | LLVM_READOBJ_DT_FLAG_ENT(RHF, REQUICKSTART), |
| 1620 | LLVM_READOBJ_DT_FLAG_ENT(RHF, REQUICKSTARTED), |
| 1621 | LLVM_READOBJ_DT_FLAG_ENT(RHF, CORD), |
| 1622 | LLVM_READOBJ_DT_FLAG_ENT(RHF, NO_UNRES_UNDEF), |
| 1623 | LLVM_READOBJ_DT_FLAG_ENT(RHF, RLD_ORDER_SAFE) |
| 1624 | }; |
| 1625 | |
| 1626 | #undef LLVM_READOBJ_DT_FLAG_ENT |
| 1627 | |
| 1628 | template <typename T, typename TFlag> |
| 1629 | void printFlags(T Value, ArrayRef<EnumEntry<TFlag>> Flags, raw_ostream &OS) { |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 1630 | using FlagEntry = EnumEntry<TFlag>; |
| 1631 | using FlagVector = SmallVector<FlagEntry, 10>; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1632 | FlagVector SetFlags; |
| 1633 | |
| 1634 | for (const auto &Flag : Flags) { |
| 1635 | if (Flag.Value == 0) |
| 1636 | continue; |
| 1637 | |
| 1638 | if ((Value & Flag.Value) == Flag.Value) |
| 1639 | SetFlags.push_back(Flag); |
| 1640 | } |
| 1641 | |
| 1642 | for (const auto &Flag : SetFlags) { |
| 1643 | OS << Flag.Name << " "; |
| 1644 | } |
| 1645 | } |
| 1646 | |
| 1647 | template <class ELFT> |
| 1648 | StringRef ELFDumper<ELFT>::getDynamicString(uint64_t Value) const { |
| 1649 | if (Value >= DynamicStringTable.size()) |
| 1650 | reportError("Invalid dynamic string table reference"); |
| 1651 | return StringRef(DynamicStringTable.data() + Value); |
| 1652 | } |
| 1653 | |
George Rimar | efd3ffb | 2017-07-14 16:00:16 +0000 | [diff] [blame] | 1654 | static void printLibrary(raw_ostream &OS, const Twine &Tag, const Twine &Name) { |
| 1655 | OS << Tag << ": [" << Name << "]"; |
| 1656 | } |
| 1657 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1658 | template <class ELFT> |
| 1659 | void ELFDumper<ELFT>::printValue(uint64_t Type, uint64_t Value) { |
| 1660 | raw_ostream &OS = W.getOStream(); |
Hemant Kulkarni | cb21f3c | 2016-05-12 22:16:53 +0000 | [diff] [blame] | 1661 | const char* ConvChar = (opts::Output == opts::GNU) ? "0x%" PRIx64 : "0x%" PRIX64; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1662 | switch (Type) { |
| 1663 | case DT_PLTREL: |
| 1664 | if (Value == DT_REL) { |
| 1665 | OS << "REL"; |
| 1666 | break; |
| 1667 | } else if (Value == DT_RELA) { |
| 1668 | OS << "RELA"; |
| 1669 | break; |
| 1670 | } |
Justin Bogner | b03fd12 | 2016-08-17 05:10:15 +0000 | [diff] [blame] | 1671 | LLVM_FALLTHROUGH; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1672 | case DT_PLTGOT: |
| 1673 | case DT_HASH: |
| 1674 | case DT_STRTAB: |
| 1675 | case DT_SYMTAB: |
| 1676 | case DT_RELA: |
| 1677 | case DT_INIT: |
| 1678 | case DT_FINI: |
| 1679 | case DT_REL: |
| 1680 | case DT_JMPREL: |
| 1681 | case DT_INIT_ARRAY: |
| 1682 | case DT_FINI_ARRAY: |
| 1683 | case DT_PREINIT_ARRAY: |
| 1684 | case DT_DEBUG: |
| 1685 | case DT_VERDEF: |
| 1686 | case DT_VERNEED: |
| 1687 | case DT_VERSYM: |
| 1688 | case DT_GNU_HASH: |
| 1689 | case DT_NULL: |
| 1690 | case DT_MIPS_BASE_ADDRESS: |
| 1691 | case DT_MIPS_GOTSYM: |
| 1692 | case DT_MIPS_RLD_MAP: |
| 1693 | case DT_MIPS_RLD_MAP_REL: |
| 1694 | case DT_MIPS_PLTGOT: |
| 1695 | case DT_MIPS_OPTIONS: |
Hemant Kulkarni | cb21f3c | 2016-05-12 22:16:53 +0000 | [diff] [blame] | 1696 | OS << format(ConvChar, Value); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1697 | break; |
Davide Italiano | 8c50367 | 2016-01-16 06:06:36 +0000 | [diff] [blame] | 1698 | case DT_RELACOUNT: |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1699 | case DT_RELCOUNT: |
| 1700 | case DT_VERDEFNUM: |
| 1701 | case DT_VERNEEDNUM: |
| 1702 | case DT_MIPS_RLD_VERSION: |
| 1703 | case DT_MIPS_LOCAL_GOTNO: |
| 1704 | case DT_MIPS_SYMTABNO: |
| 1705 | case DT_MIPS_UNREFEXTNO: |
| 1706 | OS << Value; |
| 1707 | break; |
| 1708 | case DT_PLTRELSZ: |
| 1709 | case DT_RELASZ: |
| 1710 | case DT_RELAENT: |
| 1711 | case DT_STRSZ: |
| 1712 | case DT_SYMENT: |
| 1713 | case DT_RELSZ: |
| 1714 | case DT_RELENT: |
| 1715 | case DT_INIT_ARRAYSZ: |
| 1716 | case DT_FINI_ARRAYSZ: |
| 1717 | case DT_PREINIT_ARRAYSZ: |
| 1718 | OS << Value << " (bytes)"; |
| 1719 | break; |
| 1720 | case DT_NEEDED: |
George Rimar | efd3ffb | 2017-07-14 16:00:16 +0000 | [diff] [blame] | 1721 | printLibrary(OS, "Shared library", getDynamicString(Value)); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1722 | break; |
| 1723 | case DT_SONAME: |
George Rimar | efd3ffb | 2017-07-14 16:00:16 +0000 | [diff] [blame] | 1724 | printLibrary(OS, "Library soname", getDynamicString(Value)); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1725 | break; |
George Rimar | d8a4eca | 2016-09-02 07:35:19 +0000 | [diff] [blame] | 1726 | case DT_AUXILIARY: |
George Rimar | efd3ffb | 2017-07-14 16:00:16 +0000 | [diff] [blame] | 1727 | printLibrary(OS, "Auxiliary library", getDynamicString(Value)); |
| 1728 | break; |
| 1729 | case DT_FILTER: |
| 1730 | printLibrary(OS, "Filter library", getDynamicString(Value)); |
George Rimar | d8a4eca | 2016-09-02 07:35:19 +0000 | [diff] [blame] | 1731 | break; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1732 | case DT_RPATH: |
| 1733 | case DT_RUNPATH: |
| 1734 | OS << getDynamicString(Value); |
| 1735 | break; |
| 1736 | case DT_MIPS_FLAGS: |
| 1737 | printFlags(Value, makeArrayRef(ElfDynamicDTMipsFlags), OS); |
| 1738 | break; |
| 1739 | case DT_FLAGS: |
| 1740 | printFlags(Value, makeArrayRef(ElfDynamicDTFlags), OS); |
| 1741 | break; |
| 1742 | case DT_FLAGS_1: |
| 1743 | printFlags(Value, makeArrayRef(ElfDynamicDTFlags1), OS); |
| 1744 | break; |
| 1745 | default: |
Hemant Kulkarni | cb21f3c | 2016-05-12 22:16:53 +0000 | [diff] [blame] | 1746 | OS << format(ConvChar, Value); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1747 | break; |
| 1748 | } |
| 1749 | } |
| 1750 | |
| 1751 | template<class ELFT> |
| 1752 | void ELFDumper<ELFT>::printUnwindInfo() { |
| 1753 | W.startLine() << "UnwindInfo not implemented.\n"; |
| 1754 | } |
| 1755 | |
| 1756 | namespace { |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 1757 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1758 | template <> void ELFDumper<ELFType<support::little, false>>::printUnwindInfo() { |
| 1759 | const unsigned Machine = Obj->getHeader()->e_machine; |
| 1760 | if (Machine == EM_ARM) { |
| 1761 | ARM::EHABI::PrinterContext<ELFType<support::little, false>> Ctx( |
| 1762 | W, Obj, DotSymtabSec); |
| 1763 | return Ctx.PrintUnwindInformation(); |
| 1764 | } |
| 1765 | W.startLine() << "UnwindInfo not implemented.\n"; |
| 1766 | } |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 1767 | |
| 1768 | } // end anonymous namespace |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1769 | |
| 1770 | template<class ELFT> |
| 1771 | void ELFDumper<ELFT>::printDynamicTable() { |
Rafael Espindola | e17c3f3 | 2016-02-17 16:48:00 +0000 | [diff] [blame] | 1772 | auto I = dynamic_table().begin(); |
| 1773 | auto E = dynamic_table().end(); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1774 | |
| 1775 | if (I == E) |
| 1776 | return; |
| 1777 | |
| 1778 | --E; |
| 1779 | while (I != E && E->getTag() == ELF::DT_NULL) |
| 1780 | --E; |
| 1781 | if (E->getTag() != ELF::DT_NULL) |
| 1782 | ++E; |
| 1783 | ++E; |
| 1784 | |
| 1785 | ptrdiff_t Total = std::distance(I, E); |
| 1786 | if (Total == 0) |
| 1787 | return; |
| 1788 | |
| 1789 | raw_ostream &OS = W.getOStream(); |
| 1790 | W.startLine() << "DynamicSection [ (" << Total << " entries)\n"; |
| 1791 | |
| 1792 | bool Is64 = ELFT::Is64Bits; |
| 1793 | |
| 1794 | W.startLine() |
| 1795 | << " Tag" << (Is64 ? " " : " ") << "Type" |
| 1796 | << " " << "Name/Value\n"; |
| 1797 | while (I != E) { |
| 1798 | const Elf_Dyn &Entry = *I; |
| 1799 | uintX_t Tag = Entry.getTag(); |
| 1800 | ++I; |
Hemant Kulkarni | cb21f3c | 2016-05-12 22:16:53 +0000 | [diff] [blame] | 1801 | W.startLine() << " " << format_hex(Tag, Is64 ? 18 : 10, opts::Output != opts::GNU) << " " |
Hemant Kulkarni | e60b294 | 2016-12-27 19:59:29 +0000 | [diff] [blame] | 1802 | << format("%-21s", getTypeString(Obj->getHeader()->e_machine, Tag)); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1803 | printValue(Tag, Entry.getVal()); |
| 1804 | OS << "\n"; |
| 1805 | } |
| 1806 | |
| 1807 | W.startLine() << "]\n"; |
| 1808 | } |
| 1809 | |
| 1810 | template<class ELFT> |
| 1811 | void ELFDumper<ELFT>::printNeededLibraries() { |
| 1812 | ListScope D(W, "NeededLibraries"); |
| 1813 | |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 1814 | using LibsTy = std::vector<StringRef>; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1815 | LibsTy Libs; |
| 1816 | |
| 1817 | for (const auto &Entry : dynamic_table()) |
| 1818 | if (Entry.d_tag == ELF::DT_NEEDED) |
| 1819 | Libs.push_back(getDynamicString(Entry.d_un.d_val)); |
| 1820 | |
| 1821 | std::stable_sort(Libs.begin(), Libs.end()); |
| 1822 | |
| 1823 | for (const auto &L : Libs) { |
| 1824 | outs() << " " << L << "\n"; |
| 1825 | } |
| 1826 | } |
| 1827 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1828 | |
| 1829 | template <typename ELFT> |
| 1830 | void ELFDumper<ELFT>::printHashTable() { |
| 1831 | DictScope D(W, "HashTable"); |
| 1832 | if (!HashTable) |
| 1833 | return; |
| 1834 | W.printNumber("Num Buckets", HashTable->nbucket); |
| 1835 | W.printNumber("Num Chains", HashTable->nchain); |
| 1836 | W.printList("Buckets", HashTable->buckets()); |
| 1837 | W.printList("Chains", HashTable->chains()); |
| 1838 | } |
| 1839 | |
| 1840 | template <typename ELFT> |
| 1841 | void ELFDumper<ELFT>::printGnuHashTable() { |
| 1842 | DictScope D(W, "GnuHashTable"); |
| 1843 | if (!GnuHashTable) |
| 1844 | return; |
| 1845 | W.printNumber("Num Buckets", GnuHashTable->nbuckets); |
| 1846 | W.printNumber("First Hashed Symbol Index", GnuHashTable->symndx); |
| 1847 | W.printNumber("Num Mask Words", GnuHashTable->maskwords); |
| 1848 | W.printNumber("Shift Count", GnuHashTable->shift2); |
| 1849 | W.printHexList("Bloom Filter", GnuHashTable->filter()); |
| 1850 | W.printList("Buckets", GnuHashTable->buckets()); |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 1851 | Elf_Sym_Range Syms = dynamic_symbols(); |
| 1852 | unsigned NumSyms = std::distance(Syms.begin(), Syms.end()); |
| 1853 | if (!NumSyms) |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1854 | reportError("No dynamic symbol section"); |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 1855 | W.printHexList("Values", GnuHashTable->values(NumSyms)); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1856 | } |
| 1857 | |
| 1858 | template <typename ELFT> void ELFDumper<ELFT>::printLoadName() { |
| 1859 | outs() << "LoadName: " << SOName << '\n'; |
| 1860 | } |
| 1861 | |
| 1862 | template <class ELFT> |
| 1863 | void ELFDumper<ELFT>::printAttributes() { |
| 1864 | W.startLine() << "Attributes not implemented.\n"; |
| 1865 | } |
| 1866 | |
| 1867 | namespace { |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 1868 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1869 | template <> void ELFDumper<ELFType<support::little, false>>::printAttributes() { |
| 1870 | if (Obj->getHeader()->e_machine != EM_ARM) { |
| 1871 | W.startLine() << "Attributes not implemented.\n"; |
| 1872 | return; |
| 1873 | } |
| 1874 | |
| 1875 | DictScope BA(W, "BuildAttributes"); |
Rafael Espindola | 25be8c8 | 2016-11-02 14:10:57 +0000 | [diff] [blame] | 1876 | for (const ELFO::Elf_Shdr &Sec : unwrapOrError(Obj->sections())) { |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1877 | if (Sec.sh_type != ELF::SHT_ARM_ATTRIBUTES) |
| 1878 | continue; |
| 1879 | |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 1880 | ArrayRef<uint8_t> Contents = unwrapOrError(Obj->getSectionContents(&Sec)); |
| 1881 | if (Contents[0] != ARMBuildAttrs::Format_Version) { |
| 1882 | errs() << "unrecognised FormatVersion: 0x" << utohexstr(Contents[0]) |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1883 | << '\n'; |
| 1884 | continue; |
| 1885 | } |
| 1886 | |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 1887 | W.printHex("FormatVersion", Contents[0]); |
| 1888 | if (Contents.size() == 1) |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1889 | continue; |
| 1890 | |
Sam Parker | df7c6ef | 2017-01-18 13:52:12 +0000 | [diff] [blame] | 1891 | ARMAttributeParser(&W).Parse(Contents, true); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1892 | } |
| 1893 | } |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1894 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1895 | template <class ELFT> class MipsGOTParser { |
| 1896 | public: |
Rafael Espindola | 6bc2990 | 2016-10-06 14:07:26 +0000 | [diff] [blame] | 1897 | TYPEDEF_ELF_TYPES(ELFT) |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 1898 | using GOTEntry = typename ELFO::Elf_Addr; |
| 1899 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1900 | MipsGOTParser(ELFDumper<ELFT> *Dumper, const ELFO *Obj, |
Zachary Turner | 88bb163 | 2016-05-03 00:28:04 +0000 | [diff] [blame] | 1901 | Elf_Dyn_Range DynTable, ScopedPrinter &W); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1902 | |
| 1903 | void parseGOT(); |
| 1904 | void parsePLT(); |
| 1905 | |
| 1906 | private: |
| 1907 | ELFDumper<ELFT> *Dumper; |
| 1908 | const ELFO *Obj; |
Zachary Turner | 88bb163 | 2016-05-03 00:28:04 +0000 | [diff] [blame] | 1909 | ScopedPrinter &W; |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 1910 | Optional<uint64_t> DtPltGot; |
| 1911 | Optional<uint64_t> DtLocalGotNum; |
| 1912 | Optional<uint64_t> DtGotSym; |
| 1913 | Optional<uint64_t> DtMipsPltGot; |
| 1914 | Optional<uint64_t> DtJmpRel; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1915 | |
| 1916 | std::size_t getGOTTotal(ArrayRef<uint8_t> GOT) const; |
| 1917 | const GOTEntry *makeGOTIter(ArrayRef<uint8_t> GOT, std::size_t EntryNum); |
| 1918 | |
| 1919 | void printGotEntry(uint64_t GotAddr, const GOTEntry *BeginIt, |
| 1920 | const GOTEntry *It); |
| 1921 | void printGlobalGotEntry(uint64_t GotAddr, const GOTEntry *BeginIt, |
| 1922 | const GOTEntry *It, const Elf_Sym *Sym, |
| 1923 | StringRef StrTable, bool IsDynamic); |
| 1924 | void printPLTEntry(uint64_t PLTAddr, const GOTEntry *BeginIt, |
| 1925 | const GOTEntry *It, StringRef Purpose); |
| 1926 | void printPLTEntry(uint64_t PLTAddr, const GOTEntry *BeginIt, |
| 1927 | const GOTEntry *It, StringRef StrTable, |
| 1928 | const Elf_Sym *Sym); |
| 1929 | }; |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 1930 | |
| 1931 | } // end anonymous namespace |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1932 | |
| 1933 | template <class ELFT> |
| 1934 | MipsGOTParser<ELFT>::MipsGOTParser(ELFDumper<ELFT> *Dumper, const ELFO *Obj, |
Zachary Turner | 88bb163 | 2016-05-03 00:28:04 +0000 | [diff] [blame] | 1935 | Elf_Dyn_Range DynTable, ScopedPrinter &W) |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1936 | : Dumper(Dumper), Obj(Obj), W(W) { |
| 1937 | for (const auto &Entry : DynTable) { |
| 1938 | switch (Entry.getTag()) { |
| 1939 | case ELF::DT_PLTGOT: |
| 1940 | DtPltGot = Entry.getVal(); |
| 1941 | break; |
| 1942 | case ELF::DT_MIPS_LOCAL_GOTNO: |
| 1943 | DtLocalGotNum = Entry.getVal(); |
| 1944 | break; |
| 1945 | case ELF::DT_MIPS_GOTSYM: |
| 1946 | DtGotSym = Entry.getVal(); |
| 1947 | break; |
| 1948 | case ELF::DT_MIPS_PLTGOT: |
| 1949 | DtMipsPltGot = Entry.getVal(); |
| 1950 | break; |
| 1951 | case ELF::DT_JMPREL: |
| 1952 | DtJmpRel = Entry.getVal(); |
| 1953 | break; |
| 1954 | } |
| 1955 | } |
| 1956 | } |
| 1957 | |
| 1958 | template <class ELFT> void MipsGOTParser<ELFT>::parseGOT() { |
| 1959 | // See "Global Offset Table" in Chapter 5 in the following document |
| 1960 | // for detailed GOT description. |
| 1961 | // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf |
| 1962 | if (!DtPltGot) { |
| 1963 | W.startLine() << "Cannot find PLTGOT dynamic table tag.\n"; |
| 1964 | return; |
| 1965 | } |
| 1966 | if (!DtLocalGotNum) { |
| 1967 | W.startLine() << "Cannot find MIPS_LOCAL_GOTNO dynamic table tag.\n"; |
| 1968 | return; |
| 1969 | } |
| 1970 | if (!DtGotSym) { |
| 1971 | W.startLine() << "Cannot find MIPS_GOTSYM dynamic table tag.\n"; |
| 1972 | return; |
| 1973 | } |
| 1974 | |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 1975 | StringRef StrTable = Dumper->getDynamicStringTable(); |
| 1976 | const Elf_Sym *DynSymBegin = Dumper->dynamic_symbols().begin(); |
| 1977 | const Elf_Sym *DynSymEnd = Dumper->dynamic_symbols().end(); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1978 | std::size_t DynSymTotal = std::size_t(std::distance(DynSymBegin, DynSymEnd)); |
| 1979 | |
Simon Atanasyan | cb1175c | 2016-02-09 18:45:35 +0000 | [diff] [blame] | 1980 | if (*DtGotSym > DynSymTotal) |
| 1981 | report_fatal_error("MIPS_GOTSYM exceeds a number of dynamic symbols"); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1982 | |
| 1983 | std::size_t GlobalGotNum = DynSymTotal - *DtGotSym; |
| 1984 | |
Simon Atanasyan | cb1175c | 2016-02-09 18:45:35 +0000 | [diff] [blame] | 1985 | if (*DtLocalGotNum + GlobalGotNum == 0) { |
| 1986 | W.startLine() << "GOT is empty.\n"; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1987 | return; |
| 1988 | } |
| 1989 | |
Simon Atanasyan | cb1175c | 2016-02-09 18:45:35 +0000 | [diff] [blame] | 1990 | const Elf_Shdr *GOTShdr = findNotEmptySectionByAddress(Obj, *DtPltGot); |
| 1991 | if (!GOTShdr) |
| 1992 | report_fatal_error("There is no not empty GOT section at 0x" + |
| 1993 | Twine::utohexstr(*DtPltGot)); |
| 1994 | |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 1995 | ArrayRef<uint8_t> GOT = unwrapOrError(Obj->getSectionContents(GOTShdr)); |
Simon Atanasyan | cb1175c | 2016-02-09 18:45:35 +0000 | [diff] [blame] | 1996 | |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 1997 | if (*DtLocalGotNum + GlobalGotNum > getGOTTotal(GOT)) |
Simon Atanasyan | cb1175c | 2016-02-09 18:45:35 +0000 | [diff] [blame] | 1998 | report_fatal_error("Number of GOT entries exceeds the size of GOT section"); |
| 1999 | |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 2000 | const GOTEntry *GotBegin = makeGOTIter(GOT, 0); |
| 2001 | const GOTEntry *GotLocalEnd = makeGOTIter(GOT, *DtLocalGotNum); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2002 | const GOTEntry *It = GotBegin; |
| 2003 | |
| 2004 | DictScope GS(W, "Primary GOT"); |
| 2005 | |
| 2006 | W.printHex("Canonical gp value", GOTShdr->sh_addr + 0x7ff0); |
| 2007 | { |
| 2008 | ListScope RS(W, "Reserved entries"); |
| 2009 | |
| 2010 | { |
| 2011 | DictScope D(W, "Entry"); |
| 2012 | printGotEntry(GOTShdr->sh_addr, GotBegin, It++); |
| 2013 | W.printString("Purpose", StringRef("Lazy resolver")); |
| 2014 | } |
| 2015 | |
| 2016 | if (It != GotLocalEnd && (*It >> (sizeof(GOTEntry) * 8 - 1)) != 0) { |
| 2017 | DictScope D(W, "Entry"); |
| 2018 | printGotEntry(GOTShdr->sh_addr, GotBegin, It++); |
| 2019 | W.printString("Purpose", StringRef("Module pointer (GNU extension)")); |
| 2020 | } |
| 2021 | } |
| 2022 | { |
| 2023 | ListScope LS(W, "Local entries"); |
| 2024 | for (; It != GotLocalEnd; ++It) { |
| 2025 | DictScope D(W, "Entry"); |
| 2026 | printGotEntry(GOTShdr->sh_addr, GotBegin, It); |
| 2027 | } |
| 2028 | } |
| 2029 | { |
| 2030 | ListScope GS(W, "Global entries"); |
| 2031 | |
| 2032 | const GOTEntry *GotGlobalEnd = |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 2033 | makeGOTIter(GOT, *DtLocalGotNum + GlobalGotNum); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2034 | const Elf_Sym *GotDynSym = DynSymBegin + *DtGotSym; |
| 2035 | for (; It != GotGlobalEnd; ++It) { |
| 2036 | DictScope D(W, "Entry"); |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 2037 | printGlobalGotEntry(GOTShdr->sh_addr, GotBegin, It, GotDynSym++, StrTable, |
| 2038 | true); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2039 | } |
| 2040 | } |
| 2041 | |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 2042 | std::size_t SpecGotNum = getGOTTotal(GOT) - *DtLocalGotNum - GlobalGotNum; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2043 | W.printNumber("Number of TLS and multi-GOT entries", uint64_t(SpecGotNum)); |
| 2044 | } |
| 2045 | |
| 2046 | template <class ELFT> void MipsGOTParser<ELFT>::parsePLT() { |
| 2047 | if (!DtMipsPltGot) { |
| 2048 | W.startLine() << "Cannot find MIPS_PLTGOT dynamic table tag.\n"; |
| 2049 | return; |
| 2050 | } |
| 2051 | if (!DtJmpRel) { |
| 2052 | W.startLine() << "Cannot find JMPREL dynamic table tag.\n"; |
| 2053 | return; |
| 2054 | } |
| 2055 | |
Simon Atanasyan | cb1175c | 2016-02-09 18:45:35 +0000 | [diff] [blame] | 2056 | const Elf_Shdr *PLTShdr = findNotEmptySectionByAddress(Obj, *DtMipsPltGot); |
| 2057 | if (!PLTShdr) |
| 2058 | report_fatal_error("There is no not empty PLTGOT section at 0x " + |
| 2059 | Twine::utohexstr(*DtMipsPltGot)); |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 2060 | ArrayRef<uint8_t> PLT = unwrapOrError(Obj->getSectionContents(PLTShdr)); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2061 | |
Simon Atanasyan | cb1175c | 2016-02-09 18:45:35 +0000 | [diff] [blame] | 2062 | const Elf_Shdr *PLTRelShdr = findNotEmptySectionByAddress(Obj, *DtJmpRel); |
| 2063 | if (!PLTRelShdr) |
| 2064 | report_fatal_error("There is no not empty RELPLT section at 0x" + |
| 2065 | Twine::utohexstr(*DtJmpRel)); |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 2066 | const Elf_Shdr *SymTable = |
| 2067 | unwrapOrError(Obj->getSection(PLTRelShdr->sh_link)); |
| 2068 | StringRef StrTable = unwrapOrError(Obj->getStringTableForSymtab(*SymTable)); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2069 | |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 2070 | const GOTEntry *PLTBegin = makeGOTIter(PLT, 0); |
| 2071 | const GOTEntry *PLTEnd = makeGOTIter(PLT, getGOTTotal(PLT)); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2072 | const GOTEntry *It = PLTBegin; |
| 2073 | |
| 2074 | DictScope GS(W, "PLT GOT"); |
| 2075 | { |
| 2076 | ListScope RS(W, "Reserved entries"); |
| 2077 | printPLTEntry(PLTShdr->sh_addr, PLTBegin, It++, "PLT lazy resolver"); |
| 2078 | if (It != PLTEnd) |
| 2079 | printPLTEntry(PLTShdr->sh_addr, PLTBegin, It++, "Module pointer"); |
| 2080 | } |
| 2081 | { |
| 2082 | ListScope GS(W, "Entries"); |
| 2083 | |
| 2084 | switch (PLTRelShdr->sh_type) { |
| 2085 | case ELF::SHT_REL: |
Rafael Espindola | 354680a | 2016-11-03 19:07:15 +0000 | [diff] [blame] | 2086 | for (const Elf_Rel &Rel : unwrapOrError(Obj->rels(PLTRelShdr))) { |
Rafael Espindola | ed1395a | 2016-11-03 18:05:33 +0000 | [diff] [blame] | 2087 | const Elf_Sym *Sym = |
| 2088 | unwrapOrError(Obj->getRelocationSymbol(&Rel, SymTable)); |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 2089 | printPLTEntry(PLTShdr->sh_addr, PLTBegin, It, StrTable, Sym); |
Rafael Espindola | 28c63d3 | 2016-10-06 13:11:12 +0000 | [diff] [blame] | 2090 | if (++It == PLTEnd) |
| 2091 | break; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2092 | } |
| 2093 | break; |
| 2094 | case ELF::SHT_RELA: |
Rafael Espindola | 354680a | 2016-11-03 19:07:15 +0000 | [diff] [blame] | 2095 | for (const Elf_Rela &Rel : unwrapOrError(Obj->relas(PLTRelShdr))) { |
Rafael Espindola | ed1395a | 2016-11-03 18:05:33 +0000 | [diff] [blame] | 2096 | const Elf_Sym *Sym = |
| 2097 | unwrapOrError(Obj->getRelocationSymbol(&Rel, SymTable)); |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 2098 | printPLTEntry(PLTShdr->sh_addr, PLTBegin, It, StrTable, Sym); |
Rafael Espindola | 28c63d3 | 2016-10-06 13:11:12 +0000 | [diff] [blame] | 2099 | if (++It == PLTEnd) |
| 2100 | break; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2101 | } |
| 2102 | break; |
| 2103 | } |
| 2104 | } |
| 2105 | } |
| 2106 | |
| 2107 | template <class ELFT> |
| 2108 | std::size_t MipsGOTParser<ELFT>::getGOTTotal(ArrayRef<uint8_t> GOT) const { |
| 2109 | return GOT.size() / sizeof(GOTEntry); |
| 2110 | } |
| 2111 | |
| 2112 | template <class ELFT> |
| 2113 | const typename MipsGOTParser<ELFT>::GOTEntry * |
| 2114 | MipsGOTParser<ELFT>::makeGOTIter(ArrayRef<uint8_t> GOT, std::size_t EntryNum) { |
| 2115 | const char *Data = reinterpret_cast<const char *>(GOT.data()); |
| 2116 | return reinterpret_cast<const GOTEntry *>(Data + EntryNum * sizeof(GOTEntry)); |
| 2117 | } |
| 2118 | |
| 2119 | template <class ELFT> |
| 2120 | void MipsGOTParser<ELFT>::printGotEntry(uint64_t GotAddr, |
| 2121 | const GOTEntry *BeginIt, |
| 2122 | const GOTEntry *It) { |
| 2123 | int64_t Offset = std::distance(BeginIt, It) * sizeof(GOTEntry); |
| 2124 | W.printHex("Address", GotAddr + Offset); |
| 2125 | W.printNumber("Access", Offset - 0x7ff0); |
| 2126 | W.printHex("Initial", *It); |
| 2127 | } |
| 2128 | |
| 2129 | template <class ELFT> |
| 2130 | void MipsGOTParser<ELFT>::printGlobalGotEntry( |
| 2131 | uint64_t GotAddr, const GOTEntry *BeginIt, const GOTEntry *It, |
| 2132 | const Elf_Sym *Sym, StringRef StrTable, bool IsDynamic) { |
| 2133 | printGotEntry(GotAddr, BeginIt, It); |
| 2134 | |
| 2135 | W.printHex("Value", Sym->st_value); |
| 2136 | W.printEnum("Type", Sym->getType(), makeArrayRef(ElfSymbolTypes)); |
| 2137 | |
| 2138 | unsigned SectionIndex = 0; |
| 2139 | StringRef SectionName; |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 2140 | getSectionNameIndex(*Obj, Sym, Dumper->dynamic_symbols().begin(), |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2141 | Dumper->getShndxTable(), SectionName, SectionIndex); |
| 2142 | W.printHex("Section", SectionName, SectionIndex); |
| 2143 | |
| 2144 | std::string FullSymbolName = |
| 2145 | Dumper->getFullSymbolName(Sym, StrTable, IsDynamic); |
| 2146 | W.printNumber("Name", FullSymbolName, Sym->st_name); |
| 2147 | } |
| 2148 | |
| 2149 | template <class ELFT> |
| 2150 | void MipsGOTParser<ELFT>::printPLTEntry(uint64_t PLTAddr, |
| 2151 | const GOTEntry *BeginIt, |
| 2152 | const GOTEntry *It, StringRef Purpose) { |
| 2153 | DictScope D(W, "Entry"); |
| 2154 | int64_t Offset = std::distance(BeginIt, It) * sizeof(GOTEntry); |
| 2155 | W.printHex("Address", PLTAddr + Offset); |
| 2156 | W.printHex("Initial", *It); |
| 2157 | W.printString("Purpose", Purpose); |
| 2158 | } |
| 2159 | |
| 2160 | template <class ELFT> |
| 2161 | void MipsGOTParser<ELFT>::printPLTEntry(uint64_t PLTAddr, |
| 2162 | const GOTEntry *BeginIt, |
| 2163 | const GOTEntry *It, StringRef StrTable, |
| 2164 | const Elf_Sym *Sym) { |
| 2165 | DictScope D(W, "Entry"); |
| 2166 | int64_t Offset = std::distance(BeginIt, It) * sizeof(GOTEntry); |
| 2167 | W.printHex("Address", PLTAddr + Offset); |
| 2168 | W.printHex("Initial", *It); |
| 2169 | W.printHex("Value", Sym->st_value); |
| 2170 | W.printEnum("Type", Sym->getType(), makeArrayRef(ElfSymbolTypes)); |
| 2171 | |
| 2172 | unsigned SectionIndex = 0; |
| 2173 | StringRef SectionName; |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 2174 | getSectionNameIndex(*Obj, Sym, Dumper->dynamic_symbols().begin(), |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2175 | Dumper->getShndxTable(), SectionName, SectionIndex); |
| 2176 | W.printHex("Section", SectionName, SectionIndex); |
| 2177 | |
| 2178 | std::string FullSymbolName = Dumper->getFullSymbolName(Sym, StrTable, true); |
| 2179 | W.printNumber("Name", FullSymbolName, Sym->st_name); |
| 2180 | } |
| 2181 | |
| 2182 | template <class ELFT> void ELFDumper<ELFT>::printMipsPLTGOT() { |
| 2183 | if (Obj->getHeader()->e_machine != EM_MIPS) { |
| 2184 | W.startLine() << "MIPS PLT GOT is available for MIPS targets only.\n"; |
| 2185 | return; |
| 2186 | } |
| 2187 | |
| 2188 | MipsGOTParser<ELFT> GOTParser(this, Obj, dynamic_table(), W); |
| 2189 | GOTParser.parseGOT(); |
| 2190 | GOTParser.parsePLT(); |
| 2191 | } |
| 2192 | |
| 2193 | static const EnumEntry<unsigned> ElfMipsISAExtType[] = { |
| 2194 | {"None", Mips::AFL_EXT_NONE}, |
| 2195 | {"Broadcom SB-1", Mips::AFL_EXT_SB1}, |
| 2196 | {"Cavium Networks Octeon", Mips::AFL_EXT_OCTEON}, |
| 2197 | {"Cavium Networks Octeon2", Mips::AFL_EXT_OCTEON2}, |
| 2198 | {"Cavium Networks OcteonP", Mips::AFL_EXT_OCTEONP}, |
| 2199 | {"Cavium Networks Octeon3", Mips::AFL_EXT_OCTEON3}, |
| 2200 | {"LSI R4010", Mips::AFL_EXT_4010}, |
| 2201 | {"Loongson 2E", Mips::AFL_EXT_LOONGSON_2E}, |
| 2202 | {"Loongson 2F", Mips::AFL_EXT_LOONGSON_2F}, |
| 2203 | {"Loongson 3A", Mips::AFL_EXT_LOONGSON_3A}, |
| 2204 | {"MIPS R4650", Mips::AFL_EXT_4650}, |
| 2205 | {"MIPS R5900", Mips::AFL_EXT_5900}, |
| 2206 | {"MIPS R10000", Mips::AFL_EXT_10000}, |
| 2207 | {"NEC VR4100", Mips::AFL_EXT_4100}, |
| 2208 | {"NEC VR4111/VR4181", Mips::AFL_EXT_4111}, |
| 2209 | {"NEC VR4120", Mips::AFL_EXT_4120}, |
| 2210 | {"NEC VR5400", Mips::AFL_EXT_5400}, |
| 2211 | {"NEC VR5500", Mips::AFL_EXT_5500}, |
| 2212 | {"RMI Xlr", Mips::AFL_EXT_XLR}, |
| 2213 | {"Toshiba R3900", Mips::AFL_EXT_3900} |
| 2214 | }; |
| 2215 | |
| 2216 | static const EnumEntry<unsigned> ElfMipsASEFlags[] = { |
| 2217 | {"DSP", Mips::AFL_ASE_DSP}, |
| 2218 | {"DSPR2", Mips::AFL_ASE_DSPR2}, |
| 2219 | {"Enhanced VA Scheme", Mips::AFL_ASE_EVA}, |
| 2220 | {"MCU", Mips::AFL_ASE_MCU}, |
| 2221 | {"MDMX", Mips::AFL_ASE_MDMX}, |
| 2222 | {"MIPS-3D", Mips::AFL_ASE_MIPS3D}, |
| 2223 | {"MT", Mips::AFL_ASE_MT}, |
| 2224 | {"SmartMIPS", Mips::AFL_ASE_SMARTMIPS}, |
| 2225 | {"VZ", Mips::AFL_ASE_VIRT}, |
| 2226 | {"MSA", Mips::AFL_ASE_MSA}, |
| 2227 | {"MIPS16", Mips::AFL_ASE_MIPS16}, |
| 2228 | {"microMIPS", Mips::AFL_ASE_MICROMIPS}, |
| 2229 | {"XPA", Mips::AFL_ASE_XPA} |
| 2230 | }; |
| 2231 | |
| 2232 | static const EnumEntry<unsigned> ElfMipsFpABIType[] = { |
| 2233 | {"Hard or soft float", Mips::Val_GNU_MIPS_ABI_FP_ANY}, |
| 2234 | {"Hard float (double precision)", Mips::Val_GNU_MIPS_ABI_FP_DOUBLE}, |
| 2235 | {"Hard float (single precision)", Mips::Val_GNU_MIPS_ABI_FP_SINGLE}, |
| 2236 | {"Soft float", Mips::Val_GNU_MIPS_ABI_FP_SOFT}, |
| 2237 | {"Hard float (MIPS32r2 64-bit FPU 12 callee-saved)", |
| 2238 | Mips::Val_GNU_MIPS_ABI_FP_OLD_64}, |
| 2239 | {"Hard float (32-bit CPU, Any FPU)", Mips::Val_GNU_MIPS_ABI_FP_XX}, |
| 2240 | {"Hard float (32-bit CPU, 64-bit FPU)", Mips::Val_GNU_MIPS_ABI_FP_64}, |
| 2241 | {"Hard float compat (32-bit CPU, 64-bit FPU)", |
| 2242 | Mips::Val_GNU_MIPS_ABI_FP_64A} |
| 2243 | }; |
| 2244 | |
| 2245 | static const EnumEntry<unsigned> ElfMipsFlags1[] { |
| 2246 | {"ODDSPREG", Mips::AFL_FLAGS1_ODDSPREG}, |
| 2247 | }; |
| 2248 | |
| 2249 | static int getMipsRegisterSize(uint8_t Flag) { |
| 2250 | switch (Flag) { |
| 2251 | case Mips::AFL_REG_NONE: |
| 2252 | return 0; |
| 2253 | case Mips::AFL_REG_32: |
| 2254 | return 32; |
| 2255 | case Mips::AFL_REG_64: |
| 2256 | return 64; |
| 2257 | case Mips::AFL_REG_128: |
| 2258 | return 128; |
| 2259 | default: |
| 2260 | return -1; |
| 2261 | } |
| 2262 | } |
| 2263 | |
| 2264 | template <class ELFT> void ELFDumper<ELFT>::printMipsABIFlags() { |
| 2265 | const Elf_Shdr *Shdr = findSectionByName(*Obj, ".MIPS.abiflags"); |
| 2266 | if (!Shdr) { |
| 2267 | W.startLine() << "There is no .MIPS.abiflags section in the file.\n"; |
| 2268 | return; |
| 2269 | } |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 2270 | ArrayRef<uint8_t> Sec = unwrapOrError(Obj->getSectionContents(Shdr)); |
| 2271 | if (Sec.size() != sizeof(Elf_Mips_ABIFlags<ELFT>)) { |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2272 | W.startLine() << "The .MIPS.abiflags section has a wrong size.\n"; |
| 2273 | return; |
| 2274 | } |
| 2275 | |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 2276 | auto *Flags = reinterpret_cast<const Elf_Mips_ABIFlags<ELFT> *>(Sec.data()); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2277 | |
| 2278 | raw_ostream &OS = W.getOStream(); |
| 2279 | DictScope GS(W, "MIPS ABI Flags"); |
| 2280 | |
| 2281 | W.printNumber("Version", Flags->version); |
| 2282 | W.startLine() << "ISA: "; |
| 2283 | if (Flags->isa_rev <= 1) |
| 2284 | OS << format("MIPS%u", Flags->isa_level); |
| 2285 | else |
| 2286 | OS << format("MIPS%ur%u", Flags->isa_level, Flags->isa_rev); |
| 2287 | OS << "\n"; |
| 2288 | W.printEnum("ISA Extension", Flags->isa_ext, makeArrayRef(ElfMipsISAExtType)); |
| 2289 | W.printFlags("ASEs", Flags->ases, makeArrayRef(ElfMipsASEFlags)); |
| 2290 | W.printEnum("FP ABI", Flags->fp_abi, makeArrayRef(ElfMipsFpABIType)); |
| 2291 | W.printNumber("GPR size", getMipsRegisterSize(Flags->gpr_size)); |
| 2292 | W.printNumber("CPR1 size", getMipsRegisterSize(Flags->cpr1_size)); |
| 2293 | W.printNumber("CPR2 size", getMipsRegisterSize(Flags->cpr2_size)); |
| 2294 | W.printFlags("Flags 1", Flags->flags1, makeArrayRef(ElfMipsFlags1)); |
| 2295 | W.printHex("Flags 2", Flags->flags2); |
| 2296 | } |
| 2297 | |
Simon Atanasyan | 8a71b53 | 2016-05-04 05:58:57 +0000 | [diff] [blame] | 2298 | template <class ELFT> |
| 2299 | static void printMipsReginfoData(ScopedPrinter &W, |
| 2300 | const Elf_Mips_RegInfo<ELFT> &Reginfo) { |
| 2301 | W.printHex("GP", Reginfo.ri_gp_value); |
| 2302 | W.printHex("General Mask", Reginfo.ri_gprmask); |
| 2303 | W.printHex("Co-Proc Mask0", Reginfo.ri_cprmask[0]); |
| 2304 | W.printHex("Co-Proc Mask1", Reginfo.ri_cprmask[1]); |
| 2305 | W.printHex("Co-Proc Mask2", Reginfo.ri_cprmask[2]); |
| 2306 | W.printHex("Co-Proc Mask3", Reginfo.ri_cprmask[3]); |
| 2307 | } |
| 2308 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2309 | template <class ELFT> void ELFDumper<ELFT>::printMipsReginfo() { |
| 2310 | const Elf_Shdr *Shdr = findSectionByName(*Obj, ".reginfo"); |
| 2311 | if (!Shdr) { |
| 2312 | W.startLine() << "There is no .reginfo section in the file.\n"; |
| 2313 | return; |
| 2314 | } |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 2315 | ArrayRef<uint8_t> Sec = unwrapOrError(Obj->getSectionContents(Shdr)); |
| 2316 | if (Sec.size() != sizeof(Elf_Mips_RegInfo<ELFT>)) { |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2317 | W.startLine() << "The .reginfo section has a wrong size.\n"; |
| 2318 | return; |
| 2319 | } |
| 2320 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2321 | DictScope GS(W, "MIPS RegInfo"); |
Simon Atanasyan | 8a71b53 | 2016-05-04 05:58:57 +0000 | [diff] [blame] | 2322 | auto *Reginfo = reinterpret_cast<const Elf_Mips_RegInfo<ELFT> *>(Sec.data()); |
| 2323 | printMipsReginfoData(W, *Reginfo); |
| 2324 | } |
| 2325 | |
| 2326 | template <class ELFT> void ELFDumper<ELFT>::printMipsOptions() { |
| 2327 | const Elf_Shdr *Shdr = findSectionByName(*Obj, ".MIPS.options"); |
| 2328 | if (!Shdr) { |
| 2329 | W.startLine() << "There is no .MIPS.options section in the file.\n"; |
| 2330 | return; |
| 2331 | } |
| 2332 | |
| 2333 | DictScope GS(W, "MIPS Options"); |
| 2334 | |
| 2335 | ArrayRef<uint8_t> Sec = unwrapOrError(Obj->getSectionContents(Shdr)); |
| 2336 | while (!Sec.empty()) { |
| 2337 | if (Sec.size() < sizeof(Elf_Mips_Options<ELFT>)) { |
| 2338 | W.startLine() << "The .MIPS.options section has a wrong size.\n"; |
| 2339 | return; |
| 2340 | } |
| 2341 | auto *O = reinterpret_cast<const Elf_Mips_Options<ELFT> *>(Sec.data()); |
| 2342 | DictScope GS(W, getElfMipsOptionsOdkType(O->kind)); |
| 2343 | switch (O->kind) { |
| 2344 | case ODK_REGINFO: |
| 2345 | printMipsReginfoData(W, O->getRegInfo()); |
| 2346 | break; |
| 2347 | default: |
| 2348 | W.startLine() << "Unsupported MIPS options tag.\n"; |
| 2349 | break; |
| 2350 | } |
| 2351 | Sec = Sec.slice(O->size); |
| 2352 | } |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2353 | } |
| 2354 | |
| 2355 | template <class ELFT> void ELFDumper<ELFT>::printStackMap() const { |
| 2356 | const Elf_Shdr *StackMapSection = nullptr; |
Rafael Espindola | 25be8c8 | 2016-11-02 14:10:57 +0000 | [diff] [blame] | 2357 | for (const auto &Sec : unwrapOrError(Obj->sections())) { |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 2358 | StringRef Name = unwrapOrError(Obj->getSectionName(&Sec)); |
| 2359 | if (Name == ".llvm_stackmaps") { |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2360 | StackMapSection = &Sec; |
| 2361 | break; |
| 2362 | } |
| 2363 | } |
| 2364 | |
| 2365 | if (!StackMapSection) |
| 2366 | return; |
| 2367 | |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 2368 | ArrayRef<uint8_t> StackMapContentsArray = |
| 2369 | unwrapOrError(Obj->getSectionContents(StackMapSection)); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2370 | |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 2371 | prettyPrintStackMap(outs(), StackMapV2Parser<ELFT::TargetEndianness>( |
| 2372 | StackMapContentsArray)); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2373 | } |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2374 | |
Hemant Kulkarni | ab4a46f | 2016-01-26 19:46:39 +0000 | [diff] [blame] | 2375 | template <class ELFT> void ELFDumper<ELFT>::printGroupSections() { |
Hemant Kulkarni | 206ba84 | 2016-03-09 19:16:13 +0000 | [diff] [blame] | 2376 | ELFDumperStyle->printGroupSections(Obj); |
Hemant Kulkarni | ab4a46f | 2016-01-26 19:46:39 +0000 | [diff] [blame] | 2377 | } |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2378 | |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2379 | static inline void printFields(formatted_raw_ostream &OS, StringRef Str1, |
| 2380 | StringRef Str2) { |
| 2381 | OS.PadToColumn(2u); |
| 2382 | OS << Str1; |
| 2383 | OS.PadToColumn(37u); |
| 2384 | OS << Str2 << "\n"; |
| 2385 | OS.flush(); |
| 2386 | } |
| 2387 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2388 | template <class ELFT> void GNUStyle<ELFT>::printFileHeaders(const ELFO *Obj) { |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2389 | const Elf_Ehdr *e = Obj->getHeader(); |
| 2390 | OS << "ELF Header:\n"; |
| 2391 | OS << " Magic: "; |
| 2392 | std::string Str; |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2393 | for (int i = 0; i < ELF::EI_NIDENT; i++) |
| 2394 | OS << format(" %02x", static_cast<int>(e->e_ident[i])); |
| 2395 | OS << "\n"; |
| 2396 | Str = printEnum(e->e_ident[ELF::EI_CLASS], makeArrayRef(ElfClass)); |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2397 | printFields(OS, "Class:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2398 | Str = printEnum(e->e_ident[ELF::EI_DATA], makeArrayRef(ElfDataEncoding)); |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2399 | printFields(OS, "Data:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2400 | OS.PadToColumn(2u); |
| 2401 | OS << "Version:"; |
| 2402 | OS.PadToColumn(37u); |
| 2403 | OS << to_hexString(e->e_ident[ELF::EI_VERSION]); |
| 2404 | if (e->e_version == ELF::EV_CURRENT) |
| 2405 | OS << " (current)"; |
| 2406 | OS << "\n"; |
| 2407 | Str = printEnum(e->e_ident[ELF::EI_OSABI], makeArrayRef(ElfOSABI)); |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2408 | printFields(OS, "OS/ABI:", Str); |
Chandler Carruth | e8fa5ae | 2016-11-03 17:11:11 +0000 | [diff] [blame] | 2409 | Str = "0x" + to_hexString(e->e_ident[ELF::EI_ABIVERSION]); |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2410 | printFields(OS, "ABI Version:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2411 | Str = printEnum(e->e_type, makeArrayRef(ElfObjectFileType)); |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2412 | printFields(OS, "Type:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2413 | Str = printEnum(e->e_machine, makeArrayRef(ElfMachineType)); |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2414 | printFields(OS, "Machine:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2415 | Str = "0x" + to_hexString(e->e_version); |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2416 | printFields(OS, "Version:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2417 | Str = "0x" + to_hexString(e->e_entry); |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2418 | printFields(OS, "Entry point address:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2419 | Str = to_string(e->e_phoff) + " (bytes into file)"; |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2420 | printFields(OS, "Start of program headers:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2421 | Str = to_string(e->e_shoff) + " (bytes into file)"; |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2422 | printFields(OS, "Start of section headers:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2423 | Str = "0x" + to_hexString(e->e_flags); |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2424 | printFields(OS, "Flags:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2425 | Str = to_string(e->e_ehsize) + " (bytes)"; |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2426 | printFields(OS, "Size of this header:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2427 | Str = to_string(e->e_phentsize) + " (bytes)"; |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2428 | printFields(OS, "Size of program headers:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2429 | Str = to_string(e->e_phnum); |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2430 | printFields(OS, "Number of program headers:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2431 | Str = to_string(e->e_shentsize) + " (bytes)"; |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2432 | printFields(OS, "Size of section headers:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2433 | Str = to_string(e->e_shnum); |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2434 | printFields(OS, "Number of section headers:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2435 | Str = to_string(e->e_shstrndx); |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2436 | printFields(OS, "Section header string table index:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2437 | } |
| 2438 | |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 2439 | namespace { |
| 2440 | struct GroupMember { |
| 2441 | StringRef Name; |
| 2442 | uint64_t Index; |
| 2443 | }; |
| 2444 | |
| 2445 | struct GroupSection { |
| 2446 | StringRef Name; |
| 2447 | StringRef Signature; |
| 2448 | uint64_t ShName; |
| 2449 | uint64_t Index; |
| 2450 | uint32_t Type; |
| 2451 | std::vector<GroupMember> Members; |
| 2452 | }; |
| 2453 | |
| 2454 | template <class ELFT> |
| 2455 | std::vector<GroupSection> getGroups(const ELFFile<ELFT> *Obj) { |
| 2456 | using Elf_Shdr = typename ELFFile<ELFT>::Elf_Shdr; |
| 2457 | using Elf_Sym = typename ELFFile<ELFT>::Elf_Sym; |
| 2458 | using Elf_Word = typename ELFFile<ELFT>::Elf_Word; |
| 2459 | |
| 2460 | std::vector<GroupSection> Ret; |
| 2461 | uint64_t I = 0; |
George Rimar | 3c0f396 | 2017-09-14 07:26:14 +0000 | [diff] [blame] | 2462 | for (const Elf_Shdr &Sec : unwrapOrError(Obj->sections())) { |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 2463 | ++I; |
| 2464 | if (Sec.sh_type != ELF::SHT_GROUP) |
| 2465 | continue; |
| 2466 | |
| 2467 | const Elf_Shdr *Symtab = unwrapOrError(Obj->getSection(Sec.sh_link)); |
| 2468 | StringRef StrTable = unwrapOrError(Obj->getStringTableForSymtab(*Symtab)); |
| 2469 | const Elf_Sym *Sym = |
| 2470 | unwrapOrError(Obj->template getEntry<Elf_Sym>(Symtab, Sec.sh_info)); |
| 2471 | auto Data = |
| 2472 | unwrapOrError(Obj->template getSectionContentsAsArray<Elf_Word>(&Sec)); |
| 2473 | |
| 2474 | StringRef Name = unwrapOrError(Obj->getSectionName(&Sec)); |
| 2475 | StringRef Signature = StrTable.data() + Sym->st_name; |
| 2476 | Ret.push_back({Name, Signature, Sec.sh_name, I - 1, Data[0], {}}); |
| 2477 | |
| 2478 | std::vector<GroupMember> &GM = Ret.back().Members; |
| 2479 | for (uint32_t Ndx : Data.slice(1)) { |
| 2480 | auto Sec = unwrapOrError(Obj->getSection(Ndx)); |
| 2481 | const StringRef Name = unwrapOrError(Obj->getSectionName(Sec)); |
| 2482 | GM.push_back({Name, Ndx}); |
George Rimar | 3c0f396 | 2017-09-14 07:26:14 +0000 | [diff] [blame] | 2483 | } |
George Rimar | c2657cd | 2017-09-14 07:17:04 +0000 | [diff] [blame] | 2484 | } |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 2485 | return Ret; |
| 2486 | } |
George Rimar | 762abff6 | 2017-09-16 14:29:51 +0000 | [diff] [blame] | 2487 | |
| 2488 | DenseMap<uint64_t, const GroupSection *> |
| 2489 | mapSectionsToGroups(ArrayRef<GroupSection> Groups) { |
| 2490 | DenseMap<uint64_t, const GroupSection *> Ret; |
| 2491 | for (const GroupSection &G : Groups) |
| 2492 | for (const GroupMember &GM : G.Members) |
| 2493 | Ret.insert({GM.Index, &G}); |
| 2494 | return Ret; |
| 2495 | } |
| 2496 | |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 2497 | } // namespace |
| 2498 | |
| 2499 | template <class ELFT> void GNUStyle<ELFT>::printGroupSections(const ELFO *Obj) { |
| 2500 | std::vector<GroupSection> V = getGroups<ELFT>(Obj); |
George Rimar | 762abff6 | 2017-09-16 14:29:51 +0000 | [diff] [blame] | 2501 | DenseMap<uint64_t, const GroupSection *> Map = mapSectionsToGroups(V); |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 2502 | for (const GroupSection &G : V) { |
| 2503 | OS << "\n" |
| 2504 | << getGroupType(G.Type) << " group section [" |
| 2505 | << format_decimal(G.Index, 5) << "] `" << G.Name << "' [" << G.Signature |
| 2506 | << "] contains " << G.Members.size() << " sections:\n" |
| 2507 | << " [Index] Name\n"; |
George Rimar | 762abff6 | 2017-09-16 14:29:51 +0000 | [diff] [blame] | 2508 | for (const GroupMember &GM : G.Members) { |
| 2509 | const GroupSection *MainGroup = Map[GM.Index]; |
| 2510 | if (MainGroup != &G) { |
| 2511 | OS.flush(); |
| 2512 | errs() << "Error: section [" << format_decimal(GM.Index, 5) |
| 2513 | << "] in group section [" << format_decimal(G.Index, 5) |
| 2514 | << "] already in group section [" |
| 2515 | << format_decimal(MainGroup->Index, 5) << "]"; |
| 2516 | errs().flush(); |
| 2517 | continue; |
| 2518 | } |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 2519 | OS << " [" << format_decimal(GM.Index, 5) << "] " << GM.Name << "\n"; |
George Rimar | 762abff6 | 2017-09-16 14:29:51 +0000 | [diff] [blame] | 2520 | } |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 2521 | } |
| 2522 | |
| 2523 | if (V.empty()) |
Hemant Kulkarni | 206ba84 | 2016-03-09 19:16:13 +0000 | [diff] [blame] | 2524 | OS << "There are no section groups in this file.\n"; |
| 2525 | } |
| 2526 | |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2527 | template <class ELFT> |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2528 | void GNUStyle<ELFT>::printRelocation(const ELFO *Obj, const Elf_Shdr *SymTab, |
| 2529 | const Elf_Rela &R, bool IsRela) { |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 2530 | std::string Offset, Info, Addend, Value; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2531 | SmallString<32> RelocName; |
| 2532 | StringRef StrTable = unwrapOrError(Obj->getStringTableForSymtab(*SymTab)); |
| 2533 | StringRef TargetName; |
| 2534 | const Elf_Sym *Sym = nullptr; |
Hemant Kulkarni | 2e3254e | 2016-03-29 14:20:20 +0000 | [diff] [blame] | 2535 | unsigned Width = ELFT::Is64Bits ? 16 : 8; |
Hemant Kulkarni | a79c798 | 2016-03-29 02:41:49 +0000 | [diff] [blame] | 2536 | unsigned Bias = ELFT::Is64Bits ? 8 : 0; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2537 | |
| 2538 | // First two fields are bit width dependent. The rest of them are after are |
| 2539 | // fixed width. |
| 2540 | Field Fields[5] = {0, 10 + Bias, 19 + 2 * Bias, 42 + 2 * Bias, 53 + 2 * Bias}; |
| 2541 | Obj->getRelocationTypeName(R.getType(Obj->isMips64EL()), RelocName); |
Rafael Espindola | ed1395a | 2016-11-03 18:05:33 +0000 | [diff] [blame] | 2542 | Sym = unwrapOrError(Obj->getRelocationSymbol(&R, SymTab)); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2543 | if (Sym && Sym->getType() == ELF::STT_SECTION) { |
| 2544 | const Elf_Shdr *Sec = unwrapOrError( |
| 2545 | Obj->getSection(Sym, SymTab, this->dumper()->getShndxTable())); |
| 2546 | TargetName = unwrapOrError(Obj->getSectionName(Sec)); |
| 2547 | } else if (Sym) { |
| 2548 | TargetName = unwrapOrError(Sym->getName(StrTable)); |
| 2549 | } |
| 2550 | |
| 2551 | if (Sym && IsRela) { |
| 2552 | if (R.r_addend < 0) |
| 2553 | Addend = " - "; |
| 2554 | else |
| 2555 | Addend = " + "; |
| 2556 | } |
| 2557 | |
| 2558 | Offset = to_string(format_hex_no_prefix(R.r_offset, Width)); |
| 2559 | Info = to_string(format_hex_no_prefix(R.r_info, Width)); |
| 2560 | |
| 2561 | int64_t RelAddend = R.r_addend; |
| 2562 | if (IsRela) |
| 2563 | Addend += to_hexString(std::abs(RelAddend), false); |
| 2564 | |
| 2565 | if (Sym) |
| 2566 | Value = to_string(format_hex_no_prefix(Sym->getValue(), Width)); |
| 2567 | |
| 2568 | Fields[0].Str = Offset; |
| 2569 | Fields[1].Str = Info; |
| 2570 | Fields[2].Str = RelocName; |
| 2571 | Fields[3].Str = Value; |
| 2572 | Fields[4].Str = TargetName; |
| 2573 | for (auto &field : Fields) |
| 2574 | printField(field); |
Hemant Kulkarni | a79c798 | 2016-03-29 02:41:49 +0000 | [diff] [blame] | 2575 | OS << Addend; |
| 2576 | OS << "\n"; |
| 2577 | } |
| 2578 | |
| 2579 | static inline void printRelocHeader(raw_ostream &OS, bool Is64, bool IsRela) { |
| 2580 | if (Is64) |
| 2581 | OS << " Offset Info Type" |
| 2582 | << " Symbol's Value Symbol's Name"; |
| 2583 | else |
| 2584 | OS << " Offset Info Type Sym. Value " |
| 2585 | << "Symbol's Name"; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2586 | if (IsRela) |
Hemant Kulkarni | 2e3254e | 2016-03-29 14:20:20 +0000 | [diff] [blame] | 2587 | OS << (IsRela ? " + Addend" : ""); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2588 | OS << "\n"; |
| 2589 | } |
| 2590 | |
| 2591 | template <class ELFT> void GNUStyle<ELFT>::printRelocations(const ELFO *Obj) { |
| 2592 | bool HasRelocSections = false; |
Rafael Espindola | 25be8c8 | 2016-11-02 14:10:57 +0000 | [diff] [blame] | 2593 | for (const Elf_Shdr &Sec : unwrapOrError(Obj->sections())) { |
Peter Collingbourne | 689e6c05 | 2017-10-25 03:37:12 +0000 | [diff] [blame^] | 2594 | if (Sec.sh_type != ELF::SHT_REL && Sec.sh_type != ELF::SHT_RELA && |
| 2595 | Sec.sh_type != ELF::SHT_ANDROID_REL && |
| 2596 | Sec.sh_type != ELF::SHT_ANDROID_RELA) |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2597 | continue; |
| 2598 | HasRelocSections = true; |
| 2599 | StringRef Name = unwrapOrError(Obj->getSectionName(&Sec)); |
| 2600 | unsigned Entries = Sec.getEntityCount(); |
| 2601 | uintX_t Offset = Sec.sh_offset; |
| 2602 | OS << "\nRelocation section '" << Name << "' at offset 0x" |
| 2603 | << to_hexString(Offset, false) << " contains " << Entries |
| 2604 | << " entries:\n"; |
Peter Collingbourne | 689e6c05 | 2017-10-25 03:37:12 +0000 | [diff] [blame^] | 2605 | printRelocHeader(OS, ELFT::Is64Bits, |
| 2606 | Sec.sh_type == ELF::SHT_RELA || |
| 2607 | Sec.sh_type == ELF::SHT_ANDROID_RELA); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2608 | const Elf_Shdr *SymTab = unwrapOrError(Obj->getSection(Sec.sh_link)); |
Peter Collingbourne | 689e6c05 | 2017-10-25 03:37:12 +0000 | [diff] [blame^] | 2609 | switch (Sec.sh_type) { |
| 2610 | case ELF::SHT_REL: |
Rafael Espindola | 354680a | 2016-11-03 19:07:15 +0000 | [diff] [blame] | 2611 | for (const auto &R : unwrapOrError(Obj->rels(&Sec))) { |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2612 | Elf_Rela Rela; |
| 2613 | Rela.r_offset = R.r_offset; |
| 2614 | Rela.r_info = R.r_info; |
| 2615 | Rela.r_addend = 0; |
| 2616 | printRelocation(Obj, SymTab, Rela, false); |
| 2617 | } |
Peter Collingbourne | 689e6c05 | 2017-10-25 03:37:12 +0000 | [diff] [blame^] | 2618 | break; |
| 2619 | case ELF::SHT_RELA: |
Rafael Espindola | 354680a | 2016-11-03 19:07:15 +0000 | [diff] [blame] | 2620 | for (const auto &R : unwrapOrError(Obj->relas(&Sec))) |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2621 | printRelocation(Obj, SymTab, R, true); |
Peter Collingbourne | 689e6c05 | 2017-10-25 03:37:12 +0000 | [diff] [blame^] | 2622 | break; |
| 2623 | case ELF::SHT_ANDROID_REL: |
| 2624 | case ELF::SHT_ANDROID_RELA: |
| 2625 | for (const auto &R : unwrapOrError(Obj->android_relas(&Sec))) |
| 2626 | printRelocation(Obj, SymTab, R, Sec.sh_type == ELF::SHT_ANDROID_RELA); |
| 2627 | break; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2628 | } |
| 2629 | } |
| 2630 | if (!HasRelocSections) |
| 2631 | OS << "\nThere are no relocations in this file.\n"; |
| 2632 | } |
| 2633 | |
| 2634 | std::string getSectionTypeString(unsigned Arch, unsigned Type) { |
| 2635 | using namespace ELF; |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 2636 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2637 | switch (Arch) { |
| 2638 | case EM_ARM: |
| 2639 | switch (Type) { |
| 2640 | case SHT_ARM_EXIDX: |
| 2641 | return "ARM_EXIDX"; |
| 2642 | case SHT_ARM_PREEMPTMAP: |
| 2643 | return "ARM_PREEMPTMAP"; |
| 2644 | case SHT_ARM_ATTRIBUTES: |
| 2645 | return "ARM_ATTRIBUTES"; |
| 2646 | case SHT_ARM_DEBUGOVERLAY: |
| 2647 | return "ARM_DEBUGOVERLAY"; |
| 2648 | case SHT_ARM_OVERLAYSECTION: |
| 2649 | return "ARM_OVERLAYSECTION"; |
| 2650 | } |
| 2651 | case EM_X86_64: |
| 2652 | switch (Type) { |
| 2653 | case SHT_X86_64_UNWIND: |
| 2654 | return "X86_64_UNWIND"; |
| 2655 | } |
| 2656 | case EM_MIPS: |
| 2657 | case EM_MIPS_RS3_LE: |
| 2658 | switch (Type) { |
| 2659 | case SHT_MIPS_REGINFO: |
| 2660 | return "MIPS_REGINFO"; |
| 2661 | case SHT_MIPS_OPTIONS: |
| 2662 | return "MIPS_OPTIONS"; |
| 2663 | case SHT_MIPS_ABIFLAGS: |
| 2664 | return "MIPS_ABIFLAGS"; |
Simon Atanasyan | 6cfb101 | 2017-03-10 08:22:25 +0000 | [diff] [blame] | 2665 | case SHT_MIPS_DWARF: |
| 2666 | return "SHT_MIPS_DWARF"; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2667 | } |
| 2668 | } |
| 2669 | switch (Type) { |
| 2670 | case SHT_NULL: |
| 2671 | return "NULL"; |
| 2672 | case SHT_PROGBITS: |
| 2673 | return "PROGBITS"; |
| 2674 | case SHT_SYMTAB: |
| 2675 | return "SYMTAB"; |
| 2676 | case SHT_STRTAB: |
| 2677 | return "STRTAB"; |
| 2678 | case SHT_RELA: |
| 2679 | return "RELA"; |
| 2680 | case SHT_HASH: |
| 2681 | return "HASH"; |
| 2682 | case SHT_DYNAMIC: |
| 2683 | return "DYNAMIC"; |
| 2684 | case SHT_NOTE: |
| 2685 | return "NOTE"; |
| 2686 | case SHT_NOBITS: |
| 2687 | return "NOBITS"; |
| 2688 | case SHT_REL: |
| 2689 | return "REL"; |
| 2690 | case SHT_SHLIB: |
| 2691 | return "SHLIB"; |
| 2692 | case SHT_DYNSYM: |
| 2693 | return "DYNSYM"; |
| 2694 | case SHT_INIT_ARRAY: |
| 2695 | return "INIT_ARRAY"; |
| 2696 | case SHT_FINI_ARRAY: |
| 2697 | return "FINI_ARRAY"; |
| 2698 | case SHT_PREINIT_ARRAY: |
| 2699 | return "PREINIT_ARRAY"; |
| 2700 | case SHT_GROUP: |
| 2701 | return "GROUP"; |
| 2702 | case SHT_SYMTAB_SHNDX: |
| 2703 | return "SYMTAB SECTION INDICES"; |
Peter Collingbourne | f0e26e7 | 2017-06-14 18:52:12 +0000 | [diff] [blame] | 2704 | case SHT_LLVM_ODRTAB: |
| 2705 | return "LLVM_ODRTAB"; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2706 | // FIXME: Parse processor specific GNU attributes |
| 2707 | case SHT_GNU_ATTRIBUTES: |
| 2708 | return "ATTRIBUTES"; |
| 2709 | case SHT_GNU_HASH: |
| 2710 | return "GNU_HASH"; |
| 2711 | case SHT_GNU_verdef: |
| 2712 | return "VERDEF"; |
| 2713 | case SHT_GNU_verneed: |
| 2714 | return "VERNEED"; |
| 2715 | case SHT_GNU_versym: |
| 2716 | return "VERSYM"; |
| 2717 | default: |
| 2718 | return ""; |
| 2719 | } |
| 2720 | return ""; |
| 2721 | } |
| 2722 | |
| 2723 | template <class ELFT> void GNUStyle<ELFT>::printSections(const ELFO *Obj) { |
| 2724 | size_t SectionIndex = 0; |
| 2725 | std::string Number, Type, Size, Address, Offset, Flags, Link, Info, EntrySize, |
| 2726 | Alignment; |
| 2727 | unsigned Bias; |
| 2728 | unsigned Width; |
| 2729 | |
| 2730 | if (ELFT::Is64Bits) { |
| 2731 | Bias = 0; |
| 2732 | Width = 16; |
| 2733 | } else { |
| 2734 | Bias = 8; |
| 2735 | Width = 8; |
| 2736 | } |
| 2737 | OS << "There are " << to_string(Obj->getHeader()->e_shnum) |
| 2738 | << " section headers, starting at offset " |
| 2739 | << "0x" << to_hexString(Obj->getHeader()->e_shoff, false) << ":\n\n"; |
| 2740 | OS << "Section Headers:\n"; |
| 2741 | Field Fields[11] = {{"[Nr]", 2}, |
| 2742 | {"Name", 7}, |
| 2743 | {"Type", 25}, |
| 2744 | {"Address", 41}, |
| 2745 | {"Off", 58 - Bias}, |
| 2746 | {"Size", 65 - Bias}, |
| 2747 | {"ES", 72 - Bias}, |
| 2748 | {"Flg", 75 - Bias}, |
| 2749 | {"Lk", 79 - Bias}, |
| 2750 | {"Inf", 82 - Bias}, |
| 2751 | {"Al", 86 - Bias}}; |
| 2752 | for (auto &f : Fields) |
| 2753 | printField(f); |
| 2754 | OS << "\n"; |
| 2755 | |
Rafael Espindola | 25be8c8 | 2016-11-02 14:10:57 +0000 | [diff] [blame] | 2756 | for (const Elf_Shdr &Sec : unwrapOrError(Obj->sections())) { |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2757 | Number = to_string(SectionIndex); |
| 2758 | Fields[0].Str = Number; |
| 2759 | Fields[1].Str = unwrapOrError(Obj->getSectionName(&Sec)); |
| 2760 | Type = getSectionTypeString(Obj->getHeader()->e_machine, Sec.sh_type); |
| 2761 | Fields[2].Str = Type; |
| 2762 | Address = to_string(format_hex_no_prefix(Sec.sh_addr, Width)); |
| 2763 | Fields[3].Str = Address; |
| 2764 | Offset = to_string(format_hex_no_prefix(Sec.sh_offset, 6)); |
| 2765 | Fields[4].Str = Offset; |
| 2766 | Size = to_string(format_hex_no_prefix(Sec.sh_size, 6)); |
| 2767 | Fields[5].Str = Size; |
| 2768 | EntrySize = to_string(format_hex_no_prefix(Sec.sh_entsize, 2)); |
| 2769 | Fields[6].Str = EntrySize; |
| 2770 | Flags = getGNUFlags(Sec.sh_flags); |
| 2771 | Fields[7].Str = Flags; |
| 2772 | Link = to_string(Sec.sh_link); |
| 2773 | Fields[8].Str = Link; |
| 2774 | Info = to_string(Sec.sh_info); |
| 2775 | Fields[9].Str = Info; |
| 2776 | Alignment = to_string(Sec.sh_addralign); |
| 2777 | Fields[10].Str = Alignment; |
| 2778 | OS.PadToColumn(Fields[0].Column); |
| 2779 | OS << "[" << right_justify(Fields[0].Str, 2) << "]"; |
| 2780 | for (int i = 1; i < 7; i++) |
| 2781 | printField(Fields[i]); |
| 2782 | OS.PadToColumn(Fields[7].Column); |
| 2783 | OS << right_justify(Fields[7].Str, 3); |
| 2784 | OS.PadToColumn(Fields[8].Column); |
| 2785 | OS << right_justify(Fields[8].Str, 2); |
| 2786 | OS.PadToColumn(Fields[9].Column); |
| 2787 | OS << right_justify(Fields[9].Str, 3); |
| 2788 | OS.PadToColumn(Fields[10].Column); |
| 2789 | OS << right_justify(Fields[10].Str, 2); |
| 2790 | OS << "\n"; |
| 2791 | ++SectionIndex; |
| 2792 | } |
| 2793 | OS << "Key to Flags:\n" |
| 2794 | << " W (write), A (alloc), X (execute), M (merge), S (strings), l " |
| 2795 | "(large)\n" |
| 2796 | << " I (info), L (link order), G (group), T (TLS), E (exclude),\ |
| 2797 | x (unknown)\n" |
| 2798 | << " O (extra OS processing required) o (OS specific),\ |
| 2799 | p (processor specific)\n"; |
| 2800 | } |
| 2801 | |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 2802 | template <class ELFT> |
| 2803 | void GNUStyle<ELFT>::printSymtabMessage(const ELFO *Obj, StringRef Name, |
| 2804 | size_t Entries) { |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 2805 | if (!Name.empty()) |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 2806 | OS << "\nSymbol table '" << Name << "' contains " << Entries |
| 2807 | << " entries:\n"; |
| 2808 | else |
| 2809 | OS << "\n Symbol table for image:\n"; |
| 2810 | |
| 2811 | if (ELFT::Is64Bits) |
| 2812 | OS << " Num: Value Size Type Bind Vis Ndx Name\n"; |
| 2813 | else |
| 2814 | OS << " Num: Value Size Type Bind Vis Ndx Name\n"; |
| 2815 | } |
| 2816 | |
| 2817 | template <class ELFT> |
| 2818 | std::string GNUStyle<ELFT>::getSymbolSectionNdx(const ELFO *Obj, |
| 2819 | const Elf_Sym *Symbol, |
| 2820 | const Elf_Sym *FirstSym) { |
| 2821 | unsigned SectionIndex = Symbol->st_shndx; |
| 2822 | switch (SectionIndex) { |
| 2823 | case ELF::SHN_UNDEF: |
| 2824 | return "UND"; |
| 2825 | case ELF::SHN_ABS: |
| 2826 | return "ABS"; |
| 2827 | case ELF::SHN_COMMON: |
| 2828 | return "COM"; |
| 2829 | case ELF::SHN_XINDEX: |
Rafael Espindola | 714c295 | 2016-11-03 14:41:17 +0000 | [diff] [blame] | 2830 | SectionIndex = unwrapOrError(object::getExtendedSymbolTableIndex<ELFT>( |
Rafael Espindola | 7b2750a | 2016-11-03 13:58:15 +0000 | [diff] [blame] | 2831 | Symbol, FirstSym, this->dumper()->getShndxTable())); |
Galina Kistanova | 9ee35cf | 2017-05-31 01:33:39 +0000 | [diff] [blame] | 2832 | LLVM_FALLTHROUGH; |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 2833 | default: |
| 2834 | // Find if: |
| 2835 | // Processor specific |
| 2836 | if (SectionIndex >= ELF::SHN_LOPROC && SectionIndex <= ELF::SHN_HIPROC) |
| 2837 | return std::string("PRC[0x") + |
| 2838 | to_string(format_hex_no_prefix(SectionIndex, 4)) + "]"; |
| 2839 | // OS specific |
| 2840 | if (SectionIndex >= ELF::SHN_LOOS && SectionIndex <= ELF::SHN_HIOS) |
| 2841 | return std::string("OS[0x") + |
| 2842 | to_string(format_hex_no_prefix(SectionIndex, 4)) + "]"; |
| 2843 | // Architecture reserved: |
| 2844 | if (SectionIndex >= ELF::SHN_LORESERVE && |
| 2845 | SectionIndex <= ELF::SHN_HIRESERVE) |
| 2846 | return std::string("RSV[0x") + |
| 2847 | to_string(format_hex_no_prefix(SectionIndex, 4)) + "]"; |
| 2848 | // A normal section with an index |
| 2849 | return to_string(format_decimal(SectionIndex, 3)); |
| 2850 | } |
| 2851 | } |
| 2852 | |
| 2853 | template <class ELFT> |
| 2854 | void GNUStyle<ELFT>::printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, |
| 2855 | const Elf_Sym *FirstSym, StringRef StrTable, |
| 2856 | bool IsDynamic) { |
| 2857 | static int Idx = 0; |
| 2858 | static bool Dynamic = true; |
| 2859 | size_t Width; |
| 2860 | |
| 2861 | // If this function was called with a different value from IsDynamic |
| 2862 | // from last call, happens when we move from dynamic to static symbol |
| 2863 | // table, "Num" field should be reset. |
| 2864 | if (!Dynamic != !IsDynamic) { |
| 2865 | Idx = 0; |
| 2866 | Dynamic = false; |
| 2867 | } |
| 2868 | std::string Num, Name, Value, Size, Binding, Type, Visibility, Section; |
| 2869 | unsigned Bias = 0; |
| 2870 | if (ELFT::Is64Bits) { |
| 2871 | Bias = 8; |
| 2872 | Width = 16; |
| 2873 | } else { |
| 2874 | Bias = 0; |
| 2875 | Width = 8; |
| 2876 | } |
| 2877 | Field Fields[8] = {0, 8, 17 + Bias, 23 + Bias, |
| 2878 | 31 + Bias, 38 + Bias, 47 + Bias, 51 + Bias}; |
| 2879 | Num = to_string(format_decimal(Idx++, 6)) + ":"; |
| 2880 | Value = to_string(format_hex_no_prefix(Symbol->st_value, Width)); |
| 2881 | Size = to_string(format_decimal(Symbol->st_size, 5)); |
| 2882 | unsigned char SymbolType = Symbol->getType(); |
| 2883 | if (Obj->getHeader()->e_machine == ELF::EM_AMDGPU && |
| 2884 | SymbolType >= ELF::STT_LOOS && SymbolType < ELF::STT_HIOS) |
| 2885 | Type = printEnum(SymbolType, makeArrayRef(AMDGPUSymbolTypes)); |
| 2886 | else |
| 2887 | Type = printEnum(SymbolType, makeArrayRef(ElfSymbolTypes)); |
| 2888 | unsigned Vis = Symbol->getVisibility(); |
| 2889 | Binding = printEnum(Symbol->getBinding(), makeArrayRef(ElfSymbolBindings)); |
| 2890 | Visibility = printEnum(Vis, makeArrayRef(ElfSymbolVisibilities)); |
| 2891 | Section = getSymbolSectionNdx(Obj, Symbol, FirstSym); |
| 2892 | Name = this->dumper()->getFullSymbolName(Symbol, StrTable, IsDynamic); |
| 2893 | Fields[0].Str = Num; |
| 2894 | Fields[1].Str = Value; |
| 2895 | Fields[2].Str = Size; |
| 2896 | Fields[3].Str = Type; |
| 2897 | Fields[4].Str = Binding; |
| 2898 | Fields[5].Str = Visibility; |
| 2899 | Fields[6].Str = Section; |
| 2900 | Fields[7].Str = Name; |
| 2901 | for (auto &Entry : Fields) |
| 2902 | printField(Entry); |
| 2903 | OS << "\n"; |
| 2904 | } |
Hemant Kulkarni | a6ee9fd | 2016-11-23 18:04:23 +0000 | [diff] [blame] | 2905 | template <class ELFT> |
| 2906 | void GNUStyle<ELFT>::printHashedSymbol(const ELFO *Obj, const Elf_Sym *FirstSym, |
| 2907 | uint32_t Sym, StringRef StrTable, |
| 2908 | uint32_t Bucket) { |
| 2909 | std::string Num, Buc, Name, Value, Size, Binding, Type, Visibility, Section; |
| 2910 | unsigned Width, Bias = 0; |
| 2911 | if (ELFT::Is64Bits) { |
| 2912 | Bias = 8; |
| 2913 | Width = 16; |
| 2914 | } else { |
| 2915 | Bias = 0; |
| 2916 | Width = 8; |
| 2917 | } |
| 2918 | Field Fields[9] = {0, 6, 11, 20 + Bias, 25 + Bias, |
| 2919 | 34 + Bias, 41 + Bias, 49 + Bias, 53 + Bias}; |
| 2920 | Num = to_string(format_decimal(Sym, 5)); |
| 2921 | Buc = to_string(format_decimal(Bucket, 3)) + ":"; |
| 2922 | |
| 2923 | const auto Symbol = FirstSym + Sym; |
| 2924 | Value = to_string(format_hex_no_prefix(Symbol->st_value, Width)); |
| 2925 | Size = to_string(format_decimal(Symbol->st_size, 5)); |
| 2926 | unsigned char SymbolType = Symbol->getType(); |
| 2927 | if (Obj->getHeader()->e_machine == ELF::EM_AMDGPU && |
| 2928 | SymbolType >= ELF::STT_LOOS && SymbolType < ELF::STT_HIOS) |
| 2929 | Type = printEnum(SymbolType, makeArrayRef(AMDGPUSymbolTypes)); |
| 2930 | else |
| 2931 | Type = printEnum(SymbolType, makeArrayRef(ElfSymbolTypes)); |
| 2932 | unsigned Vis = Symbol->getVisibility(); |
| 2933 | Binding = printEnum(Symbol->getBinding(), makeArrayRef(ElfSymbolBindings)); |
| 2934 | Visibility = printEnum(Vis, makeArrayRef(ElfSymbolVisibilities)); |
| 2935 | Section = getSymbolSectionNdx(Obj, Symbol, FirstSym); |
| 2936 | Name = this->dumper()->getFullSymbolName(Symbol, StrTable, true); |
| 2937 | Fields[0].Str = Num; |
| 2938 | Fields[1].Str = Buc; |
| 2939 | Fields[2].Str = Value; |
| 2940 | Fields[3].Str = Size; |
| 2941 | Fields[4].Str = Type; |
| 2942 | Fields[5].Str = Binding; |
| 2943 | Fields[6].Str = Visibility; |
| 2944 | Fields[7].Str = Section; |
| 2945 | Fields[8].Str = Name; |
| 2946 | for (auto &Entry : Fields) |
| 2947 | printField(Entry); |
| 2948 | OS << "\n"; |
| 2949 | } |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 2950 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2951 | template <class ELFT> void GNUStyle<ELFT>::printSymbols(const ELFO *Obj) { |
Hemant Kulkarni | a6ee9fd | 2016-11-23 18:04:23 +0000 | [diff] [blame] | 2952 | if (opts::DynamicSymbols) |
| 2953 | return; |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 2954 | this->dumper()->printSymbolsHelper(true); |
| 2955 | this->dumper()->printSymbolsHelper(false); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2956 | } |
| 2957 | |
| 2958 | template <class ELFT> |
| 2959 | void GNUStyle<ELFT>::printDynamicSymbols(const ELFO *Obj) { |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 2960 | if (this->dumper()->getDynamicStringTable().empty()) |
Hemant Kulkarni | a6ee9fd | 2016-11-23 18:04:23 +0000 | [diff] [blame] | 2961 | return; |
| 2962 | auto StringTable = this->dumper()->getDynamicStringTable(); |
| 2963 | auto DynSyms = this->dumper()->dynamic_symbols(); |
| 2964 | auto GnuHash = this->dumper()->getGnuHashTable(); |
| 2965 | auto SysVHash = this->dumper()->getHashTable(); |
| 2966 | |
| 2967 | // If no hash or .gnu.hash found, try using symbol table |
| 2968 | if (GnuHash == nullptr && SysVHash == nullptr) |
| 2969 | this->dumper()->printSymbolsHelper(true); |
| 2970 | |
| 2971 | // Try printing .hash |
| 2972 | if (this->dumper()->getHashTable()) { |
| 2973 | OS << "\n Symbol table of .hash for image:\n"; |
| 2974 | if (ELFT::Is64Bits) |
| 2975 | OS << " Num Buc: Value Size Type Bind Vis Ndx Name"; |
| 2976 | else |
| 2977 | OS << " Num Buc: Value Size Type Bind Vis Ndx Name"; |
| 2978 | OS << "\n"; |
| 2979 | |
| 2980 | uint32_t NBuckets = SysVHash->nbucket; |
| 2981 | uint32_t NChains = SysVHash->nchain; |
| 2982 | auto Buckets = SysVHash->buckets(); |
| 2983 | auto Chains = SysVHash->chains(); |
| 2984 | for (uint32_t Buc = 0; Buc < NBuckets; Buc++) { |
| 2985 | if (Buckets[Buc] == ELF::STN_UNDEF) |
| 2986 | continue; |
| 2987 | for (uint32_t Ch = Buckets[Buc]; Ch < NChains; Ch = Chains[Ch]) { |
| 2988 | if (Ch == ELF::STN_UNDEF) |
| 2989 | break; |
| 2990 | printHashedSymbol(Obj, &DynSyms[0], Ch, StringTable, Buc); |
| 2991 | } |
| 2992 | } |
| 2993 | } |
| 2994 | |
| 2995 | // Try printing .gnu.hash |
| 2996 | if (GnuHash) { |
| 2997 | OS << "\n Symbol table of .gnu.hash for image:\n"; |
| 2998 | if (ELFT::Is64Bits) |
| 2999 | OS << " Num Buc: Value Size Type Bind Vis Ndx Name"; |
| 3000 | else |
| 3001 | OS << " Num Buc: Value Size Type Bind Vis Ndx Name"; |
| 3002 | OS << "\n"; |
| 3003 | uint32_t NBuckets = GnuHash->nbuckets; |
| 3004 | auto Buckets = GnuHash->buckets(); |
| 3005 | for (uint32_t Buc = 0; Buc < NBuckets; Buc++) { |
| 3006 | if (Buckets[Buc] == ELF::STN_UNDEF) |
| 3007 | continue; |
| 3008 | uint32_t Index = Buckets[Buc]; |
| 3009 | uint32_t GnuHashable = Index - GnuHash->symndx; |
| 3010 | // Print whole chain |
| 3011 | while (true) { |
| 3012 | printHashedSymbol(Obj, &DynSyms[0], Index++, StringTable, Buc); |
| 3013 | // Chain ends at symbol with stopper bit |
| 3014 | if ((GnuHash->values(DynSyms.size())[GnuHashable++] & 1) == 1) |
| 3015 | break; |
| 3016 | } |
| 3017 | } |
| 3018 | } |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3019 | } |
| 3020 | |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 3021 | static inline std::string printPhdrFlags(unsigned Flag) { |
| 3022 | std::string Str; |
| 3023 | Str = (Flag & PF_R) ? "R" : " "; |
| 3024 | Str += (Flag & PF_W) ? "W" : " "; |
| 3025 | Str += (Flag & PF_X) ? "E" : " "; |
| 3026 | return Str; |
| 3027 | } |
| 3028 | |
| 3029 | // SHF_TLS sections are only in PT_TLS, PT_LOAD or PT_GNU_RELRO |
| 3030 | // PT_TLS must only have SHF_TLS sections |
| 3031 | template <class ELFT> |
| 3032 | bool GNUStyle<ELFT>::checkTLSSections(const Elf_Phdr &Phdr, |
| 3033 | const Elf_Shdr &Sec) { |
| 3034 | return (((Sec.sh_flags & ELF::SHF_TLS) && |
| 3035 | ((Phdr.p_type == ELF::PT_TLS) || (Phdr.p_type == ELF::PT_LOAD) || |
| 3036 | (Phdr.p_type == ELF::PT_GNU_RELRO))) || |
| 3037 | (!(Sec.sh_flags & ELF::SHF_TLS) && Phdr.p_type != ELF::PT_TLS)); |
| 3038 | } |
| 3039 | |
| 3040 | // Non-SHT_NOBITS must have its offset inside the segment |
| 3041 | // Only non-zero section can be at end of segment |
| 3042 | template <class ELFT> |
| 3043 | bool GNUStyle<ELFT>::checkoffsets(const Elf_Phdr &Phdr, const Elf_Shdr &Sec) { |
| 3044 | if (Sec.sh_type == ELF::SHT_NOBITS) |
| 3045 | return true; |
| 3046 | bool IsSpecial = |
| 3047 | (Sec.sh_type == ELF::SHT_NOBITS) && ((Sec.sh_flags & ELF::SHF_TLS) != 0); |
| 3048 | // .tbss is special, it only has memory in PT_TLS and has NOBITS properties |
| 3049 | auto SectionSize = |
| 3050 | (IsSpecial && Phdr.p_type != ELF::PT_TLS) ? 0 : Sec.sh_size; |
| 3051 | if (Sec.sh_offset >= Phdr.p_offset) |
| 3052 | return ((Sec.sh_offset + SectionSize <= Phdr.p_filesz + Phdr.p_offset) |
| 3053 | /*only non-zero sized sections at end*/ && |
| 3054 | (Sec.sh_offset + 1 <= Phdr.p_offset + Phdr.p_filesz)); |
| 3055 | return false; |
| 3056 | } |
| 3057 | |
| 3058 | // SHF_ALLOC must have VMA inside segment |
| 3059 | // Only non-zero section can be at end of segment |
| 3060 | template <class ELFT> |
| 3061 | bool GNUStyle<ELFT>::checkVMA(const Elf_Phdr &Phdr, const Elf_Shdr &Sec) { |
| 3062 | if (!(Sec.sh_flags & ELF::SHF_ALLOC)) |
| 3063 | return true; |
| 3064 | bool IsSpecial = |
| 3065 | (Sec.sh_type == ELF::SHT_NOBITS) && ((Sec.sh_flags & ELF::SHF_TLS) != 0); |
| 3066 | // .tbss is special, it only has memory in PT_TLS and has NOBITS properties |
| 3067 | auto SectionSize = |
| 3068 | (IsSpecial && Phdr.p_type != ELF::PT_TLS) ? 0 : Sec.sh_size; |
| 3069 | if (Sec.sh_addr >= Phdr.p_vaddr) |
| 3070 | return ((Sec.sh_addr + SectionSize <= Phdr.p_vaddr + Phdr.p_memsz) && |
| 3071 | (Sec.sh_addr + 1 <= Phdr.p_vaddr + Phdr.p_memsz)); |
| 3072 | return false; |
| 3073 | } |
| 3074 | |
| 3075 | // No section with zero size must be at start or end of PT_DYNAMIC |
| 3076 | template <class ELFT> |
| 3077 | bool GNUStyle<ELFT>::checkPTDynamic(const Elf_Phdr &Phdr, const Elf_Shdr &Sec) { |
| 3078 | if (Phdr.p_type != ELF::PT_DYNAMIC || Sec.sh_size != 0 || Phdr.p_memsz == 0) |
| 3079 | return true; |
| 3080 | // Is section within the phdr both based on offset and VMA ? |
| 3081 | return ((Sec.sh_type == ELF::SHT_NOBITS) || |
| 3082 | (Sec.sh_offset > Phdr.p_offset && |
| 3083 | Sec.sh_offset < Phdr.p_offset + Phdr.p_filesz)) && |
| 3084 | (!(Sec.sh_flags & ELF::SHF_ALLOC) || |
| 3085 | (Sec.sh_addr > Phdr.p_vaddr && Sec.sh_addr < Phdr.p_memsz)); |
| 3086 | } |
| 3087 | |
| 3088 | template <class ELFT> |
| 3089 | void GNUStyle<ELFT>::printProgramHeaders(const ELFO *Obj) { |
Hemant Kulkarni | 2e3254e | 2016-03-29 14:20:20 +0000 | [diff] [blame] | 3090 | unsigned Bias = ELFT::Is64Bits ? 8 : 0; |
| 3091 | unsigned Width = ELFT::Is64Bits ? 18 : 10; |
| 3092 | unsigned SizeWidth = ELFT::Is64Bits ? 8 : 7; |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 3093 | std::string Type, Offset, VMA, LMA, FileSz, MemSz, Flag, Align; |
| 3094 | |
| 3095 | const Elf_Ehdr *Header = Obj->getHeader(); |
| 3096 | Field Fields[8] = {2, 17, 26, 37 + Bias, |
| 3097 | 48 + Bias, 56 + Bias, 64 + Bias, 68 + Bias}; |
| 3098 | OS << "\nElf file type is " |
| 3099 | << printEnum(Header->e_type, makeArrayRef(ElfObjectFileType)) << "\n" |
Hemant Kulkarni | 787c2ed | 2016-05-12 22:51:26 +0000 | [diff] [blame] | 3100 | << "Entry point " << format_hex(Header->e_entry, 3) << "\n" |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 3101 | << "There are " << Header->e_phnum << " program headers," |
| 3102 | << " starting at offset " << Header->e_phoff << "\n\n" |
| 3103 | << "Program Headers:\n"; |
| 3104 | if (ELFT::Is64Bits) |
| 3105 | OS << " Type Offset VirtAddr PhysAddr " |
| 3106 | << " FileSiz MemSiz Flg Align\n"; |
| 3107 | else |
| 3108 | OS << " Type Offset VirtAddr PhysAddr FileSiz " |
| 3109 | << "MemSiz Flg Align\n"; |
Rafael Espindola | 6a49497 | 2016-11-03 17:28:33 +0000 | [diff] [blame] | 3110 | for (const auto &Phdr : unwrapOrError(Obj->program_headers())) { |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 3111 | Type = getElfPtType(Header->e_machine, Phdr.p_type); |
| 3112 | Offset = to_string(format_hex(Phdr.p_offset, 8)); |
| 3113 | VMA = to_string(format_hex(Phdr.p_vaddr, Width)); |
| 3114 | LMA = to_string(format_hex(Phdr.p_paddr, Width)); |
| 3115 | FileSz = to_string(format_hex(Phdr.p_filesz, SizeWidth)); |
| 3116 | MemSz = to_string(format_hex(Phdr.p_memsz, SizeWidth)); |
| 3117 | Flag = printPhdrFlags(Phdr.p_flags); |
| 3118 | Align = to_string(format_hex(Phdr.p_align, 1)); |
| 3119 | Fields[0].Str = Type; |
| 3120 | Fields[1].Str = Offset; |
| 3121 | Fields[2].Str = VMA; |
| 3122 | Fields[3].Str = LMA; |
| 3123 | Fields[4].Str = FileSz; |
| 3124 | Fields[5].Str = MemSz; |
| 3125 | Fields[6].Str = Flag; |
| 3126 | Fields[7].Str = Align; |
| 3127 | for (auto Field : Fields) |
| 3128 | printField(Field); |
| 3129 | if (Phdr.p_type == ELF::PT_INTERP) { |
| 3130 | OS << "\n [Requesting program interpreter: "; |
| 3131 | OS << reinterpret_cast<const char *>(Obj->base()) + Phdr.p_offset << "]"; |
| 3132 | } |
| 3133 | OS << "\n"; |
| 3134 | } |
| 3135 | OS << "\n Section to Segment mapping:\n Segment Sections...\n"; |
| 3136 | int Phnum = 0; |
Rafael Espindola | 6a49497 | 2016-11-03 17:28:33 +0000 | [diff] [blame] | 3137 | for (const Elf_Phdr &Phdr : unwrapOrError(Obj->program_headers())) { |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 3138 | std::string Sections; |
| 3139 | OS << format(" %2.2d ", Phnum++); |
Rafael Espindola | 25be8c8 | 2016-11-02 14:10:57 +0000 | [diff] [blame] | 3140 | for (const Elf_Shdr &Sec : unwrapOrError(Obj->sections())) { |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 3141 | // Check if each section is in a segment and then print mapping. |
| 3142 | // readelf additionally makes sure it does not print zero sized sections |
| 3143 | // at end of segments and for PT_DYNAMIC both start and end of section |
| 3144 | // .tbss must only be shown in PT_TLS section. |
| 3145 | bool TbssInNonTLS = (Sec.sh_type == ELF::SHT_NOBITS) && |
| 3146 | ((Sec.sh_flags & ELF::SHF_TLS) != 0) && |
| 3147 | Phdr.p_type != ELF::PT_TLS; |
| 3148 | if (!TbssInNonTLS && checkTLSSections(Phdr, Sec) && |
| 3149 | checkoffsets(Phdr, Sec) && checkVMA(Phdr, Sec) && |
| 3150 | checkPTDynamic(Phdr, Sec) && (Sec.sh_type != ELF::SHT_NULL)) |
| 3151 | Sections += unwrapOrError(Obj->getSectionName(&Sec)).str() + " "; |
| 3152 | } |
| 3153 | OS << Sections << "\n"; |
| 3154 | OS.flush(); |
| 3155 | } |
| 3156 | } |
| 3157 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3158 | template <class ELFT> |
Hemant Kulkarni | a79c798 | 2016-03-29 02:41:49 +0000 | [diff] [blame] | 3159 | void GNUStyle<ELFT>::printDynamicRelocation(const ELFO *Obj, Elf_Rela R, |
| 3160 | bool IsRela) { |
| 3161 | SmallString<32> RelocName; |
| 3162 | StringRef SymbolName; |
Hemant Kulkarni | 2e3254e | 2016-03-29 14:20:20 +0000 | [diff] [blame] | 3163 | unsigned Width = ELFT::Is64Bits ? 16 : 8; |
Hemant Kulkarni | a79c798 | 2016-03-29 02:41:49 +0000 | [diff] [blame] | 3164 | unsigned Bias = ELFT::Is64Bits ? 8 : 0; |
| 3165 | // First two fields are bit width dependent. The rest of them are after are |
| 3166 | // fixed width. |
| 3167 | Field Fields[5] = {0, 10 + Bias, 19 + 2 * Bias, 42 + 2 * Bias, 53 + 2 * Bias}; |
| 3168 | |
| 3169 | uint32_t SymIndex = R.getSymbol(Obj->isMips64EL()); |
| 3170 | const Elf_Sym *Sym = this->dumper()->dynamic_symbols().begin() + SymIndex; |
| 3171 | Obj->getRelocationTypeName(R.getType(Obj->isMips64EL()), RelocName); |
| 3172 | SymbolName = |
| 3173 | unwrapOrError(Sym->getName(this->dumper()->getDynamicStringTable())); |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 3174 | std::string Addend, Info, Offset, Value; |
Hemant Kulkarni | a79c798 | 2016-03-29 02:41:49 +0000 | [diff] [blame] | 3175 | Offset = to_string(format_hex_no_prefix(R.r_offset, Width)); |
| 3176 | Info = to_string(format_hex_no_prefix(R.r_info, Width)); |
| 3177 | Value = to_string(format_hex_no_prefix(Sym->getValue(), Width)); |
| 3178 | int64_t RelAddend = R.r_addend; |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 3179 | if (!SymbolName.empty() && IsRela) { |
Hemant Kulkarni | a79c798 | 2016-03-29 02:41:49 +0000 | [diff] [blame] | 3180 | if (R.r_addend < 0) |
| 3181 | Addend = " - "; |
| 3182 | else |
| 3183 | Addend = " + "; |
| 3184 | } |
| 3185 | |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 3186 | if (SymbolName.empty() && Sym->getValue() == 0) |
Hemant Kulkarni | a79c798 | 2016-03-29 02:41:49 +0000 | [diff] [blame] | 3187 | Value = ""; |
| 3188 | |
| 3189 | if (IsRela) |
| 3190 | Addend += to_string(format_hex_no_prefix(std::abs(RelAddend), 1)); |
| 3191 | |
| 3192 | |
| 3193 | Fields[0].Str = Offset; |
| 3194 | Fields[1].Str = Info; |
| 3195 | Fields[2].Str = RelocName.c_str(); |
| 3196 | Fields[3].Str = Value; |
| 3197 | Fields[4].Str = SymbolName; |
| 3198 | for (auto &Field : Fields) |
| 3199 | printField(Field); |
| 3200 | OS << Addend; |
| 3201 | OS << "\n"; |
| 3202 | } |
| 3203 | |
| 3204 | template <class ELFT> |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3205 | void GNUStyle<ELFT>::printDynamicRelocations(const ELFO *Obj) { |
Hemant Kulkarni | a79c798 | 2016-03-29 02:41:49 +0000 | [diff] [blame] | 3206 | const DynRegionInfo &DynRelRegion = this->dumper()->getDynRelRegion(); |
| 3207 | const DynRegionInfo &DynRelaRegion = this->dumper()->getDynRelaRegion(); |
| 3208 | const DynRegionInfo &DynPLTRelRegion = this->dumper()->getDynPLTRelRegion(); |
| 3209 | if (DynRelaRegion.Size > 0) { |
| 3210 | OS << "\n'RELA' relocation section at offset " |
| 3211 | << format_hex(reinterpret_cast<const uint8_t *>(DynRelaRegion.Addr) - |
| 3212 | Obj->base(), |
| 3213 | 1) << " contains " << DynRelaRegion.Size << " bytes:\n"; |
| 3214 | printRelocHeader(OS, ELFT::Is64Bits, true); |
| 3215 | for (const Elf_Rela &Rela : this->dumper()->dyn_relas()) |
| 3216 | printDynamicRelocation(Obj, Rela, true); |
| 3217 | } |
| 3218 | if (DynRelRegion.Size > 0) { |
| 3219 | OS << "\n'REL' relocation section at offset " |
| 3220 | << format_hex(reinterpret_cast<const uint8_t *>(DynRelRegion.Addr) - |
| 3221 | Obj->base(), |
| 3222 | 1) << " contains " << DynRelRegion.Size << " bytes:\n"; |
| 3223 | printRelocHeader(OS, ELFT::Is64Bits, false); |
| 3224 | for (const Elf_Rel &Rel : this->dumper()->dyn_rels()) { |
| 3225 | Elf_Rela Rela; |
| 3226 | Rela.r_offset = Rel.r_offset; |
| 3227 | Rela.r_info = Rel.r_info; |
| 3228 | Rela.r_addend = 0; |
| 3229 | printDynamicRelocation(Obj, Rela, false); |
| 3230 | } |
| 3231 | } |
| 3232 | if (DynPLTRelRegion.Size) { |
| 3233 | OS << "\n'PLT' relocation section at offset " |
| 3234 | << format_hex(reinterpret_cast<const uint8_t *>(DynPLTRelRegion.Addr) - |
| 3235 | Obj->base(), |
| 3236 | 1) << " contains " << DynPLTRelRegion.Size << " bytes:\n"; |
| 3237 | } |
| 3238 | if (DynPLTRelRegion.EntSize == sizeof(Elf_Rela)) { |
| 3239 | printRelocHeader(OS, ELFT::Is64Bits, true); |
Rafael Espindola | aafcf75 | 2016-04-05 14:47:22 +0000 | [diff] [blame] | 3240 | for (const Elf_Rela &Rela : DynPLTRelRegion.getAsArrayRef<Elf_Rela>()) |
Hemant Kulkarni | a79c798 | 2016-03-29 02:41:49 +0000 | [diff] [blame] | 3241 | printDynamicRelocation(Obj, Rela, true); |
| 3242 | } else { |
| 3243 | printRelocHeader(OS, ELFT::Is64Bits, false); |
Rafael Espindola | aafcf75 | 2016-04-05 14:47:22 +0000 | [diff] [blame] | 3244 | for (const Elf_Rel &Rel : DynPLTRelRegion.getAsArrayRef<Elf_Rel>()) { |
Hemant Kulkarni | a79c798 | 2016-03-29 02:41:49 +0000 | [diff] [blame] | 3245 | Elf_Rela Rela; |
| 3246 | Rela.r_offset = Rel.r_offset; |
| 3247 | Rela.r_info = Rel.r_info; |
| 3248 | Rela.r_addend = 0; |
| 3249 | printDynamicRelocation(Obj, Rela, false); |
| 3250 | } |
| 3251 | } |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3252 | } |
| 3253 | |
Hemant Kulkarni | 9b1b7f0 | 2016-04-11 17:15:30 +0000 | [diff] [blame] | 3254 | // Hash histogram shows statistics of how efficient the hash was for the |
| 3255 | // dynamic symbol table. The table shows number of hash buckets for different |
| 3256 | // lengths of chains as absolute number and percentage of the total buckets. |
| 3257 | // Additionally cumulative coverage of symbols for each set of buckets. |
| 3258 | template <class ELFT> |
| 3259 | void GNUStyle<ELFT>::printHashHistogram(const ELFFile<ELFT> *Obj) { |
| 3260 | |
| 3261 | const Elf_Hash *HashTable = this->dumper()->getHashTable(); |
| 3262 | const Elf_GnuHash *GnuHashTable = this->dumper()->getGnuHashTable(); |
| 3263 | |
| 3264 | // Print histogram for .hash section |
| 3265 | if (HashTable) { |
| 3266 | size_t NBucket = HashTable->nbucket; |
| 3267 | size_t NChain = HashTable->nchain; |
| 3268 | ArrayRef<Elf_Word> Buckets = HashTable->buckets(); |
| 3269 | ArrayRef<Elf_Word> Chains = HashTable->chains(); |
| 3270 | size_t TotalSyms = 0; |
| 3271 | // If hash table is correct, we have at least chains with 0 length |
| 3272 | size_t MaxChain = 1; |
| 3273 | size_t CumulativeNonZero = 0; |
| 3274 | |
| 3275 | if (NChain == 0 || NBucket == 0) |
| 3276 | return; |
| 3277 | |
| 3278 | std::vector<size_t> ChainLen(NBucket, 0); |
| 3279 | // Go over all buckets and and note chain lengths of each bucket (total |
| 3280 | // unique chain lengths). |
| 3281 | for (size_t B = 0; B < NBucket; B++) { |
| 3282 | for (size_t C = Buckets[B]; C > 0 && C < NChain; C = Chains[C]) |
| 3283 | if (MaxChain <= ++ChainLen[B]) |
| 3284 | MaxChain++; |
| 3285 | TotalSyms += ChainLen[B]; |
| 3286 | } |
| 3287 | |
| 3288 | if (!TotalSyms) |
| 3289 | return; |
| 3290 | |
| 3291 | std::vector<size_t> Count(MaxChain, 0) ; |
| 3292 | // Count how long is the chain for each bucket |
| 3293 | for (size_t B = 0; B < NBucket; B++) |
| 3294 | ++Count[ChainLen[B]]; |
| 3295 | // Print Number of buckets with each chain lengths and their cumulative |
| 3296 | // coverage of the symbols |
| 3297 | OS << "Histogram for bucket list length (total of " << NBucket |
| 3298 | << " buckets)\n" |
| 3299 | << " Length Number % of total Coverage\n"; |
| 3300 | for (size_t I = 0; I < MaxChain; I++) { |
| 3301 | CumulativeNonZero += Count[I] * I; |
| 3302 | OS << format("%7lu %-10lu (%5.1f%%) %5.1f%%\n", I, Count[I], |
| 3303 | (Count[I] * 100.0) / NBucket, |
| 3304 | (CumulativeNonZero * 100.0) / TotalSyms); |
| 3305 | } |
| 3306 | } |
| 3307 | |
| 3308 | // Print histogram for .gnu.hash section |
| 3309 | if (GnuHashTable) { |
| 3310 | size_t NBucket = GnuHashTable->nbuckets; |
| 3311 | ArrayRef<Elf_Word> Buckets = GnuHashTable->buckets(); |
| 3312 | unsigned NumSyms = this->dumper()->dynamic_symbols().size(); |
| 3313 | if (!NumSyms) |
| 3314 | return; |
| 3315 | ArrayRef<Elf_Word> Chains = GnuHashTable->values(NumSyms); |
| 3316 | size_t Symndx = GnuHashTable->symndx; |
| 3317 | size_t TotalSyms = 0; |
| 3318 | size_t MaxChain = 1; |
| 3319 | size_t CumulativeNonZero = 0; |
| 3320 | |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 3321 | if (Chains.empty() || NBucket == 0) |
Hemant Kulkarni | 9b1b7f0 | 2016-04-11 17:15:30 +0000 | [diff] [blame] | 3322 | return; |
| 3323 | |
| 3324 | std::vector<size_t> ChainLen(NBucket, 0); |
| 3325 | |
| 3326 | for (size_t B = 0; B < NBucket; B++) { |
| 3327 | if (!Buckets[B]) |
| 3328 | continue; |
| 3329 | size_t Len = 1; |
| 3330 | for (size_t C = Buckets[B] - Symndx; |
| 3331 | C < Chains.size() && (Chains[C] & 1) == 0; C++) |
| 3332 | if (MaxChain < ++Len) |
| 3333 | MaxChain++; |
| 3334 | ChainLen[B] = Len; |
| 3335 | TotalSyms += Len; |
| 3336 | } |
| 3337 | MaxChain++; |
| 3338 | |
| 3339 | if (!TotalSyms) |
| 3340 | return; |
| 3341 | |
| 3342 | std::vector<size_t> Count(MaxChain, 0) ; |
| 3343 | for (size_t B = 0; B < NBucket; B++) |
| 3344 | ++Count[ChainLen[B]]; |
| 3345 | // Print Number of buckets with each chain lengths and their cumulative |
| 3346 | // coverage of the symbols |
| 3347 | OS << "Histogram for `.gnu.hash' bucket list length (total of " << NBucket |
| 3348 | << " buckets)\n" |
| 3349 | << " Length Number % of total Coverage\n"; |
| 3350 | for (size_t I = 0; I <MaxChain; I++) { |
| 3351 | CumulativeNonZero += Count[I] * I; |
| 3352 | OS << format("%7lu %-10lu (%5.1f%%) %5.1f%%\n", I, Count[I], |
| 3353 | (Count[I] * 100.0) / NBucket, |
| 3354 | (CumulativeNonZero * 100.0) / TotalSyms); |
| 3355 | } |
| 3356 | } |
| 3357 | } |
| 3358 | |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 3359 | static std::string getGNUNoteTypeName(const uint32_t NT) { |
| 3360 | static const struct { |
| 3361 | uint32_t ID; |
| 3362 | const char *Name; |
| 3363 | } Notes[] = { |
| 3364 | {ELF::NT_GNU_ABI_TAG, "NT_GNU_ABI_TAG (ABI version tag)"}, |
| 3365 | {ELF::NT_GNU_HWCAP, "NT_GNU_HWCAP (DSO-supplied software HWCAP info)"}, |
| 3366 | {ELF::NT_GNU_BUILD_ID, "NT_GNU_BUILD_ID (unique build ID bitstring)"}, |
| 3367 | {ELF::NT_GNU_GOLD_VERSION, "NT_GNU_GOLD_VERSION (gold version)"}, |
| 3368 | }; |
| 3369 | |
| 3370 | for (const auto &Note : Notes) |
| 3371 | if (Note.ID == NT) |
| 3372 | return std::string(Note.Name); |
| 3373 | |
| 3374 | std::string string; |
| 3375 | raw_string_ostream OS(string); |
| 3376 | OS << format("Unknown note type (0x%08x)", NT); |
Konstantin Zhuravlyov | 716af74 | 2017-10-14 16:43:46 +0000 | [diff] [blame] | 3377 | return OS.str(); |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 3378 | } |
| 3379 | |
Saleem Abdulrasool | 4b08913 | 2017-02-12 18:55:33 +0000 | [diff] [blame] | 3380 | static std::string getFreeBSDNoteTypeName(const uint32_t NT) { |
| 3381 | static const struct { |
| 3382 | uint32_t ID; |
| 3383 | const char *Name; |
| 3384 | } Notes[] = { |
| 3385 | {ELF::NT_FREEBSD_THRMISC, "NT_THRMISC (thrmisc structure)"}, |
| 3386 | {ELF::NT_FREEBSD_PROCSTAT_PROC, "NT_PROCSTAT_PROC (proc data)"}, |
| 3387 | {ELF::NT_FREEBSD_PROCSTAT_FILES, "NT_PROCSTAT_FILES (files data)"}, |
| 3388 | {ELF::NT_FREEBSD_PROCSTAT_VMMAP, "NT_PROCSTAT_VMMAP (vmmap data)"}, |
| 3389 | {ELF::NT_FREEBSD_PROCSTAT_GROUPS, "NT_PROCSTAT_GROUPS (groups data)"}, |
| 3390 | {ELF::NT_FREEBSD_PROCSTAT_UMASK, "NT_PROCSTAT_UMASK (umask data)"}, |
| 3391 | {ELF::NT_FREEBSD_PROCSTAT_RLIMIT, "NT_PROCSTAT_RLIMIT (rlimit data)"}, |
| 3392 | {ELF::NT_FREEBSD_PROCSTAT_OSREL, "NT_PROCSTAT_OSREL (osreldate data)"}, |
| 3393 | {ELF::NT_FREEBSD_PROCSTAT_PSSTRINGS, |
| 3394 | "NT_PROCSTAT_PSSTRINGS (ps_strings data)"}, |
| 3395 | {ELF::NT_FREEBSD_PROCSTAT_AUXV, "NT_PROCSTAT_AUXV (auxv data)"}, |
| 3396 | }; |
| 3397 | |
| 3398 | for (const auto &Note : Notes) |
| 3399 | if (Note.ID == NT) |
| 3400 | return std::string(Note.Name); |
| 3401 | |
| 3402 | std::string string; |
| 3403 | raw_string_ostream OS(string); |
| 3404 | OS << format("Unknown note type (0x%08x)", NT); |
Konstantin Zhuravlyov | 716af74 | 2017-10-14 16:43:46 +0000 | [diff] [blame] | 3405 | return OS.str(); |
| 3406 | } |
| 3407 | |
| 3408 | static std::string getAMDGPUNoteTypeName(const uint32_t NT) { |
| 3409 | static const struct { |
| 3410 | uint32_t ID; |
| 3411 | const char *Name; |
| 3412 | } Notes[] = { |
| 3413 | {ELF::NT_AMD_AMDGPU_HSA_METADATA, |
| 3414 | "NT_AMD_AMDGPU_HSA_METADATA (HSA Metadata)"}, |
| 3415 | {ELF::NT_AMD_AMDGPU_ISA, |
| 3416 | "NT_AMD_AMDGPU_ISA (ISA Version)"}, |
| 3417 | {ELF::NT_AMD_AMDGPU_PAL_METADATA, |
| 3418 | "NT_AMD_AMDGPU_PAL_METADATA (PAL Metadata)"} |
| 3419 | }; |
| 3420 | |
| 3421 | for (const auto &Note : Notes) |
| 3422 | if (Note.ID == NT) |
| 3423 | return std::string(Note.Name); |
| 3424 | |
| 3425 | std::string string; |
| 3426 | raw_string_ostream OS(string); |
| 3427 | OS << format("Unknown note type (0x%08x)", NT); |
| 3428 | return OS.str(); |
Saleem Abdulrasool | 4b08913 | 2017-02-12 18:55:33 +0000 | [diff] [blame] | 3429 | } |
| 3430 | |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 3431 | template <typename ELFT> |
| 3432 | static void printGNUNote(raw_ostream &OS, uint32_t NoteType, |
Petr Hosek | 02185c0 | 2017-04-05 18:55:50 +0000 | [diff] [blame] | 3433 | ArrayRef<typename ELFFile<ELFT>::Elf_Word> Words, |
| 3434 | size_t Size) { |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 3435 | switch (NoteType) { |
| 3436 | default: |
| 3437 | return; |
| 3438 | case ELF::NT_GNU_ABI_TAG: { |
| 3439 | static const char *OSNames[] = { |
| 3440 | "Linux", "Hurd", "Solaris", "FreeBSD", "NetBSD", "Syllable", "NaCl", |
| 3441 | }; |
| 3442 | |
| 3443 | StringRef OSName = "Unknown"; |
| 3444 | if (Words[0] < array_lengthof(OSNames)) |
| 3445 | OSName = OSNames[Words[0]]; |
| 3446 | uint32_t Major = Words[1], Minor = Words[2], Patch = Words[3]; |
| 3447 | |
| 3448 | if (Words.size() < 4) |
| 3449 | OS << " <corrupt GNU_ABI_TAG>"; |
| 3450 | else |
| 3451 | OS << " OS: " << OSName << ", ABI: " << Major << "." << Minor << "." |
| 3452 | << Patch; |
| 3453 | break; |
| 3454 | } |
| 3455 | case ELF::NT_GNU_BUILD_ID: { |
| 3456 | OS << " Build ID: "; |
Petr Hosek | 02185c0 | 2017-04-05 18:55:50 +0000 | [diff] [blame] | 3457 | ArrayRef<uint8_t> ID(reinterpret_cast<const uint8_t *>(Words.data()), Size); |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 3458 | for (const auto &B : ID) |
| 3459 | OS << format_hex_no_prefix(B, 2); |
| 3460 | break; |
| 3461 | } |
| 3462 | case ELF::NT_GNU_GOLD_VERSION: |
| 3463 | OS << " Version: " |
Petr Hosek | 02185c0 | 2017-04-05 18:55:50 +0000 | [diff] [blame] | 3464 | << StringRef(reinterpret_cast<const char *>(Words.data()), Size); |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 3465 | break; |
| 3466 | } |
| 3467 | |
| 3468 | OS << '\n'; |
| 3469 | } |
| 3470 | |
Konstantin Zhuravlyov | b3c605d | 2017-10-14 18:21:42 +0000 | [diff] [blame] | 3471 | template <typename ELFT> |
| 3472 | static void printAMDGPUNote(raw_ostream &OS, uint32_t NoteType, |
| 3473 | ArrayRef<typename ELFFile<ELFT>::Elf_Word> Words, |
| 3474 | size_t Size) { |
| 3475 | switch (NoteType) { |
| 3476 | default: |
| 3477 | return; |
| 3478 | case ELF::NT_AMD_AMDGPU_HSA_METADATA: |
| 3479 | OS << " HSA Metadata:\n" |
| 3480 | << StringRef(reinterpret_cast<const char *>(Words.data()), Size); |
| 3481 | break; |
| 3482 | case ELF::NT_AMD_AMDGPU_ISA: |
| 3483 | OS << " ISA Version:\n" |
| 3484 | << " " |
| 3485 | << StringRef(reinterpret_cast<const char *>(Words.data()), Size); |
| 3486 | break; |
| 3487 | case ELF::NT_AMD_AMDGPU_PAL_METADATA: |
| 3488 | const uint32_t *PALMetadataBegin = reinterpret_cast<const uint32_t *>(Words.data()); |
| 3489 | const uint32_t *PALMetadataEnd = PALMetadataBegin + Size; |
| 3490 | std::vector<uint32_t> PALMetadata(PALMetadataBegin, PALMetadataEnd); |
| 3491 | std::string PALMetadataString; |
| 3492 | auto Error = AMDGPU::PALMD::toString(PALMetadata, PALMetadataString); |
| 3493 | OS << " PAL Metadata:\n"; |
| 3494 | if (Error) { |
| 3495 | OS << " Invalid"; |
| 3496 | return; |
| 3497 | } |
| 3498 | OS << PALMetadataString; |
| 3499 | break; |
| 3500 | } |
| 3501 | OS.flush(); |
| 3502 | } |
| 3503 | |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 3504 | template <class ELFT> |
| 3505 | void GNUStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) { |
| 3506 | const Elf_Ehdr *e = Obj->getHeader(); |
| 3507 | bool IsCore = e->e_type == ELF::ET_CORE; |
| 3508 | |
| 3509 | auto process = [&](const typename ELFFile<ELFT>::Elf_Off Offset, |
| 3510 | const typename ELFFile<ELFT>::Elf_Addr Size) { |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 3511 | if (Size <= 0) |
| 3512 | return; |
| 3513 | |
| 3514 | const auto *P = static_cast<const uint8_t *>(Obj->base() + Offset); |
| 3515 | const auto *E = P + Size; |
| 3516 | |
| 3517 | OS << "Displaying notes found at file offset " << format_hex(Offset, 10) |
| 3518 | << " with length " << format_hex(Size, 10) << ":\n" |
| 3519 | << " Owner Data size\tDescription\n"; |
| 3520 | |
| 3521 | while (P < E) { |
Reid Kleckner | 34151b3 | 2016-08-31 22:45:36 +0000 | [diff] [blame] | 3522 | const Elf_Word *Words = reinterpret_cast<const Elf_Word *>(&P[0]); |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 3523 | |
| 3524 | uint32_t NameSize = Words[0]; |
| 3525 | uint32_t DescriptorSize = Words[1]; |
| 3526 | uint32_t Type = Words[2]; |
| 3527 | |
Reid Kleckner | 34151b3 | 2016-08-31 22:45:36 +0000 | [diff] [blame] | 3528 | ArrayRef<Elf_Word> Descriptor(&Words[3 + (alignTo<4>(NameSize) / 4)], |
| 3529 | alignTo<4>(DescriptorSize) / 4); |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 3530 | |
| 3531 | StringRef Name; |
| 3532 | if (NameSize) |
| 3533 | Name = |
| 3534 | StringRef(reinterpret_cast<const char *>(&Words[3]), NameSize - 1); |
| 3535 | |
| 3536 | OS << " " << Name << std::string(22 - NameSize, ' ') |
| 3537 | << format_hex(DescriptorSize, 10) << '\t'; |
| 3538 | |
| 3539 | if (Name == "GNU") { |
| 3540 | OS << getGNUNoteTypeName(Type) << '\n'; |
Petr Hosek | 02185c0 | 2017-04-05 18:55:50 +0000 | [diff] [blame] | 3541 | printGNUNote<ELFT>(OS, Type, Descriptor, DescriptorSize); |
Saleem Abdulrasool | 4b08913 | 2017-02-12 18:55:33 +0000 | [diff] [blame] | 3542 | } else if (Name == "FreeBSD") { |
| 3543 | OS << getFreeBSDNoteTypeName(Type) << '\n'; |
Konstantin Zhuravlyov | 716af74 | 2017-10-14 16:43:46 +0000 | [diff] [blame] | 3544 | } else if (Name == "AMD") { |
| 3545 | OS << getAMDGPUNoteTypeName(Type) << '\n'; |
Konstantin Zhuravlyov | b3c605d | 2017-10-14 18:21:42 +0000 | [diff] [blame] | 3546 | printAMDGPUNote<ELFT>(OS, Type, Descriptor, DescriptorSize); |
Konstantin Zhuravlyov | 803b141 | 2017-02-02 23:44:49 +0000 | [diff] [blame] | 3547 | } else { |
| 3548 | OS << "Unknown note type: (" << format_hex(Type, 10) << ')'; |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 3549 | } |
| 3550 | OS << '\n'; |
| 3551 | |
Konstantin Zhuravlyov | 803b141 | 2017-02-02 23:44:49 +0000 | [diff] [blame] | 3552 | P = P + 3 * sizeof(Elf_Word) + alignTo<4>(NameSize) + |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 3553 | alignTo<4>(DescriptorSize); |
| 3554 | } |
| 3555 | }; |
| 3556 | |
| 3557 | if (IsCore) { |
Rafael Espindola | 6a49497 | 2016-11-03 17:28:33 +0000 | [diff] [blame] | 3558 | for (const auto &P : unwrapOrError(Obj->program_headers())) |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 3559 | if (P.p_type == PT_NOTE) |
| 3560 | process(P.p_offset, P.p_filesz); |
| 3561 | } else { |
Rafael Espindola | 25be8c8 | 2016-11-02 14:10:57 +0000 | [diff] [blame] | 3562 | for (const auto &S : unwrapOrError(Obj->sections())) |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 3563 | if (S.sh_type == SHT_NOTE) |
| 3564 | process(S.sh_offset, S.sh_size); |
| 3565 | } |
| 3566 | } |
| 3567 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3568 | template <class ELFT> void LLVMStyle<ELFT>::printFileHeaders(const ELFO *Obj) { |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 3569 | const Elf_Ehdr *e = Obj->getHeader(); |
| 3570 | { |
| 3571 | DictScope D(W, "ElfHeader"); |
| 3572 | { |
| 3573 | DictScope D(W, "Ident"); |
| 3574 | W.printBinary("Magic", makeArrayRef(e->e_ident).slice(ELF::EI_MAG0, 4)); |
| 3575 | W.printEnum("Class", e->e_ident[ELF::EI_CLASS], makeArrayRef(ElfClass)); |
| 3576 | W.printEnum("DataEncoding", e->e_ident[ELF::EI_DATA], |
| 3577 | makeArrayRef(ElfDataEncoding)); |
| 3578 | W.printNumber("FileVersion", e->e_ident[ELF::EI_VERSION]); |
| 3579 | |
Konstantin Zhuravlyov | 121125f | 2017-10-02 20:49:58 +0000 | [diff] [blame] | 3580 | auto OSABI = makeArrayRef(ElfOSABI); |
| 3581 | if (e->e_ident[ELF::EI_OSABI] >= ELF::ELFOSABI_FIRST_ARCH && |
| 3582 | e->e_ident[ELF::EI_OSABI] <= ELF::ELFOSABI_LAST_ARCH) { |
| 3583 | switch (e->e_machine) { |
| 3584 | case ELF::EM_AMDGPU: |
| 3585 | OSABI = makeArrayRef(AMDGPUElfOSABI); |
| 3586 | break; |
| 3587 | case ELF::EM_ARM: |
| 3588 | OSABI = makeArrayRef(ARMElfOSABI); |
| 3589 | break; |
| 3590 | case ELF::EM_TI_C6000: |
| 3591 | OSABI = makeArrayRef(C6000ElfOSABI); |
| 3592 | break; |
| 3593 | } |
| 3594 | } |
| 3595 | W.printEnum("OS/ABI", e->e_ident[ELF::EI_OSABI], OSABI); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 3596 | W.printNumber("ABIVersion", e->e_ident[ELF::EI_ABIVERSION]); |
| 3597 | W.printBinary("Unused", makeArrayRef(e->e_ident).slice(ELF::EI_PAD)); |
| 3598 | } |
| 3599 | |
| 3600 | W.printEnum("Type", e->e_type, makeArrayRef(ElfObjectFileType)); |
| 3601 | W.printEnum("Machine", e->e_machine, makeArrayRef(ElfMachineType)); |
| 3602 | W.printNumber("Version", e->e_version); |
| 3603 | W.printHex("Entry", e->e_entry); |
| 3604 | W.printHex("ProgramHeaderOffset", e->e_phoff); |
| 3605 | W.printHex("SectionHeaderOffset", e->e_shoff); |
| 3606 | if (e->e_machine == EM_MIPS) |
| 3607 | W.printFlags("Flags", e->e_flags, makeArrayRef(ElfHeaderMipsFlags), |
| 3608 | unsigned(ELF::EF_MIPS_ARCH), unsigned(ELF::EF_MIPS_ABI), |
| 3609 | unsigned(ELF::EF_MIPS_MACH)); |
Konstantin Zhuravlyov | aa0835a | 2017-10-05 16:19:18 +0000 | [diff] [blame] | 3610 | else if (e->e_machine == EM_AMDGPU) |
| 3611 | W.printFlags("Flags", e->e_flags, makeArrayRef(ElfHeaderAMDGPUFlags), |
| 3612 | unsigned(ELF::EF_AMDGPU_ARCH)); |
Alex Bradbury | bb89b2b | 2017-10-03 08:41:59 +0000 | [diff] [blame] | 3613 | else if (e->e_machine == EM_RISCV) |
| 3614 | W.printFlags("Flags", e->e_flags, makeArrayRef(ElfHeaderRISCVFlags)); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 3615 | else |
| 3616 | W.printFlags("Flags", e->e_flags); |
| 3617 | W.printNumber("HeaderSize", e->e_ehsize); |
| 3618 | W.printNumber("ProgramHeaderEntrySize", e->e_phentsize); |
| 3619 | W.printNumber("ProgramHeaderCount", e->e_phnum); |
| 3620 | W.printNumber("SectionHeaderEntrySize", e->e_shentsize); |
| 3621 | W.printNumber("SectionHeaderCount", e->e_shnum); |
| 3622 | W.printNumber("StringTableSectionIndex", e->e_shstrndx); |
| 3623 | } |
| 3624 | } |
Hemant Kulkarni | 206ba84 | 2016-03-09 19:16:13 +0000 | [diff] [blame] | 3625 | |
| 3626 | template <class ELFT> |
| 3627 | void LLVMStyle<ELFT>::printGroupSections(const ELFO *Obj) { |
| 3628 | DictScope Lists(W, "Groups"); |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 3629 | std::vector<GroupSection> V = getGroups<ELFT>(Obj); |
George Rimar | 762abff6 | 2017-09-16 14:29:51 +0000 | [diff] [blame] | 3630 | DenseMap<uint64_t, const GroupSection *> Map = mapSectionsToGroups(V); |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 3631 | for (const GroupSection &G : V) { |
| 3632 | DictScope D(W, "Group"); |
| 3633 | W.printNumber("Name", G.Name, G.ShName); |
| 3634 | W.printNumber("Index", G.Index); |
| 3635 | W.printHex("Type", getGroupType(G.Type), G.Type); |
| 3636 | W.startLine() << "Signature: " << G.Signature << "\n"; |
| 3637 | |
| 3638 | ListScope L(W, "Section(s) in group"); |
George Rimar | 762abff6 | 2017-09-16 14:29:51 +0000 | [diff] [blame] | 3639 | for (const GroupMember &GM : G.Members) { |
| 3640 | const GroupSection *MainGroup = Map[GM.Index]; |
| 3641 | if (MainGroup != &G) { |
| 3642 | W.flush(); |
| 3643 | errs() << "Error: " << GM.Name << " (" << GM.Index |
| 3644 | << ") in a group " + G.Name + " (" << G.Index |
| 3645 | << ") is already in a group " + MainGroup->Name + " (" |
| 3646 | << MainGroup->Index << ")\n"; |
| 3647 | errs().flush(); |
| 3648 | continue; |
| 3649 | } |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 3650 | W.startLine() << GM.Name << " (" << GM.Index << ")\n"; |
George Rimar | 762abff6 | 2017-09-16 14:29:51 +0000 | [diff] [blame] | 3651 | } |
Hemant Kulkarni | 206ba84 | 2016-03-09 19:16:13 +0000 | [diff] [blame] | 3652 | } |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 3653 | |
| 3654 | if (V.empty()) |
Hemant Kulkarni | 206ba84 | 2016-03-09 19:16:13 +0000 | [diff] [blame] | 3655 | W.startLine() << "There are no group sections in the file.\n"; |
| 3656 | } |
George Rimar | 762abff6 | 2017-09-16 14:29:51 +0000 | [diff] [blame] | 3657 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3658 | template <class ELFT> void LLVMStyle<ELFT>::printRelocations(const ELFO *Obj) { |
| 3659 | ListScope D(W, "Relocations"); |
| 3660 | |
| 3661 | int SectionNumber = -1; |
Rafael Espindola | 25be8c8 | 2016-11-02 14:10:57 +0000 | [diff] [blame] | 3662 | for (const Elf_Shdr &Sec : unwrapOrError(Obj->sections())) { |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3663 | ++SectionNumber; |
| 3664 | |
Peter Collingbourne | 689e6c05 | 2017-10-25 03:37:12 +0000 | [diff] [blame^] | 3665 | if (Sec.sh_type != ELF::SHT_REL && Sec.sh_type != ELF::SHT_RELA && |
| 3666 | Sec.sh_type != ELF::SHT_ANDROID_REL && |
| 3667 | Sec.sh_type != ELF::SHT_ANDROID_RELA) |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3668 | continue; |
| 3669 | |
| 3670 | StringRef Name = unwrapOrError(Obj->getSectionName(&Sec)); |
| 3671 | |
| 3672 | W.startLine() << "Section (" << SectionNumber << ") " << Name << " {\n"; |
| 3673 | W.indent(); |
| 3674 | |
| 3675 | printRelocations(&Sec, Obj); |
| 3676 | |
| 3677 | W.unindent(); |
| 3678 | W.startLine() << "}\n"; |
| 3679 | } |
| 3680 | } |
| 3681 | |
| 3682 | template <class ELFT> |
| 3683 | void LLVMStyle<ELFT>::printRelocations(const Elf_Shdr *Sec, const ELFO *Obj) { |
| 3684 | const Elf_Shdr *SymTab = unwrapOrError(Obj->getSection(Sec->sh_link)); |
| 3685 | |
| 3686 | switch (Sec->sh_type) { |
| 3687 | case ELF::SHT_REL: |
Rafael Espindola | 354680a | 2016-11-03 19:07:15 +0000 | [diff] [blame] | 3688 | for (const Elf_Rel &R : unwrapOrError(Obj->rels(Sec))) { |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3689 | Elf_Rela Rela; |
| 3690 | Rela.r_offset = R.r_offset; |
| 3691 | Rela.r_info = R.r_info; |
| 3692 | Rela.r_addend = 0; |
| 3693 | printRelocation(Obj, Rela, SymTab); |
| 3694 | } |
| 3695 | break; |
| 3696 | case ELF::SHT_RELA: |
Rafael Espindola | 354680a | 2016-11-03 19:07:15 +0000 | [diff] [blame] | 3697 | for (const Elf_Rela &R : unwrapOrError(Obj->relas(Sec))) |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3698 | printRelocation(Obj, R, SymTab); |
| 3699 | break; |
Peter Collingbourne | 689e6c05 | 2017-10-25 03:37:12 +0000 | [diff] [blame^] | 3700 | case ELF::SHT_ANDROID_REL: |
| 3701 | case ELF::SHT_ANDROID_RELA: |
| 3702 | for (const Elf_Rela &R : unwrapOrError(Obj->android_relas(Sec))) |
| 3703 | printRelocation(Obj, R, SymTab); |
| 3704 | break; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3705 | } |
| 3706 | } |
| 3707 | |
| 3708 | template <class ELFT> |
| 3709 | void LLVMStyle<ELFT>::printRelocation(const ELFO *Obj, Elf_Rela Rel, |
| 3710 | const Elf_Shdr *SymTab) { |
| 3711 | SmallString<32> RelocName; |
| 3712 | Obj->getRelocationTypeName(Rel.getType(Obj->isMips64EL()), RelocName); |
| 3713 | StringRef TargetName; |
Rafael Espindola | ed1395a | 2016-11-03 18:05:33 +0000 | [diff] [blame] | 3714 | const Elf_Sym *Sym = unwrapOrError(Obj->getRelocationSymbol(&Rel, SymTab)); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3715 | if (Sym && Sym->getType() == ELF::STT_SECTION) { |
| 3716 | const Elf_Shdr *Sec = unwrapOrError( |
| 3717 | Obj->getSection(Sym, SymTab, this->dumper()->getShndxTable())); |
| 3718 | TargetName = unwrapOrError(Obj->getSectionName(Sec)); |
| 3719 | } else if (Sym) { |
| 3720 | StringRef StrTable = unwrapOrError(Obj->getStringTableForSymtab(*SymTab)); |
| 3721 | TargetName = unwrapOrError(Sym->getName(StrTable)); |
| 3722 | } |
| 3723 | |
| 3724 | if (opts::ExpandRelocs) { |
| 3725 | DictScope Group(W, "Relocation"); |
| 3726 | W.printHex("Offset", Rel.r_offset); |
| 3727 | W.printNumber("Type", RelocName, (int)Rel.getType(Obj->isMips64EL())); |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 3728 | W.printNumber("Symbol", !TargetName.empty() ? TargetName : "-", |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3729 | Rel.getSymbol(Obj->isMips64EL())); |
| 3730 | W.printHex("Addend", Rel.r_addend); |
| 3731 | } else { |
| 3732 | raw_ostream &OS = W.startLine(); |
| 3733 | OS << W.hex(Rel.r_offset) << " " << RelocName << " " |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 3734 | << (!TargetName.empty() ? TargetName : "-") << " " |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3735 | << W.hex(Rel.r_addend) << "\n"; |
| 3736 | } |
| 3737 | } |
| 3738 | |
| 3739 | template <class ELFT> void LLVMStyle<ELFT>::printSections(const ELFO *Obj) { |
| 3740 | ListScope SectionsD(W, "Sections"); |
| 3741 | |
| 3742 | int SectionIndex = -1; |
Rafael Espindola | 25be8c8 | 2016-11-02 14:10:57 +0000 | [diff] [blame] | 3743 | for (const Elf_Shdr &Sec : unwrapOrError(Obj->sections())) { |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3744 | ++SectionIndex; |
| 3745 | |
| 3746 | StringRef Name = unwrapOrError(Obj->getSectionName(&Sec)); |
| 3747 | |
| 3748 | DictScope SectionD(W, "Section"); |
| 3749 | W.printNumber("Index", SectionIndex); |
| 3750 | W.printNumber("Name", Name, Sec.sh_name); |
Rafael Espindola | 3ba2573 | 2017-05-02 14:04:52 +0000 | [diff] [blame] | 3751 | W.printHex( |
| 3752 | "Type", |
| 3753 | object::getELFSectionTypeName(Obj->getHeader()->e_machine, Sec.sh_type), |
| 3754 | Sec.sh_type); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3755 | std::vector<EnumEntry<unsigned>> SectionFlags(std::begin(ElfSectionFlags), |
| 3756 | std::end(ElfSectionFlags)); |
| 3757 | switch (Obj->getHeader()->e_machine) { |
Prakhar Bahuguna | 52a7dd7 | 2016-12-15 07:59:08 +0000 | [diff] [blame] | 3758 | case EM_ARM: |
| 3759 | SectionFlags.insert(SectionFlags.end(), std::begin(ElfARMSectionFlags), |
| 3760 | std::end(ElfARMSectionFlags)); |
| 3761 | break; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3762 | case EM_HEXAGON: |
| 3763 | SectionFlags.insert(SectionFlags.end(), |
| 3764 | std::begin(ElfHexagonSectionFlags), |
| 3765 | std::end(ElfHexagonSectionFlags)); |
| 3766 | break; |
| 3767 | case EM_MIPS: |
| 3768 | SectionFlags.insert(SectionFlags.end(), std::begin(ElfMipsSectionFlags), |
| 3769 | std::end(ElfMipsSectionFlags)); |
| 3770 | break; |
| 3771 | case EM_X86_64: |
| 3772 | SectionFlags.insert(SectionFlags.end(), std::begin(ElfX86_64SectionFlags), |
| 3773 | std::end(ElfX86_64SectionFlags)); |
| 3774 | break; |
George Rimar | c13c59a | 2016-05-21 10:16:58 +0000 | [diff] [blame] | 3775 | case EM_XCORE: |
| 3776 | SectionFlags.insert(SectionFlags.end(), std::begin(ElfXCoreSectionFlags), |
| 3777 | std::end(ElfXCoreSectionFlags)); |
| 3778 | break; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3779 | default: |
| 3780 | // Nothing to do. |
| 3781 | break; |
| 3782 | } |
| 3783 | W.printFlags("Flags", Sec.sh_flags, makeArrayRef(SectionFlags)); |
| 3784 | W.printHex("Address", Sec.sh_addr); |
| 3785 | W.printHex("Offset", Sec.sh_offset); |
| 3786 | W.printNumber("Size", Sec.sh_size); |
| 3787 | W.printNumber("Link", Sec.sh_link); |
| 3788 | W.printNumber("Info", Sec.sh_info); |
| 3789 | W.printNumber("AddressAlignment", Sec.sh_addralign); |
| 3790 | W.printNumber("EntrySize", Sec.sh_entsize); |
| 3791 | |
| 3792 | if (opts::SectionRelocations) { |
| 3793 | ListScope D(W, "Relocations"); |
| 3794 | printRelocations(&Sec, Obj); |
| 3795 | } |
| 3796 | |
| 3797 | if (opts::SectionSymbols) { |
| 3798 | ListScope D(W, "Symbols"); |
| 3799 | const Elf_Shdr *Symtab = this->dumper()->getDotSymtabSec(); |
| 3800 | StringRef StrTable = unwrapOrError(Obj->getStringTableForSymtab(*Symtab)); |
| 3801 | |
Rafael Espindola | 9ea6834 | 2016-11-03 13:43:30 +0000 | [diff] [blame] | 3802 | for (const Elf_Sym &Sym : unwrapOrError(Obj->symbols(Symtab))) { |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3803 | const Elf_Shdr *SymSec = unwrapOrError( |
| 3804 | Obj->getSection(&Sym, Symtab, this->dumper()->getShndxTable())); |
| 3805 | if (SymSec == &Sec) |
Rafael Espindola | 9ea6834 | 2016-11-03 13:43:30 +0000 | [diff] [blame] | 3806 | printSymbol(Obj, &Sym, unwrapOrError(Obj->symbols(Symtab)).begin(), |
| 3807 | StrTable, false); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3808 | } |
| 3809 | } |
| 3810 | |
| 3811 | if (opts::SectionData && Sec.sh_type != ELF::SHT_NOBITS) { |
| 3812 | ArrayRef<uint8_t> Data = unwrapOrError(Obj->getSectionContents(&Sec)); |
| 3813 | W.printBinaryBlock("SectionData", |
| 3814 | StringRef((const char *)Data.data(), Data.size())); |
| 3815 | } |
| 3816 | } |
| 3817 | } |
| 3818 | |
| 3819 | template <class ELFT> |
| 3820 | void LLVMStyle<ELFT>::printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, |
| 3821 | const Elf_Sym *First, StringRef StrTable, |
| 3822 | bool IsDynamic) { |
| 3823 | unsigned SectionIndex = 0; |
| 3824 | StringRef SectionName; |
| 3825 | getSectionNameIndex(*Obj, Symbol, First, this->dumper()->getShndxTable(), |
| 3826 | SectionName, SectionIndex); |
| 3827 | std::string FullSymbolName = |
| 3828 | this->dumper()->getFullSymbolName(Symbol, StrTable, IsDynamic); |
| 3829 | unsigned char SymbolType = Symbol->getType(); |
| 3830 | |
| 3831 | DictScope D(W, "Symbol"); |
| 3832 | W.printNumber("Name", FullSymbolName, Symbol->st_name); |
| 3833 | W.printHex("Value", Symbol->st_value); |
| 3834 | W.printNumber("Size", Symbol->st_size); |
| 3835 | W.printEnum("Binding", Symbol->getBinding(), makeArrayRef(ElfSymbolBindings)); |
| 3836 | if (Obj->getHeader()->e_machine == ELF::EM_AMDGPU && |
| 3837 | SymbolType >= ELF::STT_LOOS && SymbolType < ELF::STT_HIOS) |
| 3838 | W.printEnum("Type", SymbolType, makeArrayRef(AMDGPUSymbolTypes)); |
| 3839 | else |
| 3840 | W.printEnum("Type", SymbolType, makeArrayRef(ElfSymbolTypes)); |
Simon Atanasyan | b7807a0 | 2016-03-24 16:10:37 +0000 | [diff] [blame] | 3841 | if (Symbol->st_other == 0) |
| 3842 | // Usually st_other flag is zero. Do not pollute the output |
| 3843 | // by flags enumeration in that case. |
| 3844 | W.printNumber("Other", 0); |
| 3845 | else { |
| 3846 | std::vector<EnumEntry<unsigned>> SymOtherFlags(std::begin(ElfSymOtherFlags), |
| 3847 | std::end(ElfSymOtherFlags)); |
| 3848 | if (Obj->getHeader()->e_machine == EM_MIPS) { |
| 3849 | // Someones in their infinite wisdom decided to make STO_MIPS_MIPS16 |
| 3850 | // flag overlapped with other ST_MIPS_xxx flags. So consider both |
| 3851 | // cases separately. |
| 3852 | if ((Symbol->st_other & STO_MIPS_MIPS16) == STO_MIPS_MIPS16) |
| 3853 | SymOtherFlags.insert(SymOtherFlags.end(), |
| 3854 | std::begin(ElfMips16SymOtherFlags), |
| 3855 | std::end(ElfMips16SymOtherFlags)); |
| 3856 | else |
| 3857 | SymOtherFlags.insert(SymOtherFlags.end(), |
| 3858 | std::begin(ElfMipsSymOtherFlags), |
| 3859 | std::end(ElfMipsSymOtherFlags)); |
| 3860 | } |
| 3861 | W.printFlags("Other", Symbol->st_other, makeArrayRef(SymOtherFlags), 0x3u); |
| 3862 | } |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3863 | W.printHex("Section", SectionName, SectionIndex); |
| 3864 | } |
| 3865 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3866 | template <class ELFT> void LLVMStyle<ELFT>::printSymbols(const ELFO *Obj) { |
| 3867 | ListScope Group(W, "Symbols"); |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 3868 | this->dumper()->printSymbolsHelper(false); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3869 | } |
| 3870 | |
| 3871 | template <class ELFT> |
| 3872 | void LLVMStyle<ELFT>::printDynamicSymbols(const ELFO *Obj) { |
| 3873 | ListScope Group(W, "DynamicSymbols"); |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 3874 | this->dumper()->printSymbolsHelper(true); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3875 | } |
| 3876 | |
| 3877 | template <class ELFT> |
| 3878 | void LLVMStyle<ELFT>::printDynamicRelocations(const ELFO *Obj) { |
| 3879 | const DynRegionInfo &DynRelRegion = this->dumper()->getDynRelRegion(); |
| 3880 | const DynRegionInfo &DynRelaRegion = this->dumper()->getDynRelaRegion(); |
| 3881 | const DynRegionInfo &DynPLTRelRegion = this->dumper()->getDynPLTRelRegion(); |
| 3882 | if (DynRelRegion.Size && DynRelaRegion.Size) |
| 3883 | report_fatal_error("There are both REL and RELA dynamic relocations"); |
| 3884 | W.startLine() << "Dynamic Relocations {\n"; |
| 3885 | W.indent(); |
| 3886 | if (DynRelaRegion.Size > 0) |
| 3887 | for (const Elf_Rela &Rela : this->dumper()->dyn_relas()) |
| 3888 | printDynamicRelocation(Obj, Rela); |
| 3889 | else |
| 3890 | for (const Elf_Rel &Rel : this->dumper()->dyn_rels()) { |
| 3891 | Elf_Rela Rela; |
| 3892 | Rela.r_offset = Rel.r_offset; |
| 3893 | Rela.r_info = Rel.r_info; |
| 3894 | Rela.r_addend = 0; |
| 3895 | printDynamicRelocation(Obj, Rela); |
| 3896 | } |
| 3897 | if (DynPLTRelRegion.EntSize == sizeof(Elf_Rela)) |
Rafael Espindola | aafcf75 | 2016-04-05 14:47:22 +0000 | [diff] [blame] | 3898 | for (const Elf_Rela &Rela : DynPLTRelRegion.getAsArrayRef<Elf_Rela>()) |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3899 | printDynamicRelocation(Obj, Rela); |
| 3900 | else |
Rafael Espindola | aafcf75 | 2016-04-05 14:47:22 +0000 | [diff] [blame] | 3901 | for (const Elf_Rel &Rel : DynPLTRelRegion.getAsArrayRef<Elf_Rel>()) { |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3902 | Elf_Rela Rela; |
| 3903 | Rela.r_offset = Rel.r_offset; |
| 3904 | Rela.r_info = Rel.r_info; |
| 3905 | Rela.r_addend = 0; |
| 3906 | printDynamicRelocation(Obj, Rela); |
| 3907 | } |
| 3908 | W.unindent(); |
| 3909 | W.startLine() << "}\n"; |
| 3910 | } |
| 3911 | |
| 3912 | template <class ELFT> |
| 3913 | void LLVMStyle<ELFT>::printDynamicRelocation(const ELFO *Obj, Elf_Rela Rel) { |
| 3914 | SmallString<32> RelocName; |
| 3915 | Obj->getRelocationTypeName(Rel.getType(Obj->isMips64EL()), RelocName); |
| 3916 | StringRef SymbolName; |
| 3917 | uint32_t SymIndex = Rel.getSymbol(Obj->isMips64EL()); |
| 3918 | const Elf_Sym *Sym = this->dumper()->dynamic_symbols().begin() + SymIndex; |
| 3919 | SymbolName = |
| 3920 | unwrapOrError(Sym->getName(this->dumper()->getDynamicStringTable())); |
| 3921 | if (opts::ExpandRelocs) { |
| 3922 | DictScope Group(W, "Relocation"); |
| 3923 | W.printHex("Offset", Rel.r_offset); |
| 3924 | W.printNumber("Type", RelocName, (int)Rel.getType(Obj->isMips64EL())); |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 3925 | W.printString("Symbol", !SymbolName.empty() ? SymbolName : "-"); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3926 | W.printHex("Addend", Rel.r_addend); |
| 3927 | } else { |
| 3928 | raw_ostream &OS = W.startLine(); |
| 3929 | OS << W.hex(Rel.r_offset) << " " << RelocName << " " |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 3930 | << (!SymbolName.empty() ? SymbolName : "-") << " " |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3931 | << W.hex(Rel.r_addend) << "\n"; |
| 3932 | } |
| 3933 | } |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 3934 | |
| 3935 | template <class ELFT> |
| 3936 | void LLVMStyle<ELFT>::printProgramHeaders(const ELFO *Obj) { |
| 3937 | ListScope L(W, "ProgramHeaders"); |
| 3938 | |
Rafael Espindola | 6a49497 | 2016-11-03 17:28:33 +0000 | [diff] [blame] | 3939 | for (const Elf_Phdr &Phdr : unwrapOrError(Obj->program_headers())) { |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 3940 | DictScope P(W, "ProgramHeader"); |
| 3941 | W.printHex("Type", |
| 3942 | getElfSegmentType(Obj->getHeader()->e_machine, Phdr.p_type), |
| 3943 | Phdr.p_type); |
| 3944 | W.printHex("Offset", Phdr.p_offset); |
| 3945 | W.printHex("VirtualAddress", Phdr.p_vaddr); |
| 3946 | W.printHex("PhysicalAddress", Phdr.p_paddr); |
| 3947 | W.printNumber("FileSize", Phdr.p_filesz); |
| 3948 | W.printNumber("MemSize", Phdr.p_memsz); |
| 3949 | W.printFlags("Flags", Phdr.p_flags, makeArrayRef(ElfSegmentFlags)); |
| 3950 | W.printNumber("Alignment", Phdr.p_align); |
| 3951 | } |
| 3952 | } |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 3953 | |
Hemant Kulkarni | 9b1b7f0 | 2016-04-11 17:15:30 +0000 | [diff] [blame] | 3954 | template <class ELFT> |
| 3955 | void LLVMStyle<ELFT>::printHashHistogram(const ELFFile<ELFT> *Obj) { |
| 3956 | W.startLine() << "Hash Histogram not implemented!\n"; |
| 3957 | } |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 3958 | |
| 3959 | template <class ELFT> |
| 3960 | void LLVMStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) { |
| 3961 | W.startLine() << "printNotes not implemented!\n"; |
| 3962 | } |