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