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 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// |
| 9 | /// \file |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 10 | /// This file implements the ELF-specific dumper for llvm-readobj. |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 14 | #include "ARMEHABIPrinter.h" |
Rafael Auler | 86fb7bf | 2018-03-08 00:46:53 +0000 | [diff] [blame] | 15 | #include "DwarfCFIEHPrinter.h" |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 16 | #include "Error.h" |
| 17 | #include "ObjDumper.h" |
| 18 | #include "StackMapPrinter.h" |
Zachary Turner | 88bb163 | 2016-05-03 00:28:04 +0000 | [diff] [blame] | 19 | #include "llvm-readobj.h" |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/ArrayRef.h" |
George Rimar | 762abff6 | 2017-09-16 14:29:51 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/DenseMap.h" |
Matt Davis | 0d0e9c0 | 2019-02-05 21:01:01 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/DenseSet.h" |
Wolfgang Pieb | c71c629 | 2019-08-05 22:47:07 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/MapVector.h" |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/Optional.h" |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/PointerIntPair.h" |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/STLExtras.h" |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/SmallString.h" |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 28 | #include "llvm/ADT/SmallVector.h" |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 29 | #include "llvm/ADT/StringExtras.h" |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/StringRef.h" |
| 31 | #include "llvm/ADT/Twine.h" |
Scott Linder | f5b36e5 | 2018-12-12 19:39:27 +0000 | [diff] [blame] | 32 | #include "llvm/BinaryFormat/AMDGPUMetadataVerifier.h" |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 33 | #include "llvm/BinaryFormat/ELF.h" |
James Henderson | e50d9cb | 2019-01-17 15:34:12 +0000 | [diff] [blame] | 34 | #include "llvm/Demangle/Demangle.h" |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 35 | #include "llvm/Object/ELF.h" |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 36 | #include "llvm/Object/ELFObjectFile.h" |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 37 | #include "llvm/Object/ELFTypes.h" |
| 38 | #include "llvm/Object/Error.h" |
| 39 | #include "llvm/Object/ObjectFile.h" |
Wolfgang Pieb | c71c629 | 2019-08-05 22:47:07 +0000 | [diff] [blame] | 40 | #include "llvm/Object/RelocationResolver.h" |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 41 | #include "llvm/Object/StackMapParser.h" |
Konstantin Zhuravlyov | b3c605d | 2017-10-14 18:21:42 +0000 | [diff] [blame] | 42 | #include "llvm/Support/AMDGPUMetadata.h" |
Sam Parker | 34315ee | 2017-01-13 10:50:01 +0000 | [diff] [blame] | 43 | #include "llvm/Support/ARMAttributeParser.h" |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 44 | #include "llvm/Support/ARMBuildAttributes.h" |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 45 | #include "llvm/Support/Casting.h" |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 46 | #include "llvm/Support/Compiler.h" |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 47 | #include "llvm/Support/Endian.h" |
| 48 | #include "llvm/Support/ErrorHandling.h" |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 49 | #include "llvm/Support/Format.h" |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 50 | #include "llvm/Support/FormatVariadic.h" |
Zachary Turner | 88bb163 | 2016-05-03 00:28:04 +0000 | [diff] [blame] | 51 | #include "llvm/Support/FormattedStream.h" |
Peter Collingbourne | 3e22733 | 2018-07-17 22:17:18 +0000 | [diff] [blame] | 52 | #include "llvm/Support/LEB128.h" |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 53 | #include "llvm/Support/MathExtras.h" |
| 54 | #include "llvm/Support/MipsABIFlags.h" |
Zachary Turner | 88bb163 | 2016-05-03 00:28:04 +0000 | [diff] [blame] | 55 | #include "llvm/Support/ScopedPrinter.h" |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 56 | #include "llvm/Support/raw_ostream.h" |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 57 | #include <algorithm> |
| 58 | #include <cinttypes> |
| 59 | #include <cstddef> |
| 60 | #include <cstdint> |
| 61 | #include <cstdlib> |
| 62 | #include <iterator> |
| 63 | #include <memory> |
| 64 | #include <string> |
| 65 | #include <system_error> |
George Rimar | 67ea32a | 2019-08-08 07:17:35 +0000 | [diff] [blame] | 66 | #include <unordered_set> |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 67 | #include <vector> |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 68 | |
| 69 | using namespace llvm; |
| 70 | using namespace llvm::object; |
| 71 | using namespace ELF; |
| 72 | |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 73 | #define LLVM_READOBJ_ENUM_CASE(ns, enum) \ |
| 74 | case ns::enum: \ |
| 75 | return #enum; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 76 | |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 77 | #define ENUM_ENT(enum, altName) \ |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 78 | { #enum, altName, ELF::enum } |
| 79 | |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 80 | #define ENUM_ENT_1(enum) \ |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 81 | { #enum, #enum, ELF::enum } |
| 82 | |
Hemant Kulkarni | 7d564ba | 2016-03-28 17:20:23 +0000 | [diff] [blame] | 83 | #define LLVM_READOBJ_PHDR_ENUM(ns, enum) \ |
| 84 | case ns::enum: \ |
| 85 | return std::string(#enum).substr(3); |
| 86 | |
Hemant Kulkarni | 206ba84 | 2016-03-09 19:16:13 +0000 | [diff] [blame] | 87 | #define TYPEDEF_ELF_TYPES(ELFT) \ |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 88 | using ELFO = ELFFile<ELFT>; \ |
Rui Ueyama | 478d635 | 2018-01-12 02:28:31 +0000 | [diff] [blame] | 89 | using Elf_Addr = typename ELFT::Addr; \ |
| 90 | using Elf_Shdr = typename ELFT::Shdr; \ |
| 91 | using Elf_Sym = typename ELFT::Sym; \ |
| 92 | using Elf_Dyn = typename ELFT::Dyn; \ |
| 93 | using Elf_Dyn_Range = typename ELFT::DynRange; \ |
| 94 | using Elf_Rel = typename ELFT::Rel; \ |
| 95 | using Elf_Rela = typename ELFT::Rela; \ |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 96 | using Elf_Relr = typename ELFT::Relr; \ |
Rui Ueyama | 478d635 | 2018-01-12 02:28:31 +0000 | [diff] [blame] | 97 | using Elf_Rel_Range = typename ELFT::RelRange; \ |
| 98 | using Elf_Rela_Range = typename ELFT::RelaRange; \ |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 99 | using Elf_Relr_Range = typename ELFT::RelrRange; \ |
Rui Ueyama | 478d635 | 2018-01-12 02:28:31 +0000 | [diff] [blame] | 100 | using Elf_Phdr = typename ELFT::Phdr; \ |
| 101 | using Elf_Half = typename ELFT::Half; \ |
| 102 | using Elf_Ehdr = typename ELFT::Ehdr; \ |
| 103 | using Elf_Word = typename ELFT::Word; \ |
| 104 | using Elf_Hash = typename ELFT::Hash; \ |
| 105 | using Elf_GnuHash = typename ELFT::GnuHash; \ |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 106 | using Elf_Note = typename ELFT::Note; \ |
Rui Ueyama | 478d635 | 2018-01-12 02:28:31 +0000 | [diff] [blame] | 107 | using Elf_Sym_Range = typename ELFT::SymRange; \ |
| 108 | using Elf_Versym = typename ELFT::Versym; \ |
| 109 | using Elf_Verneed = typename ELFT::Verneed; \ |
| 110 | using Elf_Vernaux = typename ELFT::Vernaux; \ |
| 111 | using Elf_Verdef = typename ELFT::Verdef; \ |
| 112 | using Elf_Verdaux = typename ELFT::Verdaux; \ |
Michael J. Spencer | ae6eeae | 2018-06-02 16:33:01 +0000 | [diff] [blame] | 113 | using Elf_CGProfile = typename ELFT::CGProfile; \ |
Rui Ueyama | 478d635 | 2018-01-12 02:28:31 +0000 | [diff] [blame] | 114 | using uintX_t = typename ELFT::uint; |
Hemant Kulkarni | 206ba84 | 2016-03-09 19:16:13 +0000 | [diff] [blame] | 115 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 116 | namespace { |
| 117 | |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 118 | template <class ELFT> class DumpStyle; |
| 119 | |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 120 | /// Represents a contiguous uniform range in the file. We cannot just create a |
| 121 | /// range directly because when creating one of these from the .dynamic table |
| 122 | /// the size, entity size and virtual address are different entries in arbitrary |
| 123 | /// order (DT_REL, DT_RELSZ, DT_RELENT for example). |
Rafael Espindola | 65a6fd8 | 2016-02-16 14:27:33 +0000 | [diff] [blame] | 124 | struct DynRegionInfo { |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 125 | DynRegionInfo() = default; |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 126 | DynRegionInfo(const void *A, uint64_t S, uint64_t ES) |
| 127 | : Addr(A), Size(S), EntSize(ES) {} |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 128 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 129 | /// Address in current address space. |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 130 | const void *Addr = nullptr; |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 131 | /// Size in bytes of the region. |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 132 | uint64_t Size = 0; |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 133 | /// Size of each entity in the region. |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 134 | uint64_t EntSize = 0; |
Rafael Espindola | c70aeda | 2016-02-16 14:50:39 +0000 | [diff] [blame] | 135 | |
Rafael Espindola | aafcf75 | 2016-04-05 14:47:22 +0000 | [diff] [blame] | 136 | template <typename Type> ArrayRef<Type> getAsArrayRef() const { |
Rafael Espindola | c70aeda | 2016-02-16 14:50:39 +0000 | [diff] [blame] | 137 | const Type *Start = reinterpret_cast<const Type *>(Addr); |
Rafael Espindola | 944f655 | 2016-02-16 15:16:00 +0000 | [diff] [blame] | 138 | if (!Start) |
| 139 | return {Start, Start}; |
George Rimar | badece0 | 2019-07-11 12:26:48 +0000 | [diff] [blame] | 140 | if (EntSize != sizeof(Type) || Size % EntSize) { |
| 141 | // TODO: Add a section index to this warning. |
| 142 | reportWarning("invalid section size (" + Twine(Size) + |
| 143 | ") or entity size (" + Twine(EntSize) + ")"); |
| 144 | return {Start, Start}; |
| 145 | } |
Rafael Espindola | c70aeda | 2016-02-16 14:50:39 +0000 | [diff] [blame] | 146 | return {Start, Start + (Size / EntSize)}; |
| 147 | } |
Rafael Espindola | 65a6fd8 | 2016-02-16 14:27:33 +0000 | [diff] [blame] | 148 | }; |
| 149 | |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 150 | template <typename ELFT> class ELFDumper : public ObjDumper { |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 151 | public: |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 152 | ELFDumper(const object::ELFObjectFile<ELFT> *ObjF, ScopedPrinter &Writer); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 153 | |
| 154 | void printFileHeaders() override; |
Jordan Rupprecht | dbf552c | 2018-11-12 18:02:38 +0000 | [diff] [blame] | 155 | void printSectionHeaders() override; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 156 | void printRelocations() override; |
| 157 | void printDynamicRelocations() override; |
James Henderson | 21ed868 | 2019-01-23 16:15:39 +0000 | [diff] [blame] | 158 | void printSymbols(bool PrintSymbols, bool PrintDynamicSymbols) override; |
James Henderson | 5fc812f | 2019-01-22 09:35:35 +0000 | [diff] [blame] | 159 | void printHashSymbols() override; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 160 | void printUnwindInfo() override; |
| 161 | |
| 162 | void printDynamicTable() override; |
| 163 | void printNeededLibraries() override; |
Matt Davis | 50ca8ed | 2019-02-01 18:51:10 +0000 | [diff] [blame] | 164 | void printProgramHeaders(bool PrintProgramHeaders, |
| 165 | cl::boolOrDefault PrintSectionMapping) override; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 166 | void printHashTable() override; |
| 167 | void printGnuHashTable() override; |
| 168 | void printLoadName() override; |
| 169 | void printVersionInfo() override; |
Hemant Kulkarni | ab4a46f | 2016-01-26 19:46:39 +0000 | [diff] [blame] | 170 | void printGroupSections() override; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 171 | |
| 172 | void printAttributes() override; |
| 173 | void printMipsPLTGOT() override; |
| 174 | void printMipsABIFlags() override; |
| 175 | void printMipsReginfo() override; |
Simon Atanasyan | 8a71b53 | 2016-05-04 05:58:57 +0000 | [diff] [blame] | 176 | void printMipsOptions() override; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 177 | |
| 178 | void printStackMap() const override; |
| 179 | |
Hemant Kulkarni | 9b1b7f0 | 2016-04-11 17:15:30 +0000 | [diff] [blame] | 180 | void printHashHistogram() override; |
| 181 | |
Michael J. Spencer | ae6eeae | 2018-06-02 16:33:01 +0000 | [diff] [blame] | 182 | void printCGProfile() override; |
Peter Collingbourne | 3e22733 | 2018-07-17 22:17:18 +0000 | [diff] [blame] | 183 | void printAddrsig() override; |
Michael J. Spencer | ae6eeae | 2018-06-02 16:33:01 +0000 | [diff] [blame] | 184 | |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 185 | void printNotes() override; |
| 186 | |
Saleem Abdulrasool | b36fbbc | 2018-01-30 16:29:29 +0000 | [diff] [blame] | 187 | void printELFLinkerOptions() override; |
Wolfgang Pieb | c71c629 | 2019-08-05 22:47:07 +0000 | [diff] [blame] | 188 | void printStackSizes() override; |
Saleem Abdulrasool | b36fbbc | 2018-01-30 16:29:29 +0000 | [diff] [blame] | 189 | |
George Rimar | a137087 | 2019-07-16 11:07:30 +0000 | [diff] [blame] | 190 | const object::ELFObjectFile<ELFT> *getElfObject() const { return ObjF; }; |
| 191 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 192 | private: |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 193 | std::unique_ptr<DumpStyle<ELFT>> ELFDumperStyle; |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 194 | |
Rafael Espindola | 6bc2990 | 2016-10-06 14:07:26 +0000 | [diff] [blame] | 195 | TYPEDEF_ELF_TYPES(ELFT) |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 196 | |
Rafael Espindola | e17c3f3 | 2016-02-17 16:48:00 +0000 | [diff] [blame] | 197 | DynRegionInfo checkDRI(DynRegionInfo DRI) { |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 198 | const ELFFile<ELFT> *Obj = ObjF->getELFFile(); |
Rafael Espindola | e17c3f3 | 2016-02-17 16:48:00 +0000 | [diff] [blame] | 199 | if (DRI.Addr < Obj->base() || |
Xing GUO | 0df95d2 | 2019-04-08 11:48:36 +0000 | [diff] [blame] | 200 | reinterpret_cast<const uint8_t *>(DRI.Addr) + DRI.Size > |
| 201 | Obj->base() + Obj->getBufSize()) |
Rafael Espindola | e17c3f3 | 2016-02-17 16:48:00 +0000 | [diff] [blame] | 202 | error(llvm::object::object_error::parse_failed); |
| 203 | return DRI; |
| 204 | } |
| 205 | |
| 206 | DynRegionInfo createDRIFrom(const Elf_Phdr *P, uintX_t EntSize) { |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 207 | return checkDRI( |
| 208 | {ObjF->getELFFile()->base() + P->p_offset, P->p_filesz, EntSize}); |
Rafael Espindola | e17c3f3 | 2016-02-17 16:48:00 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 211 | DynRegionInfo createDRIFrom(const Elf_Shdr *S) { |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 212 | return checkDRI( |
| 213 | {ObjF->getELFFile()->base() + S->sh_offset, S->sh_size, S->sh_entsize}); |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 214 | } |
| 215 | |
George Rimar | 72f821d | 2019-05-20 15:41:48 +0000 | [diff] [blame] | 216 | void loadDynamicTable(const ELFFile<ELFT> *Obj); |
| 217 | void parseDynamicTable(); |
Michael J. Spencer | 60d82b2 | 2016-02-11 04:59:37 +0000 | [diff] [blame] | 218 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 219 | StringRef getSymbolVersion(StringRef StrTab, const Elf_Sym *symb, |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 220 | bool &IsDefault) const; |
| 221 | void LoadVersionMap() const; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 222 | void LoadVersionNeeds(const Elf_Shdr *ec) const; |
| 223 | void LoadVersionDefs(const Elf_Shdr *sec) const; |
| 224 | |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 225 | const object::ELFObjectFile<ELFT> *ObjF; |
Simon Atanasyan | 72155c3 | 2016-01-16 22:40:09 +0000 | [diff] [blame] | 226 | DynRegionInfo DynRelRegion; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 227 | DynRegionInfo DynRelaRegion; |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 228 | DynRegionInfo DynRelrRegion; |
Rafael Espindola | 944f655 | 2016-02-16 15:16:00 +0000 | [diff] [blame] | 229 | DynRegionInfo DynPLTRelRegion; |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 230 | DynRegionInfo DynSymRegion; |
Rafael Espindola | e17c3f3 | 2016-02-17 16:48:00 +0000 | [diff] [blame] | 231 | DynRegionInfo DynamicTable; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 232 | StringRef DynamicStringTable; |
Yuanfang Chen | abbc3ff | 2019-07-18 17:04:28 +0000 | [diff] [blame] | 233 | std::string SOName = "<Not found>"; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 234 | const Elf_Hash *HashTable = nullptr; |
| 235 | const Elf_GnuHash *GnuHashTable = nullptr; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 236 | const Elf_Shdr *DotSymtabSec = nullptr; |
Michael J. Spencer | ae6eeae | 2018-06-02 16:33:01 +0000 | [diff] [blame] | 237 | const Elf_Shdr *DotCGProfileSec = nullptr; |
Peter Collingbourne | 3e22733 | 2018-07-17 22:17:18 +0000 | [diff] [blame] | 238 | const Elf_Shdr *DotAddrsigSec = nullptr; |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 239 | StringRef DynSymtabName; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 240 | ArrayRef<Elf_Word> ShndxTable; |
| 241 | |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 242 | const Elf_Shdr *SymbolVersionSection = nullptr; // .gnu.version |
Xing GUO | 09a77fe | 2019-03-29 01:26:36 +0000 | [diff] [blame] | 243 | const Elf_Shdr *SymbolVersionNeedSection = nullptr; // .gnu.version_r |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 244 | const Elf_Shdr *SymbolVersionDefSection = nullptr; // .gnu.version_d |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 245 | |
| 246 | // Records for each version index the corresponding Verdef or Vernaux entry. |
| 247 | // This is filled the first time LoadVersionMap() is called. |
| 248 | class VersionMapEntry : public PointerIntPair<const void *, 1> { |
| 249 | public: |
| 250 | // If the integer is 0, this is an Elf_Verdef*. |
| 251 | // If the integer is 1, this is an Elf_Vernaux*. |
| 252 | VersionMapEntry() : PointerIntPair<const void *, 1>(nullptr, 0) {} |
| 253 | VersionMapEntry(const Elf_Verdef *verdef) |
| 254 | : PointerIntPair<const void *, 1>(verdef, 0) {} |
| 255 | VersionMapEntry(const Elf_Vernaux *vernaux) |
| 256 | : PointerIntPair<const void *, 1>(vernaux, 1) {} |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 257 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 258 | bool isNull() const { return getPointer() == nullptr; } |
| 259 | bool isVerdef() const { return !isNull() && getInt() == 0; } |
| 260 | bool isVernaux() const { return !isNull() && getInt() == 1; } |
| 261 | const Elf_Verdef *getVerdef() const { |
| 262 | return isVerdef() ? (const Elf_Verdef *)getPointer() : nullptr; |
| 263 | } |
| 264 | const Elf_Vernaux *getVernaux() const { |
| 265 | return isVernaux() ? (const Elf_Vernaux *)getPointer() : nullptr; |
| 266 | } |
| 267 | }; |
| 268 | mutable SmallVector<VersionMapEntry, 16> VersionMap; |
| 269 | |
| 270 | public: |
| 271 | Elf_Dyn_Range dynamic_table() const { |
Simon Atanasyan | 8362cbe | 2019-05-24 12:22:53 +0000 | [diff] [blame] | 272 | // A valid .dynamic section contains an array of entries terminated |
| 273 | // with a DT_NULL entry. However, sometimes the section content may |
| 274 | // continue past the DT_NULL entry, so to dump the section correctly, |
| 275 | // we first find the end of the entries by iterating over them. |
| 276 | Elf_Dyn_Range Table = DynamicTable.getAsArrayRef<Elf_Dyn>(); |
| 277 | |
| 278 | size_t Size = 0; |
| 279 | while (Size < Table.size()) |
| 280 | if (Table[Size++].getTag() == DT_NULL) |
| 281 | break; |
| 282 | |
| 283 | return Table.slice(0, Size); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 284 | } |
| 285 | |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 286 | Elf_Sym_Range dynamic_symbols() const { |
Rafael Espindola | aafcf75 | 2016-04-05 14:47:22 +0000 | [diff] [blame] | 287 | return DynSymRegion.getAsArrayRef<Elf_Sym>(); |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 288 | } |
| 289 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 290 | Elf_Rel_Range dyn_rels() const; |
| 291 | Elf_Rela_Range dyn_relas() const; |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 292 | Elf_Relr_Range dyn_relrs() const; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 293 | std::string getFullSymbolName(const Elf_Sym *Symbol, StringRef StrTable, |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 294 | bool IsDynamic) const; |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 295 | void getSectionNameIndex(const Elf_Sym *Symbol, const Elf_Sym *FirstSym, |
| 296 | StringRef &SectionName, |
| 297 | unsigned &SectionIndex) const; |
James Henderson | e50d9cb | 2019-01-17 15:34:12 +0000 | [diff] [blame] | 298 | std::string getStaticSymbolName(uint32_t Index) const; |
Yuanfang Chen | abbc3ff | 2019-07-18 17:04:28 +0000 | [diff] [blame] | 299 | std::string getDynamicString(uint64_t Value) const; |
Liang Zou | 9f4a4d3 | 2019-03-31 14:49:00 +0000 | [diff] [blame] | 300 | StringRef getSymbolVersionByIndex(StringRef StrTab, |
| 301 | uint32_t VersionSymbolIndex, |
Xing GUO | 7ffd911 | 2019-03-28 12:51:46 +0000 | [diff] [blame] | 302 | bool &IsDefault) const; |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 303 | |
| 304 | void printSymbolsHelper(bool IsDynamic) const; |
Simon Atanasyan | 8362cbe | 2019-05-24 12:22:53 +0000 | [diff] [blame] | 305 | void printDynamicEntry(raw_ostream &OS, uint64_t Type, uint64_t Value) const; |
| 306 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 307 | const Elf_Shdr *getDotSymtabSec() const { return DotSymtabSec; } |
Michael J. Spencer | ae6eeae | 2018-06-02 16:33:01 +0000 | [diff] [blame] | 308 | const Elf_Shdr *getDotCGProfileSec() const { return DotCGProfileSec; } |
Peter Collingbourne | 3e22733 | 2018-07-17 22:17:18 +0000 | [diff] [blame] | 309 | const Elf_Shdr *getDotAddrsigSec() const { return DotAddrsigSec; } |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 310 | ArrayRef<Elf_Word> getShndxTable() const { return ShndxTable; } |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 311 | StringRef getDynamicStringTable() const { return DynamicStringTable; } |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 312 | const DynRegionInfo &getDynRelRegion() const { return DynRelRegion; } |
| 313 | const DynRegionInfo &getDynRelaRegion() const { return DynRelaRegion; } |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 314 | const DynRegionInfo &getDynRelrRegion() const { return DynRelrRegion; } |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 315 | const DynRegionInfo &getDynPLTRelRegion() const { return DynPLTRelRegion; } |
Simon Atanasyan | 8362cbe | 2019-05-24 12:22:53 +0000 | [diff] [blame] | 316 | const DynRegionInfo &getDynamicTableRegion() const { return DynamicTable; } |
Hemant Kulkarni | 9b1b7f0 | 2016-04-11 17:15:30 +0000 | [diff] [blame] | 317 | const Elf_Hash *getHashTable() const { return HashTable; } |
| 318 | const Elf_GnuHash *getGnuHashTable() const { return GnuHashTable; } |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 319 | }; |
| 320 | |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 321 | template <class ELFT> |
| 322 | void ELFDumper<ELFT>::printSymbolsHelper(bool IsDynamic) const { |
| 323 | StringRef StrTable, SymtabName; |
| 324 | size_t Entries = 0; |
| 325 | Elf_Sym_Range Syms(nullptr, nullptr); |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 326 | const ELFFile<ELFT> *Obj = ObjF->getELFFile(); |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 327 | if (IsDynamic) { |
| 328 | StrTable = DynamicStringTable; |
| 329 | Syms = dynamic_symbols(); |
| 330 | SymtabName = DynSymtabName; |
| 331 | if (DynSymRegion.Addr) |
| 332 | Entries = DynSymRegion.Size / DynSymRegion.EntSize; |
| 333 | } else { |
| 334 | if (!DotSymtabSec) |
| 335 | return; |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 336 | StrTable = unwrapOrError(ObjF->getFileName(), |
| 337 | Obj->getStringTableForSymtab(*DotSymtabSec)); |
| 338 | Syms = unwrapOrError(ObjF->getFileName(), Obj->symbols(DotSymtabSec)); |
| 339 | SymtabName = |
| 340 | unwrapOrError(ObjF->getFileName(), Obj->getSectionName(DotSymtabSec)); |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 341 | Entries = DotSymtabSec->getEntityCount(); |
| 342 | } |
| 343 | if (Syms.begin() == Syms.end()) |
| 344 | return; |
| 345 | ELFDumperStyle->printSymtabMessage(Obj, SymtabName, Entries); |
| 346 | for (const auto &Sym : Syms) |
| 347 | ELFDumperStyle->printSymbol(Obj, &Sym, Syms.begin(), StrTable, IsDynamic); |
| 348 | } |
| 349 | |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 350 | template <class ELFT> class MipsGOTParser; |
| 351 | |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 352 | template <typename ELFT> class DumpStyle { |
| 353 | public: |
Rui Ueyama | 478d635 | 2018-01-12 02:28:31 +0000 | [diff] [blame] | 354 | using Elf_Shdr = typename ELFT::Shdr; |
| 355 | using Elf_Sym = typename ELFT::Sym; |
Wolfgang Pieb | c71c629 | 2019-08-05 22:47:07 +0000 | [diff] [blame] | 356 | using Elf_Addr = typename ELFT::Addr; |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 357 | |
George Rimar | 67ea32a | 2019-08-08 07:17:35 +0000 | [diff] [blame] | 358 | DumpStyle(ELFDumper<ELFT> *Dumper) : Dumper(Dumper) { |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 359 | FileName = this->Dumper->getElfObject()->getFileName(); |
| 360 | |
George Rimar | 67ea32a | 2019-08-08 07:17:35 +0000 | [diff] [blame] | 361 | // Dumper reports all non-critical errors as warnings. |
| 362 | // It does not print the same warning more than once. |
| 363 | WarningHandler = [this](const Twine &Msg) { |
George Rimar | 67ea32a | 2019-08-08 07:17:35 +0000 | [diff] [blame] | 364 | if (Warnings.insert(Msg.str()).second) |
| 365 | reportWarning(FileName, createError(Msg)); |
| 366 | return Error::success(); |
| 367 | }; |
| 368 | } |
| 369 | |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 370 | virtual ~DumpStyle() = default; |
| 371 | |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 372 | virtual void printFileHeaders(const ELFFile<ELFT> *Obj) = 0; |
Hemant Kulkarni | 206ba84 | 2016-03-09 19:16:13 +0000 | [diff] [blame] | 373 | virtual void printGroupSections(const ELFFile<ELFT> *Obj) = 0; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 374 | virtual void printRelocations(const ELFFile<ELFT> *Obj) = 0; |
Jordan Rupprecht | dbf552c | 2018-11-12 18:02:38 +0000 | [diff] [blame] | 375 | virtual void printSectionHeaders(const ELFFile<ELFT> *Obj) = 0; |
James Henderson | 21ed868 | 2019-01-23 16:15:39 +0000 | [diff] [blame] | 376 | virtual void printSymbols(const ELFFile<ELFT> *Obj, bool PrintSymbols, |
| 377 | bool PrintDynamicSymbols) = 0; |
James Henderson | 5fc812f | 2019-01-22 09:35:35 +0000 | [diff] [blame] | 378 | virtual void printHashSymbols(const ELFFile<ELFT> *Obj) {} |
Simon Atanasyan | 8362cbe | 2019-05-24 12:22:53 +0000 | [diff] [blame] | 379 | virtual void printDynamic(const ELFFile<ELFT> *Obj) {} |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 380 | virtual void printDynamicRelocations(const ELFFile<ELFT> *Obj) = 0; |
James Henderson | 5fc812f | 2019-01-22 09:35:35 +0000 | [diff] [blame] | 381 | virtual void printSymtabMessage(const ELFFile<ELFT> *Obj, StringRef Name, |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 382 | size_t Offset) {} |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 383 | virtual void printSymbol(const ELFFile<ELFT> *Obj, const Elf_Sym *Symbol, |
| 384 | const Elf_Sym *FirstSym, StringRef StrTable, |
| 385 | bool IsDynamic) = 0; |
Matt Davis | 50ca8ed | 2019-02-01 18:51:10 +0000 | [diff] [blame] | 386 | virtual void printProgramHeaders(const ELFFile<ELFT> *Obj, |
| 387 | bool PrintProgramHeaders, |
| 388 | cl::boolOrDefault PrintSectionMapping) = 0; |
Xing GUO | ea16be1 | 2019-03-25 11:02:49 +0000 | [diff] [blame] | 389 | virtual void printVersionSymbolSection(const ELFFile<ELFT> *Obj, |
| 390 | const Elf_Shdr *Sec) = 0; |
| 391 | virtual void printVersionDefinitionSection(const ELFFile<ELFT> *Obj, |
| 392 | const Elf_Shdr *Sec) = 0; |
| 393 | virtual void printVersionDependencySection(const ELFFile<ELFT> *Obj, |
| 394 | const Elf_Shdr *Sec) = 0; |
Hemant Kulkarni | 9b1b7f0 | 2016-04-11 17:15:30 +0000 | [diff] [blame] | 395 | virtual void printHashHistogram(const ELFFile<ELFT> *Obj) = 0; |
Michael J. Spencer | ae6eeae | 2018-06-02 16:33:01 +0000 | [diff] [blame] | 396 | virtual void printCGProfile(const ELFFile<ELFT> *Obj) = 0; |
Peter Collingbourne | 3e22733 | 2018-07-17 22:17:18 +0000 | [diff] [blame] | 397 | virtual void printAddrsig(const ELFFile<ELFT> *Obj) = 0; |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 398 | virtual void printNotes(const ELFFile<ELFT> *Obj) = 0; |
Saleem Abdulrasool | b36fbbc | 2018-01-30 16:29:29 +0000 | [diff] [blame] | 399 | virtual void printELFLinkerOptions(const ELFFile<ELFT> *Obj) = 0; |
Wolfgang Pieb | c71c629 | 2019-08-05 22:47:07 +0000 | [diff] [blame] | 400 | virtual void printStackSizes(const ELFObjectFile<ELFT> *Obj) = 0; |
| 401 | void printNonRelocatableStackSizes(const ELFObjectFile<ELFT> *Obj, |
| 402 | std::function<void()> PrintHeader); |
| 403 | void printRelocatableStackSizes(const ELFObjectFile<ELFT> *Obj, |
| 404 | std::function<void()> PrintHeader); |
| 405 | void printFunctionStackSize(const ELFObjectFile<ELFT> *Obj, uint64_t SymValue, |
| 406 | SectionRef FunctionSec, |
| 407 | const StringRef SectionName, DataExtractor Data, |
| 408 | uint64_t *Offset); |
| 409 | void printStackSize(const ELFObjectFile<ELFT> *Obj, RelocationRef Rel, |
| 410 | SectionRef FunctionSec, |
| 411 | const StringRef &StackSizeSectionName, |
| 412 | const RelocationResolver &Resolver, DataExtractor Data); |
| 413 | virtual void printStackSizeEntry(uint64_t Size, StringRef FuncName) = 0; |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 414 | virtual void printMipsGOT(const MipsGOTParser<ELFT> &Parser) = 0; |
| 415 | virtual void printMipsPLT(const MipsGOTParser<ELFT> &Parser) = 0; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 416 | const ELFDumper<ELFT> *dumper() const { return Dumper; } |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 417 | |
George Rimar | 67ea32a | 2019-08-08 07:17:35 +0000 | [diff] [blame] | 418 | protected: |
| 419 | std::function<Error(const Twine &Msg)> WarningHandler; |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 420 | StringRef FileName; |
George Rimar | 67ea32a | 2019-08-08 07:17:35 +0000 | [diff] [blame] | 421 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 422 | private: |
George Rimar | 67ea32a | 2019-08-08 07:17:35 +0000 | [diff] [blame] | 423 | std::unordered_set<std::string> Warnings; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 424 | const ELFDumper<ELFT> *Dumper; |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 425 | }; |
| 426 | |
| 427 | template <typename ELFT> class GNUStyle : public DumpStyle<ELFT> { |
Jordan Rupprecht | 565f1e2 | 2019-06-12 20:16:22 +0000 | [diff] [blame] | 428 | formatted_raw_ostream &OS; |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 429 | |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 430 | public: |
Hemant Kulkarni | 206ba84 | 2016-03-09 19:16:13 +0000 | [diff] [blame] | 431 | TYPEDEF_ELF_TYPES(ELFT) |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 432 | |
Zachary Turner | 88bb163 | 2016-05-03 00:28:04 +0000 | [diff] [blame] | 433 | GNUStyle(ScopedPrinter &W, ELFDumper<ELFT> *Dumper) |
Jordan Rupprecht | 565f1e2 | 2019-06-12 20:16:22 +0000 | [diff] [blame] | 434 | : DumpStyle<ELFT>(Dumper), |
| 435 | OS(static_cast<formatted_raw_ostream&>(W.getOStream())) { |
| 436 | assert (&W.getOStream() == &llvm::fouts()); |
| 437 | } |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 438 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 439 | void printFileHeaders(const ELFO *Obj) override; |
Hemant Kulkarni | 206ba84 | 2016-03-09 19:16:13 +0000 | [diff] [blame] | 440 | void printGroupSections(const ELFFile<ELFT> *Obj) override; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 441 | void printRelocations(const ELFO *Obj) override; |
Jordan Rupprecht | dbf552c | 2018-11-12 18:02:38 +0000 | [diff] [blame] | 442 | void printSectionHeaders(const ELFO *Obj) override; |
James Henderson | 21ed868 | 2019-01-23 16:15:39 +0000 | [diff] [blame] | 443 | void printSymbols(const ELFO *Obj, bool PrintSymbols, |
| 444 | bool PrintDynamicSymbols) override; |
James Henderson | 5fc812f | 2019-01-22 09:35:35 +0000 | [diff] [blame] | 445 | void printHashSymbols(const ELFO *Obj) override; |
Simon Atanasyan | 8362cbe | 2019-05-24 12:22:53 +0000 | [diff] [blame] | 446 | void printDynamic(const ELFFile<ELFT> *Obj) override; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 447 | void printDynamicRelocations(const ELFO *Obj) override; |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 448 | void printSymtabMessage(const ELFO *Obj, StringRef Name, |
| 449 | size_t Offset) override; |
Matt Davis | 50ca8ed | 2019-02-01 18:51:10 +0000 | [diff] [blame] | 450 | void printProgramHeaders(const ELFO *Obj, bool PrintProgramHeaders, |
| 451 | cl::boolOrDefault PrintSectionMapping) override; |
Xing GUO | ea16be1 | 2019-03-25 11:02:49 +0000 | [diff] [blame] | 452 | void printVersionSymbolSection(const ELFFile<ELFT> *Obj, |
| 453 | const Elf_Shdr *Sec) override; |
| 454 | void printVersionDefinitionSection(const ELFFile<ELFT> *Obj, |
| 455 | const Elf_Shdr *Sec) override; |
| 456 | void printVersionDependencySection(const ELFFile<ELFT> *Obj, |
| 457 | const Elf_Shdr *Sec) override; |
Hemant Kulkarni | 9b1b7f0 | 2016-04-11 17:15:30 +0000 | [diff] [blame] | 458 | void printHashHistogram(const ELFFile<ELFT> *Obj) override; |
Michael J. Spencer | ae6eeae | 2018-06-02 16:33:01 +0000 | [diff] [blame] | 459 | void printCGProfile(const ELFFile<ELFT> *Obj) override; |
Peter Collingbourne | 3e22733 | 2018-07-17 22:17:18 +0000 | [diff] [blame] | 460 | void printAddrsig(const ELFFile<ELFT> *Obj) override; |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 461 | void printNotes(const ELFFile<ELFT> *Obj) override; |
Saleem Abdulrasool | b36fbbc | 2018-01-30 16:29:29 +0000 | [diff] [blame] | 462 | void printELFLinkerOptions(const ELFFile<ELFT> *Obj) override; |
Wolfgang Pieb | c71c629 | 2019-08-05 22:47:07 +0000 | [diff] [blame] | 463 | void printStackSizes(const ELFObjectFile<ELFT> *Obj) override; |
| 464 | void printStackSizeEntry(uint64_t Size, StringRef FuncName) 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 | struct Field { |
George Rimar | 4b4899b | 2019-01-30 14:08:55 +0000 | [diff] [blame] | 470 | std::string Str; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 471 | unsigned Column; |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 472 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 473 | Field(StringRef S, unsigned Col) : Str(S), Column(Col) {} |
George Rimar | 4b4899b | 2019-01-30 14:08:55 +0000 | [diff] [blame] | 474 | Field(unsigned Col) : Column(Col) {} |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 475 | }; |
| 476 | |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 477 | template <typename T, typename TEnum> |
| 478 | std::string printEnum(T Value, ArrayRef<EnumEntry<TEnum>> EnumValues) { |
| 479 | for (const auto &EnumItem : EnumValues) |
| 480 | if (EnumItem.Value == Value) |
| 481 | return EnumItem.AltName; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 482 | return to_hexString(Value, false); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 483 | } |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 484 | |
Simon Atanasyan | 1993254 | 2018-10-25 05:39:27 +0000 | [diff] [blame] | 485 | template <typename T, typename TEnum> |
| 486 | std::string printFlags(T Value, ArrayRef<EnumEntry<TEnum>> EnumValues, |
| 487 | TEnum EnumMask1 = {}, TEnum EnumMask2 = {}, |
| 488 | TEnum EnumMask3 = {}) { |
| 489 | std::string Str; |
| 490 | for (const auto &Flag : EnumValues) { |
| 491 | if (Flag.Value == 0) |
| 492 | continue; |
| 493 | |
| 494 | TEnum EnumMask{}; |
| 495 | if (Flag.Value & EnumMask1) |
| 496 | EnumMask = EnumMask1; |
| 497 | else if (Flag.Value & EnumMask2) |
| 498 | EnumMask = EnumMask2; |
| 499 | else if (Flag.Value & EnumMask3) |
| 500 | EnumMask = EnumMask3; |
| 501 | bool IsEnum = (Flag.Value & EnumMask) != 0; |
| 502 | if ((!IsEnum && (Value & Flag.Value) == Flag.Value) || |
| 503 | (IsEnum && (Value & EnumMask) == Flag.Value)) { |
| 504 | if (!Str.empty()) |
| 505 | Str += ", "; |
| 506 | Str += Flag.AltName; |
| 507 | } |
| 508 | } |
| 509 | return Str; |
| 510 | } |
| 511 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 512 | formatted_raw_ostream &printField(struct Field F) { |
| 513 | if (F.Column != 0) |
| 514 | OS.PadToColumn(F.Column); |
| 515 | OS << F.Str; |
| 516 | OS.flush(); |
| 517 | return OS; |
| 518 | } |
Hemant Kulkarni | a6ee9fd | 2016-11-23 18:04:23 +0000 | [diff] [blame] | 519 | void printHashedSymbol(const ELFO *Obj, const Elf_Sym *FirstSym, uint32_t Sym, |
| 520 | StringRef StrTable, uint32_t Bucket); |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 521 | void printRelocHeader(unsigned SType); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 522 | void printRelocation(const ELFO *Obj, const Elf_Shdr *SymTab, |
| 523 | const Elf_Rela &R, bool IsRela); |
James Henderson | 814ab37 | 2019-03-29 11:47:19 +0000 | [diff] [blame] | 524 | void printRelocation(const ELFO *Obj, const Elf_Sym *Sym, |
| 525 | StringRef SymbolName, const Elf_Rela &R, bool IsRela); |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 526 | void printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, const Elf_Sym *First, |
| 527 | StringRef StrTable, bool IsDynamic) override; |
| 528 | std::string getSymbolSectionNdx(const ELFO *Obj, const Elf_Sym *Symbol, |
| 529 | const Elf_Sym *FirstSym); |
Hemant Kulkarni | a79c798 | 2016-03-29 02:41:49 +0000 | [diff] [blame] | 530 | void printDynamicRelocation(const ELFO *Obj, Elf_Rela R, bool IsRela); |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 531 | bool checkTLSSections(const Elf_Phdr &Phdr, const Elf_Shdr &Sec); |
| 532 | bool checkoffsets(const Elf_Phdr &Phdr, const Elf_Shdr &Sec); |
| 533 | bool checkVMA(const Elf_Phdr &Phdr, const Elf_Shdr &Sec); |
| 534 | bool checkPTDynamic(const Elf_Phdr &Phdr, const Elf_Shdr &Sec); |
Matt Davis | 50ca8ed | 2019-02-01 18:51:10 +0000 | [diff] [blame] | 535 | void printProgramHeaders(const ELFO *Obj); |
| 536 | void printSectionMapping(const ELFO *Obj); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 537 | }; |
| 538 | |
| 539 | template <typename ELFT> class LLVMStyle : public DumpStyle<ELFT> { |
| 540 | public: |
Hemant Kulkarni | 206ba84 | 2016-03-09 19:16:13 +0000 | [diff] [blame] | 541 | TYPEDEF_ELF_TYPES(ELFT) |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 542 | |
Zachary Turner | 88bb163 | 2016-05-03 00:28:04 +0000 | [diff] [blame] | 543 | LLVMStyle(ScopedPrinter &W, ELFDumper<ELFT> *Dumper) |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 544 | : DumpStyle<ELFT>(Dumper), W(W) {} |
| 545 | |
| 546 | void printFileHeaders(const ELFO *Obj) override; |
Hemant Kulkarni | 206ba84 | 2016-03-09 19:16:13 +0000 | [diff] [blame] | 547 | void printGroupSections(const ELFFile<ELFT> *Obj) override; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 548 | void printRelocations(const ELFO *Obj) override; |
| 549 | void printRelocations(const Elf_Shdr *Sec, const ELFO *Obj); |
Jordan Rupprecht | dbf552c | 2018-11-12 18:02:38 +0000 | [diff] [blame] | 550 | void printSectionHeaders(const ELFO *Obj) override; |
James Henderson | 21ed868 | 2019-01-23 16:15:39 +0000 | [diff] [blame] | 551 | void printSymbols(const ELFO *Obj, bool PrintSymbols, |
| 552 | bool PrintDynamicSymbols) override; |
Simon Atanasyan | 8362cbe | 2019-05-24 12:22:53 +0000 | [diff] [blame] | 553 | void printDynamic(const ELFFile<ELFT> *Obj) override; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 554 | void printDynamicRelocations(const ELFO *Obj) override; |
Matt Davis | 50ca8ed | 2019-02-01 18:51:10 +0000 | [diff] [blame] | 555 | void printProgramHeaders(const ELFO *Obj, bool PrintProgramHeaders, |
| 556 | cl::boolOrDefault PrintSectionMapping) override; |
Xing GUO | ea16be1 | 2019-03-25 11:02:49 +0000 | [diff] [blame] | 557 | void printVersionSymbolSection(const ELFFile<ELFT> *Obj, |
| 558 | const Elf_Shdr *Sec) override; |
| 559 | void printVersionDefinitionSection(const ELFFile<ELFT> *Obj, |
| 560 | const Elf_Shdr *Sec) override; |
| 561 | void printVersionDependencySection(const ELFFile<ELFT> *Obj, |
| 562 | const Elf_Shdr *Sec) override; |
Hemant Kulkarni | 9b1b7f0 | 2016-04-11 17:15:30 +0000 | [diff] [blame] | 563 | void printHashHistogram(const ELFFile<ELFT> *Obj) override; |
Michael J. Spencer | ae6eeae | 2018-06-02 16:33:01 +0000 | [diff] [blame] | 564 | void printCGProfile(const ELFFile<ELFT> *Obj) override; |
Peter Collingbourne | 3e22733 | 2018-07-17 22:17:18 +0000 | [diff] [blame] | 565 | void printAddrsig(const ELFFile<ELFT> *Obj) override; |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 566 | void printNotes(const ELFFile<ELFT> *Obj) override; |
Saleem Abdulrasool | b36fbbc | 2018-01-30 16:29:29 +0000 | [diff] [blame] | 567 | void printELFLinkerOptions(const ELFFile<ELFT> *Obj) override; |
Wolfgang Pieb | c71c629 | 2019-08-05 22:47:07 +0000 | [diff] [blame] | 568 | void printStackSizes(const ELFObjectFile<ELFT> *Obj) override; |
| 569 | void printStackSizeEntry(uint64_t Size, StringRef FuncName) override; |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 570 | void printMipsGOT(const MipsGOTParser<ELFT> &Parser) override; |
| 571 | void printMipsPLT(const MipsGOTParser<ELFT> &Parser) override; |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 572 | |
| 573 | private: |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 574 | void printRelocation(const ELFO *Obj, Elf_Rela Rel, const Elf_Shdr *SymTab); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 575 | void printDynamicRelocation(const ELFO *Obj, Elf_Rela Rel); |
James Henderson | 21ed868 | 2019-01-23 16:15:39 +0000 | [diff] [blame] | 576 | void printSymbols(const ELFO *Obj); |
| 577 | void printDynamicSymbols(const ELFO *Obj); |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 578 | void printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, const Elf_Sym *First, |
| 579 | StringRef StrTable, bool IsDynamic) override; |
Matt Davis | 50ca8ed | 2019-02-01 18:51:10 +0000 | [diff] [blame] | 580 | void printProgramHeaders(const ELFO *Obj); |
| 581 | void printSectionMapping(const ELFO *Obj) {} |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 582 | |
Zachary Turner | 88bb163 | 2016-05-03 00:28:04 +0000 | [diff] [blame] | 583 | ScopedPrinter &W; |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 584 | }; |
| 585 | |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 586 | } // end anonymous namespace |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 587 | |
| 588 | namespace llvm { |
| 589 | |
| 590 | template <class ELFT> |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 591 | static std::error_code createELFDumper(const ELFObjectFile<ELFT> *Obj, |
Zachary Turner | 88bb163 | 2016-05-03 00:28:04 +0000 | [diff] [blame] | 592 | ScopedPrinter &Writer, |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 593 | std::unique_ptr<ObjDumper> &Result) { |
| 594 | Result.reset(new ELFDumper<ELFT>(Obj, Writer)); |
| 595 | return readobj_error::success; |
| 596 | } |
| 597 | |
| 598 | std::error_code createELFDumper(const object::ObjectFile *Obj, |
Zachary Turner | 88bb163 | 2016-05-03 00:28:04 +0000 | [diff] [blame] | 599 | ScopedPrinter &Writer, |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 600 | std::unique_ptr<ObjDumper> &Result) { |
| 601 | // Little-endian 32-bit |
| 602 | if (const ELF32LEObjectFile *ELFObj = dyn_cast<ELF32LEObjectFile>(Obj)) |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 603 | return createELFDumper(ELFObj, Writer, Result); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 604 | |
| 605 | // Big-endian 32-bit |
| 606 | if (const ELF32BEObjectFile *ELFObj = dyn_cast<ELF32BEObjectFile>(Obj)) |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 607 | return createELFDumper(ELFObj, Writer, Result); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 608 | |
| 609 | // Little-endian 64-bit |
| 610 | if (const ELF64LEObjectFile *ELFObj = dyn_cast<ELF64LEObjectFile>(Obj)) |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 611 | return createELFDumper(ELFObj, Writer, Result); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 612 | |
| 613 | // Big-endian 64-bit |
| 614 | if (const ELF64BEObjectFile *ELFObj = dyn_cast<ELF64BEObjectFile>(Obj)) |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 615 | return createELFDumper(ELFObj, Writer, Result); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 616 | |
| 617 | return readobj_error::unsupported_obj_file_format; |
| 618 | } |
| 619 | |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 620 | } // end namespace llvm |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 621 | |
| 622 | // Iterate through the versions needed section, and place each Elf_Vernaux |
| 623 | // in the VersionMap according to its index. |
| 624 | template <class ELFT> |
Xing GUO | e855e2e | 2019-04-12 07:09:41 +0000 | [diff] [blame] | 625 | void ELFDumper<ELFT>::LoadVersionNeeds(const Elf_Shdr *Sec) const { |
| 626 | unsigned VerneedSize = Sec->sh_size; // Size of section in bytes |
| 627 | unsigned VerneedEntries = Sec->sh_info; // Number of Verneed entries |
| 628 | const uint8_t *VerneedStart = reinterpret_cast<const uint8_t *>( |
| 629 | ObjF->getELFFile()->base() + Sec->sh_offset); |
| 630 | const uint8_t *VerneedEnd = VerneedStart + VerneedSize; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 631 | // The first Verneed entry is at the start of the section. |
Xing GUO | e855e2e | 2019-04-12 07:09:41 +0000 | [diff] [blame] | 632 | const uint8_t *VerneedBuf = VerneedStart; |
| 633 | for (unsigned VerneedIndex = 0; VerneedIndex < VerneedEntries; |
| 634 | ++VerneedIndex) { |
| 635 | if (VerneedBuf + sizeof(Elf_Verneed) > VerneedEnd) |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 636 | report_fatal_error("Section ended unexpectedly while scanning " |
| 637 | "version needed records."); |
Xing GUO | e855e2e | 2019-04-12 07:09:41 +0000 | [diff] [blame] | 638 | const Elf_Verneed *Verneed = |
| 639 | reinterpret_cast<const Elf_Verneed *>(VerneedBuf); |
| 640 | if (Verneed->vn_version != ELF::VER_NEED_CURRENT) |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 641 | report_fatal_error("Unexpected verneed version"); |
| 642 | // Iterate through the Vernaux entries |
Xing GUO | e855e2e | 2019-04-12 07:09:41 +0000 | [diff] [blame] | 643 | const uint8_t *VernauxBuf = VerneedBuf + Verneed->vn_aux; |
| 644 | for (unsigned VernauxIndex = 0; VernauxIndex < Verneed->vn_cnt; |
| 645 | ++VernauxIndex) { |
| 646 | if (VernauxBuf + sizeof(Elf_Vernaux) > VerneedEnd) |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 647 | report_fatal_error("Section ended unexpected while scanning auxiliary " |
| 648 | "version needed records."); |
Xing GUO | e855e2e | 2019-04-12 07:09:41 +0000 | [diff] [blame] | 649 | const Elf_Vernaux *Vernaux = |
| 650 | reinterpret_cast<const Elf_Vernaux *>(VernauxBuf); |
| 651 | size_t Index = Vernaux->vna_other & ELF::VERSYM_VERSION; |
| 652 | if (Index >= VersionMap.size()) |
| 653 | VersionMap.resize(Index + 1); |
| 654 | VersionMap[Index] = VersionMapEntry(Vernaux); |
| 655 | VernauxBuf += Vernaux->vna_next; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 656 | } |
Xing GUO | e855e2e | 2019-04-12 07:09:41 +0000 | [diff] [blame] | 657 | VerneedBuf += Verneed->vn_next; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 658 | } |
| 659 | } |
| 660 | |
| 661 | // Iterate through the version definitions, and place each Elf_Verdef |
| 662 | // in the VersionMap according to its index. |
| 663 | template <class ELFT> |
Xing GUO | e855e2e | 2019-04-12 07:09:41 +0000 | [diff] [blame] | 664 | void ELFDumper<ELFT>::LoadVersionDefs(const Elf_Shdr *Sec) const { |
| 665 | unsigned VerdefSize = Sec->sh_size; // Size of section in bytes |
| 666 | unsigned VerdefEntries = Sec->sh_info; // Number of Verdef entries |
| 667 | const uint8_t *VerdefStart = reinterpret_cast<const uint8_t *>( |
| 668 | ObjF->getELFFile()->base() + Sec->sh_offset); |
| 669 | const uint8_t *VerdefEnd = VerdefStart + VerdefSize; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 670 | // The first Verdef entry is at the start of the section. |
Xing GUO | e855e2e | 2019-04-12 07:09:41 +0000 | [diff] [blame] | 671 | const uint8_t *VerdefBuf = VerdefStart; |
| 672 | for (unsigned VerdefIndex = 0; VerdefIndex < VerdefEntries; ++VerdefIndex) { |
| 673 | if (VerdefBuf + sizeof(Elf_Verdef) > VerdefEnd) |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 674 | report_fatal_error("Section ended unexpectedly while scanning " |
| 675 | "version definitions."); |
Xing GUO | e855e2e | 2019-04-12 07:09:41 +0000 | [diff] [blame] | 676 | const Elf_Verdef *Verdef = reinterpret_cast<const Elf_Verdef *>(VerdefBuf); |
| 677 | if (Verdef->vd_version != ELF::VER_DEF_CURRENT) |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 678 | report_fatal_error("Unexpected verdef version"); |
Xing GUO | e855e2e | 2019-04-12 07:09:41 +0000 | [diff] [blame] | 679 | size_t Index = Verdef->vd_ndx & ELF::VERSYM_VERSION; |
| 680 | if (Index >= VersionMap.size()) |
| 681 | VersionMap.resize(Index + 1); |
| 682 | VersionMap[Index] = VersionMapEntry(Verdef); |
| 683 | VerdefBuf += Verdef->vd_next; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 684 | } |
| 685 | } |
| 686 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 687 | template <class ELFT> void ELFDumper<ELFT>::LoadVersionMap() const { |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 688 | // If there is no dynamic symtab or version table, there is nothing to do. |
Xing GUO | 09a77fe | 2019-03-29 01:26:36 +0000 | [diff] [blame] | 689 | if (!DynSymRegion.Addr || !SymbolVersionSection) |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 690 | return; |
| 691 | |
| 692 | // Has the VersionMap already been loaded? |
Jordan Rupprecht | 16a0de2 | 2018-12-20 00:57:06 +0000 | [diff] [blame] | 693 | if (!VersionMap.empty()) |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 694 | return; |
| 695 | |
| 696 | // The first two version indexes are reserved. |
| 697 | // Index 0 is LOCAL, index 1 is GLOBAL. |
| 698 | VersionMap.push_back(VersionMapEntry()); |
| 699 | VersionMap.push_back(VersionMapEntry()); |
| 700 | |
Xing GUO | 09a77fe | 2019-03-29 01:26:36 +0000 | [diff] [blame] | 701 | if (SymbolVersionDefSection) |
| 702 | LoadVersionDefs(SymbolVersionDefSection); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 703 | |
Xing GUO | 09a77fe | 2019-03-29 01:26:36 +0000 | [diff] [blame] | 704 | if (SymbolVersionNeedSection) |
| 705 | LoadVersionNeeds(SymbolVersionNeedSection); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 706 | } |
| 707 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 708 | template <typename ELFT> |
| 709 | StringRef ELFDumper<ELFT>::getSymbolVersion(StringRef StrTab, |
Xing GUO | 137315e | 2019-03-28 12:51:35 +0000 | [diff] [blame] | 710 | const Elf_Sym *Sym, |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 711 | bool &IsDefault) const { |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 712 | // This is a dynamic symbol. Look in the GNU symbol version table. |
Xing GUO | 09a77fe | 2019-03-29 01:26:36 +0000 | [diff] [blame] | 713 | if (!SymbolVersionSection) { |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 714 | // No version table. |
| 715 | IsDefault = false; |
Xing GUO | 12632c7 | 2019-03-28 12:51:56 +0000 | [diff] [blame] | 716 | return ""; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | // Determine the position in the symbol table of this entry. |
Xing GUO | 137315e | 2019-03-28 12:51:35 +0000 | [diff] [blame] | 720 | size_t EntryIndex = (reinterpret_cast<uintptr_t>(Sym) - |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 721 | reinterpret_cast<uintptr_t>(DynSymRegion.Addr)) / |
| 722 | sizeof(Elf_Sym); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 723 | |
Xing GUO | 7ffd911 | 2019-03-28 12:51:46 +0000 | [diff] [blame] | 724 | // Get the corresponding version index entry. |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 725 | const Elf_Versym *Versym = unwrapOrError( |
| 726 | ObjF->getFileName(), ObjF->getELFFile()->template getEntry<Elf_Versym>( |
| 727 | SymbolVersionSection, EntryIndex)); |
Xing GUO | 7ffd911 | 2019-03-28 12:51:46 +0000 | [diff] [blame] | 728 | return this->getSymbolVersionByIndex(StrTab, Versym->vs_index, IsDefault); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 729 | } |
| 730 | |
James Henderson | e50d9cb | 2019-01-17 15:34:12 +0000 | [diff] [blame] | 731 | static std::string maybeDemangle(StringRef Name) { |
| 732 | return opts::Demangle ? demangle(Name) : Name.str(); |
| 733 | } |
| 734 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 735 | template <typename ELFT> |
James Henderson | e50d9cb | 2019-01-17 15:34:12 +0000 | [diff] [blame] | 736 | std::string ELFDumper<ELFT>::getStaticSymbolName(uint32_t Index) const { |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 737 | const ELFFile<ELFT> *Obj = ObjF->getELFFile(); |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 738 | StringRef StrTable = unwrapOrError( |
| 739 | ObjF->getFileName(), Obj->getStringTableForSymtab(*DotSymtabSec)); |
| 740 | Elf_Sym_Range Syms = |
| 741 | unwrapOrError(ObjF->getFileName(), Obj->symbols(DotSymtabSec)); |
Michael J. Spencer | ae6eeae | 2018-06-02 16:33:01 +0000 | [diff] [blame] | 742 | if (Index >= Syms.size()) |
| 743 | reportError("Invalid symbol index"); |
| 744 | const Elf_Sym *Sym = &Syms[Index]; |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 745 | return maybeDemangle( |
| 746 | unwrapOrError(ObjF->getFileName(), Sym->getName(StrTable))); |
Michael J. Spencer | ae6eeae | 2018-06-02 16:33:01 +0000 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | template <typename ELFT> |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 750 | StringRef ELFDumper<ELFT>::getSymbolVersionByIndex(StringRef StrTab, |
| 751 | uint32_t SymbolVersionIndex, |
| 752 | bool &IsDefault) const { |
Xing GUO | 137315e | 2019-03-28 12:51:35 +0000 | [diff] [blame] | 753 | size_t VersionIndex = SymbolVersionIndex & VERSYM_VERSION; |
| 754 | |
| 755 | // Special markers for unversioned symbols. |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 756 | if (VersionIndex == VER_NDX_LOCAL || VersionIndex == VER_NDX_GLOBAL) { |
Xing GUO | 137315e | 2019-03-28 12:51:35 +0000 | [diff] [blame] | 757 | IsDefault = false; |
Xing GUO | 12632c7 | 2019-03-28 12:51:56 +0000 | [diff] [blame] | 758 | return ""; |
Xing GUO | 137315e | 2019-03-28 12:51:35 +0000 | [diff] [blame] | 759 | } |
| 760 | |
Xing GUO | 7ffd911 | 2019-03-28 12:51:46 +0000 | [diff] [blame] | 761 | // Lookup this symbol in the version table. |
Xing GUO | 137315e | 2019-03-28 12:51:35 +0000 | [diff] [blame] | 762 | LoadVersionMap(); |
| 763 | if (VersionIndex >= VersionMap.size() || VersionMap[VersionIndex].isNull()) |
| 764 | reportError("Invalid version entry"); |
| 765 | const VersionMapEntry &Entry = VersionMap[VersionIndex]; |
| 766 | |
Xing GUO | 7ffd911 | 2019-03-28 12:51:46 +0000 | [diff] [blame] | 767 | // Get the version name string. |
Xing GUO | 137315e | 2019-03-28 12:51:35 +0000 | [diff] [blame] | 768 | size_t NameOffset; |
| 769 | if (Entry.isVerdef()) { |
| 770 | // The first Verdaux entry holds the name. |
| 771 | NameOffset = Entry.getVerdef()->getAux()->vda_name; |
| 772 | IsDefault = !(SymbolVersionIndex & VERSYM_HIDDEN); |
| 773 | } else { |
| 774 | NameOffset = Entry.getVernaux()->vna_name; |
| 775 | IsDefault = false; |
| 776 | } |
| 777 | if (NameOffset >= StrTab.size()) |
| 778 | reportError("Invalid string offset"); |
Xing GUO | 12632c7 | 2019-03-28 12:51:56 +0000 | [diff] [blame] | 779 | return StrTab.data() + NameOffset; |
Xing GUO | 137315e | 2019-03-28 12:51:35 +0000 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | template <typename ELFT> |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 783 | std::string ELFDumper<ELFT>::getFullSymbolName(const Elf_Sym *Symbol, |
| 784 | StringRef StrTable, |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 785 | bool IsDynamic) const { |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 786 | std::string SymbolName = maybeDemangle( |
| 787 | unwrapOrError(ObjF->getFileName(), Symbol->getName(StrTable))); |
Matt Davis | 8a6f11f | 2019-03-01 17:31:32 +0000 | [diff] [blame] | 788 | |
| 789 | if (SymbolName.empty() && Symbol->getType() == ELF::STT_SECTION) { |
| 790 | unsigned SectionIndex; |
| 791 | StringRef SectionName; |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 792 | Elf_Sym_Range Syms = unwrapOrError( |
| 793 | ObjF->getFileName(), ObjF->getELFFile()->symbols(DotSymtabSec)); |
Matt Davis | 8a6f11f | 2019-03-01 17:31:32 +0000 | [diff] [blame] | 794 | getSectionNameIndex(Symbol, Syms.begin(), SectionName, SectionIndex); |
| 795 | return SectionName; |
| 796 | } |
| 797 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 798 | if (!IsDynamic) |
| 799 | return SymbolName; |
| 800 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 801 | bool IsDefault; |
| 802 | StringRef Version = getSymbolVersion(StrTable, &*Symbol, IsDefault); |
James Henderson | 6135b0f8 | 2019-01-08 10:58:05 +0000 | [diff] [blame] | 803 | if (!Version.empty()) { |
James Henderson | e50d9cb | 2019-01-17 15:34:12 +0000 | [diff] [blame] | 804 | SymbolName += (IsDefault ? "@@" : "@"); |
| 805 | SymbolName += Version; |
James Henderson | 6135b0f8 | 2019-01-08 10:58:05 +0000 | [diff] [blame] | 806 | } |
James Henderson | e50d9cb | 2019-01-17 15:34:12 +0000 | [diff] [blame] | 807 | return SymbolName; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 808 | } |
| 809 | |
Rafael Espindola | 714c295 | 2016-11-03 14:41:17 +0000 | [diff] [blame] | 810 | template <typename ELFT> |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 811 | void ELFDumper<ELFT>::getSectionNameIndex(const Elf_Sym *Symbol, |
| 812 | const Elf_Sym *FirstSym, |
| 813 | StringRef &SectionName, |
| 814 | unsigned &SectionIndex) const { |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 815 | SectionIndex = Symbol->st_shndx; |
| 816 | if (Symbol->isUndefined()) |
| 817 | SectionName = "Undefined"; |
| 818 | else if (Symbol->isProcessorSpecific()) |
| 819 | SectionName = "Processor Specific"; |
| 820 | else if (Symbol->isOSSpecific()) |
| 821 | SectionName = "Operating System Specific"; |
| 822 | else if (Symbol->isAbsolute()) |
| 823 | SectionName = "Absolute"; |
| 824 | else if (Symbol->isCommon()) |
| 825 | SectionName = "Common"; |
| 826 | else if (Symbol->isReserved() && SectionIndex != SHN_XINDEX) |
| 827 | SectionName = "Reserved"; |
| 828 | else { |
| 829 | if (SectionIndex == SHN_XINDEX) |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 830 | SectionIndex = unwrapOrError(ObjF->getFileName(), |
| 831 | object::getExtendedSymbolTableIndex<ELFT>( |
| 832 | Symbol, FirstSym, ShndxTable)); |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 833 | const ELFFile<ELFT> *Obj = ObjF->getELFFile(); |
Rafael Espindola | 714c295 | 2016-11-03 14:41:17 +0000 | [diff] [blame] | 834 | const typename ELFT::Shdr *Sec = |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 835 | unwrapOrError(ObjF->getFileName(), Obj->getSection(SectionIndex)); |
| 836 | SectionName = unwrapOrError(ObjF->getFileName(), Obj->getSectionName(Sec)); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 837 | } |
| 838 | } |
| 839 | |
| 840 | template <class ELFO> |
Simon Atanasyan | cb1175c | 2016-02-09 18:45:35 +0000 | [diff] [blame] | 841 | static const typename ELFO::Elf_Shdr * |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 842 | findNotEmptySectionByAddress(const ELFO *Obj, StringRef FileName, |
| 843 | uint64_t Addr) { |
| 844 | for (const auto &Shdr : unwrapOrError(FileName, Obj->sections())) |
Simon Atanasyan | cb1175c | 2016-02-09 18:45:35 +0000 | [diff] [blame] | 845 | if (Shdr.sh_addr == Addr && Shdr.sh_size > 0) |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 846 | return &Shdr; |
| 847 | return nullptr; |
| 848 | } |
| 849 | |
| 850 | template <class ELFO> |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 851 | static const typename ELFO::Elf_Shdr * |
| 852 | findSectionByName(const ELFO &Obj, StringRef FileName, StringRef Name) { |
| 853 | for (const auto &Shdr : unwrapOrError(FileName, Obj.sections())) |
| 854 | if (Name == unwrapOrError(FileName, Obj.getSectionName(&Shdr))) |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 855 | return &Shdr; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 856 | return nullptr; |
| 857 | } |
| 858 | |
| 859 | static const EnumEntry<unsigned> ElfClass[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 860 | {"None", "none", ELF::ELFCLASSNONE}, |
| 861 | {"32-bit", "ELF32", ELF::ELFCLASS32}, |
| 862 | {"64-bit", "ELF64", ELF::ELFCLASS64}, |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 863 | }; |
| 864 | |
| 865 | static const EnumEntry<unsigned> ElfDataEncoding[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 866 | {"None", "none", ELF::ELFDATANONE}, |
| 867 | {"LittleEndian", "2's complement, little endian", ELF::ELFDATA2LSB}, |
| 868 | {"BigEndian", "2's complement, big endian", ELF::ELFDATA2MSB}, |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 869 | }; |
| 870 | |
| 871 | static const EnumEntry<unsigned> ElfObjectFileType[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 872 | {"None", "NONE (none)", ELF::ET_NONE}, |
| 873 | {"Relocatable", "REL (Relocatable file)", ELF::ET_REL}, |
| 874 | {"Executable", "EXEC (Executable file)", ELF::ET_EXEC}, |
| 875 | {"SharedObject", "DYN (Shared object file)", ELF::ET_DYN}, |
| 876 | {"Core", "CORE (Core file)", ELF::ET_CORE}, |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 877 | }; |
| 878 | |
| 879 | static const EnumEntry<unsigned> ElfOSABI[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 880 | {"SystemV", "UNIX - System V", ELF::ELFOSABI_NONE}, |
| 881 | {"HPUX", "UNIX - HP-UX", ELF::ELFOSABI_HPUX}, |
| 882 | {"NetBSD", "UNIX - NetBSD", ELF::ELFOSABI_NETBSD}, |
| 883 | {"GNU/Linux", "UNIX - GNU", ELF::ELFOSABI_LINUX}, |
| 884 | {"GNU/Hurd", "GNU/Hurd", ELF::ELFOSABI_HURD}, |
| 885 | {"Solaris", "UNIX - Solaris", ELF::ELFOSABI_SOLARIS}, |
| 886 | {"AIX", "UNIX - AIX", ELF::ELFOSABI_AIX}, |
| 887 | {"IRIX", "UNIX - IRIX", ELF::ELFOSABI_IRIX}, |
| 888 | {"FreeBSD", "UNIX - FreeBSD", ELF::ELFOSABI_FREEBSD}, |
| 889 | {"TRU64", "UNIX - TRU64", ELF::ELFOSABI_TRU64}, |
| 890 | {"Modesto", "Novell - Modesto", ELF::ELFOSABI_MODESTO}, |
| 891 | {"OpenBSD", "UNIX - OpenBSD", ELF::ELFOSABI_OPENBSD}, |
| 892 | {"OpenVMS", "VMS - OpenVMS", ELF::ELFOSABI_OPENVMS}, |
| 893 | {"NSK", "HP - Non-Stop Kernel", ELF::ELFOSABI_NSK}, |
| 894 | {"AROS", "AROS", ELF::ELFOSABI_AROS}, |
| 895 | {"FenixOS", "FenixOS", ELF::ELFOSABI_FENIXOS}, |
| 896 | {"CloudABI", "CloudABI", ELF::ELFOSABI_CLOUDABI}, |
| 897 | {"Standalone", "Standalone App", ELF::ELFOSABI_STANDALONE} |
| 898 | }; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 899 | |
Xing GUO | ea16be1 | 2019-03-25 11:02:49 +0000 | [diff] [blame] | 900 | static const EnumEntry<unsigned> SymVersionFlags[] = { |
| 901 | {"Base", "BASE", VER_FLG_BASE}, |
| 902 | {"Weak", "WEAK", VER_FLG_WEAK}, |
| 903 | {"Info", "INFO", VER_FLG_INFO}}; |
| 904 | |
Konstantin Zhuravlyov | 121125f | 2017-10-02 20:49:58 +0000 | [diff] [blame] | 905 | static const EnumEntry<unsigned> AMDGPUElfOSABI[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 906 | {"AMDGPU_HSA", "AMDGPU - HSA", ELF::ELFOSABI_AMDGPU_HSA}, |
| 907 | {"AMDGPU_PAL", "AMDGPU - PAL", ELF::ELFOSABI_AMDGPU_PAL}, |
| 908 | {"AMDGPU_MESA3D", "AMDGPU - MESA3D", ELF::ELFOSABI_AMDGPU_MESA3D} |
| 909 | }; |
Konstantin Zhuravlyov | 121125f | 2017-10-02 20:49:58 +0000 | [diff] [blame] | 910 | |
| 911 | static const EnumEntry<unsigned> ARMElfOSABI[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 912 | {"ARM", "ARM", ELF::ELFOSABI_ARM} |
| 913 | }; |
Konstantin Zhuravlyov | 121125f | 2017-10-02 20:49:58 +0000 | [diff] [blame] | 914 | |
| 915 | static const EnumEntry<unsigned> C6000ElfOSABI[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 916 | {"C6000_ELFABI", "Bare-metal C6000", ELF::ELFOSABI_C6000_ELFABI}, |
| 917 | {"C6000_LINUX", "Linux C6000", ELF::ELFOSABI_C6000_LINUX} |
| 918 | }; |
Konstantin Zhuravlyov | 121125f | 2017-10-02 20:49:58 +0000 | [diff] [blame] | 919 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 920 | static const EnumEntry<unsigned> ElfMachineType[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 921 | ENUM_ENT(EM_NONE, "None"), |
| 922 | ENUM_ENT(EM_M32, "WE32100"), |
| 923 | ENUM_ENT(EM_SPARC, "Sparc"), |
| 924 | ENUM_ENT(EM_386, "Intel 80386"), |
| 925 | ENUM_ENT(EM_68K, "MC68000"), |
| 926 | ENUM_ENT(EM_88K, "MC88000"), |
| 927 | ENUM_ENT(EM_IAMCU, "EM_IAMCU"), |
| 928 | ENUM_ENT(EM_860, "Intel 80860"), |
| 929 | ENUM_ENT(EM_MIPS, "MIPS R3000"), |
| 930 | ENUM_ENT(EM_S370, "IBM System/370"), |
| 931 | ENUM_ENT(EM_MIPS_RS3_LE, "MIPS R3000 little-endian"), |
| 932 | ENUM_ENT(EM_PARISC, "HPPA"), |
| 933 | ENUM_ENT(EM_VPP500, "Fujitsu VPP500"), |
| 934 | ENUM_ENT(EM_SPARC32PLUS, "Sparc v8+"), |
| 935 | ENUM_ENT(EM_960, "Intel 80960"), |
| 936 | ENUM_ENT(EM_PPC, "PowerPC"), |
| 937 | ENUM_ENT(EM_PPC64, "PowerPC64"), |
| 938 | ENUM_ENT(EM_S390, "IBM S/390"), |
| 939 | ENUM_ENT(EM_SPU, "SPU"), |
| 940 | ENUM_ENT(EM_V800, "NEC V800 series"), |
| 941 | ENUM_ENT(EM_FR20, "Fujistsu FR20"), |
| 942 | ENUM_ENT(EM_RH32, "TRW RH-32"), |
| 943 | ENUM_ENT(EM_RCE, "Motorola RCE"), |
| 944 | ENUM_ENT(EM_ARM, "ARM"), |
| 945 | ENUM_ENT(EM_ALPHA, "EM_ALPHA"), |
| 946 | ENUM_ENT(EM_SH, "Hitachi SH"), |
| 947 | ENUM_ENT(EM_SPARCV9, "Sparc v9"), |
| 948 | ENUM_ENT(EM_TRICORE, "Siemens Tricore"), |
| 949 | ENUM_ENT(EM_ARC, "ARC"), |
| 950 | ENUM_ENT(EM_H8_300, "Hitachi H8/300"), |
| 951 | ENUM_ENT(EM_H8_300H, "Hitachi H8/300H"), |
| 952 | ENUM_ENT(EM_H8S, "Hitachi H8S"), |
| 953 | ENUM_ENT(EM_H8_500, "Hitachi H8/500"), |
| 954 | ENUM_ENT(EM_IA_64, "Intel IA-64"), |
| 955 | ENUM_ENT(EM_MIPS_X, "Stanford MIPS-X"), |
| 956 | ENUM_ENT(EM_COLDFIRE, "Motorola Coldfire"), |
| 957 | ENUM_ENT(EM_68HC12, "Motorola MC68HC12 Microcontroller"), |
| 958 | ENUM_ENT(EM_MMA, "Fujitsu Multimedia Accelerator"), |
| 959 | ENUM_ENT(EM_PCP, "Siemens PCP"), |
| 960 | ENUM_ENT(EM_NCPU, "Sony nCPU embedded RISC processor"), |
| 961 | ENUM_ENT(EM_NDR1, "Denso NDR1 microprocesspr"), |
| 962 | ENUM_ENT(EM_STARCORE, "Motorola Star*Core processor"), |
| 963 | ENUM_ENT(EM_ME16, "Toyota ME16 processor"), |
| 964 | ENUM_ENT(EM_ST100, "STMicroelectronics ST100 processor"), |
| 965 | ENUM_ENT(EM_TINYJ, "Advanced Logic Corp. TinyJ embedded processor"), |
| 966 | ENUM_ENT(EM_X86_64, "Advanced Micro Devices X86-64"), |
| 967 | ENUM_ENT(EM_PDSP, "Sony DSP processor"), |
| 968 | ENUM_ENT(EM_PDP10, "Digital Equipment Corp. PDP-10"), |
| 969 | ENUM_ENT(EM_PDP11, "Digital Equipment Corp. PDP-11"), |
| 970 | ENUM_ENT(EM_FX66, "Siemens FX66 microcontroller"), |
| 971 | ENUM_ENT(EM_ST9PLUS, "STMicroelectronics ST9+ 8/16 bit microcontroller"), |
| 972 | ENUM_ENT(EM_ST7, "STMicroelectronics ST7 8-bit microcontroller"), |
| 973 | ENUM_ENT(EM_68HC16, "Motorola MC68HC16 Microcontroller"), |
| 974 | ENUM_ENT(EM_68HC11, "Motorola MC68HC11 Microcontroller"), |
| 975 | ENUM_ENT(EM_68HC08, "Motorola MC68HC08 Microcontroller"), |
| 976 | ENUM_ENT(EM_68HC05, "Motorola MC68HC05 Microcontroller"), |
| 977 | ENUM_ENT(EM_SVX, "Silicon Graphics SVx"), |
| 978 | ENUM_ENT(EM_ST19, "STMicroelectronics ST19 8-bit microcontroller"), |
| 979 | ENUM_ENT(EM_VAX, "Digital VAX"), |
| 980 | ENUM_ENT(EM_CRIS, "Axis Communications 32-bit embedded processor"), |
| 981 | ENUM_ENT(EM_JAVELIN, "Infineon Technologies 32-bit embedded cpu"), |
| 982 | ENUM_ENT(EM_FIREPATH, "Element 14 64-bit DSP processor"), |
| 983 | ENUM_ENT(EM_ZSP, "LSI Logic's 16-bit DSP processor"), |
| 984 | ENUM_ENT(EM_MMIX, "Donald Knuth's educational 64-bit processor"), |
| 985 | ENUM_ENT(EM_HUANY, "Harvard Universitys's machine-independent object format"), |
| 986 | ENUM_ENT(EM_PRISM, "Vitesse Prism"), |
| 987 | ENUM_ENT(EM_AVR, "Atmel AVR 8-bit microcontroller"), |
| 988 | ENUM_ENT(EM_FR30, "Fujitsu FR30"), |
| 989 | ENUM_ENT(EM_D10V, "Mitsubishi D10V"), |
| 990 | ENUM_ENT(EM_D30V, "Mitsubishi D30V"), |
| 991 | ENUM_ENT(EM_V850, "NEC v850"), |
| 992 | ENUM_ENT(EM_M32R, "Renesas M32R (formerly Mitsubishi M32r)"), |
| 993 | ENUM_ENT(EM_MN10300, "Matsushita MN10300"), |
| 994 | ENUM_ENT(EM_MN10200, "Matsushita MN10200"), |
| 995 | ENUM_ENT(EM_PJ, "picoJava"), |
| 996 | ENUM_ENT(EM_OPENRISC, "OpenRISC 32-bit embedded processor"), |
| 997 | ENUM_ENT(EM_ARC_COMPACT, "EM_ARC_COMPACT"), |
| 998 | ENUM_ENT(EM_XTENSA, "Tensilica Xtensa Processor"), |
| 999 | ENUM_ENT(EM_VIDEOCORE, "Alphamosaic VideoCore processor"), |
| 1000 | ENUM_ENT(EM_TMM_GPP, "Thompson Multimedia General Purpose Processor"), |
| 1001 | ENUM_ENT(EM_NS32K, "National Semiconductor 32000 series"), |
| 1002 | ENUM_ENT(EM_TPC, "Tenor Network TPC processor"), |
| 1003 | ENUM_ENT(EM_SNP1K, "EM_SNP1K"), |
| 1004 | ENUM_ENT(EM_ST200, "STMicroelectronics ST200 microcontroller"), |
| 1005 | ENUM_ENT(EM_IP2K, "Ubicom IP2xxx 8-bit microcontrollers"), |
| 1006 | ENUM_ENT(EM_MAX, "MAX Processor"), |
| 1007 | ENUM_ENT(EM_CR, "National Semiconductor CompactRISC"), |
| 1008 | ENUM_ENT(EM_F2MC16, "Fujitsu F2MC16"), |
| 1009 | ENUM_ENT(EM_MSP430, "Texas Instruments msp430 microcontroller"), |
| 1010 | ENUM_ENT(EM_BLACKFIN, "Analog Devices Blackfin"), |
| 1011 | ENUM_ENT(EM_SE_C33, "S1C33 Family of Seiko Epson processors"), |
| 1012 | ENUM_ENT(EM_SEP, "Sharp embedded microprocessor"), |
| 1013 | ENUM_ENT(EM_ARCA, "Arca RISC microprocessor"), |
| 1014 | ENUM_ENT(EM_UNICORE, "Unicore"), |
| 1015 | ENUM_ENT(EM_EXCESS, "eXcess 16/32/64-bit configurable embedded CPU"), |
| 1016 | ENUM_ENT(EM_DXP, "Icera Semiconductor Inc. Deep Execution Processor"), |
| 1017 | ENUM_ENT(EM_ALTERA_NIOS2, "Altera Nios"), |
| 1018 | ENUM_ENT(EM_CRX, "National Semiconductor CRX microprocessor"), |
| 1019 | ENUM_ENT(EM_XGATE, "Motorola XGATE embedded processor"), |
| 1020 | ENUM_ENT(EM_C166, "Infineon Technologies xc16x"), |
| 1021 | ENUM_ENT(EM_M16C, "Renesas M16C"), |
| 1022 | ENUM_ENT(EM_DSPIC30F, "Microchip Technology dsPIC30F Digital Signal Controller"), |
| 1023 | ENUM_ENT(EM_CE, "Freescale Communication Engine RISC core"), |
| 1024 | ENUM_ENT(EM_M32C, "Renesas M32C"), |
| 1025 | ENUM_ENT(EM_TSK3000, "Altium TSK3000 core"), |
| 1026 | ENUM_ENT(EM_RS08, "Freescale RS08 embedded processor"), |
| 1027 | ENUM_ENT(EM_SHARC, "EM_SHARC"), |
| 1028 | ENUM_ENT(EM_ECOG2, "Cyan Technology eCOG2 microprocessor"), |
| 1029 | ENUM_ENT(EM_SCORE7, "SUNPLUS S+Core"), |
| 1030 | ENUM_ENT(EM_DSP24, "New Japan Radio (NJR) 24-bit DSP Processor"), |
| 1031 | ENUM_ENT(EM_VIDEOCORE3, "Broadcom VideoCore III processor"), |
| 1032 | ENUM_ENT(EM_LATTICEMICO32, "Lattice Mico32"), |
| 1033 | ENUM_ENT(EM_SE_C17, "Seiko Epson C17 family"), |
| 1034 | ENUM_ENT(EM_TI_C6000, "Texas Instruments TMS320C6000 DSP family"), |
| 1035 | ENUM_ENT(EM_TI_C2000, "Texas Instruments TMS320C2000 DSP family"), |
| 1036 | ENUM_ENT(EM_TI_C5500, "Texas Instruments TMS320C55x DSP family"), |
| 1037 | ENUM_ENT(EM_MMDSP_PLUS, "STMicroelectronics 64bit VLIW Data Signal Processor"), |
| 1038 | ENUM_ENT(EM_CYPRESS_M8C, "Cypress M8C microprocessor"), |
| 1039 | ENUM_ENT(EM_R32C, "Renesas R32C series microprocessors"), |
| 1040 | ENUM_ENT(EM_TRIMEDIA, "NXP Semiconductors TriMedia architecture family"), |
| 1041 | ENUM_ENT(EM_HEXAGON, "Qualcomm Hexagon"), |
| 1042 | ENUM_ENT(EM_8051, "Intel 8051 and variants"), |
| 1043 | ENUM_ENT(EM_STXP7X, "STMicroelectronics STxP7x family"), |
| 1044 | ENUM_ENT(EM_NDS32, "Andes Technology compact code size embedded RISC processor family"), |
| 1045 | ENUM_ENT(EM_ECOG1, "Cyan Technology eCOG1 microprocessor"), |
| 1046 | ENUM_ENT(EM_ECOG1X, "Cyan Technology eCOG1X family"), |
| 1047 | ENUM_ENT(EM_MAXQ30, "Dallas Semiconductor MAXQ30 Core microcontrollers"), |
| 1048 | ENUM_ENT(EM_XIMO16, "New Japan Radio (NJR) 16-bit DSP Processor"), |
| 1049 | ENUM_ENT(EM_MANIK, "M2000 Reconfigurable RISC Microprocessor"), |
| 1050 | ENUM_ENT(EM_CRAYNV2, "Cray Inc. NV2 vector architecture"), |
| 1051 | ENUM_ENT(EM_RX, "Renesas RX"), |
| 1052 | ENUM_ENT(EM_METAG, "Imagination Technologies Meta processor architecture"), |
| 1053 | ENUM_ENT(EM_MCST_ELBRUS, "MCST Elbrus general purpose hardware architecture"), |
| 1054 | ENUM_ENT(EM_ECOG16, "Cyan Technology eCOG16 family"), |
| 1055 | ENUM_ENT(EM_CR16, "Xilinx MicroBlaze"), |
| 1056 | ENUM_ENT(EM_ETPU, "Freescale Extended Time Processing Unit"), |
| 1057 | ENUM_ENT(EM_SLE9X, "Infineon Technologies SLE9X core"), |
| 1058 | ENUM_ENT(EM_L10M, "EM_L10M"), |
| 1059 | ENUM_ENT(EM_K10M, "EM_K10M"), |
| 1060 | ENUM_ENT(EM_AARCH64, "AArch64"), |
| 1061 | ENUM_ENT(EM_AVR32, "Atmel Corporation 32-bit microprocessor family"), |
| 1062 | ENUM_ENT(EM_STM8, "STMicroeletronics STM8 8-bit microcontroller"), |
| 1063 | ENUM_ENT(EM_TILE64, "Tilera TILE64 multicore architecture family"), |
| 1064 | ENUM_ENT(EM_TILEPRO, "Tilera TILEPro multicore architecture family"), |
| 1065 | ENUM_ENT(EM_CUDA, "NVIDIA CUDA architecture"), |
| 1066 | ENUM_ENT(EM_TILEGX, "Tilera TILE-Gx multicore architecture family"), |
| 1067 | ENUM_ENT(EM_CLOUDSHIELD, "EM_CLOUDSHIELD"), |
| 1068 | ENUM_ENT(EM_COREA_1ST, "EM_COREA_1ST"), |
| 1069 | ENUM_ENT(EM_COREA_2ND, "EM_COREA_2ND"), |
| 1070 | ENUM_ENT(EM_ARC_COMPACT2, "EM_ARC_COMPACT2"), |
| 1071 | ENUM_ENT(EM_OPEN8, "EM_OPEN8"), |
| 1072 | ENUM_ENT(EM_RL78, "Renesas RL78"), |
| 1073 | ENUM_ENT(EM_VIDEOCORE5, "Broadcom VideoCore V processor"), |
| 1074 | ENUM_ENT(EM_78KOR, "EM_78KOR"), |
| 1075 | ENUM_ENT(EM_56800EX, "EM_56800EX"), |
| 1076 | ENUM_ENT(EM_AMDGPU, "EM_AMDGPU"), |
| 1077 | ENUM_ENT(EM_RISCV, "RISC-V"), |
| 1078 | ENUM_ENT(EM_LANAI, "EM_LANAI"), |
| 1079 | ENUM_ENT(EM_BPF, "EM_BPF"), |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1080 | }; |
| 1081 | |
| 1082 | static const EnumEntry<unsigned> ElfSymbolBindings[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1083 | {"Local", "LOCAL", ELF::STB_LOCAL}, |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 1084 | {"Global", "GLOBAL", ELF::STB_GLOBAL}, |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1085 | {"Weak", "WEAK", ELF::STB_WEAK}, |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 1086 | {"Unique", "UNIQUE", ELF::STB_GNU_UNIQUE}}; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1087 | |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 1088 | static const EnumEntry<unsigned> ElfSymbolVisibilities[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1089 | {"DEFAULT", "DEFAULT", ELF::STV_DEFAULT}, |
| 1090 | {"INTERNAL", "INTERNAL", ELF::STV_INTERNAL}, |
| 1091 | {"HIDDEN", "HIDDEN", ELF::STV_HIDDEN}, |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 1092 | {"PROTECTED", "PROTECTED", ELF::STV_PROTECTED}}; |
| 1093 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1094 | static const EnumEntry<unsigned> AMDGPUSymbolTypes[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1095 | { "AMDGPU_HSA_KERNEL", ELF::STT_AMDGPU_HSA_KERNEL } |
| 1096 | }; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1097 | |
Hemant Kulkarni | ab4a46f | 2016-01-26 19:46:39 +0000 | [diff] [blame] | 1098 | static const char *getGroupType(uint32_t Flag) { |
| 1099 | if (Flag & ELF::GRP_COMDAT) |
| 1100 | return "COMDAT"; |
| 1101 | else |
| 1102 | return "(unknown)"; |
| 1103 | } |
| 1104 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1105 | static const EnumEntry<unsigned> ElfSectionFlags[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1106 | ENUM_ENT(SHF_WRITE, "W"), |
| 1107 | ENUM_ENT(SHF_ALLOC, "A"), |
| 1108 | ENUM_ENT(SHF_EXCLUDE, "E"), |
| 1109 | ENUM_ENT(SHF_EXECINSTR, "X"), |
| 1110 | ENUM_ENT(SHF_MERGE, "M"), |
| 1111 | ENUM_ENT(SHF_STRINGS, "S"), |
| 1112 | ENUM_ENT(SHF_INFO_LINK, "I"), |
| 1113 | ENUM_ENT(SHF_LINK_ORDER, "L"), |
| 1114 | ENUM_ENT(SHF_OS_NONCONFORMING, "o"), |
| 1115 | ENUM_ENT(SHF_GROUP, "G"), |
| 1116 | ENUM_ENT(SHF_TLS, "T"), |
| 1117 | ENUM_ENT(SHF_MASKOS, "o"), |
| 1118 | ENUM_ENT(SHF_MASKPROC, "p"), |
| 1119 | ENUM_ENT_1(SHF_COMPRESSED), |
George Rimar | c13c59a | 2016-05-21 10:16:58 +0000 | [diff] [blame] | 1120 | }; |
| 1121 | |
| 1122 | static const EnumEntry<unsigned> ElfXCoreSectionFlags[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1123 | LLVM_READOBJ_ENUM_ENT(ELF, XCORE_SHF_CP_SECTION), |
| 1124 | LLVM_READOBJ_ENUM_ENT(ELF, XCORE_SHF_DP_SECTION) |
| 1125 | }; |
Simon Atanasyan | 2d0d853 | 2016-01-20 19:15:18 +0000 | [diff] [blame] | 1126 | |
Prakhar Bahuguna | 52a7dd7 | 2016-12-15 07:59:08 +0000 | [diff] [blame] | 1127 | static const EnumEntry<unsigned> ElfARMSectionFlags[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1128 | LLVM_READOBJ_ENUM_ENT(ELF, SHF_ARM_PURECODE) |
| 1129 | }; |
Prakhar Bahuguna | 52a7dd7 | 2016-12-15 07:59:08 +0000 | [diff] [blame] | 1130 | |
Simon Atanasyan | 2d0d853 | 2016-01-20 19:15:18 +0000 | [diff] [blame] | 1131 | static const EnumEntry<unsigned> ElfHexagonSectionFlags[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1132 | LLVM_READOBJ_ENUM_ENT(ELF, SHF_HEX_GPREL) |
| 1133 | }; |
Simon Atanasyan | 2d0d853 | 2016-01-20 19:15:18 +0000 | [diff] [blame] | 1134 | |
| 1135 | static const EnumEntry<unsigned> ElfMipsSectionFlags[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1136 | LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_NODUPES), |
| 1137 | LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_NAMES ), |
| 1138 | LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_LOCAL ), |
| 1139 | LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_NOSTRIP), |
| 1140 | LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_GPREL ), |
| 1141 | LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_MERGE ), |
| 1142 | LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_ADDR ), |
| 1143 | LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_STRING ) |
| 1144 | }; |
Simon Atanasyan | 2d0d853 | 2016-01-20 19:15:18 +0000 | [diff] [blame] | 1145 | |
| 1146 | static const EnumEntry<unsigned> ElfX86_64SectionFlags[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1147 | LLVM_READOBJ_ENUM_ENT(ELF, SHF_X86_64_LARGE) |
| 1148 | }; |
Simon Atanasyan | 2d0d853 | 2016-01-20 19:15:18 +0000 | [diff] [blame] | 1149 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 1150 | static std::string getGNUFlags(uint64_t Flags) { |
| 1151 | std::string Str; |
| 1152 | for (auto Entry : ElfSectionFlags) { |
| 1153 | uint64_t Flag = Entry.Value & Flags; |
| 1154 | Flags &= ~Entry.Value; |
| 1155 | switch (Flag) { |
| 1156 | case ELF::SHF_WRITE: |
| 1157 | case ELF::SHF_ALLOC: |
| 1158 | case ELF::SHF_EXECINSTR: |
| 1159 | case ELF::SHF_MERGE: |
| 1160 | case ELF::SHF_STRINGS: |
| 1161 | case ELF::SHF_INFO_LINK: |
| 1162 | case ELF::SHF_LINK_ORDER: |
| 1163 | case ELF::SHF_OS_NONCONFORMING: |
| 1164 | case ELF::SHF_GROUP: |
| 1165 | case ELF::SHF_TLS: |
| 1166 | case ELF::SHF_EXCLUDE: |
| 1167 | Str += Entry.AltName; |
| 1168 | break; |
| 1169 | default: |
Hemant Kulkarni | 04ac3d7 | 2016-05-12 19:58:52 +0000 | [diff] [blame] | 1170 | if (Flag & ELF::SHF_MASKOS) |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 1171 | Str += "o"; |
Hemant Kulkarni | 04ac3d7 | 2016-05-12 19:58:52 +0000 | [diff] [blame] | 1172 | else if (Flag & ELF::SHF_MASKPROC) |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 1173 | Str += "p"; |
| 1174 | else if (Flag) |
| 1175 | Str += "x"; |
| 1176 | } |
| 1177 | } |
| 1178 | return Str; |
| 1179 | } |
| 1180 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1181 | static const char *getElfSegmentType(unsigned Arch, unsigned Type) { |
| 1182 | // Check potentially overlapped processor-specific |
| 1183 | // program header type. |
| 1184 | switch (Arch) { |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1185 | case ELF::EM_ARM: |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 1186 | switch (Type) { LLVM_READOBJ_ENUM_CASE(ELF, PT_ARM_EXIDX); } |
Ryan Prichard | 0c20b5b | 2018-10-26 23:01:54 +0000 | [diff] [blame] | 1187 | break; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1188 | case ELF::EM_MIPS: |
| 1189 | case ELF::EM_MIPS_RS3_LE: |
| 1190 | switch (Type) { |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 1191 | LLVM_READOBJ_ENUM_CASE(ELF, PT_MIPS_REGINFO); |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1192 | LLVM_READOBJ_ENUM_CASE(ELF, PT_MIPS_RTPROC); |
| 1193 | LLVM_READOBJ_ENUM_CASE(ELF, PT_MIPS_OPTIONS); |
| 1194 | LLVM_READOBJ_ENUM_CASE(ELF, PT_MIPS_ABIFLAGS); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1195 | } |
Ryan Prichard | 0c20b5b | 2018-10-26 23:01:54 +0000 | [diff] [blame] | 1196 | break; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | switch (Type) { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1200 | LLVM_READOBJ_ENUM_CASE(ELF, PT_NULL ); |
| 1201 | LLVM_READOBJ_ENUM_CASE(ELF, PT_LOAD ); |
| 1202 | LLVM_READOBJ_ENUM_CASE(ELF, PT_DYNAMIC); |
| 1203 | LLVM_READOBJ_ENUM_CASE(ELF, PT_INTERP ); |
| 1204 | LLVM_READOBJ_ENUM_CASE(ELF, PT_NOTE ); |
| 1205 | LLVM_READOBJ_ENUM_CASE(ELF, PT_SHLIB ); |
| 1206 | LLVM_READOBJ_ENUM_CASE(ELF, PT_PHDR ); |
| 1207 | LLVM_READOBJ_ENUM_CASE(ELF, PT_TLS ); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1208 | |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1209 | LLVM_READOBJ_ENUM_CASE(ELF, PT_GNU_EH_FRAME); |
| 1210 | LLVM_READOBJ_ENUM_CASE(ELF, PT_SUNW_UNWIND); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1211 | |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 1212 | LLVM_READOBJ_ENUM_CASE(ELF, PT_GNU_STACK); |
| 1213 | LLVM_READOBJ_ENUM_CASE(ELF, PT_GNU_RELRO); |
George Rimar | bcfcb9e | 2016-10-18 10:54:56 +0000 | [diff] [blame] | 1214 | |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 1215 | LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_RANDOMIZE); |
| 1216 | LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_WXNEEDED); |
| 1217 | LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_BOOTDATA); |
George Rimar | bcfcb9e | 2016-10-18 10:54:56 +0000 | [diff] [blame] | 1218 | |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 1219 | default: |
| 1220 | return ""; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1221 | } |
| 1222 | } |
| 1223 | |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 1224 | static std::string getElfPtType(unsigned Arch, unsigned Type) { |
| 1225 | switch (Type) { |
Hemant Kulkarni | 7d564ba | 2016-03-28 17:20:23 +0000 | [diff] [blame] | 1226 | LLVM_READOBJ_PHDR_ENUM(ELF, PT_NULL) |
| 1227 | LLVM_READOBJ_PHDR_ENUM(ELF, PT_LOAD) |
| 1228 | LLVM_READOBJ_PHDR_ENUM(ELF, PT_DYNAMIC) |
| 1229 | LLVM_READOBJ_PHDR_ENUM(ELF, PT_INTERP) |
| 1230 | LLVM_READOBJ_PHDR_ENUM(ELF, PT_NOTE) |
| 1231 | LLVM_READOBJ_PHDR_ENUM(ELF, PT_SHLIB) |
| 1232 | LLVM_READOBJ_PHDR_ENUM(ELF, PT_PHDR) |
| 1233 | LLVM_READOBJ_PHDR_ENUM(ELF, PT_TLS) |
| 1234 | LLVM_READOBJ_PHDR_ENUM(ELF, PT_GNU_EH_FRAME) |
| 1235 | LLVM_READOBJ_PHDR_ENUM(ELF, PT_SUNW_UNWIND) |
| 1236 | LLVM_READOBJ_PHDR_ENUM(ELF, PT_GNU_STACK) |
| 1237 | LLVM_READOBJ_PHDR_ENUM(ELF, PT_GNU_RELRO) |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 1238 | default: |
| 1239 | // All machine specific PT_* types |
| 1240 | switch (Arch) { |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 1241 | case ELF::EM_ARM: |
| 1242 | if (Type == ELF::PT_ARM_EXIDX) |
| 1243 | return "EXIDX"; |
Ryan Prichard | 0c20b5b | 2018-10-26 23:01:54 +0000 | [diff] [blame] | 1244 | break; |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 1245 | case ELF::EM_MIPS: |
| 1246 | case ELF::EM_MIPS_RS3_LE: |
| 1247 | switch (Type) { |
| 1248 | case PT_MIPS_REGINFO: |
| 1249 | return "REGINFO"; |
| 1250 | case PT_MIPS_RTPROC: |
| 1251 | return "RTPROC"; |
| 1252 | case PT_MIPS_OPTIONS: |
| 1253 | return "OPTIONS"; |
| 1254 | case PT_MIPS_ABIFLAGS: |
| 1255 | return "ABIFLAGS"; |
| 1256 | } |
Ryan Prichard | 0c20b5b | 2018-10-26 23:01:54 +0000 | [diff] [blame] | 1257 | break; |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 1258 | } |
| 1259 | } |
| 1260 | return std::string("<unknown>: ") + to_string(format_hex(Type, 1)); |
| 1261 | } |
| 1262 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1263 | static const EnumEntry<unsigned> ElfSegmentFlags[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1264 | LLVM_READOBJ_ENUM_ENT(ELF, PF_X), |
| 1265 | LLVM_READOBJ_ENUM_ENT(ELF, PF_W), |
| 1266 | LLVM_READOBJ_ENUM_ENT(ELF, PF_R) |
| 1267 | }; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1268 | |
| 1269 | static const EnumEntry<unsigned> ElfHeaderMipsFlags[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1270 | ENUM_ENT(EF_MIPS_NOREORDER, "noreorder"), |
| 1271 | ENUM_ENT(EF_MIPS_PIC, "pic"), |
| 1272 | ENUM_ENT(EF_MIPS_CPIC, "cpic"), |
| 1273 | ENUM_ENT(EF_MIPS_ABI2, "abi2"), |
| 1274 | ENUM_ENT(EF_MIPS_32BITMODE, "32bitmode"), |
| 1275 | ENUM_ENT(EF_MIPS_FP64, "fp64"), |
| 1276 | ENUM_ENT(EF_MIPS_NAN2008, "nan2008"), |
| 1277 | ENUM_ENT(EF_MIPS_ABI_O32, "o32"), |
| 1278 | ENUM_ENT(EF_MIPS_ABI_O64, "o64"), |
| 1279 | ENUM_ENT(EF_MIPS_ABI_EABI32, "eabi32"), |
| 1280 | ENUM_ENT(EF_MIPS_ABI_EABI64, "eabi64"), |
| 1281 | ENUM_ENT(EF_MIPS_MACH_3900, "3900"), |
| 1282 | ENUM_ENT(EF_MIPS_MACH_4010, "4010"), |
| 1283 | ENUM_ENT(EF_MIPS_MACH_4100, "4100"), |
| 1284 | ENUM_ENT(EF_MIPS_MACH_4650, "4650"), |
| 1285 | ENUM_ENT(EF_MIPS_MACH_4120, "4120"), |
| 1286 | ENUM_ENT(EF_MIPS_MACH_4111, "4111"), |
| 1287 | ENUM_ENT(EF_MIPS_MACH_SB1, "sb1"), |
| 1288 | ENUM_ENT(EF_MIPS_MACH_OCTEON, "octeon"), |
| 1289 | ENUM_ENT(EF_MIPS_MACH_XLR, "xlr"), |
| 1290 | ENUM_ENT(EF_MIPS_MACH_OCTEON2, "octeon2"), |
| 1291 | ENUM_ENT(EF_MIPS_MACH_OCTEON3, "octeon3"), |
| 1292 | ENUM_ENT(EF_MIPS_MACH_5400, "5400"), |
| 1293 | ENUM_ENT(EF_MIPS_MACH_5900, "5900"), |
| 1294 | ENUM_ENT(EF_MIPS_MACH_5500, "5500"), |
| 1295 | ENUM_ENT(EF_MIPS_MACH_9000, "9000"), |
| 1296 | ENUM_ENT(EF_MIPS_MACH_LS2E, "loongson-2e"), |
| 1297 | ENUM_ENT(EF_MIPS_MACH_LS2F, "loongson-2f"), |
| 1298 | ENUM_ENT(EF_MIPS_MACH_LS3A, "loongson-3a"), |
| 1299 | ENUM_ENT(EF_MIPS_MICROMIPS, "micromips"), |
| 1300 | ENUM_ENT(EF_MIPS_ARCH_ASE_M16, "mips16"), |
| 1301 | ENUM_ENT(EF_MIPS_ARCH_ASE_MDMX, "mdmx"), |
| 1302 | ENUM_ENT(EF_MIPS_ARCH_1, "mips1"), |
| 1303 | ENUM_ENT(EF_MIPS_ARCH_2, "mips2"), |
| 1304 | ENUM_ENT(EF_MIPS_ARCH_3, "mips3"), |
| 1305 | ENUM_ENT(EF_MIPS_ARCH_4, "mips4"), |
| 1306 | ENUM_ENT(EF_MIPS_ARCH_5, "mips5"), |
| 1307 | ENUM_ENT(EF_MIPS_ARCH_32, "mips32"), |
| 1308 | ENUM_ENT(EF_MIPS_ARCH_64, "mips64"), |
| 1309 | ENUM_ENT(EF_MIPS_ARCH_32R2, "mips32r2"), |
| 1310 | ENUM_ENT(EF_MIPS_ARCH_64R2, "mips64r2"), |
| 1311 | ENUM_ENT(EF_MIPS_ARCH_32R6, "mips32r6"), |
| 1312 | ENUM_ENT(EF_MIPS_ARCH_64R6, "mips64r6") |
| 1313 | }; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1314 | |
Konstantin Zhuravlyov | aa0835a | 2017-10-05 16:19:18 +0000 | [diff] [blame] | 1315 | static const EnumEntry<unsigned> ElfHeaderAMDGPUFlags[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1316 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_NONE), |
| 1317 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_R600), |
| 1318 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_R630), |
| 1319 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_RS880), |
| 1320 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_RV670), |
| 1321 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_RV710), |
| 1322 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_RV730), |
| 1323 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_RV770), |
| 1324 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_CEDAR), |
| 1325 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_CYPRESS), |
| 1326 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_JUNIPER), |
| 1327 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_REDWOOD), |
| 1328 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_SUMO), |
| 1329 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_BARTS), |
| 1330 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_CAICOS), |
| 1331 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_CAYMAN), |
| 1332 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_TURKS), |
| 1333 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX600), |
| 1334 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX601), |
| 1335 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX700), |
| 1336 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX701), |
| 1337 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX702), |
| 1338 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX703), |
| 1339 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX704), |
| 1340 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX801), |
| 1341 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX802), |
| 1342 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX803), |
| 1343 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX810), |
| 1344 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX900), |
| 1345 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX902), |
| 1346 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX904), |
| 1347 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX906), |
Stanislav Mekhanoshin | 22b2c3d | 2019-07-09 18:10:06 +0000 | [diff] [blame] | 1348 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX908), |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1349 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX909), |
| 1350 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX1010), |
Stanislav Mekhanoshin | c43e67b | 2019-06-14 00:33:31 +0000 | [diff] [blame] | 1351 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX1011), |
| 1352 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX1012), |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1353 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_XNACK), |
| 1354 | LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_SRAM_ECC) |
| 1355 | }; |
Konstantin Zhuravlyov | aa0835a | 2017-10-05 16:19:18 +0000 | [diff] [blame] | 1356 | |
Alex Bradbury | bb89b2b | 2017-10-03 08:41:59 +0000 | [diff] [blame] | 1357 | static const EnumEntry<unsigned> ElfHeaderRISCVFlags[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1358 | ENUM_ENT(EF_RISCV_RVC, "RVC"), |
| 1359 | ENUM_ENT(EF_RISCV_FLOAT_ABI_SINGLE, "single-float ABI"), |
| 1360 | ENUM_ENT(EF_RISCV_FLOAT_ABI_DOUBLE, "double-float ABI"), |
| 1361 | ENUM_ENT(EF_RISCV_FLOAT_ABI_QUAD, "quad-float ABI"), |
| 1362 | ENUM_ENT(EF_RISCV_RVE, "RVE") |
| 1363 | }; |
Alex Bradbury | bb89b2b | 2017-10-03 08:41:59 +0000 | [diff] [blame] | 1364 | |
Simon Atanasyan | b7807a0 | 2016-03-24 16:10:37 +0000 | [diff] [blame] | 1365 | static const EnumEntry<unsigned> ElfSymOtherFlags[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1366 | LLVM_READOBJ_ENUM_ENT(ELF, STV_INTERNAL), |
| 1367 | LLVM_READOBJ_ENUM_ENT(ELF, STV_HIDDEN), |
| 1368 | LLVM_READOBJ_ENUM_ENT(ELF, STV_PROTECTED) |
| 1369 | }; |
Simon Atanasyan | b7807a0 | 2016-03-24 16:10:37 +0000 | [diff] [blame] | 1370 | |
| 1371 | static const EnumEntry<unsigned> ElfMipsSymOtherFlags[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1372 | LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_OPTIONAL), |
| 1373 | LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_PLT), |
| 1374 | LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_PIC), |
| 1375 | LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_MICROMIPS) |
| 1376 | }; |
Simon Atanasyan | b7807a0 | 2016-03-24 16:10:37 +0000 | [diff] [blame] | 1377 | |
| 1378 | static const EnumEntry<unsigned> ElfMips16SymOtherFlags[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1379 | LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_OPTIONAL), |
| 1380 | LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_PLT), |
| 1381 | LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_MIPS16) |
| 1382 | }; |
Simon Atanasyan | b7807a0 | 2016-03-24 16:10:37 +0000 | [diff] [blame] | 1383 | |
Simon Atanasyan | 8a71b53 | 2016-05-04 05:58:57 +0000 | [diff] [blame] | 1384 | static const char *getElfMipsOptionsOdkType(unsigned Odk) { |
| 1385 | switch (Odk) { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1386 | LLVM_READOBJ_ENUM_CASE(ELF, ODK_NULL); |
| 1387 | LLVM_READOBJ_ENUM_CASE(ELF, ODK_REGINFO); |
| 1388 | LLVM_READOBJ_ENUM_CASE(ELF, ODK_EXCEPTIONS); |
| 1389 | LLVM_READOBJ_ENUM_CASE(ELF, ODK_PAD); |
| 1390 | LLVM_READOBJ_ENUM_CASE(ELF, ODK_HWPATCH); |
| 1391 | LLVM_READOBJ_ENUM_CASE(ELF, ODK_FILL); |
| 1392 | LLVM_READOBJ_ENUM_CASE(ELF, ODK_TAGS); |
| 1393 | LLVM_READOBJ_ENUM_CASE(ELF, ODK_HWAND); |
| 1394 | LLVM_READOBJ_ENUM_CASE(ELF, ODK_HWOR); |
| 1395 | LLVM_READOBJ_ENUM_CASE(ELF, ODK_GP_GROUP); |
| 1396 | LLVM_READOBJ_ENUM_CASE(ELF, ODK_IDENT); |
| 1397 | LLVM_READOBJ_ENUM_CASE(ELF, ODK_PAGESIZE); |
Simon Atanasyan | 8a71b53 | 2016-05-04 05:58:57 +0000 | [diff] [blame] | 1398 | default: |
| 1399 | return "Unknown"; |
| 1400 | } |
| 1401 | } |
| 1402 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1403 | template <typename ELFT> |
George Rimar | 72f821d | 2019-05-20 15:41:48 +0000 | [diff] [blame] | 1404 | void ELFDumper<ELFT>::loadDynamicTable(const ELFFile<ELFT> *Obj) { |
George Rimar | 8ac7b2d | 2019-05-29 10:31:46 +0000 | [diff] [blame] | 1405 | // Try to locate the PT_DYNAMIC header. |
George Rimar | 72f821d | 2019-05-20 15:41:48 +0000 | [diff] [blame] | 1406 | const Elf_Phdr *DynamicPhdr = nullptr; |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 1407 | for (const Elf_Phdr &Phdr : |
| 1408 | unwrapOrError(ObjF->getFileName(), Obj->program_headers())) { |
George Rimar | 72f821d | 2019-05-20 15:41:48 +0000 | [diff] [blame] | 1409 | if (Phdr.p_type != ELF::PT_DYNAMIC) |
| 1410 | continue; |
| 1411 | DynamicPhdr = &Phdr; |
| 1412 | break; |
| 1413 | } |
| 1414 | |
George Rimar | 72f821d | 2019-05-20 15:41:48 +0000 | [diff] [blame] | 1415 | // Try to locate the .dynamic section in the sections header table. |
| 1416 | const Elf_Shdr *DynamicSec = nullptr; |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 1417 | for (const Elf_Shdr &Sec : |
| 1418 | unwrapOrError(ObjF->getFileName(), Obj->sections())) { |
George Rimar | 72f821d | 2019-05-20 15:41:48 +0000 | [diff] [blame] | 1419 | if (Sec.sh_type != ELF::SHT_DYNAMIC) |
| 1420 | continue; |
| 1421 | DynamicSec = &Sec; |
| 1422 | break; |
| 1423 | } |
| 1424 | |
| 1425 | // Information in the section header has priority over the information |
| 1426 | // in a PT_DYNAMIC header. |
| 1427 | // Ignore sh_entsize and use the expected value for entry size explicitly. |
| 1428 | // This allows us to dump the dynamic sections with a broken sh_entsize |
| 1429 | // field. |
George Rimar | 8ac7b2d | 2019-05-29 10:31:46 +0000 | [diff] [blame] | 1430 | if (DynamicSec) { |
George Rimar | 72f821d | 2019-05-20 15:41:48 +0000 | [diff] [blame] | 1431 | DynamicTable = checkDRI({ObjF->getELFFile()->base() + DynamicSec->sh_offset, |
| 1432 | DynamicSec->sh_size, sizeof(Elf_Dyn)}); |
George Rimar | 8ac7b2d | 2019-05-29 10:31:46 +0000 | [diff] [blame] | 1433 | parseDynamicTable(); |
| 1434 | } |
| 1435 | |
| 1436 | // If we have a PT_DYNAMIC header, we will either check the found dynamic |
| 1437 | // section or take the dynamic table data directly from the header. |
| 1438 | if (!DynamicPhdr) |
| 1439 | return; |
George Rimar | 72f821d | 2019-05-20 15:41:48 +0000 | [diff] [blame] | 1440 | |
| 1441 | if (DynamicPhdr->p_offset + DynamicPhdr->p_filesz > |
Jordan Rupprecht | f927b34 | 2019-08-12 14:05:37 +0000 | [diff] [blame] | 1442 | ObjF->getMemoryBufferRef().getBufferSize()) { |
| 1443 | reportWarning( |
George Rimar | 72f821d | 2019-05-20 15:41:48 +0000 | [diff] [blame] | 1444 | "PT_DYNAMIC segment offset + size exceeds the size of the file"); |
Jordan Rupprecht | f927b34 | 2019-08-12 14:05:37 +0000 | [diff] [blame] | 1445 | return; |
| 1446 | } |
George Rimar | 72f821d | 2019-05-20 15:41:48 +0000 | [diff] [blame] | 1447 | |
| 1448 | if (!DynamicSec) { |
| 1449 | DynamicTable = createDRIFrom(DynamicPhdr, sizeof(Elf_Dyn)); |
| 1450 | parseDynamicTable(); |
| 1451 | return; |
| 1452 | } |
| 1453 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 1454 | StringRef Name = |
| 1455 | unwrapOrError(ObjF->getFileName(), Obj->getSectionName(DynamicSec)); |
George Rimar | 72f821d | 2019-05-20 15:41:48 +0000 | [diff] [blame] | 1456 | if (DynamicSec->sh_addr + DynamicSec->sh_size > |
| 1457 | DynamicPhdr->p_vaddr + DynamicPhdr->p_memsz || |
| 1458 | DynamicSec->sh_addr < DynamicPhdr->p_vaddr) |
| 1459 | reportWarning("The SHT_DYNAMIC section '" + Name + |
| 1460 | "' is not contained within the " |
| 1461 | "PT_DYNAMIC segment"); |
| 1462 | |
| 1463 | if (DynamicSec->sh_addr != DynamicPhdr->p_vaddr) |
| 1464 | reportWarning("The SHT_DYNAMIC section '" + Name + |
| 1465 | "' is not at the start of " |
| 1466 | "PT_DYNAMIC segment"); |
George Rimar | 72f821d | 2019-05-20 15:41:48 +0000 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | template <typename ELFT> |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 1470 | ELFDumper<ELFT>::ELFDumper(const object::ELFObjectFile<ELFT> *ObjF, |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1471 | ScopedPrinter &Writer) |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 1472 | : ObjDumper(Writer), ObjF(ObjF) { |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 1473 | const ELFFile<ELFT> *Obj = ObjF->getELFFile(); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1474 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 1475 | for (const Elf_Shdr &Sec : |
| 1476 | unwrapOrError(ObjF->getFileName(), Obj->sections())) { |
Michael J. Spencer | 37304f1 | 2016-02-11 04:59:26 +0000 | [diff] [blame] | 1477 | switch (Sec.sh_type) { |
Michael J. Spencer | 94f060c | 2016-02-11 04:59:32 +0000 | [diff] [blame] | 1478 | case ELF::SHT_SYMTAB: |
Peter Collingbourne | 0dac476 | 2019-05-28 20:01:25 +0000 | [diff] [blame] | 1479 | if (!DotSymtabSec) |
| 1480 | DotSymtabSec = &Sec; |
Michael J. Spencer | 94f060c | 2016-02-11 04:59:32 +0000 | [diff] [blame] | 1481 | break; |
| 1482 | case ELF::SHT_DYNSYM: |
Peter Collingbourne | 0dac476 | 2019-05-28 20:01:25 +0000 | [diff] [blame] | 1483 | if (!DynSymRegion.Size) { |
| 1484 | DynSymRegion = createDRIFrom(&Sec); |
| 1485 | // This is only used (if Elf_Shdr present)for naming section in GNU |
| 1486 | // style |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 1487 | DynSymtabName = |
| 1488 | unwrapOrError(ObjF->getFileName(), Obj->getSectionName(&Sec)); |
George Rimar | dd4f253 | 2019-06-10 14:23:46 +0000 | [diff] [blame] | 1489 | |
| 1490 | if (Expected<StringRef> E = Obj->getStringTableForSymtab(Sec)) |
| 1491 | DynamicStringTable = *E; |
| 1492 | else |
| 1493 | warn(E.takeError()); |
Peter Collingbourne | 0dac476 | 2019-05-28 20:01:25 +0000 | [diff] [blame] | 1494 | } |
Michael J. Spencer | 94f060c | 2016-02-11 04:59:32 +0000 | [diff] [blame] | 1495 | break; |
Michael J. Spencer | 1c793ef | 2016-02-17 22:30:41 +0000 | [diff] [blame] | 1496 | case ELF::SHT_SYMTAB_SHNDX: |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 1497 | ShndxTable = unwrapOrError(ObjF->getFileName(), Obj->getSHNDXTable(Sec)); |
Michael J. Spencer | 94f060c | 2016-02-11 04:59:32 +0000 | [diff] [blame] | 1498 | break; |
Michael J. Spencer | 37304f1 | 2016-02-11 04:59:26 +0000 | [diff] [blame] | 1499 | case ELF::SHT_GNU_versym: |
Peter Collingbourne | 0dac476 | 2019-05-28 20:01:25 +0000 | [diff] [blame] | 1500 | if (!SymbolVersionSection) |
| 1501 | SymbolVersionSection = &Sec; |
Michael J. Spencer | 37304f1 | 2016-02-11 04:59:26 +0000 | [diff] [blame] | 1502 | break; |
| 1503 | case ELF::SHT_GNU_verdef: |
Peter Collingbourne | 0dac476 | 2019-05-28 20:01:25 +0000 | [diff] [blame] | 1504 | if (!SymbolVersionDefSection) |
| 1505 | SymbolVersionDefSection = &Sec; |
Michael J. Spencer | 37304f1 | 2016-02-11 04:59:26 +0000 | [diff] [blame] | 1506 | break; |
| 1507 | case ELF::SHT_GNU_verneed: |
Peter Collingbourne | 0dac476 | 2019-05-28 20:01:25 +0000 | [diff] [blame] | 1508 | if (!SymbolVersionNeedSection) |
| 1509 | SymbolVersionNeedSection = &Sec; |
Michael J. Spencer | 37304f1 | 2016-02-11 04:59:26 +0000 | [diff] [blame] | 1510 | break; |
Michael J. Spencer | ae6eeae | 2018-06-02 16:33:01 +0000 | [diff] [blame] | 1511 | case ELF::SHT_LLVM_CALL_GRAPH_PROFILE: |
Peter Collingbourne | 0dac476 | 2019-05-28 20:01:25 +0000 | [diff] [blame] | 1512 | if (!DotCGProfileSec) |
| 1513 | DotCGProfileSec = &Sec; |
Peter Collingbourne | 3e22733 | 2018-07-17 22:17:18 +0000 | [diff] [blame] | 1514 | break; |
| 1515 | case ELF::SHT_LLVM_ADDRSIG: |
Peter Collingbourne | 0dac476 | 2019-05-28 20:01:25 +0000 | [diff] [blame] | 1516 | if (!DotAddrsigSec) |
| 1517 | DotAddrsigSec = &Sec; |
Peter Collingbourne | 3e22733 | 2018-07-17 22:17:18 +0000 | [diff] [blame] | 1518 | break; |
Michael J. Spencer | 37304f1 | 2016-02-11 04:59:26 +0000 | [diff] [blame] | 1519 | } |
| 1520 | } |
| 1521 | |
George Rimar | 72f821d | 2019-05-20 15:41:48 +0000 | [diff] [blame] | 1522 | loadDynamicTable(Obj); |
Michael J. Spencer | 60d82b2 | 2016-02-11 04:59:37 +0000 | [diff] [blame] | 1523 | |
| 1524 | if (opts::Output == opts::GNU) |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 1525 | ELFDumperStyle.reset(new GNUStyle<ELFT>(Writer, this)); |
Michael J. Spencer | 60d82b2 | 2016-02-11 04:59:37 +0000 | [diff] [blame] | 1526 | else |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 1527 | ELFDumperStyle.reset(new LLVMStyle<ELFT>(Writer, this)); |
Michael J. Spencer | 60d82b2 | 2016-02-11 04:59:37 +0000 | [diff] [blame] | 1528 | } |
| 1529 | |
George Rimar | 8ac7b2d | 2019-05-29 10:31:46 +0000 | [diff] [blame] | 1530 | static const char *getTypeString(unsigned Arch, uint64_t Type) { |
| 1531 | #define DYNAMIC_TAG(n, v) |
| 1532 | switch (Arch) { |
Peter Smith | 49d7221 | 2019-06-04 11:44:33 +0000 | [diff] [blame] | 1533 | |
| 1534 | case EM_AARCH64: |
| 1535 | switch (Type) { |
| 1536 | #define AARCH64_DYNAMIC_TAG(name, value) \ |
| 1537 | case DT_##name: \ |
| 1538 | return #name; |
| 1539 | #include "llvm/BinaryFormat/DynamicTags.def" |
| 1540 | #undef AARCH64_DYNAMIC_TAG |
| 1541 | } |
| 1542 | break; |
| 1543 | |
George Rimar | 8ac7b2d | 2019-05-29 10:31:46 +0000 | [diff] [blame] | 1544 | case EM_HEXAGON: |
| 1545 | switch (Type) { |
| 1546 | #define HEXAGON_DYNAMIC_TAG(name, value) \ |
| 1547 | case DT_##name: \ |
| 1548 | return #name; |
| 1549 | #include "llvm/BinaryFormat/DynamicTags.def" |
| 1550 | #undef HEXAGON_DYNAMIC_TAG |
| 1551 | } |
| 1552 | break; |
| 1553 | |
| 1554 | case EM_MIPS: |
| 1555 | switch (Type) { |
| 1556 | #define MIPS_DYNAMIC_TAG(name, value) \ |
| 1557 | case DT_##name: \ |
| 1558 | return #name; |
| 1559 | #include "llvm/BinaryFormat/DynamicTags.def" |
| 1560 | #undef MIPS_DYNAMIC_TAG |
| 1561 | } |
| 1562 | break; |
| 1563 | |
| 1564 | case EM_PPC64: |
| 1565 | switch (Type) { |
| 1566 | #define PPC64_DYNAMIC_TAG(name, value) \ |
| 1567 | case DT_##name: \ |
| 1568 | return #name; |
| 1569 | #include "llvm/BinaryFormat/DynamicTags.def" |
| 1570 | #undef PPC64_DYNAMIC_TAG |
| 1571 | } |
| 1572 | break; |
| 1573 | } |
| 1574 | #undef DYNAMIC_TAG |
| 1575 | switch (Type) { |
| 1576 | // Now handle all dynamic tags except the architecture specific ones |
Peter Smith | 49d7221 | 2019-06-04 11:44:33 +0000 | [diff] [blame] | 1577 | #define AARCH64_DYNAMIC_TAG(name, value) |
George Rimar | 8ac7b2d | 2019-05-29 10:31:46 +0000 | [diff] [blame] | 1578 | #define MIPS_DYNAMIC_TAG(name, value) |
| 1579 | #define HEXAGON_DYNAMIC_TAG(name, value) |
| 1580 | #define PPC64_DYNAMIC_TAG(name, value) |
| 1581 | // Also ignore marker tags such as DT_HIOS (maps to DT_VERNEEDNUM), etc. |
| 1582 | #define DYNAMIC_TAG_MARKER(name, value) |
| 1583 | #define DYNAMIC_TAG(name, value) \ |
| 1584 | case DT_##name: \ |
| 1585 | return #name; |
| 1586 | #include "llvm/BinaryFormat/DynamicTags.def" |
| 1587 | #undef DYNAMIC_TAG |
Peter Smith | 49d7221 | 2019-06-04 11:44:33 +0000 | [diff] [blame] | 1588 | #undef AARCH64_DYNAMIC_TAG |
George Rimar | 8ac7b2d | 2019-05-29 10:31:46 +0000 | [diff] [blame] | 1589 | #undef MIPS_DYNAMIC_TAG |
| 1590 | #undef HEXAGON_DYNAMIC_TAG |
| 1591 | #undef PPC64_DYNAMIC_TAG |
| 1592 | #undef DYNAMIC_TAG_MARKER |
| 1593 | default: |
| 1594 | return "unknown"; |
| 1595 | } |
| 1596 | } |
| 1597 | |
George Rimar | 72f821d | 2019-05-20 15:41:48 +0000 | [diff] [blame] | 1598 | template <typename ELFT> void ELFDumper<ELFT>::parseDynamicTable() { |
George Rimar | 8ac7b2d | 2019-05-29 10:31:46 +0000 | [diff] [blame] | 1599 | auto toMappedAddr = [&](uint64_t Tag, uint64_t VAddr) -> const uint8_t * { |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 1600 | auto MappedAddrOrError = ObjF->getELFFile()->toMappedAddr(VAddr); |
George Rimar | 8ac7b2d | 2019-05-29 10:31:46 +0000 | [diff] [blame] | 1601 | if (!MappedAddrOrError) { |
| 1602 | reportWarning("Unable to parse DT_" + |
| 1603 | Twine(getTypeString( |
| 1604 | ObjF->getELFFile()->getHeader()->e_machine, Tag)) + |
| 1605 | ": " + llvm::toString(MappedAddrOrError.takeError())); |
| 1606 | return nullptr; |
| 1607 | } |
Xing GUO | fe5a6c3 | 2018-12-08 05:32:28 +0000 | [diff] [blame] | 1608 | return MappedAddrOrError.get(); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1609 | }; |
| 1610 | |
| 1611 | uint64_t SONameOffset = 0; |
| 1612 | const char *StringTableBegin = nullptr; |
| 1613 | uint64_t StringTableSize = 0; |
| 1614 | for (const Elf_Dyn &Dyn : dynamic_table()) { |
| 1615 | switch (Dyn.d_tag) { |
| 1616 | case ELF::DT_HASH: |
George Rimar | 8ac7b2d | 2019-05-29 10:31:46 +0000 | [diff] [blame] | 1617 | HashTable = reinterpret_cast<const Elf_Hash *>( |
| 1618 | toMappedAddr(Dyn.getTag(), Dyn.getPtr())); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1619 | break; |
| 1620 | case ELF::DT_GNU_HASH: |
George Rimar | 8ac7b2d | 2019-05-29 10:31:46 +0000 | [diff] [blame] | 1621 | GnuHashTable = reinterpret_cast<const Elf_GnuHash *>( |
| 1622 | toMappedAddr(Dyn.getTag(), Dyn.getPtr())); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1623 | break; |
Michael J. Spencer | 94f060c | 2016-02-11 04:59:32 +0000 | [diff] [blame] | 1624 | case ELF::DT_STRTAB: |
George Rimar | 8ac7b2d | 2019-05-29 10:31:46 +0000 | [diff] [blame] | 1625 | StringTableBegin = reinterpret_cast<const char *>( |
| 1626 | toMappedAddr(Dyn.getTag(), Dyn.getPtr())); |
Simon Atanasyan | 72155c3 | 2016-01-16 22:40:09 +0000 | [diff] [blame] | 1627 | break; |
Michael J. Spencer | 94f060c | 2016-02-11 04:59:32 +0000 | [diff] [blame] | 1628 | case ELF::DT_STRSZ: |
| 1629 | StringTableSize = Dyn.getVal(); |
Simon Atanasyan | 72155c3 | 2016-01-16 22:40:09 +0000 | [diff] [blame] | 1630 | break; |
Michael J. Spencer | 94f060c | 2016-02-11 04:59:32 +0000 | [diff] [blame] | 1631 | case ELF::DT_SYMTAB: |
George Rimar | 8ac7b2d | 2019-05-29 10:31:46 +0000 | [diff] [blame] | 1632 | DynSymRegion.Addr = toMappedAddr(Dyn.getTag(), Dyn.getPtr()); |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 1633 | DynSymRegion.EntSize = sizeof(Elf_Sym); |
Simon Atanasyan | 72155c3 | 2016-01-16 22:40:09 +0000 | [diff] [blame] | 1634 | break; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1635 | case ELF::DT_RELA: |
George Rimar | 8ac7b2d | 2019-05-29 10:31:46 +0000 | [diff] [blame] | 1636 | DynRelaRegion.Addr = toMappedAddr(Dyn.getTag(), Dyn.getPtr()); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1637 | break; |
| 1638 | case ELF::DT_RELASZ: |
| 1639 | DynRelaRegion.Size = Dyn.getVal(); |
| 1640 | break; |
| 1641 | case ELF::DT_RELAENT: |
| 1642 | DynRelaRegion.EntSize = Dyn.getVal(); |
| 1643 | break; |
| 1644 | case ELF::DT_SONAME: |
| 1645 | SONameOffset = Dyn.getVal(); |
| 1646 | break; |
Michael J. Spencer | 94f060c | 2016-02-11 04:59:32 +0000 | [diff] [blame] | 1647 | case ELF::DT_REL: |
George Rimar | 8ac7b2d | 2019-05-29 10:31:46 +0000 | [diff] [blame] | 1648 | DynRelRegion.Addr = toMappedAddr(Dyn.getTag(), Dyn.getPtr()); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1649 | break; |
Michael J. Spencer | 94f060c | 2016-02-11 04:59:32 +0000 | [diff] [blame] | 1650 | case ELF::DT_RELSZ: |
| 1651 | DynRelRegion.Size = Dyn.getVal(); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1652 | break; |
Michael J. Spencer | 94f060c | 2016-02-11 04:59:32 +0000 | [diff] [blame] | 1653 | case ELF::DT_RELENT: |
| 1654 | DynRelRegion.EntSize = Dyn.getVal(); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1655 | break; |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 1656 | case ELF::DT_RELR: |
| 1657 | case ELF::DT_ANDROID_RELR: |
George Rimar | 8ac7b2d | 2019-05-29 10:31:46 +0000 | [diff] [blame] | 1658 | DynRelrRegion.Addr = toMappedAddr(Dyn.getTag(), Dyn.getPtr()); |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 1659 | break; |
| 1660 | case ELF::DT_RELRSZ: |
| 1661 | case ELF::DT_ANDROID_RELRSZ: |
| 1662 | DynRelrRegion.Size = Dyn.getVal(); |
| 1663 | break; |
| 1664 | case ELF::DT_RELRENT: |
| 1665 | case ELF::DT_ANDROID_RELRENT: |
| 1666 | DynRelrRegion.EntSize = Dyn.getVal(); |
| 1667 | break; |
Rafael Espindola | 944f655 | 2016-02-16 15:16:00 +0000 | [diff] [blame] | 1668 | case ELF::DT_PLTREL: |
| 1669 | if (Dyn.getVal() == DT_REL) |
| 1670 | DynPLTRelRegion.EntSize = sizeof(Elf_Rel); |
| 1671 | else if (Dyn.getVal() == DT_RELA) |
| 1672 | DynPLTRelRegion.EntSize = sizeof(Elf_Rela); |
| 1673 | else |
| 1674 | reportError(Twine("unknown DT_PLTREL value of ") + |
| 1675 | Twine((uint64_t)Dyn.getVal())); |
| 1676 | break; |
| 1677 | case ELF::DT_JMPREL: |
George Rimar | 8ac7b2d | 2019-05-29 10:31:46 +0000 | [diff] [blame] | 1678 | DynPLTRelRegion.Addr = toMappedAddr(Dyn.getTag(), Dyn.getPtr()); |
Rafael Espindola | 944f655 | 2016-02-16 15:16:00 +0000 | [diff] [blame] | 1679 | break; |
| 1680 | case ELF::DT_PLTRELSZ: |
| 1681 | DynPLTRelRegion.Size = Dyn.getVal(); |
| 1682 | break; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1683 | } |
| 1684 | } |
| 1685 | if (StringTableBegin) |
| 1686 | DynamicStringTable = StringRef(StringTableBegin, StringTableSize); |
Yuanfang Chen | abbc3ff | 2019-07-18 17:04:28 +0000 | [diff] [blame] | 1687 | SOName = getDynamicString(SONameOffset); |
Rafael Espindola | 6009db6 | 2016-02-16 14:17:48 +0000 | [diff] [blame] | 1688 | } |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1689 | |
Rafael Espindola | 6009db6 | 2016-02-16 14:17:48 +0000 | [diff] [blame] | 1690 | template <typename ELFT> |
Simon Atanasyan | 72155c3 | 2016-01-16 22:40:09 +0000 | [diff] [blame] | 1691 | typename ELFDumper<ELFT>::Elf_Rel_Range ELFDumper<ELFT>::dyn_rels() const { |
Rafael Espindola | aafcf75 | 2016-04-05 14:47:22 +0000 | [diff] [blame] | 1692 | return DynRelRegion.getAsArrayRef<Elf_Rel>(); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | template <typename ELFT> |
| 1696 | typename ELFDumper<ELFT>::Elf_Rela_Range ELFDumper<ELFT>::dyn_relas() const { |
Rafael Espindola | aafcf75 | 2016-04-05 14:47:22 +0000 | [diff] [blame] | 1697 | return DynRelaRegion.getAsArrayRef<Elf_Rela>(); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1698 | } |
| 1699 | |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 1700 | template <typename ELFT> |
| 1701 | typename ELFDumper<ELFT>::Elf_Relr_Range ELFDumper<ELFT>::dyn_relrs() const { |
| 1702 | return DynRelrRegion.getAsArrayRef<Elf_Relr>(); |
| 1703 | } |
| 1704 | |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 1705 | template <class ELFT> void ELFDumper<ELFT>::printFileHeaders() { |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 1706 | ELFDumperStyle->printFileHeaders(ObjF->getELFFile()); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1707 | } |
| 1708 | |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 1709 | template <class ELFT> void ELFDumper<ELFT>::printSectionHeaders() { |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 1710 | ELFDumperStyle->printSectionHeaders(ObjF->getELFFile()); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1711 | } |
| 1712 | |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 1713 | template <class ELFT> void ELFDumper<ELFT>::printRelocations() { |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 1714 | ELFDumperStyle->printRelocations(ObjF->getELFFile()); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1715 | } |
| 1716 | |
Matt Davis | 50ca8ed | 2019-02-01 18:51:10 +0000 | [diff] [blame] | 1717 | template <class ELFT> |
| 1718 | void ELFDumper<ELFT>::printProgramHeaders( |
| 1719 | bool PrintProgramHeaders, cl::boolOrDefault PrintSectionMapping) { |
| 1720 | ELFDumperStyle->printProgramHeaders(ObjF->getELFFile(), PrintProgramHeaders, |
| 1721 | PrintSectionMapping); |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 1722 | } |
| 1723 | |
Xing GUO | ea16be1 | 2019-03-25 11:02:49 +0000 | [diff] [blame] | 1724 | template <typename ELFT> void ELFDumper<ELFT>::printVersionInfo() { |
| 1725 | // Dump version symbol section. |
| 1726 | ELFDumperStyle->printVersionSymbolSection(ObjF->getELFFile(), |
Xing GUO | 09a77fe | 2019-03-29 01:26:36 +0000 | [diff] [blame] | 1727 | SymbolVersionSection); |
Xing GUO | ea16be1 | 2019-03-25 11:02:49 +0000 | [diff] [blame] | 1728 | |
| 1729 | // Dump version definition section. |
| 1730 | ELFDumperStyle->printVersionDefinitionSection(ObjF->getELFFile(), |
Xing GUO | 09a77fe | 2019-03-29 01:26:36 +0000 | [diff] [blame] | 1731 | SymbolVersionDefSection); |
Xing GUO | ea16be1 | 2019-03-25 11:02:49 +0000 | [diff] [blame] | 1732 | |
| 1733 | // Dump version dependency section. |
| 1734 | ELFDumperStyle->printVersionDependencySection(ObjF->getELFFile(), |
Xing GUO | 09a77fe | 2019-03-29 01:26:36 +0000 | [diff] [blame] | 1735 | SymbolVersionNeedSection); |
Xing GUO | ea16be1 | 2019-03-25 11:02:49 +0000 | [diff] [blame] | 1736 | } |
| 1737 | |
Simon Atanasyan | 72155c3 | 2016-01-16 22:40:09 +0000 | [diff] [blame] | 1738 | template <class ELFT> void ELFDumper<ELFT>::printDynamicRelocations() { |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 1739 | ELFDumperStyle->printDynamicRelocations(ObjF->getELFFile()); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1740 | } |
| 1741 | |
James Henderson | 21ed868 | 2019-01-23 16:15:39 +0000 | [diff] [blame] | 1742 | template <class ELFT> |
| 1743 | void ELFDumper<ELFT>::printSymbols(bool PrintSymbols, |
| 1744 | bool PrintDynamicSymbols) { |
| 1745 | ELFDumperStyle->printSymbols(ObjF->getELFFile(), PrintSymbols, |
| 1746 | PrintDynamicSymbols); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1747 | } |
| 1748 | |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 1749 | template <class ELFT> void ELFDumper<ELFT>::printHashSymbols() { |
James Henderson | 5fc812f | 2019-01-22 09:35:35 +0000 | [diff] [blame] | 1750 | ELFDumperStyle->printHashSymbols(ObjF->getELFFile()); |
| 1751 | } |
| 1752 | |
Hemant Kulkarni | 9b1b7f0 | 2016-04-11 17:15:30 +0000 | [diff] [blame] | 1753 | template <class ELFT> void ELFDumper<ELFT>::printHashHistogram() { |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 1754 | ELFDumperStyle->printHashHistogram(ObjF->getELFFile()); |
Hemant Kulkarni | 9b1b7f0 | 2016-04-11 17:15:30 +0000 | [diff] [blame] | 1755 | } |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 1756 | |
Michael J. Spencer | ae6eeae | 2018-06-02 16:33:01 +0000 | [diff] [blame] | 1757 | template <class ELFT> void ELFDumper<ELFT>::printCGProfile() { |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 1758 | ELFDumperStyle->printCGProfile(ObjF->getELFFile()); |
Michael J. Spencer | ae6eeae | 2018-06-02 16:33:01 +0000 | [diff] [blame] | 1759 | } |
| 1760 | |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 1761 | template <class ELFT> void ELFDumper<ELFT>::printNotes() { |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 1762 | ELFDumperStyle->printNotes(ObjF->getELFFile()); |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 1763 | } |
| 1764 | |
Saleem Abdulrasool | b36fbbc | 2018-01-30 16:29:29 +0000 | [diff] [blame] | 1765 | template <class ELFT> void ELFDumper<ELFT>::printELFLinkerOptions() { |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 1766 | ELFDumperStyle->printELFLinkerOptions(ObjF->getELFFile()); |
Saleem Abdulrasool | b36fbbc | 2018-01-30 16:29:29 +0000 | [diff] [blame] | 1767 | } |
| 1768 | |
Wolfgang Pieb | c71c629 | 2019-08-05 22:47:07 +0000 | [diff] [blame] | 1769 | template <class ELFT> void ELFDumper<ELFT>::printStackSizes() { |
| 1770 | ELFDumperStyle->printStackSizes(ObjF); |
| 1771 | } |
| 1772 | |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 1773 | #define LLVM_READOBJ_DT_FLAG_ENT(prefix, enum) \ |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1774 | { #enum, prefix##_##enum } |
| 1775 | |
| 1776 | static const EnumEntry<unsigned> ElfDynamicDTFlags[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1777 | LLVM_READOBJ_DT_FLAG_ENT(DF, ORIGIN), |
| 1778 | LLVM_READOBJ_DT_FLAG_ENT(DF, SYMBOLIC), |
| 1779 | LLVM_READOBJ_DT_FLAG_ENT(DF, TEXTREL), |
| 1780 | LLVM_READOBJ_DT_FLAG_ENT(DF, BIND_NOW), |
| 1781 | LLVM_READOBJ_DT_FLAG_ENT(DF, STATIC_TLS) |
| 1782 | }; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1783 | |
| 1784 | static const EnumEntry<unsigned> ElfDynamicDTFlags1[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1785 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, NOW), |
| 1786 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, GLOBAL), |
| 1787 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, GROUP), |
| 1788 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, NODELETE), |
| 1789 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, LOADFLTR), |
| 1790 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, INITFIRST), |
| 1791 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, NOOPEN), |
| 1792 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, ORIGIN), |
| 1793 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, DIRECT), |
| 1794 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, TRANS), |
| 1795 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, INTERPOSE), |
| 1796 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, NODEFLIB), |
| 1797 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, NODUMP), |
| 1798 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, CONFALT), |
| 1799 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, ENDFILTEE), |
| 1800 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, DISPRELDNE), |
| 1801 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, DISPRELPND), |
| 1802 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, NODIRECT), |
| 1803 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, IGNMULDEF), |
| 1804 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, NOKSYMS), |
| 1805 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, NOHDR), |
| 1806 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, EDITED), |
| 1807 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, NORELOC), |
| 1808 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, SYMINTPOSE), |
| 1809 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, GLOBAUDIT), |
| 1810 | LLVM_READOBJ_DT_FLAG_ENT(DF_1, SINGLETON) |
| 1811 | }; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1812 | |
| 1813 | static const EnumEntry<unsigned> ElfDynamicDTMipsFlags[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 1814 | LLVM_READOBJ_DT_FLAG_ENT(RHF, NONE), |
| 1815 | LLVM_READOBJ_DT_FLAG_ENT(RHF, QUICKSTART), |
| 1816 | LLVM_READOBJ_DT_FLAG_ENT(RHF, NOTPOT), |
| 1817 | LLVM_READOBJ_DT_FLAG_ENT(RHS, NO_LIBRARY_REPLACEMENT), |
| 1818 | LLVM_READOBJ_DT_FLAG_ENT(RHF, NO_MOVE), |
| 1819 | LLVM_READOBJ_DT_FLAG_ENT(RHF, SGI_ONLY), |
| 1820 | LLVM_READOBJ_DT_FLAG_ENT(RHF, GUARANTEE_INIT), |
| 1821 | LLVM_READOBJ_DT_FLAG_ENT(RHF, DELTA_C_PLUS_PLUS), |
| 1822 | LLVM_READOBJ_DT_FLAG_ENT(RHF, GUARANTEE_START_INIT), |
| 1823 | LLVM_READOBJ_DT_FLAG_ENT(RHF, PIXIE), |
| 1824 | LLVM_READOBJ_DT_FLAG_ENT(RHF, DEFAULT_DELAY_LOAD), |
| 1825 | LLVM_READOBJ_DT_FLAG_ENT(RHF, REQUICKSTART), |
| 1826 | LLVM_READOBJ_DT_FLAG_ENT(RHF, REQUICKSTARTED), |
| 1827 | LLVM_READOBJ_DT_FLAG_ENT(RHF, CORD), |
| 1828 | LLVM_READOBJ_DT_FLAG_ENT(RHF, NO_UNRES_UNDEF), |
| 1829 | LLVM_READOBJ_DT_FLAG_ENT(RHF, RLD_ORDER_SAFE) |
| 1830 | }; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1831 | |
| 1832 | #undef LLVM_READOBJ_DT_FLAG_ENT |
| 1833 | |
| 1834 | template <typename T, typename TFlag> |
| 1835 | void printFlags(T Value, ArrayRef<EnumEntry<TFlag>> Flags, raw_ostream &OS) { |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 1836 | using FlagEntry = EnumEntry<TFlag>; |
| 1837 | using FlagVector = SmallVector<FlagEntry, 10>; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1838 | FlagVector SetFlags; |
| 1839 | |
| 1840 | for (const auto &Flag : Flags) { |
| 1841 | if (Flag.Value == 0) |
| 1842 | continue; |
| 1843 | |
| 1844 | if ((Value & Flag.Value) == Flag.Value) |
| 1845 | SetFlags.push_back(Flag); |
| 1846 | } |
| 1847 | |
| 1848 | for (const auto &Flag : SetFlags) { |
| 1849 | OS << Flag.Name << " "; |
| 1850 | } |
| 1851 | } |
| 1852 | |
| 1853 | template <class ELFT> |
Simon Atanasyan | 8362cbe | 2019-05-24 12:22:53 +0000 | [diff] [blame] | 1854 | void ELFDumper<ELFT>::printDynamicEntry(raw_ostream &OS, uint64_t Type, |
| 1855 | uint64_t Value) const { |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 1856 | const char *ConvChar = |
| 1857 | (opts::Output == opts::GNU) ? "0x%" PRIx64 : "0x%" PRIX64; |
Peter Smith | 49d7221 | 2019-06-04 11:44:33 +0000 | [diff] [blame] | 1858 | |
| 1859 | // Handle custom printing of architecture specific tags |
| 1860 | switch (ObjF->getELFFile()->getHeader()->e_machine) { |
| 1861 | case EM_AARCH64: |
| 1862 | switch (Type) { |
| 1863 | case DT_AARCH64_BTI_PLT: |
| 1864 | case DT_AARCH64_PAC_PLT: |
| 1865 | OS << Value; |
| 1866 | return; |
| 1867 | default: |
| 1868 | break; |
| 1869 | } |
| 1870 | break; |
| 1871 | case EM_HEXAGON: |
| 1872 | switch (Type) { |
| 1873 | case DT_HEXAGON_VER: |
| 1874 | OS << Value; |
| 1875 | return; |
| 1876 | case DT_HEXAGON_SYMSZ: |
| 1877 | case DT_HEXAGON_PLT: |
| 1878 | OS << format(ConvChar, Value); |
| 1879 | return; |
| 1880 | default: |
| 1881 | break; |
| 1882 | } |
| 1883 | break; |
| 1884 | case EM_MIPS: |
| 1885 | switch (Type) { |
| 1886 | case DT_MIPS_RLD_VERSION: |
| 1887 | case DT_MIPS_LOCAL_GOTNO: |
| 1888 | case DT_MIPS_SYMTABNO: |
| 1889 | case DT_MIPS_UNREFEXTNO: |
| 1890 | OS << Value; |
| 1891 | return; |
| 1892 | case DT_MIPS_TIME_STAMP: |
| 1893 | case DT_MIPS_ICHECKSUM: |
| 1894 | case DT_MIPS_IVERSION: |
| 1895 | case DT_MIPS_BASE_ADDRESS: |
| 1896 | case DT_MIPS_MSYM: |
| 1897 | case DT_MIPS_CONFLICT: |
| 1898 | case DT_MIPS_LIBLIST: |
| 1899 | case DT_MIPS_CONFLICTNO: |
| 1900 | case DT_MIPS_LIBLISTNO: |
| 1901 | case DT_MIPS_GOTSYM: |
| 1902 | case DT_MIPS_HIPAGENO: |
| 1903 | case DT_MIPS_RLD_MAP: |
| 1904 | case DT_MIPS_DELTA_CLASS: |
| 1905 | case DT_MIPS_DELTA_CLASS_NO: |
| 1906 | case DT_MIPS_DELTA_INSTANCE: |
| 1907 | case DT_MIPS_DELTA_RELOC: |
| 1908 | case DT_MIPS_DELTA_RELOC_NO: |
| 1909 | case DT_MIPS_DELTA_SYM: |
| 1910 | case DT_MIPS_DELTA_SYM_NO: |
| 1911 | case DT_MIPS_DELTA_CLASSSYM: |
| 1912 | case DT_MIPS_DELTA_CLASSSYM_NO: |
| 1913 | case DT_MIPS_CXX_FLAGS: |
| 1914 | case DT_MIPS_PIXIE_INIT: |
| 1915 | case DT_MIPS_SYMBOL_LIB: |
| 1916 | case DT_MIPS_LOCALPAGE_GOTIDX: |
| 1917 | case DT_MIPS_LOCAL_GOTIDX: |
| 1918 | case DT_MIPS_HIDDEN_GOTIDX: |
| 1919 | case DT_MIPS_PROTECTED_GOTIDX: |
| 1920 | case DT_MIPS_OPTIONS: |
| 1921 | case DT_MIPS_INTERFACE: |
| 1922 | case DT_MIPS_DYNSTR_ALIGN: |
| 1923 | case DT_MIPS_INTERFACE_SIZE: |
| 1924 | case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: |
| 1925 | case DT_MIPS_PERF_SUFFIX: |
| 1926 | case DT_MIPS_COMPACT_SIZE: |
| 1927 | case DT_MIPS_GP_VALUE: |
| 1928 | case DT_MIPS_AUX_DYNAMIC: |
| 1929 | case DT_MIPS_PLTGOT: |
| 1930 | case DT_MIPS_RWPLT: |
| 1931 | case DT_MIPS_RLD_MAP_REL: |
| 1932 | OS << format(ConvChar, Value); |
| 1933 | return; |
| 1934 | case DT_MIPS_FLAGS: |
| 1935 | printFlags(Value, makeArrayRef(ElfDynamicDTMipsFlags), OS); |
| 1936 | return; |
| 1937 | default: |
| 1938 | break; |
| 1939 | } |
| 1940 | break; |
| 1941 | default: |
| 1942 | break; |
| 1943 | } |
| 1944 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1945 | switch (Type) { |
| 1946 | case DT_PLTREL: |
| 1947 | if (Value == DT_REL) { |
| 1948 | OS << "REL"; |
| 1949 | break; |
| 1950 | } else if (Value == DT_RELA) { |
| 1951 | OS << "RELA"; |
| 1952 | break; |
| 1953 | } |
Justin Bogner | b03fd12 | 2016-08-17 05:10:15 +0000 | [diff] [blame] | 1954 | LLVM_FALLTHROUGH; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1955 | case DT_PLTGOT: |
| 1956 | case DT_HASH: |
| 1957 | case DT_STRTAB: |
| 1958 | case DT_SYMTAB: |
| 1959 | case DT_RELA: |
| 1960 | case DT_INIT: |
| 1961 | case DT_FINI: |
| 1962 | case DT_REL: |
| 1963 | case DT_JMPREL: |
| 1964 | case DT_INIT_ARRAY: |
| 1965 | case DT_FINI_ARRAY: |
| 1966 | case DT_PREINIT_ARRAY: |
| 1967 | case DT_DEBUG: |
| 1968 | case DT_VERDEF: |
| 1969 | case DT_VERNEED: |
| 1970 | case DT_VERSYM: |
| 1971 | case DT_GNU_HASH: |
| 1972 | case DT_NULL: |
Hemant Kulkarni | cb21f3c | 2016-05-12 22:16:53 +0000 | [diff] [blame] | 1973 | OS << format(ConvChar, Value); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1974 | break; |
Davide Italiano | 8c50367 | 2016-01-16 06:06:36 +0000 | [diff] [blame] | 1975 | case DT_RELACOUNT: |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1976 | case DT_RELCOUNT: |
| 1977 | case DT_VERDEFNUM: |
| 1978 | case DT_VERNEEDNUM: |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1979 | OS << Value; |
| 1980 | break; |
| 1981 | case DT_PLTRELSZ: |
| 1982 | case DT_RELASZ: |
| 1983 | case DT_RELAENT: |
| 1984 | case DT_STRSZ: |
| 1985 | case DT_SYMENT: |
| 1986 | case DT_RELSZ: |
| 1987 | case DT_RELENT: |
| 1988 | case DT_INIT_ARRAYSZ: |
| 1989 | case DT_FINI_ARRAYSZ: |
| 1990 | case DT_PREINIT_ARRAYSZ: |
Peter Collingbourne | 5c54f15 | 2017-10-27 17:49:40 +0000 | [diff] [blame] | 1991 | case DT_ANDROID_RELSZ: |
| 1992 | case DT_ANDROID_RELASZ: |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1993 | OS << Value << " (bytes)"; |
| 1994 | break; |
| 1995 | case DT_NEEDED: |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 1996 | case DT_SONAME: |
George Rimar | d8a4eca | 2016-09-02 07:35:19 +0000 | [diff] [blame] | 1997 | case DT_AUXILIARY: |
Xing GUO | eee6226 | 2019-03-07 14:53:10 +0000 | [diff] [blame] | 1998 | case DT_USED: |
Yuanfang Chen | 40a156b | 2019-06-19 19:31:07 +0000 | [diff] [blame] | 1999 | case DT_FILTER: |
| 2000 | case DT_RPATH: |
| 2001 | case DT_RUNPATH: { |
James Henderson | f7cfabb | 2019-06-14 12:02:01 +0000 | [diff] [blame] | 2002 | const std::map<uint64_t, const char*> TagNames = { |
| 2003 | {DT_NEEDED, "Shared library"}, |
| 2004 | {DT_SONAME, "Library soname"}, |
| 2005 | {DT_AUXILIARY, "Auxiliary library"}, |
| 2006 | {DT_USED, "Not needed object"}, |
| 2007 | {DT_FILTER, "Filter library"}, |
Yuanfang Chen | 40a156b | 2019-06-19 19:31:07 +0000 | [diff] [blame] | 2008 | {DT_RPATH, "Library rpath"}, |
| 2009 | {DT_RUNPATH, "Library runpath"}, |
James Henderson | f7cfabb | 2019-06-14 12:02:01 +0000 | [diff] [blame] | 2010 | }; |
Yuanfang Chen | abbc3ff | 2019-07-18 17:04:28 +0000 | [diff] [blame] | 2011 | OS << TagNames.at(Type) << ": [" << getDynamicString(Value) << "]"; |
Xing GUO | eee6226 | 2019-03-07 14:53:10 +0000 | [diff] [blame] | 2012 | break; |
James Henderson | f7cfabb | 2019-06-14 12:02:01 +0000 | [diff] [blame] | 2013 | } |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2014 | case DT_FLAGS: |
| 2015 | printFlags(Value, makeArrayRef(ElfDynamicDTFlags), OS); |
| 2016 | break; |
| 2017 | case DT_FLAGS_1: |
| 2018 | printFlags(Value, makeArrayRef(ElfDynamicDTFlags1), OS); |
| 2019 | break; |
| 2020 | default: |
Hemant Kulkarni | cb21f3c | 2016-05-12 22:16:53 +0000 | [diff] [blame] | 2021 | OS << format(ConvChar, Value); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2022 | break; |
| 2023 | } |
| 2024 | } |
| 2025 | |
Yuanfang Chen | abbc3ff | 2019-07-18 17:04:28 +0000 | [diff] [blame] | 2026 | template <class ELFT> |
| 2027 | std::string ELFDumper<ELFT>::getDynamicString(uint64_t Value) const { |
| 2028 | if (DynamicStringTable.empty()) |
| 2029 | return "<String table is empty or was not found>"; |
| 2030 | if (Value < DynamicStringTable.size()) |
| 2031 | return DynamicStringTable.data() + Value; |
| 2032 | return Twine("<Invalid offset 0x" + utohexstr(Value) + ">").str(); |
| 2033 | } |
| 2034 | |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 2035 | template <class ELFT> void ELFDumper<ELFT>::printUnwindInfo() { |
Peter Collingbourne | ac136cd | 2019-02-28 22:42:55 +0000 | [diff] [blame] | 2036 | DwarfCFIEH::PrinterContext<ELFT> Ctx(W, ObjF); |
| 2037 | Ctx.printUnwindInformation(); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | namespace { |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 2041 | |
Rui Ueyama | 1b31eb9 | 2018-01-12 01:40:32 +0000 | [diff] [blame] | 2042 | template <> void ELFDumper<ELF32LE>::printUnwindInfo() { |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 2043 | const ELFFile<ELF32LE> *Obj = ObjF->getELFFile(); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2044 | const unsigned Machine = Obj->getHeader()->e_machine; |
| 2045 | if (Machine == EM_ARM) { |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2046 | ARM::EHABI::PrinterContext<ELF32LE> Ctx(W, Obj, ObjF->getFileName(), |
| 2047 | DotSymtabSec); |
Peter Collingbourne | ac136cd | 2019-02-28 22:42:55 +0000 | [diff] [blame] | 2048 | Ctx.PrintUnwindInformation(); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2049 | } |
Peter Collingbourne | ac136cd | 2019-02-28 22:42:55 +0000 | [diff] [blame] | 2050 | DwarfCFIEH::PrinterContext<ELF32LE> Ctx(W, ObjF); |
| 2051 | Ctx.printUnwindInformation(); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2052 | } |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 2053 | |
| 2054 | } // end anonymous namespace |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2055 | |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 2056 | template <class ELFT> void ELFDumper<ELFT>::printDynamicTable() { |
Simon Atanasyan | 8362cbe | 2019-05-24 12:22:53 +0000 | [diff] [blame] | 2057 | ELFDumperStyle->printDynamic(ObjF->getELFFile()); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2058 | } |
| 2059 | |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 2060 | template <class ELFT> void ELFDumper<ELFT>::printNeededLibraries() { |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2061 | ListScope D(W, "NeededLibraries"); |
| 2062 | |
Yuanfang Chen | abbc3ff | 2019-07-18 17:04:28 +0000 | [diff] [blame] | 2063 | std::vector<std::string> Libs; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2064 | for (const auto &Entry : dynamic_table()) |
Yuanfang Chen | abbc3ff | 2019-07-18 17:04:28 +0000 | [diff] [blame] | 2065 | if (Entry.d_tag == ELF::DT_NEEDED) |
| 2066 | Libs.push_back(getDynamicString(Entry.d_un.d_val)); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2067 | |
Fangrui Song | a5355a5 | 2019-04-22 15:53:43 +0000 | [diff] [blame] | 2068 | llvm::stable_sort(Libs); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2069 | |
Sam Clegg | 88e9a15 | 2018-01-10 00:14:19 +0000 | [diff] [blame] | 2070 | for (const auto &L : Libs) |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 2071 | W.startLine() << L << "\n"; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2072 | } |
| 2073 | |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 2074 | template <typename ELFT> void ELFDumper<ELFT>::printHashTable() { |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2075 | DictScope D(W, "HashTable"); |
| 2076 | if (!HashTable) |
| 2077 | return; |
| 2078 | W.printNumber("Num Buckets", HashTable->nbucket); |
| 2079 | W.printNumber("Num Chains", HashTable->nchain); |
| 2080 | W.printList("Buckets", HashTable->buckets()); |
| 2081 | W.printList("Chains", HashTable->chains()); |
| 2082 | } |
| 2083 | |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 2084 | template <typename ELFT> void ELFDumper<ELFT>::printGnuHashTable() { |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2085 | DictScope D(W, "GnuHashTable"); |
| 2086 | if (!GnuHashTable) |
| 2087 | return; |
| 2088 | W.printNumber("Num Buckets", GnuHashTable->nbuckets); |
| 2089 | W.printNumber("First Hashed Symbol Index", GnuHashTable->symndx); |
| 2090 | W.printNumber("Num Mask Words", GnuHashTable->maskwords); |
| 2091 | W.printNumber("Shift Count", GnuHashTable->shift2); |
| 2092 | W.printHexList("Bloom Filter", GnuHashTable->filter()); |
| 2093 | W.printList("Buckets", GnuHashTable->buckets()); |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 2094 | Elf_Sym_Range Syms = dynamic_symbols(); |
| 2095 | unsigned NumSyms = std::distance(Syms.begin(), Syms.end()); |
| 2096 | if (!NumSyms) |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2097 | reportError("No dynamic symbol section"); |
Rafael Espindola | ce2fbdd | 2016-02-17 15:38:21 +0000 | [diff] [blame] | 2098 | W.printHexList("Values", GnuHashTable->values(NumSyms)); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | template <typename ELFT> void ELFDumper<ELFT>::printLoadName() { |
Sam Clegg | 88e9a15 | 2018-01-10 00:14:19 +0000 | [diff] [blame] | 2102 | W.printString("LoadName", SOName); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2103 | } |
| 2104 | |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 2105 | template <class ELFT> void ELFDumper<ELFT>::printAttributes() { |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2106 | W.startLine() << "Attributes not implemented.\n"; |
| 2107 | } |
| 2108 | |
| 2109 | namespace { |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 2110 | |
Rui Ueyama | 1b31eb9 | 2018-01-12 01:40:32 +0000 | [diff] [blame] | 2111 | template <> void ELFDumper<ELF32LE>::printAttributes() { |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 2112 | const ELFFile<ELF32LE> *Obj = ObjF->getELFFile(); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2113 | if (Obj->getHeader()->e_machine != EM_ARM) { |
| 2114 | W.startLine() << "Attributes not implemented.\n"; |
| 2115 | return; |
| 2116 | } |
| 2117 | |
| 2118 | DictScope BA(W, "BuildAttributes"); |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2119 | for (const ELFO::Elf_Shdr &Sec : |
| 2120 | unwrapOrError(ObjF->getFileName(), Obj->sections())) { |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2121 | if (Sec.sh_type != ELF::SHT_ARM_ATTRIBUTES) |
| 2122 | continue; |
| 2123 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2124 | ArrayRef<uint8_t> Contents = |
| 2125 | unwrapOrError(ObjF->getFileName(), Obj->getSectionContents(&Sec)); |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 2126 | if (Contents[0] != ARMBuildAttrs::Format_Version) { |
Benjamin Kramer | 3a13ed6 | 2017-12-28 16:58:54 +0000 | [diff] [blame] | 2127 | errs() << "unrecognised FormatVersion: 0x" |
| 2128 | << Twine::utohexstr(Contents[0]) << '\n'; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2129 | continue; |
| 2130 | } |
| 2131 | |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 2132 | W.printHex("FormatVersion", Contents[0]); |
| 2133 | if (Contents.size() == 1) |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2134 | continue; |
| 2135 | |
Sam Parker | df7c6ef | 2017-01-18 13:52:12 +0000 | [diff] [blame] | 2136 | ARMAttributeParser(&W).Parse(Contents, true); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2137 | } |
| 2138 | } |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2139 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2140 | template <class ELFT> class MipsGOTParser { |
| 2141 | public: |
Rafael Espindola | 6bc2990 | 2016-10-06 14:07:26 +0000 | [diff] [blame] | 2142 | TYPEDEF_ELF_TYPES(ELFT) |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2143 | using Entry = typename ELFO::Elf_Addr; |
| 2144 | using Entries = ArrayRef<Entry>; |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 2145 | |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2146 | const bool IsStatic; |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 2147 | const ELFO * const Obj; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2148 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2149 | MipsGOTParser(const ELFO *Obj, StringRef FileName, Elf_Dyn_Range DynTable, |
| 2150 | Elf_Sym_Range DynSyms); |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2151 | |
| 2152 | bool hasGot() const { return !GotEntries.empty(); } |
| 2153 | bool hasPlt() const { return !PltEntries.empty(); } |
| 2154 | |
| 2155 | uint64_t getGp() const; |
| 2156 | |
| 2157 | const Entry *getGotLazyResolver() const; |
| 2158 | const Entry *getGotModulePointer() const; |
| 2159 | const Entry *getPltLazyResolver() const; |
| 2160 | const Entry *getPltModulePointer() const; |
| 2161 | |
| 2162 | Entries getLocalEntries() const; |
| 2163 | Entries getGlobalEntries() const; |
| 2164 | Entries getOtherEntries() const; |
| 2165 | Entries getPltEntries() const; |
| 2166 | |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 2167 | uint64_t getGotAddress(const Entry * E) const; |
| 2168 | int64_t getGotOffset(const Entry * E) const; |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2169 | const Elf_Sym *getGotSym(const Entry *E) const; |
| 2170 | |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 2171 | uint64_t getPltAddress(const Entry * E) const; |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2172 | const Elf_Sym *getPltSym(const Entry *E) const; |
| 2173 | |
| 2174 | StringRef getPltStrTable() const { return PltStrTable; } |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2175 | |
| 2176 | private: |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2177 | const Elf_Shdr *GotSec; |
| 2178 | size_t LocalNum; |
| 2179 | size_t GlobalNum; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2180 | |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2181 | const Elf_Shdr *PltSec; |
| 2182 | const Elf_Shdr *PltRelSec; |
| 2183 | const Elf_Shdr *PltSymTable; |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2184 | StringRef FileName; |
| 2185 | |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2186 | Elf_Sym_Range GotDynSyms; |
| 2187 | StringRef PltStrTable; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2188 | |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2189 | Entries GotEntries; |
| 2190 | Entries PltEntries; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2191 | }; |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 2192 | |
| 2193 | } // end anonymous namespace |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2194 | |
| 2195 | template <class ELFT> |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2196 | MipsGOTParser<ELFT>::MipsGOTParser(const ELFO *Obj, StringRef FileName, |
| 2197 | Elf_Dyn_Range DynTable, |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2198 | Elf_Sym_Range DynSyms) |
| 2199 | : IsStatic(DynTable.empty()), Obj(Obj), GotSec(nullptr), LocalNum(0), |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2200 | GlobalNum(0), PltSec(nullptr), PltRelSec(nullptr), PltSymTable(nullptr), |
| 2201 | FileName(FileName) { |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2202 | // See "Global Offset Table" in Chapter 5 in the following document |
| 2203 | // for detailed GOT description. |
| 2204 | // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf |
| 2205 | |
| 2206 | // Find static GOT secton. |
| 2207 | if (IsStatic) { |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2208 | GotSec = findSectionByName(*Obj, FileName, ".got"); |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2209 | if (!GotSec) |
| 2210 | reportError("Cannot find .got section"); |
| 2211 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2212 | ArrayRef<uint8_t> Content = |
| 2213 | unwrapOrError(FileName, Obj->getSectionContents(GotSec)); |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2214 | GotEntries = Entries(reinterpret_cast<const Entry *>(Content.data()), |
| 2215 | Content.size() / sizeof(Entry)); |
| 2216 | LocalNum = GotEntries.size(); |
| 2217 | return; |
| 2218 | } |
| 2219 | |
| 2220 | // Lookup dynamic table tags which define GOT/PLT layouts. |
| 2221 | Optional<uint64_t> DtPltGot; |
| 2222 | Optional<uint64_t> DtLocalGotNum; |
| 2223 | Optional<uint64_t> DtGotSym; |
| 2224 | Optional<uint64_t> DtMipsPltGot; |
| 2225 | Optional<uint64_t> DtJmpRel; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2226 | for (const auto &Entry : DynTable) { |
| 2227 | switch (Entry.getTag()) { |
| 2228 | case ELF::DT_PLTGOT: |
| 2229 | DtPltGot = Entry.getVal(); |
| 2230 | break; |
| 2231 | case ELF::DT_MIPS_LOCAL_GOTNO: |
| 2232 | DtLocalGotNum = Entry.getVal(); |
| 2233 | break; |
| 2234 | case ELF::DT_MIPS_GOTSYM: |
| 2235 | DtGotSym = Entry.getVal(); |
| 2236 | break; |
| 2237 | case ELF::DT_MIPS_PLTGOT: |
| 2238 | DtMipsPltGot = Entry.getVal(); |
| 2239 | break; |
| 2240 | case ELF::DT_JMPREL: |
| 2241 | DtJmpRel = Entry.getVal(); |
| 2242 | break; |
| 2243 | } |
| 2244 | } |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2245 | |
| 2246 | // Find dynamic GOT section. |
| 2247 | if (DtPltGot || DtLocalGotNum || DtGotSym) { |
| 2248 | if (!DtPltGot) |
| 2249 | report_fatal_error("Cannot find PLTGOT dynamic table tag."); |
| 2250 | if (!DtLocalGotNum) |
| 2251 | report_fatal_error("Cannot find MIPS_LOCAL_GOTNO dynamic table tag."); |
| 2252 | if (!DtGotSym) |
| 2253 | report_fatal_error("Cannot find MIPS_GOTSYM dynamic table tag."); |
| 2254 | |
| 2255 | size_t DynSymTotal = DynSyms.size(); |
| 2256 | if (*DtGotSym > DynSymTotal) |
| 2257 | reportError("MIPS_GOTSYM exceeds a number of dynamic symbols"); |
| 2258 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2259 | GotSec = findNotEmptySectionByAddress(Obj, FileName, *DtPltGot); |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2260 | if (!GotSec) |
| 2261 | reportError("There is no not empty GOT section at 0x" + |
| 2262 | Twine::utohexstr(*DtPltGot)); |
| 2263 | |
| 2264 | LocalNum = *DtLocalGotNum; |
| 2265 | GlobalNum = DynSymTotal - *DtGotSym; |
| 2266 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2267 | ArrayRef<uint8_t> Content = |
| 2268 | unwrapOrError(FileName, Obj->getSectionContents(GotSec)); |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2269 | GotEntries = Entries(reinterpret_cast<const Entry *>(Content.data()), |
| 2270 | Content.size() / sizeof(Entry)); |
| 2271 | GotDynSyms = DynSyms.drop_front(*DtGotSym); |
| 2272 | } |
| 2273 | |
| 2274 | // Find PLT section. |
| 2275 | if (DtMipsPltGot || DtJmpRel) { |
| 2276 | if (!DtMipsPltGot) |
| 2277 | report_fatal_error("Cannot find MIPS_PLTGOT dynamic table tag."); |
| 2278 | if (!DtJmpRel) |
| 2279 | report_fatal_error("Cannot find JMPREL dynamic table tag."); |
| 2280 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2281 | PltSec = findNotEmptySectionByAddress(Obj, FileName, * DtMipsPltGot); |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2282 | if (!PltSec) |
| 2283 | report_fatal_error("There is no not empty PLTGOT section at 0x " + |
| 2284 | Twine::utohexstr(*DtMipsPltGot)); |
| 2285 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2286 | PltRelSec = findNotEmptySectionByAddress(Obj, FileName, * DtJmpRel); |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2287 | if (!PltRelSec) |
| 2288 | report_fatal_error("There is no not empty RELPLT section at 0x" + |
| 2289 | Twine::utohexstr(*DtJmpRel)); |
| 2290 | |
| 2291 | ArrayRef<uint8_t> PltContent = |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2292 | unwrapOrError(FileName, Obj->getSectionContents(PltSec)); |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2293 | PltEntries = Entries(reinterpret_cast<const Entry *>(PltContent.data()), |
| 2294 | PltContent.size() / sizeof(Entry)); |
| 2295 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2296 | PltSymTable = unwrapOrError(FileName, Obj->getSection(PltRelSec->sh_link)); |
| 2297 | PltStrTable = |
| 2298 | unwrapOrError(FileName, Obj->getStringTableForSymtab(*PltSymTable)); |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2299 | } |
| 2300 | } |
| 2301 | |
| 2302 | template <class ELFT> uint64_t MipsGOTParser<ELFT>::getGp() const { |
| 2303 | return GotSec->sh_addr + 0x7ff0; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2304 | } |
| 2305 | |
Simon Atanasyan | d4b693b | 2017-12-02 13:06:35 +0000 | [diff] [blame] | 2306 | template <class ELFT> |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2307 | const typename MipsGOTParser<ELFT>::Entry * |
| 2308 | MipsGOTParser<ELFT>::getGotLazyResolver() const { |
| 2309 | return LocalNum > 0 ? &GotEntries[0] : nullptr; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2310 | } |
| 2311 | |
| 2312 | template <class ELFT> |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2313 | const typename MipsGOTParser<ELFT>::Entry * |
| 2314 | MipsGOTParser<ELFT>::getGotModulePointer() const { |
| 2315 | if (LocalNum < 2) |
| 2316 | return nullptr; |
| 2317 | const Entry &E = GotEntries[1]; |
| 2318 | if ((E >> (sizeof(Entry) * 8 - 1)) == 0) |
| 2319 | return nullptr; |
| 2320 | return &E; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2321 | } |
| 2322 | |
| 2323 | template <class ELFT> |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2324 | typename MipsGOTParser<ELFT>::Entries |
| 2325 | MipsGOTParser<ELFT>::getLocalEntries() const { |
| 2326 | size_t Skip = getGotModulePointer() ? 2 : 1; |
| 2327 | if (LocalNum - Skip <= 0) |
| 2328 | return Entries(); |
| 2329 | return GotEntries.slice(Skip, LocalNum - Skip); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2330 | } |
| 2331 | |
| 2332 | template <class ELFT> |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2333 | typename MipsGOTParser<ELFT>::Entries |
| 2334 | MipsGOTParser<ELFT>::getGlobalEntries() const { |
| 2335 | if (GlobalNum == 0) |
| 2336 | return Entries(); |
| 2337 | return GotEntries.slice(LocalNum, GlobalNum); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2338 | } |
| 2339 | |
| 2340 | template <class ELFT> |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2341 | typename MipsGOTParser<ELFT>::Entries |
| 2342 | MipsGOTParser<ELFT>::getOtherEntries() const { |
| 2343 | size_t OtherNum = GotEntries.size() - LocalNum - GlobalNum; |
| 2344 | if (OtherNum == 0) |
| 2345 | return Entries(); |
| 2346 | return GotEntries.slice(LocalNum + GlobalNum, OtherNum); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2347 | } |
| 2348 | |
| 2349 | template <class ELFT> |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2350 | uint64_t MipsGOTParser<ELFT>::getGotAddress(const Entry *E) const { |
| 2351 | int64_t Offset = std::distance(GotEntries.data(), E) * sizeof(Entry); |
| 2352 | return GotSec->sh_addr + Offset; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2353 | } |
| 2354 | |
| 2355 | template <class ELFT> |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2356 | int64_t MipsGOTParser<ELFT>::getGotOffset(const Entry *E) const { |
| 2357 | int64_t Offset = std::distance(GotEntries.data(), E) * sizeof(Entry); |
| 2358 | return Offset - 0x7ff0; |
| 2359 | } |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2360 | |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2361 | template <class ELFT> |
| 2362 | const typename MipsGOTParser<ELFT>::Elf_Sym * |
| 2363 | MipsGOTParser<ELFT>::getGotSym(const Entry *E) const { |
| 2364 | int64_t Offset = std::distance(GotEntries.data(), E); |
| 2365 | return &GotDynSyms[Offset - LocalNum]; |
| 2366 | } |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2367 | |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2368 | template <class ELFT> |
| 2369 | const typename MipsGOTParser<ELFT>::Entry * |
| 2370 | MipsGOTParser<ELFT>::getPltLazyResolver() const { |
| 2371 | return PltEntries.empty() ? nullptr : &PltEntries[0]; |
| 2372 | } |
| 2373 | |
| 2374 | template <class ELFT> |
| 2375 | const typename MipsGOTParser<ELFT>::Entry * |
| 2376 | MipsGOTParser<ELFT>::getPltModulePointer() const { |
| 2377 | return PltEntries.size() < 2 ? nullptr : &PltEntries[1]; |
| 2378 | } |
| 2379 | |
| 2380 | template <class ELFT> |
| 2381 | typename MipsGOTParser<ELFT>::Entries |
| 2382 | MipsGOTParser<ELFT>::getPltEntries() const { |
| 2383 | if (PltEntries.size() <= 2) |
| 2384 | return Entries(); |
| 2385 | return PltEntries.slice(2, PltEntries.size() - 2); |
| 2386 | } |
| 2387 | |
| 2388 | template <class ELFT> |
| 2389 | uint64_t MipsGOTParser<ELFT>::getPltAddress(const Entry *E) const { |
| 2390 | int64_t Offset = std::distance(PltEntries.data(), E) * sizeof(Entry); |
| 2391 | return PltSec->sh_addr + Offset; |
| 2392 | } |
| 2393 | |
| 2394 | template <class ELFT> |
| 2395 | const typename MipsGOTParser<ELFT>::Elf_Sym * |
| 2396 | MipsGOTParser<ELFT>::getPltSym(const Entry *E) const { |
| 2397 | int64_t Offset = std::distance(getPltEntries().data(), E); |
| 2398 | if (PltRelSec->sh_type == ELF::SHT_REL) { |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2399 | Elf_Rel_Range Rels = unwrapOrError(FileName, Obj->rels(PltRelSec)); |
| 2400 | return unwrapOrError(FileName, |
| 2401 | Obj->getRelocationSymbol(&Rels[Offset], PltSymTable)); |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2402 | } else { |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2403 | Elf_Rela_Range Rels = unwrapOrError(FileName, Obj->relas(PltRelSec)); |
| 2404 | return unwrapOrError(FileName, |
| 2405 | Obj->getRelocationSymbol(&Rels[Offset], PltSymTable)); |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2406 | } |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2407 | } |
| 2408 | |
| 2409 | template <class ELFT> void ELFDumper<ELFT>::printMipsPLTGOT() { |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 2410 | const ELFFile<ELFT> *Obj = ObjF->getELFFile(); |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2411 | if (Obj->getHeader()->e_machine != EM_MIPS) |
| 2412 | reportError("MIPS PLT GOT is available for MIPS targets only"); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2413 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2414 | MipsGOTParser<ELFT> Parser(Obj, ObjF->getFileName(), dynamic_table(), |
| 2415 | dynamic_symbols()); |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 2416 | if (Parser.hasGot()) |
| 2417 | ELFDumperStyle->printMipsGOT(Parser); |
| 2418 | if (Parser.hasPlt()) |
| 2419 | ELFDumperStyle->printMipsPLT(Parser); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2420 | } |
| 2421 | |
| 2422 | static const EnumEntry<unsigned> ElfMipsISAExtType[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 2423 | {"None", Mips::AFL_EXT_NONE}, |
| 2424 | {"Broadcom SB-1", Mips::AFL_EXT_SB1}, |
| 2425 | {"Cavium Networks Octeon", Mips::AFL_EXT_OCTEON}, |
| 2426 | {"Cavium Networks Octeon2", Mips::AFL_EXT_OCTEON2}, |
| 2427 | {"Cavium Networks OcteonP", Mips::AFL_EXT_OCTEONP}, |
| 2428 | {"Cavium Networks Octeon3", Mips::AFL_EXT_OCTEON3}, |
| 2429 | {"LSI R4010", Mips::AFL_EXT_4010}, |
| 2430 | {"Loongson 2E", Mips::AFL_EXT_LOONGSON_2E}, |
| 2431 | {"Loongson 2F", Mips::AFL_EXT_LOONGSON_2F}, |
| 2432 | {"Loongson 3A", Mips::AFL_EXT_LOONGSON_3A}, |
| 2433 | {"MIPS R4650", Mips::AFL_EXT_4650}, |
| 2434 | {"MIPS R5900", Mips::AFL_EXT_5900}, |
| 2435 | {"MIPS R10000", Mips::AFL_EXT_10000}, |
| 2436 | {"NEC VR4100", Mips::AFL_EXT_4100}, |
| 2437 | {"NEC VR4111/VR4181", Mips::AFL_EXT_4111}, |
| 2438 | {"NEC VR4120", Mips::AFL_EXT_4120}, |
| 2439 | {"NEC VR5400", Mips::AFL_EXT_5400}, |
| 2440 | {"NEC VR5500", Mips::AFL_EXT_5500}, |
| 2441 | {"RMI Xlr", Mips::AFL_EXT_XLR}, |
| 2442 | {"Toshiba R3900", Mips::AFL_EXT_3900} |
| 2443 | }; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2444 | |
| 2445 | static const EnumEntry<unsigned> ElfMipsASEFlags[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 2446 | {"DSP", Mips::AFL_ASE_DSP}, |
| 2447 | {"DSPR2", Mips::AFL_ASE_DSPR2}, |
| 2448 | {"Enhanced VA Scheme", Mips::AFL_ASE_EVA}, |
| 2449 | {"MCU", Mips::AFL_ASE_MCU}, |
| 2450 | {"MDMX", Mips::AFL_ASE_MDMX}, |
| 2451 | {"MIPS-3D", Mips::AFL_ASE_MIPS3D}, |
| 2452 | {"MT", Mips::AFL_ASE_MT}, |
| 2453 | {"SmartMIPS", Mips::AFL_ASE_SMARTMIPS}, |
| 2454 | {"VZ", Mips::AFL_ASE_VIRT}, |
| 2455 | {"MSA", Mips::AFL_ASE_MSA}, |
| 2456 | {"MIPS16", Mips::AFL_ASE_MIPS16}, |
| 2457 | {"microMIPS", Mips::AFL_ASE_MICROMIPS}, |
| 2458 | {"XPA", Mips::AFL_ASE_XPA}, |
| 2459 | {"CRC", Mips::AFL_ASE_CRC}, |
| 2460 | {"GINV", Mips::AFL_ASE_GINV}, |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2461 | }; |
| 2462 | |
| 2463 | static const EnumEntry<unsigned> ElfMipsFpABIType[] = { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 2464 | {"Hard or soft float", Mips::Val_GNU_MIPS_ABI_FP_ANY}, |
| 2465 | {"Hard float (double precision)", Mips::Val_GNU_MIPS_ABI_FP_DOUBLE}, |
| 2466 | {"Hard float (single precision)", Mips::Val_GNU_MIPS_ABI_FP_SINGLE}, |
| 2467 | {"Soft float", Mips::Val_GNU_MIPS_ABI_FP_SOFT}, |
| 2468 | {"Hard float (MIPS32r2 64-bit FPU 12 callee-saved)", |
| 2469 | Mips::Val_GNU_MIPS_ABI_FP_OLD_64}, |
| 2470 | {"Hard float (32-bit CPU, Any FPU)", Mips::Val_GNU_MIPS_ABI_FP_XX}, |
| 2471 | {"Hard float (32-bit CPU, 64-bit FPU)", Mips::Val_GNU_MIPS_ABI_FP_64}, |
| 2472 | {"Hard float compat (32-bit CPU, 64-bit FPU)", |
| 2473 | Mips::Val_GNU_MIPS_ABI_FP_64A} |
| 2474 | }; |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2475 | |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 2476 | static const EnumEntry<unsigned> ElfMipsFlags1[] { |
| 2477 | {"ODDSPREG", Mips::AFL_FLAGS1_ODDSPREG}, |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2478 | }; |
| 2479 | |
| 2480 | static int getMipsRegisterSize(uint8_t Flag) { |
| 2481 | switch (Flag) { |
| 2482 | case Mips::AFL_REG_NONE: |
| 2483 | return 0; |
| 2484 | case Mips::AFL_REG_32: |
| 2485 | return 32; |
| 2486 | case Mips::AFL_REG_64: |
| 2487 | return 64; |
| 2488 | case Mips::AFL_REG_128: |
| 2489 | return 128; |
| 2490 | default: |
| 2491 | return -1; |
| 2492 | } |
| 2493 | } |
| 2494 | |
| 2495 | template <class ELFT> void ELFDumper<ELFT>::printMipsABIFlags() { |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 2496 | const ELFFile<ELFT> *Obj = ObjF->getELFFile(); |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2497 | const Elf_Shdr *Shdr = |
| 2498 | findSectionByName(*Obj, ObjF->getFileName(), ".MIPS.abiflags"); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2499 | if (!Shdr) { |
| 2500 | W.startLine() << "There is no .MIPS.abiflags section in the file.\n"; |
| 2501 | return; |
| 2502 | } |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2503 | ArrayRef<uint8_t> Sec = |
| 2504 | unwrapOrError(ObjF->getFileName(), Obj->getSectionContents(Shdr)); |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 2505 | if (Sec.size() != sizeof(Elf_Mips_ABIFlags<ELFT>)) { |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2506 | W.startLine() << "The .MIPS.abiflags section has a wrong size.\n"; |
| 2507 | return; |
| 2508 | } |
| 2509 | |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 2510 | auto *Flags = reinterpret_cast<const Elf_Mips_ABIFlags<ELFT> *>(Sec.data()); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2511 | |
| 2512 | raw_ostream &OS = W.getOStream(); |
| 2513 | DictScope GS(W, "MIPS ABI Flags"); |
| 2514 | |
| 2515 | W.printNumber("Version", Flags->version); |
| 2516 | W.startLine() << "ISA: "; |
| 2517 | if (Flags->isa_rev <= 1) |
| 2518 | OS << format("MIPS%u", Flags->isa_level); |
| 2519 | else |
| 2520 | OS << format("MIPS%ur%u", Flags->isa_level, Flags->isa_rev); |
| 2521 | OS << "\n"; |
| 2522 | W.printEnum("ISA Extension", Flags->isa_ext, makeArrayRef(ElfMipsISAExtType)); |
| 2523 | W.printFlags("ASEs", Flags->ases, makeArrayRef(ElfMipsASEFlags)); |
| 2524 | W.printEnum("FP ABI", Flags->fp_abi, makeArrayRef(ElfMipsFpABIType)); |
| 2525 | W.printNumber("GPR size", getMipsRegisterSize(Flags->gpr_size)); |
| 2526 | W.printNumber("CPR1 size", getMipsRegisterSize(Flags->cpr1_size)); |
| 2527 | W.printNumber("CPR2 size", getMipsRegisterSize(Flags->cpr2_size)); |
| 2528 | W.printFlags("Flags 1", Flags->flags1, makeArrayRef(ElfMipsFlags1)); |
| 2529 | W.printHex("Flags 2", Flags->flags2); |
| 2530 | } |
| 2531 | |
Simon Atanasyan | 8a71b53 | 2016-05-04 05:58:57 +0000 | [diff] [blame] | 2532 | template <class ELFT> |
| 2533 | static void printMipsReginfoData(ScopedPrinter &W, |
| 2534 | const Elf_Mips_RegInfo<ELFT> &Reginfo) { |
| 2535 | W.printHex("GP", Reginfo.ri_gp_value); |
| 2536 | W.printHex("General Mask", Reginfo.ri_gprmask); |
| 2537 | W.printHex("Co-Proc Mask0", Reginfo.ri_cprmask[0]); |
| 2538 | W.printHex("Co-Proc Mask1", Reginfo.ri_cprmask[1]); |
| 2539 | W.printHex("Co-Proc Mask2", Reginfo.ri_cprmask[2]); |
| 2540 | W.printHex("Co-Proc Mask3", Reginfo.ri_cprmask[3]); |
| 2541 | } |
| 2542 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2543 | template <class ELFT> void ELFDumper<ELFT>::printMipsReginfo() { |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 2544 | const ELFFile<ELFT> *Obj = ObjF->getELFFile(); |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2545 | const Elf_Shdr *Shdr = findSectionByName(*Obj, ObjF->getFileName(), ".reginfo"); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2546 | if (!Shdr) { |
| 2547 | W.startLine() << "There is no .reginfo section in the file.\n"; |
| 2548 | return; |
| 2549 | } |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2550 | ArrayRef<uint8_t> Sec = |
| 2551 | unwrapOrError(ObjF->getFileName(), Obj->getSectionContents(Shdr)); |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 2552 | if (Sec.size() != sizeof(Elf_Mips_RegInfo<ELFT>)) { |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2553 | W.startLine() << "The .reginfo section has a wrong size.\n"; |
| 2554 | return; |
| 2555 | } |
| 2556 | |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2557 | DictScope GS(W, "MIPS RegInfo"); |
Simon Atanasyan | 8a71b53 | 2016-05-04 05:58:57 +0000 | [diff] [blame] | 2558 | auto *Reginfo = reinterpret_cast<const Elf_Mips_RegInfo<ELFT> *>(Sec.data()); |
| 2559 | printMipsReginfoData(W, *Reginfo); |
| 2560 | } |
| 2561 | |
| 2562 | template <class ELFT> void ELFDumper<ELFT>::printMipsOptions() { |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 2563 | const ELFFile<ELFT> *Obj = ObjF->getELFFile(); |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2564 | const Elf_Shdr *Shdr = |
| 2565 | findSectionByName(*Obj, ObjF->getFileName(), ".MIPS.options"); |
Simon Atanasyan | 8a71b53 | 2016-05-04 05:58:57 +0000 | [diff] [blame] | 2566 | if (!Shdr) { |
| 2567 | W.startLine() << "There is no .MIPS.options section in the file.\n"; |
| 2568 | return; |
| 2569 | } |
| 2570 | |
| 2571 | DictScope GS(W, "MIPS Options"); |
| 2572 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2573 | ArrayRef<uint8_t> Sec = |
| 2574 | unwrapOrError(ObjF->getFileName(), Obj->getSectionContents(Shdr)); |
Simon Atanasyan | 8a71b53 | 2016-05-04 05:58:57 +0000 | [diff] [blame] | 2575 | while (!Sec.empty()) { |
| 2576 | if (Sec.size() < sizeof(Elf_Mips_Options<ELFT>)) { |
| 2577 | W.startLine() << "The .MIPS.options section has a wrong size.\n"; |
| 2578 | return; |
| 2579 | } |
| 2580 | auto *O = reinterpret_cast<const Elf_Mips_Options<ELFT> *>(Sec.data()); |
| 2581 | DictScope GS(W, getElfMipsOptionsOdkType(O->kind)); |
| 2582 | switch (O->kind) { |
| 2583 | case ODK_REGINFO: |
| 2584 | printMipsReginfoData(W, O->getRegInfo()); |
| 2585 | break; |
| 2586 | default: |
| 2587 | W.startLine() << "Unsupported MIPS options tag.\n"; |
| 2588 | break; |
| 2589 | } |
| 2590 | Sec = Sec.slice(O->size); |
| 2591 | } |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2592 | } |
| 2593 | |
| 2594 | template <class ELFT> void ELFDumper<ELFT>::printStackMap() const { |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 2595 | const ELFFile<ELFT> *Obj = ObjF->getELFFile(); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2596 | const Elf_Shdr *StackMapSection = nullptr; |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2597 | for (const auto &Sec : unwrapOrError(ObjF->getFileName(), Obj->sections())) { |
| 2598 | StringRef Name = |
| 2599 | unwrapOrError(ObjF->getFileName(), Obj->getSectionName(&Sec)); |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 2600 | if (Name == ".llvm_stackmaps") { |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2601 | StackMapSection = &Sec; |
| 2602 | break; |
| 2603 | } |
| 2604 | } |
| 2605 | |
| 2606 | if (!StackMapSection) |
| 2607 | return; |
| 2608 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2609 | ArrayRef<uint8_t> StackMapContentsArray = unwrapOrError( |
| 2610 | ObjF->getFileName(), Obj->getSectionContents(StackMapSection)); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2611 | |
Sam Clegg | 88e9a15 | 2018-01-10 00:14:19 +0000 | [diff] [blame] | 2612 | prettyPrintStackMap( |
Philip Reames | 377f507 | 2019-04-13 02:02:56 +0000 | [diff] [blame] | 2613 | W, StackMapParser<ELFT::TargetEndianness>(StackMapContentsArray)); |
George Rimar | 4793676 | 2016-01-16 00:49:19 +0000 | [diff] [blame] | 2614 | } |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2615 | |
Hemant Kulkarni | ab4a46f | 2016-01-26 19:46:39 +0000 | [diff] [blame] | 2616 | template <class ELFT> void ELFDumper<ELFT>::printGroupSections() { |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 2617 | ELFDumperStyle->printGroupSections(ObjF->getELFFile()); |
Hemant Kulkarni | ab4a46f | 2016-01-26 19:46:39 +0000 | [diff] [blame] | 2618 | } |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2619 | |
Peter Collingbourne | 3e22733 | 2018-07-17 22:17:18 +0000 | [diff] [blame] | 2620 | template <class ELFT> void ELFDumper<ELFT>::printAddrsig() { |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 2621 | ELFDumperStyle->printAddrsig(ObjF->getELFFile()); |
Peter Collingbourne | 3e22733 | 2018-07-17 22:17:18 +0000 | [diff] [blame] | 2622 | } |
| 2623 | |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2624 | static inline void printFields(formatted_raw_ostream &OS, StringRef Str1, |
| 2625 | StringRef Str2) { |
| 2626 | OS.PadToColumn(2u); |
| 2627 | OS << Str1; |
| 2628 | OS.PadToColumn(37u); |
| 2629 | OS << Str2 << "\n"; |
| 2630 | OS.flush(); |
| 2631 | } |
| 2632 | |
George Rimar | 6fdac3b | 2018-07-18 08:19:58 +0000 | [diff] [blame] | 2633 | template <class ELFT> |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2634 | static std::string getSectionHeadersNumString(const ELFFile<ELFT> *Obj, |
| 2635 | StringRef FileName) { |
George Rimar | 6fdac3b | 2018-07-18 08:19:58 +0000 | [diff] [blame] | 2636 | const typename ELFT::Ehdr *ElfHeader = Obj->getHeader(); |
| 2637 | if (ElfHeader->e_shnum != 0) |
| 2638 | return to_string(ElfHeader->e_shnum); |
| 2639 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2640 | ArrayRef<typename ELFT::Shdr> Arr = unwrapOrError(FileName, Obj->sections()); |
George Rimar | 6fdac3b | 2018-07-18 08:19:58 +0000 | [diff] [blame] | 2641 | if (Arr.empty()) |
| 2642 | return "0"; |
| 2643 | return "0 (" + to_string(Arr[0].sh_size) + ")"; |
| 2644 | } |
| 2645 | |
| 2646 | template <class ELFT> |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2647 | static std::string getSectionHeaderTableIndexString(const ELFFile<ELFT> *Obj, |
| 2648 | StringRef FileName) { |
George Rimar | 6fdac3b | 2018-07-18 08:19:58 +0000 | [diff] [blame] | 2649 | const typename ELFT::Ehdr *ElfHeader = Obj->getHeader(); |
| 2650 | if (ElfHeader->e_shstrndx != SHN_XINDEX) |
| 2651 | return to_string(ElfHeader->e_shstrndx); |
| 2652 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2653 | ArrayRef<typename ELFT::Shdr> Arr = unwrapOrError(FileName, Obj->sections()); |
George Rimar | 6fdac3b | 2018-07-18 08:19:58 +0000 | [diff] [blame] | 2654 | if (Arr.empty()) |
| 2655 | return "65535 (corrupt: out of range)"; |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 2656 | return to_string(ElfHeader->e_shstrndx) + " (" + to_string(Arr[0].sh_link) + |
| 2657 | ")"; |
George Rimar | 6fdac3b | 2018-07-18 08:19:58 +0000 | [diff] [blame] | 2658 | } |
| 2659 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2660 | template <class ELFT> void GNUStyle<ELFT>::printFileHeaders(const ELFO *Obj) { |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2661 | const Elf_Ehdr *e = Obj->getHeader(); |
| 2662 | OS << "ELF Header:\n"; |
| 2663 | OS << " Magic: "; |
| 2664 | std::string Str; |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2665 | for (int i = 0; i < ELF::EI_NIDENT; i++) |
| 2666 | OS << format(" %02x", static_cast<int>(e->e_ident[i])); |
| 2667 | OS << "\n"; |
| 2668 | Str = printEnum(e->e_ident[ELF::EI_CLASS], makeArrayRef(ElfClass)); |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2669 | printFields(OS, "Class:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2670 | Str = printEnum(e->e_ident[ELF::EI_DATA], makeArrayRef(ElfDataEncoding)); |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2671 | printFields(OS, "Data:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2672 | OS.PadToColumn(2u); |
| 2673 | OS << "Version:"; |
| 2674 | OS.PadToColumn(37u); |
| 2675 | OS << to_hexString(e->e_ident[ELF::EI_VERSION]); |
| 2676 | if (e->e_version == ELF::EV_CURRENT) |
| 2677 | OS << " (current)"; |
| 2678 | OS << "\n"; |
| 2679 | Str = printEnum(e->e_ident[ELF::EI_OSABI], makeArrayRef(ElfOSABI)); |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2680 | printFields(OS, "OS/ABI:", Str); |
Chandler Carruth | e8fa5ae | 2016-11-03 17:11:11 +0000 | [diff] [blame] | 2681 | Str = "0x" + to_hexString(e->e_ident[ELF::EI_ABIVERSION]); |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2682 | printFields(OS, "ABI Version:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2683 | Str = printEnum(e->e_type, makeArrayRef(ElfObjectFileType)); |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2684 | printFields(OS, "Type:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2685 | Str = printEnum(e->e_machine, makeArrayRef(ElfMachineType)); |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2686 | printFields(OS, "Machine:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2687 | Str = "0x" + to_hexString(e->e_version); |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2688 | printFields(OS, "Version:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2689 | Str = "0x" + to_hexString(e->e_entry); |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2690 | printFields(OS, "Entry point address:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2691 | Str = to_string(e->e_phoff) + " (bytes into file)"; |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2692 | printFields(OS, "Start of program headers:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2693 | Str = to_string(e->e_shoff) + " (bytes into file)"; |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2694 | printFields(OS, "Start of section headers:", Str); |
Simon Atanasyan | 1993254 | 2018-10-25 05:39:27 +0000 | [diff] [blame] | 2695 | std::string ElfFlags; |
| 2696 | if (e->e_machine == EM_MIPS) |
| 2697 | ElfFlags = |
| 2698 | printFlags(e->e_flags, makeArrayRef(ElfHeaderMipsFlags), |
| 2699 | unsigned(ELF::EF_MIPS_ARCH), unsigned(ELF::EF_MIPS_ABI), |
| 2700 | unsigned(ELF::EF_MIPS_MACH)); |
| 2701 | else if (e->e_machine == EM_RISCV) |
| 2702 | ElfFlags = printFlags(e->e_flags, makeArrayRef(ElfHeaderRISCVFlags)); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2703 | Str = "0x" + to_hexString(e->e_flags); |
Simon Atanasyan | 1993254 | 2018-10-25 05:39:27 +0000 | [diff] [blame] | 2704 | if (!ElfFlags.empty()) |
| 2705 | Str = Str + ", " + ElfFlags; |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2706 | printFields(OS, "Flags:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2707 | Str = to_string(e->e_ehsize) + " (bytes)"; |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2708 | printFields(OS, "Size of this header:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2709 | Str = to_string(e->e_phentsize) + " (bytes)"; |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2710 | printFields(OS, "Size of program headers:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2711 | Str = to_string(e->e_phnum); |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2712 | printFields(OS, "Number of program headers:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2713 | Str = to_string(e->e_shentsize) + " (bytes)"; |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2714 | printFields(OS, "Size of section headers:", Str); |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2715 | Str = getSectionHeadersNumString(Obj, this->FileName); |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2716 | printFields(OS, "Number of section headers:", Str); |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2717 | Str = getSectionHeaderTableIndexString(Obj, this->FileName); |
Hemant Kulkarni | f84cda7 | 2016-02-11 03:41:34 +0000 | [diff] [blame] | 2718 | printFields(OS, "Section header string table index:", Str); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2719 | } |
| 2720 | |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 2721 | namespace { |
| 2722 | struct GroupMember { |
| 2723 | StringRef Name; |
| 2724 | uint64_t Index; |
| 2725 | }; |
| 2726 | |
| 2727 | struct GroupSection { |
| 2728 | StringRef Name; |
James Henderson | e50d9cb | 2019-01-17 15:34:12 +0000 | [diff] [blame] | 2729 | std::string Signature; |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 2730 | uint64_t ShName; |
| 2731 | uint64_t Index; |
Alexander Shaposhnikov | 8febe3d | 2018-03-12 22:40:09 +0000 | [diff] [blame] | 2732 | uint32_t Link; |
| 2733 | uint32_t Info; |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 2734 | uint32_t Type; |
| 2735 | std::vector<GroupMember> Members; |
| 2736 | }; |
| 2737 | |
| 2738 | template <class ELFT> |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2739 | std::vector<GroupSection> getGroups(const ELFFile<ELFT> *Obj, |
| 2740 | StringRef FileName) { |
Rui Ueyama | 478d635 | 2018-01-12 02:28:31 +0000 | [diff] [blame] | 2741 | using Elf_Shdr = typename ELFT::Shdr; |
| 2742 | using Elf_Sym = typename ELFT::Sym; |
| 2743 | using Elf_Word = typename ELFT::Word; |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 2744 | |
| 2745 | std::vector<GroupSection> Ret; |
| 2746 | uint64_t I = 0; |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2747 | for (const Elf_Shdr &Sec : unwrapOrError(FileName, Obj->sections())) { |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 2748 | ++I; |
| 2749 | if (Sec.sh_type != ELF::SHT_GROUP) |
| 2750 | continue; |
| 2751 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2752 | const Elf_Shdr *Symtab = |
| 2753 | unwrapOrError(FileName, Obj->getSection(Sec.sh_link)); |
| 2754 | StringRef StrTable = |
| 2755 | unwrapOrError(FileName, Obj->getStringTableForSymtab(*Symtab)); |
| 2756 | const Elf_Sym *Sym = unwrapOrError( |
| 2757 | FileName, Obj->template getEntry<Elf_Sym>(Symtab, Sec.sh_info)); |
| 2758 | auto Data = unwrapOrError( |
| 2759 | FileName, Obj->template getSectionContentsAsArray<Elf_Word>(&Sec)); |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 2760 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2761 | StringRef Name = unwrapOrError(FileName, Obj->getSectionName(&Sec)); |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 2762 | StringRef Signature = StrTable.data() + Sym->st_name; |
James Henderson | e50d9cb | 2019-01-17 15:34:12 +0000 | [diff] [blame] | 2763 | Ret.push_back({Name, |
| 2764 | maybeDemangle(Signature), |
| 2765 | Sec.sh_name, |
Alexander Shaposhnikov | 8febe3d | 2018-03-12 22:40:09 +0000 | [diff] [blame] | 2766 | I - 1, |
| 2767 | Sec.sh_link, |
| 2768 | Sec.sh_info, |
James Henderson | e50d9cb | 2019-01-17 15:34:12 +0000 | [diff] [blame] | 2769 | Data[0], |
Alexander Shaposhnikov | 8febe3d | 2018-03-12 22:40:09 +0000 | [diff] [blame] | 2770 | {}}); |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 2771 | |
| 2772 | std::vector<GroupMember> &GM = Ret.back().Members; |
| 2773 | for (uint32_t Ndx : Data.slice(1)) { |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2774 | auto Sec = unwrapOrError(FileName, Obj->getSection(Ndx)); |
| 2775 | const StringRef Name = unwrapOrError(FileName, Obj->getSectionName(Sec)); |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 2776 | GM.push_back({Name, Ndx}); |
George Rimar | 3c0f396 | 2017-09-14 07:26:14 +0000 | [diff] [blame] | 2777 | } |
George Rimar | c2657cd | 2017-09-14 07:17:04 +0000 | [diff] [blame] | 2778 | } |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 2779 | return Ret; |
| 2780 | } |
George Rimar | 762abff6 | 2017-09-16 14:29:51 +0000 | [diff] [blame] | 2781 | |
| 2782 | DenseMap<uint64_t, const GroupSection *> |
| 2783 | mapSectionsToGroups(ArrayRef<GroupSection> Groups) { |
| 2784 | DenseMap<uint64_t, const GroupSection *> Ret; |
| 2785 | for (const GroupSection &G : Groups) |
| 2786 | for (const GroupMember &GM : G.Members) |
| 2787 | Ret.insert({GM.Index, &G}); |
| 2788 | return Ret; |
| 2789 | } |
| 2790 | |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 2791 | } // namespace |
| 2792 | |
| 2793 | template <class ELFT> void GNUStyle<ELFT>::printGroupSections(const ELFO *Obj) { |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2794 | std::vector<GroupSection> V = getGroups<ELFT>(Obj, this->FileName); |
George Rimar | 762abff6 | 2017-09-16 14:29:51 +0000 | [diff] [blame] | 2795 | DenseMap<uint64_t, const GroupSection *> Map = mapSectionsToGroups(V); |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 2796 | for (const GroupSection &G : V) { |
| 2797 | OS << "\n" |
| 2798 | << getGroupType(G.Type) << " group section [" |
| 2799 | << format_decimal(G.Index, 5) << "] `" << G.Name << "' [" << G.Signature |
| 2800 | << "] contains " << G.Members.size() << " sections:\n" |
| 2801 | << " [Index] Name\n"; |
George Rimar | 762abff6 | 2017-09-16 14:29:51 +0000 | [diff] [blame] | 2802 | for (const GroupMember &GM : G.Members) { |
| 2803 | const GroupSection *MainGroup = Map[GM.Index]; |
| 2804 | if (MainGroup != &G) { |
| 2805 | OS.flush(); |
| 2806 | errs() << "Error: section [" << format_decimal(GM.Index, 5) |
| 2807 | << "] in group section [" << format_decimal(G.Index, 5) |
| 2808 | << "] already in group section [" |
| 2809 | << format_decimal(MainGroup->Index, 5) << "]"; |
| 2810 | errs().flush(); |
| 2811 | continue; |
| 2812 | } |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 2813 | OS << " [" << format_decimal(GM.Index, 5) << "] " << GM.Name << "\n"; |
George Rimar | 762abff6 | 2017-09-16 14:29:51 +0000 | [diff] [blame] | 2814 | } |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 2815 | } |
| 2816 | |
| 2817 | if (V.empty()) |
Hemant Kulkarni | 206ba84 | 2016-03-09 19:16:13 +0000 | [diff] [blame] | 2818 | OS << "There are no section groups in this file.\n"; |
| 2819 | } |
| 2820 | |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 2821 | template <class ELFT> |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2822 | void GNUStyle<ELFT>::printRelocation(const ELFO *Obj, const Elf_Shdr *SymTab, |
| 2823 | const Elf_Rela &R, bool IsRela) { |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2824 | const Elf_Sym *Sym = |
| 2825 | unwrapOrError(this->FileName, Obj->getRelocationSymbol(&R, SymTab)); |
George Rimar | 1206f5a | 2019-01-30 15:39:05 +0000 | [diff] [blame] | 2826 | std::string TargetName; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2827 | if (Sym && Sym->getType() == ELF::STT_SECTION) { |
| 2828 | const Elf_Shdr *Sec = unwrapOrError( |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2829 | this->FileName, |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2830 | Obj->getSection(Sym, SymTab, this->dumper()->getShndxTable())); |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2831 | TargetName = unwrapOrError(this->FileName, Obj->getSectionName(Sec)); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2832 | } else if (Sym) { |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2833 | StringRef StrTable = |
| 2834 | unwrapOrError(this->FileName, Obj->getStringTableForSymtab(*SymTab)); |
Xing GUO | eec3206 | 2019-03-12 14:30:13 +0000 | [diff] [blame] | 2835 | TargetName = this->dumper()->getFullSymbolName( |
| 2836 | Sym, StrTable, SymTab->sh_type == SHT_DYNSYM /* IsDynamic */); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2837 | } |
James Henderson | 814ab37 | 2019-03-29 11:47:19 +0000 | [diff] [blame] | 2838 | printRelocation(Obj, Sym, TargetName, R, IsRela); |
| 2839 | } |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2840 | |
James Henderson | 814ab37 | 2019-03-29 11:47:19 +0000 | [diff] [blame] | 2841 | template <class ELFT> |
| 2842 | void GNUStyle<ELFT>::printRelocation(const ELFO *Obj, const Elf_Sym *Sym, |
| 2843 | StringRef SymbolName, const Elf_Rela &R, |
| 2844 | bool IsRela) { |
| 2845 | // First two fields are bit width dependent. The rest of them are fixed width. |
| 2846 | unsigned Bias = ELFT::Is64Bits ? 8 : 0; |
| 2847 | Field Fields[5] = {0, 10 + Bias, 19 + 2 * Bias, 42 + 2 * Bias, 53 + 2 * Bias}; |
George Rimar | 4b4899b | 2019-01-30 14:08:55 +0000 | [diff] [blame] | 2848 | unsigned Width = ELFT::Is64Bits ? 16 : 8; |
James Henderson | 814ab37 | 2019-03-29 11:47:19 +0000 | [diff] [blame] | 2849 | |
George Rimar | 4b4899b | 2019-01-30 14:08:55 +0000 | [diff] [blame] | 2850 | Fields[0].Str = to_string(format_hex_no_prefix(R.r_offset, Width)); |
| 2851 | Fields[1].Str = to_string(format_hex_no_prefix(R.r_info, Width)); |
James Henderson | 814ab37 | 2019-03-29 11:47:19 +0000 | [diff] [blame] | 2852 | |
| 2853 | SmallString<32> RelocName; |
| 2854 | Obj->getRelocationTypeName(R.getType(Obj->isMips64EL()), RelocName); |
| 2855 | Fields[2].Str = RelocName.c_str(); |
| 2856 | |
| 2857 | if (Sym && (!SymbolName.empty() || Sym->getValue() != 0)) |
George Rimar | 4b4899b | 2019-01-30 14:08:55 +0000 | [diff] [blame] | 2858 | Fields[3].Str = to_string(format_hex_no_prefix(Sym->getValue(), Width)); |
James Henderson | 814ab37 | 2019-03-29 11:47:19 +0000 | [diff] [blame] | 2859 | |
| 2860 | Fields[4].Str = SymbolName; |
| 2861 | for (const Field &F : Fields) |
George Rimar | 4b4899b | 2019-01-30 14:08:55 +0000 | [diff] [blame] | 2862 | printField(F); |
| 2863 | |
| 2864 | std::string Addend; |
James Henderson | b41130b | 2019-03-08 13:22:05 +0000 | [diff] [blame] | 2865 | if (IsRela) { |
| 2866 | int64_t RelAddend = R.r_addend; |
James Henderson | 814ab37 | 2019-03-29 11:47:19 +0000 | [diff] [blame] | 2867 | if (!SymbolName.empty()) { |
James Henderson | b41130b | 2019-03-08 13:22:05 +0000 | [diff] [blame] | 2868 | if (R.r_addend < 0) { |
| 2869 | Addend = " - "; |
| 2870 | RelAddend = std::abs(RelAddend); |
| 2871 | } else |
| 2872 | Addend = " + "; |
| 2873 | } |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2874 | |
James Henderson | b41130b | 2019-03-08 13:22:05 +0000 | [diff] [blame] | 2875 | Addend += to_hexString(RelAddend, false); |
| 2876 | } |
George Rimar | 1206f5a | 2019-01-30 15:39:05 +0000 | [diff] [blame] | 2877 | OS << Addend << "\n"; |
Hemant Kulkarni | a79c798 | 2016-03-29 02:41:49 +0000 | [diff] [blame] | 2878 | } |
| 2879 | |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 2880 | template <class ELFT> void GNUStyle<ELFT>::printRelocHeader(unsigned SType) { |
| 2881 | bool IsRela = SType == ELF::SHT_RELA || SType == ELF::SHT_ANDROID_RELA; |
| 2882 | bool IsRelr = SType == ELF::SHT_RELR || SType == ELF::SHT_ANDROID_RELR; |
| 2883 | if (ELFT::Is64Bits) |
| 2884 | OS << " "; |
| 2885 | else |
| 2886 | OS << " "; |
| 2887 | if (IsRelr && opts::RawRelr) |
| 2888 | OS << "Data "; |
| 2889 | else |
| 2890 | OS << "Offset"; |
| 2891 | if (ELFT::Is64Bits) |
| 2892 | OS << " Info Type" |
Hemant Kulkarni | a79c798 | 2016-03-29 02:41:49 +0000 | [diff] [blame] | 2893 | << " Symbol's Value Symbol's Name"; |
| 2894 | else |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 2895 | OS << " Info Type Sym. Value Symbol's Name"; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2896 | if (IsRela) |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 2897 | OS << " + Addend"; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2898 | OS << "\n"; |
| 2899 | } |
| 2900 | |
| 2901 | template <class ELFT> void GNUStyle<ELFT>::printRelocations(const ELFO *Obj) { |
| 2902 | bool HasRelocSections = false; |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2903 | for (const Elf_Shdr &Sec : unwrapOrError(this->FileName, Obj->sections())) { |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 2904 | if (Sec.sh_type != ELF::SHT_REL && Sec.sh_type != ELF::SHT_RELA && |
| 2905 | Sec.sh_type != ELF::SHT_RELR && Sec.sh_type != ELF::SHT_ANDROID_REL && |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 2906 | Sec.sh_type != ELF::SHT_ANDROID_RELA && |
| 2907 | Sec.sh_type != ELF::SHT_ANDROID_RELR) |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2908 | continue; |
| 2909 | HasRelocSections = true; |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2910 | StringRef Name = unwrapOrError(this->FileName, Obj->getSectionName(&Sec)); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2911 | unsigned Entries = Sec.getEntityCount(); |
Peter Collingbourne | cf017ad | 2018-06-07 00:02:07 +0000 | [diff] [blame] | 2912 | std::vector<Elf_Rela> AndroidRelas; |
| 2913 | if (Sec.sh_type == ELF::SHT_ANDROID_REL || |
| 2914 | Sec.sh_type == ELF::SHT_ANDROID_RELA) { |
| 2915 | // Android's packed relocation section needs to be unpacked first |
| 2916 | // to get the actual number of entries. |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2917 | AndroidRelas = unwrapOrError(this->FileName, Obj->android_relas(&Sec)); |
Peter Collingbourne | cf017ad | 2018-06-07 00:02:07 +0000 | [diff] [blame] | 2918 | Entries = AndroidRelas.size(); |
| 2919 | } |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 2920 | std::vector<Elf_Rela> RelrRelas; |
| 2921 | if (!opts::RawRelr && (Sec.sh_type == ELF::SHT_RELR || |
| 2922 | Sec.sh_type == ELF::SHT_ANDROID_RELR)) { |
| 2923 | // .relr.dyn relative relocation section needs to be unpacked first |
| 2924 | // to get the actual number of entries. |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2925 | Elf_Relr_Range Relrs = unwrapOrError(this->FileName, Obj->relrs(&Sec)); |
| 2926 | RelrRelas = unwrapOrError(this->FileName, Obj->decode_relrs(Relrs)); |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 2927 | Entries = RelrRelas.size(); |
| 2928 | } |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2929 | uintX_t Offset = Sec.sh_offset; |
| 2930 | OS << "\nRelocation section '" << Name << "' at offset 0x" |
| 2931 | << to_hexString(Offset, false) << " contains " << Entries |
| 2932 | << " entries:\n"; |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 2933 | printRelocHeader(Sec.sh_type); |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2934 | const Elf_Shdr *SymTab = |
| 2935 | unwrapOrError(this->FileName, Obj->getSection(Sec.sh_link)); |
Peter Collingbourne | 689e6c05 | 2017-10-25 03:37:12 +0000 | [diff] [blame] | 2936 | switch (Sec.sh_type) { |
| 2937 | case ELF::SHT_REL: |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2938 | for (const auto &R : unwrapOrError(this->FileName, Obj->rels(&Sec))) { |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2939 | Elf_Rela Rela; |
| 2940 | Rela.r_offset = R.r_offset; |
| 2941 | Rela.r_info = R.r_info; |
| 2942 | Rela.r_addend = 0; |
| 2943 | printRelocation(Obj, SymTab, Rela, false); |
| 2944 | } |
Peter Collingbourne | 689e6c05 | 2017-10-25 03:37:12 +0000 | [diff] [blame] | 2945 | break; |
| 2946 | case ELF::SHT_RELA: |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2947 | for (const auto &R : unwrapOrError(this->FileName, Obj->relas(&Sec))) |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2948 | printRelocation(Obj, SymTab, R, true); |
Peter Collingbourne | 689e6c05 | 2017-10-25 03:37:12 +0000 | [diff] [blame] | 2949 | break; |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 2950 | case ELF::SHT_RELR: |
| 2951 | case ELF::SHT_ANDROID_RELR: |
| 2952 | if (opts::RawRelr) |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 2953 | for (const auto &R : unwrapOrError(this->FileName, Obj->relrs(&Sec))) |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 2954 | OS << to_string(format_hex_no_prefix(R, ELFT::Is64Bits ? 16 : 8)) |
| 2955 | << "\n"; |
| 2956 | else |
| 2957 | for (const auto &R : RelrRelas) |
| 2958 | printRelocation(Obj, SymTab, R, false); |
| 2959 | break; |
Peter Collingbourne | 689e6c05 | 2017-10-25 03:37:12 +0000 | [diff] [blame] | 2960 | case ELF::SHT_ANDROID_REL: |
| 2961 | case ELF::SHT_ANDROID_RELA: |
Peter Collingbourne | cf017ad | 2018-06-07 00:02:07 +0000 | [diff] [blame] | 2962 | for (const auto &R : AndroidRelas) |
Peter Collingbourne | 689e6c05 | 2017-10-25 03:37:12 +0000 | [diff] [blame] | 2963 | printRelocation(Obj, SymTab, R, Sec.sh_type == ELF::SHT_ANDROID_RELA); |
| 2964 | break; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2965 | } |
| 2966 | } |
| 2967 | if (!HasRelocSections) |
| 2968 | OS << "\nThere are no relocations in this file.\n"; |
| 2969 | } |
| 2970 | |
Matt Davis | 7a24dbd | 2019-02-27 18:39:17 +0000 | [diff] [blame] | 2971 | // Print the offset of a particular section from anyone of the ranges: |
| 2972 | // [SHT_LOOS, SHT_HIOS], [SHT_LOPROC, SHT_HIPROC], [SHT_LOUSER, SHT_HIUSER]. |
| 2973 | // If 'Type' does not fall within any of those ranges, then a string is |
| 2974 | // returned as '<unknown>' followed by the type value. |
| 2975 | static std::string getSectionTypeOffsetString(unsigned Type) { |
| 2976 | if (Type >= SHT_LOOS && Type <= SHT_HIOS) |
| 2977 | return "LOOS+0x" + to_hexString(Type - SHT_LOOS); |
| 2978 | else if (Type >= SHT_LOPROC && Type <= SHT_HIPROC) |
| 2979 | return "LOPROC+0x" + to_hexString(Type - SHT_LOPROC); |
| 2980 | else if (Type >= SHT_LOUSER && Type <= SHT_HIUSER) |
| 2981 | return "LOUSER+0x" + to_hexString(Type - SHT_LOUSER); |
| 2982 | return "0x" + to_hexString(Type) + ": <unknown>"; |
| 2983 | } |
| 2984 | |
| 2985 | static std::string getSectionTypeString(unsigned Arch, unsigned Type) { |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2986 | using namespace ELF; |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 2987 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 2988 | switch (Arch) { |
| 2989 | case EM_ARM: |
| 2990 | switch (Type) { |
| 2991 | case SHT_ARM_EXIDX: |
| 2992 | return "ARM_EXIDX"; |
| 2993 | case SHT_ARM_PREEMPTMAP: |
| 2994 | return "ARM_PREEMPTMAP"; |
| 2995 | case SHT_ARM_ATTRIBUTES: |
| 2996 | return "ARM_ATTRIBUTES"; |
| 2997 | case SHT_ARM_DEBUGOVERLAY: |
| 2998 | return "ARM_DEBUGOVERLAY"; |
| 2999 | case SHT_ARM_OVERLAYSECTION: |
| 3000 | return "ARM_OVERLAYSECTION"; |
| 3001 | } |
Ryan Prichard | 0c20b5b | 2018-10-26 23:01:54 +0000 | [diff] [blame] | 3002 | break; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3003 | case EM_X86_64: |
| 3004 | switch (Type) { |
| 3005 | case SHT_X86_64_UNWIND: |
| 3006 | return "X86_64_UNWIND"; |
| 3007 | } |
Ryan Prichard | 0c20b5b | 2018-10-26 23:01:54 +0000 | [diff] [blame] | 3008 | break; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3009 | case EM_MIPS: |
| 3010 | case EM_MIPS_RS3_LE: |
| 3011 | switch (Type) { |
| 3012 | case SHT_MIPS_REGINFO: |
| 3013 | return "MIPS_REGINFO"; |
| 3014 | case SHT_MIPS_OPTIONS: |
| 3015 | return "MIPS_OPTIONS"; |
Fangrui Song | 8443e88 | 2019-02-21 11:35:41 +0000 | [diff] [blame] | 3016 | case SHT_MIPS_DWARF: |
| 3017 | return "MIPS_DWARF"; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3018 | case SHT_MIPS_ABIFLAGS: |
| 3019 | return "MIPS_ABIFLAGS"; |
| 3020 | } |
Ryan Prichard | 0c20b5b | 2018-10-26 23:01:54 +0000 | [diff] [blame] | 3021 | break; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3022 | } |
| 3023 | switch (Type) { |
| 3024 | case SHT_NULL: |
| 3025 | return "NULL"; |
| 3026 | case SHT_PROGBITS: |
| 3027 | return "PROGBITS"; |
| 3028 | case SHT_SYMTAB: |
| 3029 | return "SYMTAB"; |
| 3030 | case SHT_STRTAB: |
| 3031 | return "STRTAB"; |
| 3032 | case SHT_RELA: |
| 3033 | return "RELA"; |
| 3034 | case SHT_HASH: |
| 3035 | return "HASH"; |
| 3036 | case SHT_DYNAMIC: |
| 3037 | return "DYNAMIC"; |
| 3038 | case SHT_NOTE: |
| 3039 | return "NOTE"; |
| 3040 | case SHT_NOBITS: |
| 3041 | return "NOBITS"; |
| 3042 | case SHT_REL: |
| 3043 | return "REL"; |
| 3044 | case SHT_SHLIB: |
| 3045 | return "SHLIB"; |
| 3046 | case SHT_DYNSYM: |
| 3047 | return "DYNSYM"; |
| 3048 | case SHT_INIT_ARRAY: |
| 3049 | return "INIT_ARRAY"; |
| 3050 | case SHT_FINI_ARRAY: |
| 3051 | return "FINI_ARRAY"; |
| 3052 | case SHT_PREINIT_ARRAY: |
| 3053 | return "PREINIT_ARRAY"; |
| 3054 | case SHT_GROUP: |
| 3055 | return "GROUP"; |
| 3056 | case SHT_SYMTAB_SHNDX: |
| 3057 | return "SYMTAB SECTION INDICES"; |
Matt Davis | 7a24dbd | 2019-02-27 18:39:17 +0000 | [diff] [blame] | 3058 | case SHT_ANDROID_REL: |
| 3059 | return "ANDROID_REL"; |
| 3060 | case SHT_ANDROID_RELA: |
| 3061 | return "ANDROID_RELA"; |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 3062 | case SHT_RELR: |
| 3063 | case SHT_ANDROID_RELR: |
| 3064 | return "RELR"; |
Peter Collingbourne | f0e26e7 | 2017-06-14 18:52:12 +0000 | [diff] [blame] | 3065 | case SHT_LLVM_ODRTAB: |
| 3066 | return "LLVM_ODRTAB"; |
Saleem Abdulrasool | b36fbbc | 2018-01-30 16:29:29 +0000 | [diff] [blame] | 3067 | case SHT_LLVM_LINKER_OPTIONS: |
| 3068 | return "LLVM_LINKER_OPTIONS"; |
Michael J. Spencer | ae6eeae | 2018-06-02 16:33:01 +0000 | [diff] [blame] | 3069 | case SHT_LLVM_CALL_GRAPH_PROFILE: |
| 3070 | return "LLVM_CALL_GRAPH_PROFILE"; |
Peter Collingbourne | 3e22733 | 2018-07-17 22:17:18 +0000 | [diff] [blame] | 3071 | case SHT_LLVM_ADDRSIG: |
| 3072 | return "LLVM_ADDRSIG"; |
Ben Dunbobbin | 1d16515 | 2019-05-17 03:44:15 +0000 | [diff] [blame] | 3073 | case SHT_LLVM_DEPENDENT_LIBRARIES: |
| 3074 | return "LLVM_DEPENDENT_LIBRARIES"; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3075 | // FIXME: Parse processor specific GNU attributes |
| 3076 | case SHT_GNU_ATTRIBUTES: |
| 3077 | return "ATTRIBUTES"; |
| 3078 | case SHT_GNU_HASH: |
| 3079 | return "GNU_HASH"; |
| 3080 | case SHT_GNU_verdef: |
| 3081 | return "VERDEF"; |
| 3082 | case SHT_GNU_verneed: |
| 3083 | return "VERNEED"; |
| 3084 | case SHT_GNU_versym: |
| 3085 | return "VERSYM"; |
| 3086 | default: |
Matt Davis | 7a24dbd | 2019-02-27 18:39:17 +0000 | [diff] [blame] | 3087 | return getSectionTypeOffsetString(Type); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3088 | } |
| 3089 | return ""; |
| 3090 | } |
| 3091 | |
Jordan Rupprecht | dbf552c | 2018-11-12 18:02:38 +0000 | [diff] [blame] | 3092 | template <class ELFT> |
| 3093 | void GNUStyle<ELFT>::printSectionHeaders(const ELFO *Obj) { |
George Rimar | 4b4899b | 2019-01-30 14:08:55 +0000 | [diff] [blame] | 3094 | unsigned Bias = ELFT::Is64Bits ? 0 : 8; |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 3095 | ArrayRef<Elf_Shdr> Sections = unwrapOrError(this->FileName, Obj->sections()); |
George Rimar | a2b553b | 2018-07-19 14:52:57 +0000 | [diff] [blame] | 3096 | OS << "There are " << to_string(Sections.size()) |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3097 | << " section headers, starting at offset " |
| 3098 | << "0x" << to_hexString(Obj->getHeader()->e_shoff, false) << ":\n\n"; |
| 3099 | OS << "Section Headers:\n"; |
George Rimar | 4b4899b | 2019-01-30 14:08:55 +0000 | [diff] [blame] | 3100 | Field Fields[11] = { |
| 3101 | {"[Nr]", 2}, {"Name", 7}, {"Type", 25}, |
| 3102 | {"Address", 41}, {"Off", 58 - Bias}, {"Size", 65 - Bias}, |
| 3103 | {"ES", 72 - Bias}, {"Flg", 75 - Bias}, {"Lk", 79 - Bias}, |
| 3104 | {"Inf", 82 - Bias}, {"Al", 86 - Bias}}; |
| 3105 | for (auto &F : Fields) |
| 3106 | printField(F); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3107 | OS << "\n"; |
| 3108 | |
George Rimar | a137087 | 2019-07-16 11:07:30 +0000 | [diff] [blame] | 3109 | const ELFObjectFile<ELFT> *ElfObj = this->dumper()->getElfObject(); |
George Rimar | 4b4899b | 2019-01-30 14:08:55 +0000 | [diff] [blame] | 3110 | size_t SectionIndex = 0; |
George Rimar | a2b553b | 2018-07-19 14:52:57 +0000 | [diff] [blame] | 3111 | for (const Elf_Shdr &Sec : Sections) { |
George Rimar | 4b4899b | 2019-01-30 14:08:55 +0000 | [diff] [blame] | 3112 | Fields[0].Str = to_string(SectionIndex); |
George Rimar | 67ea32a | 2019-08-08 07:17:35 +0000 | [diff] [blame] | 3113 | Fields[1].Str = unwrapOrError<StringRef>( |
| 3114 | ElfObj->getFileName(), Obj->getSectionName(&Sec, this->WarningHandler)); |
George Rimar | 4b4899b | 2019-01-30 14:08:55 +0000 | [diff] [blame] | 3115 | Fields[2].Str = |
| 3116 | getSectionTypeString(Obj->getHeader()->e_machine, Sec.sh_type); |
| 3117 | Fields[3].Str = |
| 3118 | to_string(format_hex_no_prefix(Sec.sh_addr, ELFT::Is64Bits ? 16 : 8)); |
| 3119 | Fields[4].Str = to_string(format_hex_no_prefix(Sec.sh_offset, 6)); |
| 3120 | Fields[5].Str = to_string(format_hex_no_prefix(Sec.sh_size, 6)); |
| 3121 | Fields[6].Str = to_string(format_hex_no_prefix(Sec.sh_entsize, 2)); |
| 3122 | Fields[7].Str = getGNUFlags(Sec.sh_flags); |
| 3123 | Fields[8].Str = to_string(Sec.sh_link); |
| 3124 | Fields[9].Str = to_string(Sec.sh_info); |
| 3125 | Fields[10].Str = to_string(Sec.sh_addralign); |
| 3126 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3127 | OS.PadToColumn(Fields[0].Column); |
| 3128 | OS << "[" << right_justify(Fields[0].Str, 2) << "]"; |
| 3129 | for (int i = 1; i < 7; i++) |
| 3130 | printField(Fields[i]); |
| 3131 | OS.PadToColumn(Fields[7].Column); |
| 3132 | OS << right_justify(Fields[7].Str, 3); |
| 3133 | OS.PadToColumn(Fields[8].Column); |
| 3134 | OS << right_justify(Fields[8].Str, 2); |
| 3135 | OS.PadToColumn(Fields[9].Column); |
| 3136 | OS << right_justify(Fields[9].Str, 3); |
| 3137 | OS.PadToColumn(Fields[10].Column); |
| 3138 | OS << right_justify(Fields[10].Str, 2); |
| 3139 | OS << "\n"; |
| 3140 | ++SectionIndex; |
| 3141 | } |
| 3142 | OS << "Key to Flags:\n" |
| 3143 | << " W (write), A (alloc), X (execute), M (merge), S (strings), l " |
| 3144 | "(large)\n" |
| 3145 | << " I (info), L (link order), G (group), T (TLS), E (exclude),\ |
| 3146 | x (unknown)\n" |
| 3147 | << " O (extra OS processing required) o (OS specific),\ |
| 3148 | p (processor specific)\n"; |
| 3149 | } |
| 3150 | |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 3151 | template <class ELFT> |
| 3152 | void GNUStyle<ELFT>::printSymtabMessage(const ELFO *Obj, StringRef Name, |
| 3153 | size_t Entries) { |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 3154 | if (!Name.empty()) |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 3155 | OS << "\nSymbol table '" << Name << "' contains " << Entries |
| 3156 | << " entries:\n"; |
| 3157 | else |
| 3158 | OS << "\n Symbol table for image:\n"; |
| 3159 | |
| 3160 | if (ELFT::Is64Bits) |
| 3161 | OS << " Num: Value Size Type Bind Vis Ndx Name\n"; |
| 3162 | else |
| 3163 | OS << " Num: Value Size Type Bind Vis Ndx Name\n"; |
| 3164 | } |
| 3165 | |
| 3166 | template <class ELFT> |
| 3167 | std::string GNUStyle<ELFT>::getSymbolSectionNdx(const ELFO *Obj, |
| 3168 | const Elf_Sym *Symbol, |
| 3169 | const Elf_Sym *FirstSym) { |
| 3170 | unsigned SectionIndex = Symbol->st_shndx; |
| 3171 | switch (SectionIndex) { |
| 3172 | case ELF::SHN_UNDEF: |
| 3173 | return "UND"; |
| 3174 | case ELF::SHN_ABS: |
| 3175 | return "ABS"; |
| 3176 | case ELF::SHN_COMMON: |
| 3177 | return "COM"; |
| 3178 | case ELF::SHN_XINDEX: |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 3179 | return to_string(format_decimal( |
| 3180 | unwrapOrError(this->FileName, |
| 3181 | object::getExtendedSymbolTableIndex<ELFT>( |
| 3182 | Symbol, FirstSym, this->dumper()->getShndxTable())), |
| 3183 | 3)); |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 3184 | default: |
| 3185 | // Find if: |
| 3186 | // Processor specific |
| 3187 | if (SectionIndex >= ELF::SHN_LOPROC && SectionIndex <= ELF::SHN_HIPROC) |
| 3188 | return std::string("PRC[0x") + |
| 3189 | to_string(format_hex_no_prefix(SectionIndex, 4)) + "]"; |
| 3190 | // OS specific |
| 3191 | if (SectionIndex >= ELF::SHN_LOOS && SectionIndex <= ELF::SHN_HIOS) |
| 3192 | return std::string("OS[0x") + |
| 3193 | to_string(format_hex_no_prefix(SectionIndex, 4)) + "]"; |
| 3194 | // Architecture reserved: |
| 3195 | if (SectionIndex >= ELF::SHN_LORESERVE && |
| 3196 | SectionIndex <= ELF::SHN_HIRESERVE) |
| 3197 | return std::string("RSV[0x") + |
| 3198 | to_string(format_hex_no_prefix(SectionIndex, 4)) + "]"; |
| 3199 | // A normal section with an index |
| 3200 | return to_string(format_decimal(SectionIndex, 3)); |
| 3201 | } |
| 3202 | } |
| 3203 | |
| 3204 | template <class ELFT> |
| 3205 | void GNUStyle<ELFT>::printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, |
| 3206 | const Elf_Sym *FirstSym, StringRef StrTable, |
| 3207 | bool IsDynamic) { |
| 3208 | static int Idx = 0; |
| 3209 | static bool Dynamic = true; |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 3210 | |
| 3211 | // If this function was called with a different value from IsDynamic |
| 3212 | // from last call, happens when we move from dynamic to static symbol |
| 3213 | // table, "Num" field should be reset. |
| 3214 | if (!Dynamic != !IsDynamic) { |
| 3215 | Idx = 0; |
| 3216 | Dynamic = false; |
| 3217 | } |
George Rimar | 4b4899b | 2019-01-30 14:08:55 +0000 | [diff] [blame] | 3218 | |
| 3219 | unsigned Bias = ELFT::Is64Bits ? 8 : 0; |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 3220 | Field Fields[8] = {0, 8, 17 + Bias, 23 + Bias, |
| 3221 | 31 + Bias, 38 + Bias, 47 + Bias, 51 + Bias}; |
George Rimar | 4b4899b | 2019-01-30 14:08:55 +0000 | [diff] [blame] | 3222 | Fields[0].Str = to_string(format_decimal(Idx++, 6)) + ":"; |
| 3223 | Fields[1].Str = to_string( |
| 3224 | format_hex_no_prefix(Symbol->st_value, ELFT::Is64Bits ? 16 : 8)); |
| 3225 | Fields[2].Str = to_string(format_decimal(Symbol->st_size, 5)); |
| 3226 | |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 3227 | unsigned char SymbolType = Symbol->getType(); |
| 3228 | if (Obj->getHeader()->e_machine == ELF::EM_AMDGPU && |
| 3229 | SymbolType >= ELF::STT_LOOS && SymbolType < ELF::STT_HIOS) |
George Rimar | 4b4899b | 2019-01-30 14:08:55 +0000 | [diff] [blame] | 3230 | Fields[3].Str = printEnum(SymbolType, makeArrayRef(AMDGPUSymbolTypes)); |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 3231 | else |
George Rimar | 4b4899b | 2019-01-30 14:08:55 +0000 | [diff] [blame] | 3232 | Fields[3].Str = printEnum(SymbolType, makeArrayRef(ElfSymbolTypes)); |
| 3233 | |
| 3234 | Fields[4].Str = |
| 3235 | printEnum(Symbol->getBinding(), makeArrayRef(ElfSymbolBindings)); |
| 3236 | Fields[5].Str = |
| 3237 | printEnum(Symbol->getVisibility(), makeArrayRef(ElfSymbolVisibilities)); |
| 3238 | Fields[6].Str = getSymbolSectionNdx(Obj, Symbol, FirstSym); |
| 3239 | Fields[7].Str = |
| 3240 | this->dumper()->getFullSymbolName(Symbol, StrTable, IsDynamic); |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 3241 | for (auto &Entry : Fields) |
| 3242 | printField(Entry); |
| 3243 | OS << "\n"; |
| 3244 | } |
George Rimar | 4b4899b | 2019-01-30 14:08:55 +0000 | [diff] [blame] | 3245 | |
Hemant Kulkarni | a6ee9fd | 2016-11-23 18:04:23 +0000 | [diff] [blame] | 3246 | template <class ELFT> |
| 3247 | void GNUStyle<ELFT>::printHashedSymbol(const ELFO *Obj, const Elf_Sym *FirstSym, |
| 3248 | uint32_t Sym, StringRef StrTable, |
| 3249 | uint32_t Bucket) { |
George Rimar | 1206f5a | 2019-01-30 15:39:05 +0000 | [diff] [blame] | 3250 | unsigned Bias = ELFT::Is64Bits ? 8 : 0; |
Hemant Kulkarni | a6ee9fd | 2016-11-23 18:04:23 +0000 | [diff] [blame] | 3251 | Field Fields[9] = {0, 6, 11, 20 + Bias, 25 + Bias, |
| 3252 | 34 + Bias, 41 + Bias, 49 + Bias, 53 + Bias}; |
George Rimar | 4b4899b | 2019-01-30 14:08:55 +0000 | [diff] [blame] | 3253 | Fields[0].Str = to_string(format_decimal(Sym, 5)); |
| 3254 | Fields[1].Str = to_string(format_decimal(Bucket, 3)) + ":"; |
Hemant Kulkarni | a6ee9fd | 2016-11-23 18:04:23 +0000 | [diff] [blame] | 3255 | |
| 3256 | const auto Symbol = FirstSym + Sym; |
George Rimar | 1206f5a | 2019-01-30 15:39:05 +0000 | [diff] [blame] | 3257 | Fields[2].Str = to_string( |
George Rimar | ce2ef28 | 2019-07-19 10:15:03 +0000 | [diff] [blame] | 3258 | format_hex_no_prefix(Symbol->st_value, ELFT::Is64Bits ? 16 : 8)); |
George Rimar | 4b4899b | 2019-01-30 14:08:55 +0000 | [diff] [blame] | 3259 | Fields[3].Str = to_string(format_decimal(Symbol->st_size, 5)); |
| 3260 | |
Hemant Kulkarni | a6ee9fd | 2016-11-23 18:04:23 +0000 | [diff] [blame] | 3261 | unsigned char SymbolType = Symbol->getType(); |
| 3262 | if (Obj->getHeader()->e_machine == ELF::EM_AMDGPU && |
| 3263 | SymbolType >= ELF::STT_LOOS && SymbolType < ELF::STT_HIOS) |
George Rimar | 4b4899b | 2019-01-30 14:08:55 +0000 | [diff] [blame] | 3264 | Fields[4].Str = printEnum(SymbolType, makeArrayRef(AMDGPUSymbolTypes)); |
Hemant Kulkarni | a6ee9fd | 2016-11-23 18:04:23 +0000 | [diff] [blame] | 3265 | else |
George Rimar | 4b4899b | 2019-01-30 14:08:55 +0000 | [diff] [blame] | 3266 | Fields[4].Str = printEnum(SymbolType, makeArrayRef(ElfSymbolTypes)); |
| 3267 | |
| 3268 | Fields[5].Str = |
| 3269 | printEnum(Symbol->getBinding(), makeArrayRef(ElfSymbolBindings)); |
| 3270 | Fields[6].Str = |
| 3271 | printEnum(Symbol->getVisibility(), makeArrayRef(ElfSymbolVisibilities)); |
| 3272 | Fields[7].Str = getSymbolSectionNdx(Obj, Symbol, FirstSym); |
| 3273 | Fields[8].Str = this->dumper()->getFullSymbolName(Symbol, StrTable, true); |
| 3274 | |
Hemant Kulkarni | a6ee9fd | 2016-11-23 18:04:23 +0000 | [diff] [blame] | 3275 | for (auto &Entry : Fields) |
| 3276 | printField(Entry); |
| 3277 | OS << "\n"; |
| 3278 | } |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 3279 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3280 | template <class ELFT> |
James Henderson | 21ed868 | 2019-01-23 16:15:39 +0000 | [diff] [blame] | 3281 | void GNUStyle<ELFT>::printSymbols(const ELFO *Obj, bool PrintSymbols, |
| 3282 | bool PrintDynamicSymbols) { |
| 3283 | if (!PrintSymbols && !PrintDynamicSymbols) |
| 3284 | return; |
| 3285 | // GNU readelf prints both the .dynsym and .symtab with --symbols. |
James Henderson | 5fc812f | 2019-01-22 09:35:35 +0000 | [diff] [blame] | 3286 | this->dumper()->printSymbolsHelper(true); |
James Henderson | 21ed868 | 2019-01-23 16:15:39 +0000 | [diff] [blame] | 3287 | if (PrintSymbols) |
| 3288 | this->dumper()->printSymbolsHelper(false); |
James Henderson | 5fc812f | 2019-01-22 09:35:35 +0000 | [diff] [blame] | 3289 | } |
| 3290 | |
| 3291 | template <class ELFT> void GNUStyle<ELFT>::printHashSymbols(const ELFO *Obj) { |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 3292 | if (this->dumper()->getDynamicStringTable().empty()) |
Hemant Kulkarni | a6ee9fd | 2016-11-23 18:04:23 +0000 | [diff] [blame] | 3293 | return; |
| 3294 | auto StringTable = this->dumper()->getDynamicStringTable(); |
| 3295 | auto DynSyms = this->dumper()->dynamic_symbols(); |
Hemant Kulkarni | a6ee9fd | 2016-11-23 18:04:23 +0000 | [diff] [blame] | 3296 | |
Hemant Kulkarni | a6ee9fd | 2016-11-23 18:04:23 +0000 | [diff] [blame] | 3297 | // Try printing .hash |
George Rimar | 1206f5a | 2019-01-30 15:39:05 +0000 | [diff] [blame] | 3298 | if (auto SysVHash = this->dumper()->getHashTable()) { |
Hemant Kulkarni | a6ee9fd | 2016-11-23 18:04:23 +0000 | [diff] [blame] | 3299 | OS << "\n Symbol table of .hash for image:\n"; |
| 3300 | if (ELFT::Is64Bits) |
| 3301 | OS << " Num Buc: Value Size Type Bind Vis Ndx Name"; |
| 3302 | else |
| 3303 | OS << " Num Buc: Value Size Type Bind Vis Ndx Name"; |
| 3304 | OS << "\n"; |
| 3305 | |
Hemant Kulkarni | a6ee9fd | 2016-11-23 18:04:23 +0000 | [diff] [blame] | 3306 | auto Buckets = SysVHash->buckets(); |
| 3307 | auto Chains = SysVHash->chains(); |
George Rimar | 1206f5a | 2019-01-30 15:39:05 +0000 | [diff] [blame] | 3308 | for (uint32_t Buc = 0; Buc < SysVHash->nbucket; Buc++) { |
Hemant Kulkarni | a6ee9fd | 2016-11-23 18:04:23 +0000 | [diff] [blame] | 3309 | if (Buckets[Buc] == ELF::STN_UNDEF) |
| 3310 | continue; |
George Rimar | 1206f5a | 2019-01-30 15:39:05 +0000 | [diff] [blame] | 3311 | for (uint32_t Ch = Buckets[Buc]; Ch < SysVHash->nchain; Ch = Chains[Ch]) { |
Hemant Kulkarni | a6ee9fd | 2016-11-23 18:04:23 +0000 | [diff] [blame] | 3312 | if (Ch == ELF::STN_UNDEF) |
| 3313 | break; |
| 3314 | printHashedSymbol(Obj, &DynSyms[0], Ch, StringTable, Buc); |
| 3315 | } |
| 3316 | } |
| 3317 | } |
| 3318 | |
| 3319 | // Try printing .gnu.hash |
George Rimar | 1206f5a | 2019-01-30 15:39:05 +0000 | [diff] [blame] | 3320 | if (auto GnuHash = this->dumper()->getGnuHashTable()) { |
Hemant Kulkarni | a6ee9fd | 2016-11-23 18:04:23 +0000 | [diff] [blame] | 3321 | OS << "\n Symbol table of .gnu.hash for image:\n"; |
| 3322 | if (ELFT::Is64Bits) |
| 3323 | OS << " Num Buc: Value Size Type Bind Vis Ndx Name"; |
| 3324 | else |
| 3325 | OS << " Num Buc: Value Size Type Bind Vis Ndx Name"; |
| 3326 | OS << "\n"; |
Hemant Kulkarni | a6ee9fd | 2016-11-23 18:04:23 +0000 | [diff] [blame] | 3327 | auto Buckets = GnuHash->buckets(); |
George Rimar | 1206f5a | 2019-01-30 15:39:05 +0000 | [diff] [blame] | 3328 | for (uint32_t Buc = 0; Buc < GnuHash->nbuckets; Buc++) { |
Hemant Kulkarni | a6ee9fd | 2016-11-23 18:04:23 +0000 | [diff] [blame] | 3329 | if (Buckets[Buc] == ELF::STN_UNDEF) |
| 3330 | continue; |
| 3331 | uint32_t Index = Buckets[Buc]; |
| 3332 | uint32_t GnuHashable = Index - GnuHash->symndx; |
| 3333 | // Print whole chain |
| 3334 | while (true) { |
| 3335 | printHashedSymbol(Obj, &DynSyms[0], Index++, StringTable, Buc); |
| 3336 | // Chain ends at symbol with stopper bit |
| 3337 | if ((GnuHash->values(DynSyms.size())[GnuHashable++] & 1) == 1) |
| 3338 | break; |
| 3339 | } |
| 3340 | } |
| 3341 | } |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3342 | } |
| 3343 | |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 3344 | static inline std::string printPhdrFlags(unsigned Flag) { |
| 3345 | std::string Str; |
| 3346 | Str = (Flag & PF_R) ? "R" : " "; |
| 3347 | Str += (Flag & PF_W) ? "W" : " "; |
| 3348 | Str += (Flag & PF_X) ? "E" : " "; |
| 3349 | return Str; |
| 3350 | } |
| 3351 | |
| 3352 | // SHF_TLS sections are only in PT_TLS, PT_LOAD or PT_GNU_RELRO |
| 3353 | // PT_TLS must only have SHF_TLS sections |
| 3354 | template <class ELFT> |
| 3355 | bool GNUStyle<ELFT>::checkTLSSections(const Elf_Phdr &Phdr, |
| 3356 | const Elf_Shdr &Sec) { |
| 3357 | return (((Sec.sh_flags & ELF::SHF_TLS) && |
| 3358 | ((Phdr.p_type == ELF::PT_TLS) || (Phdr.p_type == ELF::PT_LOAD) || |
| 3359 | (Phdr.p_type == ELF::PT_GNU_RELRO))) || |
| 3360 | (!(Sec.sh_flags & ELF::SHF_TLS) && Phdr.p_type != ELF::PT_TLS)); |
| 3361 | } |
| 3362 | |
| 3363 | // Non-SHT_NOBITS must have its offset inside the segment |
| 3364 | // Only non-zero section can be at end of segment |
| 3365 | template <class ELFT> |
| 3366 | bool GNUStyle<ELFT>::checkoffsets(const Elf_Phdr &Phdr, const Elf_Shdr &Sec) { |
| 3367 | if (Sec.sh_type == ELF::SHT_NOBITS) |
| 3368 | return true; |
| 3369 | bool IsSpecial = |
| 3370 | (Sec.sh_type == ELF::SHT_NOBITS) && ((Sec.sh_flags & ELF::SHF_TLS) != 0); |
| 3371 | // .tbss is special, it only has memory in PT_TLS and has NOBITS properties |
| 3372 | auto SectionSize = |
| 3373 | (IsSpecial && Phdr.p_type != ELF::PT_TLS) ? 0 : Sec.sh_size; |
| 3374 | if (Sec.sh_offset >= Phdr.p_offset) |
| 3375 | return ((Sec.sh_offset + SectionSize <= Phdr.p_filesz + Phdr.p_offset) |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 3376 | /*only non-zero sized sections at end*/ |
| 3377 | && (Sec.sh_offset + 1 <= Phdr.p_offset + Phdr.p_filesz)); |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 3378 | return false; |
| 3379 | } |
| 3380 | |
| 3381 | // SHF_ALLOC must have VMA inside segment |
| 3382 | // Only non-zero section can be at end of segment |
| 3383 | template <class ELFT> |
| 3384 | bool GNUStyle<ELFT>::checkVMA(const Elf_Phdr &Phdr, const Elf_Shdr &Sec) { |
| 3385 | if (!(Sec.sh_flags & ELF::SHF_ALLOC)) |
| 3386 | return true; |
| 3387 | bool IsSpecial = |
| 3388 | (Sec.sh_type == ELF::SHT_NOBITS) && ((Sec.sh_flags & ELF::SHF_TLS) != 0); |
| 3389 | // .tbss is special, it only has memory in PT_TLS and has NOBITS properties |
| 3390 | auto SectionSize = |
| 3391 | (IsSpecial && Phdr.p_type != ELF::PT_TLS) ? 0 : Sec.sh_size; |
| 3392 | if (Sec.sh_addr >= Phdr.p_vaddr) |
| 3393 | return ((Sec.sh_addr + SectionSize <= Phdr.p_vaddr + Phdr.p_memsz) && |
| 3394 | (Sec.sh_addr + 1 <= Phdr.p_vaddr + Phdr.p_memsz)); |
| 3395 | return false; |
| 3396 | } |
| 3397 | |
| 3398 | // No section with zero size must be at start or end of PT_DYNAMIC |
| 3399 | template <class ELFT> |
| 3400 | bool GNUStyle<ELFT>::checkPTDynamic(const Elf_Phdr &Phdr, const Elf_Shdr &Sec) { |
| 3401 | if (Phdr.p_type != ELF::PT_DYNAMIC || Sec.sh_size != 0 || Phdr.p_memsz == 0) |
| 3402 | return true; |
| 3403 | // Is section within the phdr both based on offset and VMA ? |
| 3404 | return ((Sec.sh_type == ELF::SHT_NOBITS) || |
| 3405 | (Sec.sh_offset > Phdr.p_offset && |
| 3406 | Sec.sh_offset < Phdr.p_offset + Phdr.p_filesz)) && |
| 3407 | (!(Sec.sh_flags & ELF::SHF_ALLOC) || |
| 3408 | (Sec.sh_addr > Phdr.p_vaddr && Sec.sh_addr < Phdr.p_memsz)); |
| 3409 | } |
| 3410 | |
| 3411 | template <class ELFT> |
Matt Davis | 50ca8ed | 2019-02-01 18:51:10 +0000 | [diff] [blame] | 3412 | void GNUStyle<ELFT>::printProgramHeaders( |
| 3413 | const ELFO *Obj, bool PrintProgramHeaders, |
| 3414 | cl::boolOrDefault PrintSectionMapping) { |
| 3415 | if (PrintProgramHeaders) |
| 3416 | printProgramHeaders(Obj); |
| 3417 | |
| 3418 | // Display the section mapping along with the program headers, unless |
| 3419 | // -section-mapping is explicitly set to false. |
| 3420 | if (PrintSectionMapping != cl::BOU_FALSE) |
| 3421 | printSectionMapping(Obj); |
| 3422 | } |
| 3423 | |
| 3424 | template <class ELFT> |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 3425 | void GNUStyle<ELFT>::printProgramHeaders(const ELFO *Obj) { |
Hemant Kulkarni | 2e3254e | 2016-03-29 14:20:20 +0000 | [diff] [blame] | 3426 | unsigned Bias = ELFT::Is64Bits ? 8 : 0; |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 3427 | const Elf_Ehdr *Header = Obj->getHeader(); |
| 3428 | Field Fields[8] = {2, 17, 26, 37 + Bias, |
| 3429 | 48 + Bias, 56 + Bias, 64 + Bias, 68 + Bias}; |
| 3430 | OS << "\nElf file type is " |
| 3431 | << printEnum(Header->e_type, makeArrayRef(ElfObjectFileType)) << "\n" |
Hemant Kulkarni | 787c2ed | 2016-05-12 22:51:26 +0000 | [diff] [blame] | 3432 | << "Entry point " << format_hex(Header->e_entry, 3) << "\n" |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 3433 | << "There are " << Header->e_phnum << " program headers," |
| 3434 | << " starting at offset " << Header->e_phoff << "\n\n" |
| 3435 | << "Program Headers:\n"; |
| 3436 | if (ELFT::Is64Bits) |
| 3437 | OS << " Type Offset VirtAddr PhysAddr " |
| 3438 | << " FileSiz MemSiz Flg Align\n"; |
| 3439 | else |
| 3440 | OS << " Type Offset VirtAddr PhysAddr FileSiz " |
| 3441 | << "MemSiz Flg Align\n"; |
George Rimar | 1206f5a | 2019-01-30 15:39:05 +0000 | [diff] [blame] | 3442 | |
| 3443 | unsigned Width = ELFT::Is64Bits ? 18 : 10; |
| 3444 | unsigned SizeWidth = ELFT::Is64Bits ? 8 : 7; |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 3445 | for (const auto &Phdr : |
| 3446 | unwrapOrError(this->FileName, Obj->program_headers())) { |
George Rimar | 4b4899b | 2019-01-30 14:08:55 +0000 | [diff] [blame] | 3447 | Fields[0].Str = getElfPtType(Header->e_machine, Phdr.p_type); |
| 3448 | Fields[1].Str = to_string(format_hex(Phdr.p_offset, 8)); |
| 3449 | Fields[2].Str = to_string(format_hex(Phdr.p_vaddr, Width)); |
| 3450 | Fields[3].Str = to_string(format_hex(Phdr.p_paddr, Width)); |
| 3451 | Fields[4].Str = to_string(format_hex(Phdr.p_filesz, SizeWidth)); |
| 3452 | Fields[5].Str = to_string(format_hex(Phdr.p_memsz, SizeWidth)); |
| 3453 | Fields[6].Str = printPhdrFlags(Phdr.p_flags); |
| 3454 | Fields[7].Str = to_string(format_hex(Phdr.p_align, 1)); |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 3455 | for (auto Field : Fields) |
| 3456 | printField(Field); |
| 3457 | if (Phdr.p_type == ELF::PT_INTERP) { |
| 3458 | OS << "\n [Requesting program interpreter: "; |
| 3459 | OS << reinterpret_cast<const char *>(Obj->base()) + Phdr.p_offset << "]"; |
| 3460 | } |
| 3461 | OS << "\n"; |
| 3462 | } |
Matt Davis | 50ca8ed | 2019-02-01 18:51:10 +0000 | [diff] [blame] | 3463 | } |
| 3464 | |
| 3465 | template <class ELFT> |
| 3466 | void GNUStyle<ELFT>::printSectionMapping(const ELFO *Obj) { |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 3467 | OS << "\n Section to Segment mapping:\n Segment Sections...\n"; |
Matt Davis | 0d0e9c0 | 2019-02-05 21:01:01 +0000 | [diff] [blame] | 3468 | DenseSet<const Elf_Shdr *> BelongsToSegment; |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 3469 | int Phnum = 0; |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 3470 | for (const Elf_Phdr &Phdr : |
| 3471 | unwrapOrError(this->FileName, Obj->program_headers())) { |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 3472 | std::string Sections; |
| 3473 | OS << format(" %2.2d ", Phnum++); |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 3474 | for (const Elf_Shdr &Sec : unwrapOrError(this->FileName, Obj->sections())) { |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 3475 | // Check if each section is in a segment and then print mapping. |
| 3476 | // readelf additionally makes sure it does not print zero sized sections |
| 3477 | // at end of segments and for PT_DYNAMIC both start and end of section |
| 3478 | // .tbss must only be shown in PT_TLS section. |
| 3479 | bool TbssInNonTLS = (Sec.sh_type == ELF::SHT_NOBITS) && |
| 3480 | ((Sec.sh_flags & ELF::SHF_TLS) != 0) && |
| 3481 | Phdr.p_type != ELF::PT_TLS; |
| 3482 | if (!TbssInNonTLS && checkTLSSections(Phdr, Sec) && |
| 3483 | checkoffsets(Phdr, Sec) && checkVMA(Phdr, Sec) && |
Matt Davis | 0d0e9c0 | 2019-02-05 21:01:01 +0000 | [diff] [blame] | 3484 | checkPTDynamic(Phdr, Sec) && (Sec.sh_type != ELF::SHT_NULL)) { |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 3485 | Sections += |
| 3486 | unwrapOrError(this->FileName, Obj->getSectionName(&Sec)).str() + |
| 3487 | " "; |
Matt Davis | 0d0e9c0 | 2019-02-05 21:01:01 +0000 | [diff] [blame] | 3488 | BelongsToSegment.insert(&Sec); |
| 3489 | } |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 3490 | } |
| 3491 | OS << Sections << "\n"; |
| 3492 | OS.flush(); |
| 3493 | } |
Matt Davis | 0d0e9c0 | 2019-02-05 21:01:01 +0000 | [diff] [blame] | 3494 | |
| 3495 | // Display sections that do not belong to a segment. |
| 3496 | std::string Sections; |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 3497 | for (const Elf_Shdr &Sec : unwrapOrError(this->FileName, Obj->sections())) { |
Matt Davis | 0d0e9c0 | 2019-02-05 21:01:01 +0000 | [diff] [blame] | 3498 | if (BelongsToSegment.find(&Sec) == BelongsToSegment.end()) |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 3499 | Sections += |
| 3500 | unwrapOrError(this->FileName, Obj->getSectionName(&Sec)).str() + ' '; |
Matt Davis | 0d0e9c0 | 2019-02-05 21:01:01 +0000 | [diff] [blame] | 3501 | } |
| 3502 | if (!Sections.empty()) { |
| 3503 | OS << " None " << Sections << '\n'; |
| 3504 | OS.flush(); |
| 3505 | } |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 3506 | } |
| 3507 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3508 | template <class ELFT> |
Hemant Kulkarni | a79c798 | 2016-03-29 02:41:49 +0000 | [diff] [blame] | 3509 | void GNUStyle<ELFT>::printDynamicRelocation(const ELFO *Obj, Elf_Rela R, |
| 3510 | bool IsRela) { |
Hemant Kulkarni | a79c798 | 2016-03-29 02:41:49 +0000 | [diff] [blame] | 3511 | uint32_t SymIndex = R.getSymbol(Obj->isMips64EL()); |
| 3512 | const Elf_Sym *Sym = this->dumper()->dynamic_symbols().begin() + SymIndex; |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 3513 | std::string SymbolName = maybeDemangle(unwrapOrError( |
| 3514 | this->FileName, Sym->getName(this->dumper()->getDynamicStringTable()))); |
James Henderson | 814ab37 | 2019-03-29 11:47:19 +0000 | [diff] [blame] | 3515 | printRelocation(Obj, Sym, SymbolName, R, IsRela); |
Hemant Kulkarni | a79c798 | 2016-03-29 02:41:49 +0000 | [diff] [blame] | 3516 | } |
| 3517 | |
Simon Atanasyan | 8362cbe | 2019-05-24 12:22:53 +0000 | [diff] [blame] | 3518 | template <class ELFT> void GNUStyle<ELFT>::printDynamic(const ELFO *Obj) { |
| 3519 | Elf_Dyn_Range Table = this->dumper()->dynamic_table(); |
| 3520 | if (Table.empty()) |
| 3521 | return; |
| 3522 | |
| 3523 | const DynRegionInfo &DynamicTableRegion = |
| 3524 | this->dumper()->getDynamicTableRegion(); |
| 3525 | |
| 3526 | OS << "Dynamic section at offset " |
| 3527 | << format_hex(reinterpret_cast<const uint8_t *>(DynamicTableRegion.Addr) - |
| 3528 | Obj->base(), |
| 3529 | 1) |
| 3530 | << " contains " << Table.size() << " entries:\n"; |
| 3531 | |
| 3532 | bool Is64 = ELFT::Is64Bits; |
| 3533 | if (Is64) |
| 3534 | OS << " Tag Type Name/Value\n"; |
| 3535 | else |
| 3536 | OS << " Tag Type Name/Value\n"; |
| 3537 | for (auto Entry : Table) { |
| 3538 | uintX_t Tag = Entry.getTag(); |
Hans Wennborg | 80343a3 | 2019-05-28 12:30:35 +0000 | [diff] [blame] | 3539 | std::string TypeString = std::string("(") + |
| 3540 | getTypeString(Obj->getHeader()->e_machine, Tag) + |
| 3541 | ")"; |
| 3542 | OS << " " << format_hex(Tag, Is64 ? 18 : 10) |
| 3543 | << format(" %-20s ", TypeString.c_str()); |
Simon Atanasyan | 8362cbe | 2019-05-24 12:22:53 +0000 | [diff] [blame] | 3544 | this->dumper()->printDynamicEntry(OS, Tag, Entry.getVal()); |
| 3545 | OS << "\n"; |
| 3546 | } |
| 3547 | } |
| 3548 | |
Hemant Kulkarni | a79c798 | 2016-03-29 02:41:49 +0000 | [diff] [blame] | 3549 | template <class ELFT> |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3550 | void GNUStyle<ELFT>::printDynamicRelocations(const ELFO *Obj) { |
Hemant Kulkarni | a79c798 | 2016-03-29 02:41:49 +0000 | [diff] [blame] | 3551 | const DynRegionInfo &DynRelRegion = this->dumper()->getDynRelRegion(); |
| 3552 | const DynRegionInfo &DynRelaRegion = this->dumper()->getDynRelaRegion(); |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 3553 | const DynRegionInfo &DynRelrRegion = this->dumper()->getDynRelrRegion(); |
Hemant Kulkarni | a79c798 | 2016-03-29 02:41:49 +0000 | [diff] [blame] | 3554 | const DynRegionInfo &DynPLTRelRegion = this->dumper()->getDynPLTRelRegion(); |
| 3555 | if (DynRelaRegion.Size > 0) { |
| 3556 | OS << "\n'RELA' relocation section at offset " |
| 3557 | << format_hex(reinterpret_cast<const uint8_t *>(DynRelaRegion.Addr) - |
| 3558 | Obj->base(), |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 3559 | 1) |
| 3560 | << " contains " << DynRelaRegion.Size << " bytes:\n"; |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 3561 | printRelocHeader(ELF::SHT_RELA); |
Hemant Kulkarni | a79c798 | 2016-03-29 02:41:49 +0000 | [diff] [blame] | 3562 | for (const Elf_Rela &Rela : this->dumper()->dyn_relas()) |
| 3563 | printDynamicRelocation(Obj, Rela, true); |
| 3564 | } |
| 3565 | if (DynRelRegion.Size > 0) { |
| 3566 | OS << "\n'REL' relocation section at offset " |
| 3567 | << format_hex(reinterpret_cast<const uint8_t *>(DynRelRegion.Addr) - |
| 3568 | Obj->base(), |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 3569 | 1) |
| 3570 | << " contains " << DynRelRegion.Size << " bytes:\n"; |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 3571 | printRelocHeader(ELF::SHT_REL); |
Hemant Kulkarni | a79c798 | 2016-03-29 02:41:49 +0000 | [diff] [blame] | 3572 | for (const Elf_Rel &Rel : this->dumper()->dyn_rels()) { |
| 3573 | Elf_Rela Rela; |
| 3574 | Rela.r_offset = Rel.r_offset; |
| 3575 | Rela.r_info = Rel.r_info; |
| 3576 | Rela.r_addend = 0; |
| 3577 | printDynamicRelocation(Obj, Rela, false); |
| 3578 | } |
| 3579 | } |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 3580 | if (DynRelrRegion.Size > 0) { |
| 3581 | OS << "\n'RELR' relocation section at offset " |
| 3582 | << format_hex(reinterpret_cast<const uint8_t *>(DynRelrRegion.Addr) - |
| 3583 | Obj->base(), |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 3584 | 1) |
| 3585 | << " contains " << DynRelrRegion.Size << " bytes:\n"; |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 3586 | printRelocHeader(ELF::SHT_REL); |
| 3587 | Elf_Relr_Range Relrs = this->dumper()->dyn_relrs(); |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 3588 | std::vector<Elf_Rela> RelrRelas = |
| 3589 | unwrapOrError(this->FileName, Obj->decode_relrs(Relrs)); |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 3590 | for (const Elf_Rela &Rela : RelrRelas) { |
| 3591 | printDynamicRelocation(Obj, Rela, false); |
| 3592 | } |
| 3593 | } |
Hemant Kulkarni | a79c798 | 2016-03-29 02:41:49 +0000 | [diff] [blame] | 3594 | if (DynPLTRelRegion.Size) { |
| 3595 | OS << "\n'PLT' relocation section at offset " |
| 3596 | << format_hex(reinterpret_cast<const uint8_t *>(DynPLTRelRegion.Addr) - |
| 3597 | Obj->base(), |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 3598 | 1) |
| 3599 | << " contains " << DynPLTRelRegion.Size << " bytes:\n"; |
Hemant Kulkarni | a79c798 | 2016-03-29 02:41:49 +0000 | [diff] [blame] | 3600 | } |
| 3601 | if (DynPLTRelRegion.EntSize == sizeof(Elf_Rela)) { |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 3602 | printRelocHeader(ELF::SHT_RELA); |
Rafael Espindola | aafcf75 | 2016-04-05 14:47:22 +0000 | [diff] [blame] | 3603 | for (const Elf_Rela &Rela : DynPLTRelRegion.getAsArrayRef<Elf_Rela>()) |
Hemant Kulkarni | a79c798 | 2016-03-29 02:41:49 +0000 | [diff] [blame] | 3604 | printDynamicRelocation(Obj, Rela, true); |
| 3605 | } else { |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 3606 | printRelocHeader(ELF::SHT_REL); |
Rafael Espindola | aafcf75 | 2016-04-05 14:47:22 +0000 | [diff] [blame] | 3607 | for (const Elf_Rel &Rel : DynPLTRelRegion.getAsArrayRef<Elf_Rel>()) { |
Hemant Kulkarni | a79c798 | 2016-03-29 02:41:49 +0000 | [diff] [blame] | 3608 | Elf_Rela Rela; |
| 3609 | Rela.r_offset = Rel.r_offset; |
| 3610 | Rela.r_info = Rel.r_info; |
| 3611 | Rela.r_addend = 0; |
| 3612 | printDynamicRelocation(Obj, Rela, false); |
| 3613 | } |
| 3614 | } |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 3615 | } |
| 3616 | |
Xing GUO | ea16be1 | 2019-03-25 11:02:49 +0000 | [diff] [blame] | 3617 | template <class ELFT> |
George Rimar | e3406c4 | 2019-05-30 10:14:41 +0000 | [diff] [blame] | 3618 | static void printGNUVersionSectionProlog(formatted_raw_ostream &OS, |
| 3619 | const Twine &Name, unsigned EntriesNum, |
| 3620 | const ELFFile<ELFT> *Obj, |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 3621 | const typename ELFT::Shdr *Sec, |
| 3622 | StringRef FileName) { |
| 3623 | StringRef SecName = unwrapOrError(FileName, Obj->getSectionName(Sec)); |
George Rimar | e3406c4 | 2019-05-30 10:14:41 +0000 | [diff] [blame] | 3624 | OS << Name << " section '" << SecName << "' " |
| 3625 | << "contains " << EntriesNum << " entries:\n"; |
| 3626 | |
| 3627 | const typename ELFT::Shdr *SymTab = |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 3628 | unwrapOrError(FileName, Obj->getSection(Sec->sh_link)); |
| 3629 | StringRef SymTabName = unwrapOrError(FileName, Obj->getSectionName(SymTab)); |
George Rimar | e3406c4 | 2019-05-30 10:14:41 +0000 | [diff] [blame] | 3630 | OS << " Addr: " << format_hex_no_prefix(Sec->sh_addr, 16) |
| 3631 | << " Offset: " << format_hex(Sec->sh_offset, 8) |
| 3632 | << " Link: " << Sec->sh_link << " (" << SymTabName << ")\n"; |
| 3633 | } |
| 3634 | |
| 3635 | template <class ELFT> |
Xing GUO | ea16be1 | 2019-03-25 11:02:49 +0000 | [diff] [blame] | 3636 | void GNUStyle<ELFT>::printVersionSymbolSection(const ELFFile<ELFT> *Obj, |
| 3637 | const Elf_Shdr *Sec) { |
| 3638 | if (!Sec) |
| 3639 | return; |
| 3640 | |
George Rimar | e3406c4 | 2019-05-30 10:14:41 +0000 | [diff] [blame] | 3641 | unsigned Entries = Sec->sh_size / sizeof(Elf_Versym); |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 3642 | printGNUVersionSectionProlog(OS, "Version symbols", Entries, Obj, Sec, |
| 3643 | this->FileName); |
Xing GUO | 8f6166a | 2019-04-03 13:32:49 +0000 | [diff] [blame] | 3644 | |
| 3645 | const uint8_t *VersymBuf = |
| 3646 | reinterpret_cast<const uint8_t *>(Obj->base() + Sec->sh_offset); |
| 3647 | const ELFDumper<ELFT> *Dumper = this->dumper(); |
| 3648 | StringRef StrTable = Dumper->getDynamicStringTable(); |
| 3649 | |
| 3650 | // readelf prints 4 entries per line. |
| 3651 | for (uint64_t VersymRow = 0; VersymRow < Entries; VersymRow += 4) { |
| 3652 | OS << " " << format_hex_no_prefix(VersymRow, 3) << ":"; |
| 3653 | |
| 3654 | for (uint64_t VersymIndex = 0; |
| 3655 | (VersymIndex < 4) && (VersymIndex + VersymRow) < Entries; |
| 3656 | ++VersymIndex) { |
| 3657 | const Elf_Versym *Versym = |
| 3658 | reinterpret_cast<const Elf_Versym *>(VersymBuf); |
| 3659 | switch (Versym->vs_index) { |
| 3660 | case 0: |
| 3661 | OS << " 0 (*local*) "; |
| 3662 | break; |
| 3663 | case 1: |
| 3664 | OS << " 1 (*global*) "; |
| 3665 | break; |
| 3666 | default: |
| 3667 | OS << format("%4x%c", Versym->vs_index & VERSYM_VERSION, |
| 3668 | Versym->vs_index & VERSYM_HIDDEN ? 'h' : ' '); |
| 3669 | |
| 3670 | bool IsDefault = true; |
| 3671 | std::string VersionName = Dumper->getSymbolVersionByIndex( |
| 3672 | StrTable, Versym->vs_index, IsDefault); |
| 3673 | |
| 3674 | if (!VersionName.empty()) |
| 3675 | VersionName = "(" + VersionName + ")"; |
| 3676 | else |
| 3677 | VersionName = "(*invalid*)"; |
| 3678 | OS << left_justify(VersionName, 13); |
| 3679 | } |
| 3680 | VersymBuf += sizeof(Elf_Versym); |
| 3681 | } |
| 3682 | OS << '\n'; |
| 3683 | } |
| 3684 | OS << '\n'; |
Xing GUO | ea16be1 | 2019-03-25 11:02:49 +0000 | [diff] [blame] | 3685 | } |
| 3686 | |
George Rimar | c372f41 | 2019-05-30 10:36:52 +0000 | [diff] [blame] | 3687 | static std::string versionFlagToString(unsigned Flags) { |
George Rimar | e3406c4 | 2019-05-30 10:14:41 +0000 | [diff] [blame] | 3688 | if (Flags == 0) |
| 3689 | return "none"; |
| 3690 | |
| 3691 | std::string Ret; |
| 3692 | auto AddFlag = [&Ret, &Flags](unsigned Flag, StringRef Name) { |
| 3693 | if (!(Flags & Flag)) |
| 3694 | return; |
| 3695 | if (!Ret.empty()) |
| 3696 | Ret += " | "; |
| 3697 | Ret += Name; |
| 3698 | Flags &= ~Flag; |
| 3699 | }; |
| 3700 | |
| 3701 | AddFlag(VER_FLG_BASE, "BASE"); |
| 3702 | AddFlag(VER_FLG_WEAK, "WEAK"); |
| 3703 | AddFlag(VER_FLG_INFO, "INFO"); |
| 3704 | AddFlag(~0, "<unknown>"); |
| 3705 | return Ret; |
Xing GUO | ea16be1 | 2019-03-25 11:02:49 +0000 | [diff] [blame] | 3706 | } |
| 3707 | |
| 3708 | template <class ELFT> |
George Rimar | c372f41 | 2019-05-30 10:36:52 +0000 | [diff] [blame] | 3709 | void GNUStyle<ELFT>::printVersionDefinitionSection(const ELFFile<ELFT> *Obj, |
| 3710 | const Elf_Shdr *Sec) { |
| 3711 | if (!Sec) |
| 3712 | return; |
| 3713 | |
| 3714 | unsigned VerDefsNum = Sec->sh_info; |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 3715 | printGNUVersionSectionProlog(OS, "Version definition", VerDefsNum, Obj, Sec, |
| 3716 | this->FileName); |
George Rimar | c372f41 | 2019-05-30 10:36:52 +0000 | [diff] [blame] | 3717 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 3718 | const Elf_Shdr *StrTabSec = |
| 3719 | unwrapOrError(this->FileName, Obj->getSection(Sec->sh_link)); |
George Rimar | c372f41 | 2019-05-30 10:36:52 +0000 | [diff] [blame] | 3720 | StringRef StringTable( |
| 3721 | reinterpret_cast<const char *>(Obj->base() + StrTabSec->sh_offset), |
George Rimar | 28e1ff2 | 2019-05-30 10:42:47 +0000 | [diff] [blame] | 3722 | (size_t)StrTabSec->sh_size); |
George Rimar | c372f41 | 2019-05-30 10:36:52 +0000 | [diff] [blame] | 3723 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 3724 | const uint8_t *VerdefBuf = |
| 3725 | unwrapOrError(this->FileName, Obj->getSectionContents(Sec)).data(); |
George Rimar | c372f41 | 2019-05-30 10:36:52 +0000 | [diff] [blame] | 3726 | const uint8_t *Begin = VerdefBuf; |
| 3727 | |
| 3728 | while (VerDefsNum--) { |
| 3729 | const Elf_Verdef *Verdef = reinterpret_cast<const Elf_Verdef *>(VerdefBuf); |
| 3730 | OS << format(" 0x%04x: Rev: %u Flags: %s Index: %u Cnt: %u", |
| 3731 | VerdefBuf - Begin, (unsigned)Verdef->vd_version, |
| 3732 | versionFlagToString(Verdef->vd_flags).c_str(), |
| 3733 | (unsigned)Verdef->vd_ndx, (unsigned)Verdef->vd_cnt); |
| 3734 | |
| 3735 | const uint8_t *VerdauxBuf = VerdefBuf + Verdef->vd_aux; |
| 3736 | const Elf_Verdaux *Verdaux = |
| 3737 | reinterpret_cast<const Elf_Verdaux *>(VerdauxBuf); |
| 3738 | OS << format(" Name: %s\n", |
| 3739 | StringTable.drop_front(Verdaux->vda_name).data()); |
| 3740 | |
| 3741 | for (unsigned I = 1; I < Verdef->vd_cnt; ++I) { |
| 3742 | VerdauxBuf += Verdaux->vda_next; |
| 3743 | Verdaux = reinterpret_cast<const Elf_Verdaux *>(VerdauxBuf); |
| 3744 | OS << format(" 0x%04x: Parent %u: %s\n", VerdauxBuf - Begin, I, |
| 3745 | StringTable.drop_front(Verdaux->vda_name).data()); |
| 3746 | } |
| 3747 | |
| 3748 | VerdefBuf += Verdef->vd_next; |
| 3749 | } |
| 3750 | OS << '\n'; |
| 3751 | } |
| 3752 | |
| 3753 | template <class ELFT> |
Xing GUO | ea16be1 | 2019-03-25 11:02:49 +0000 | [diff] [blame] | 3754 | void GNUStyle<ELFT>::printVersionDependencySection(const ELFFile<ELFT> *Obj, |
| 3755 | const Elf_Shdr *Sec) { |
| 3756 | if (!Sec) |
| 3757 | return; |
| 3758 | |
George Rimar | e3406c4 | 2019-05-30 10:14:41 +0000 | [diff] [blame] | 3759 | unsigned VerneedNum = Sec->sh_info; |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 3760 | printGNUVersionSectionProlog(OS, "Version needs", VerneedNum, Obj, Sec, |
| 3761 | this->FileName); |
George Rimar | e3406c4 | 2019-05-30 10:14:41 +0000 | [diff] [blame] | 3762 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 3763 | ArrayRef<uint8_t> SecData = |
| 3764 | unwrapOrError(this->FileName, Obj->getSectionContents(Sec)); |
George Rimar | e3406c4 | 2019-05-30 10:14:41 +0000 | [diff] [blame] | 3765 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 3766 | const Elf_Shdr *StrTabSec = |
| 3767 | unwrapOrError(this->FileName, Obj->getSection(Sec->sh_link)); |
George Rimar | e3406c4 | 2019-05-30 10:14:41 +0000 | [diff] [blame] | 3768 | StringRef StringTable = { |
| 3769 | reinterpret_cast<const char *>(Obj->base() + StrTabSec->sh_offset), |
George Rimar | 28e1ff2 | 2019-05-30 10:42:47 +0000 | [diff] [blame] | 3770 | (size_t)StrTabSec->sh_size}; |
George Rimar | e3406c4 | 2019-05-30 10:14:41 +0000 | [diff] [blame] | 3771 | |
| 3772 | const uint8_t *VerneedBuf = SecData.data(); |
| 3773 | for (unsigned I = 0; I < VerneedNum; ++I) { |
| 3774 | const Elf_Verneed *Verneed = |
| 3775 | reinterpret_cast<const Elf_Verneed *>(VerneedBuf); |
| 3776 | |
| 3777 | OS << format(" 0x%04x: Version: %u File: %s Cnt: %u\n", |
| 3778 | reinterpret_cast<const uint8_t *>(Verneed) - SecData.begin(), |
| 3779 | (unsigned)Verneed->vn_version, |
| 3780 | StringTable.drop_front(Verneed->vn_file).data(), |
| 3781 | (unsigned)Verneed->vn_cnt); |
| 3782 | |
| 3783 | const uint8_t *VernauxBuf = VerneedBuf + Verneed->vn_aux; |
| 3784 | for (unsigned J = 0; J < Verneed->vn_cnt; ++J) { |
| 3785 | const Elf_Vernaux *Vernaux = |
| 3786 | reinterpret_cast<const Elf_Vernaux *>(VernauxBuf); |
| 3787 | |
| 3788 | OS << format(" 0x%04x: Name: %s Flags: %s Version: %u\n", |
| 3789 | reinterpret_cast<const uint8_t *>(Vernaux) - SecData.begin(), |
| 3790 | StringTable.drop_front(Vernaux->vna_name).data(), |
George Rimar | c372f41 | 2019-05-30 10:36:52 +0000 | [diff] [blame] | 3791 | versionFlagToString(Vernaux->vna_flags).c_str(), |
George Rimar | e3406c4 | 2019-05-30 10:14:41 +0000 | [diff] [blame] | 3792 | (unsigned)Vernaux->vna_other); |
| 3793 | VernauxBuf += Vernaux->vna_next; |
| 3794 | } |
| 3795 | VerneedBuf += Verneed->vn_next; |
| 3796 | } |
| 3797 | OS << '\n'; |
Xing GUO | ea16be1 | 2019-03-25 11:02:49 +0000 | [diff] [blame] | 3798 | } |
| 3799 | |
Hemant Kulkarni | 9b1b7f0 | 2016-04-11 17:15:30 +0000 | [diff] [blame] | 3800 | // Hash histogram shows statistics of how efficient the hash was for the |
| 3801 | // dynamic symbol table. The table shows number of hash buckets for different |
| 3802 | // lengths of chains as absolute number and percentage of the total buckets. |
| 3803 | // Additionally cumulative coverage of symbols for each set of buckets. |
| 3804 | template <class ELFT> |
| 3805 | void GNUStyle<ELFT>::printHashHistogram(const ELFFile<ELFT> *Obj) { |
Hemant Kulkarni | 9b1b7f0 | 2016-04-11 17:15:30 +0000 | [diff] [blame] | 3806 | // Print histogram for .hash section |
George Rimar | 1206f5a | 2019-01-30 15:39:05 +0000 | [diff] [blame] | 3807 | if (const Elf_Hash *HashTable = this->dumper()->getHashTable()) { |
Hemant Kulkarni | 9b1b7f0 | 2016-04-11 17:15:30 +0000 | [diff] [blame] | 3808 | size_t NBucket = HashTable->nbucket; |
| 3809 | size_t NChain = HashTable->nchain; |
| 3810 | ArrayRef<Elf_Word> Buckets = HashTable->buckets(); |
| 3811 | ArrayRef<Elf_Word> Chains = HashTable->chains(); |
| 3812 | size_t TotalSyms = 0; |
| 3813 | // If hash table is correct, we have at least chains with 0 length |
| 3814 | size_t MaxChain = 1; |
| 3815 | size_t CumulativeNonZero = 0; |
| 3816 | |
| 3817 | if (NChain == 0 || NBucket == 0) |
| 3818 | return; |
| 3819 | |
| 3820 | std::vector<size_t> ChainLen(NBucket, 0); |
| 3821 | // Go over all buckets and and note chain lengths of each bucket (total |
| 3822 | // unique chain lengths). |
| 3823 | for (size_t B = 0; B < NBucket; B++) { |
| 3824 | for (size_t C = Buckets[B]; C > 0 && C < NChain; C = Chains[C]) |
| 3825 | if (MaxChain <= ++ChainLen[B]) |
| 3826 | MaxChain++; |
| 3827 | TotalSyms += ChainLen[B]; |
| 3828 | } |
| 3829 | |
| 3830 | if (!TotalSyms) |
| 3831 | return; |
| 3832 | |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 3833 | std::vector<size_t> Count(MaxChain, 0) ; |
Hemant Kulkarni | 9b1b7f0 | 2016-04-11 17:15:30 +0000 | [diff] [blame] | 3834 | // Count how long is the chain for each bucket |
| 3835 | for (size_t B = 0; B < NBucket; B++) |
| 3836 | ++Count[ChainLen[B]]; |
| 3837 | // Print Number of buckets with each chain lengths and their cumulative |
| 3838 | // coverage of the symbols |
| 3839 | OS << "Histogram for bucket list length (total of " << NBucket |
| 3840 | << " buckets)\n" |
| 3841 | << " Length Number % of total Coverage\n"; |
| 3842 | for (size_t I = 0; I < MaxChain; I++) { |
| 3843 | CumulativeNonZero += Count[I] * I; |
| 3844 | OS << format("%7lu %-10lu (%5.1f%%) %5.1f%%\n", I, Count[I], |
| 3845 | (Count[I] * 100.0) / NBucket, |
| 3846 | (CumulativeNonZero * 100.0) / TotalSyms); |
| 3847 | } |
| 3848 | } |
| 3849 | |
| 3850 | // Print histogram for .gnu.hash section |
George Rimar | 1206f5a | 2019-01-30 15:39:05 +0000 | [diff] [blame] | 3851 | if (const Elf_GnuHash *GnuHashTable = this->dumper()->getGnuHashTable()) { |
Hemant Kulkarni | 9b1b7f0 | 2016-04-11 17:15:30 +0000 | [diff] [blame] | 3852 | size_t NBucket = GnuHashTable->nbuckets; |
| 3853 | ArrayRef<Elf_Word> Buckets = GnuHashTable->buckets(); |
| 3854 | unsigned NumSyms = this->dumper()->dynamic_symbols().size(); |
| 3855 | if (!NumSyms) |
| 3856 | return; |
| 3857 | ArrayRef<Elf_Word> Chains = GnuHashTable->values(NumSyms); |
| 3858 | size_t Symndx = GnuHashTable->symndx; |
| 3859 | size_t TotalSyms = 0; |
| 3860 | size_t MaxChain = 1; |
| 3861 | size_t CumulativeNonZero = 0; |
| 3862 | |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 3863 | if (Chains.empty() || NBucket == 0) |
Hemant Kulkarni | 9b1b7f0 | 2016-04-11 17:15:30 +0000 | [diff] [blame] | 3864 | return; |
| 3865 | |
| 3866 | std::vector<size_t> ChainLen(NBucket, 0); |
| 3867 | |
| 3868 | for (size_t B = 0; B < NBucket; B++) { |
| 3869 | if (!Buckets[B]) |
| 3870 | continue; |
| 3871 | size_t Len = 1; |
| 3872 | for (size_t C = Buckets[B] - Symndx; |
| 3873 | C < Chains.size() && (Chains[C] & 1) == 0; C++) |
| 3874 | if (MaxChain < ++Len) |
| 3875 | MaxChain++; |
| 3876 | ChainLen[B] = Len; |
| 3877 | TotalSyms += Len; |
| 3878 | } |
| 3879 | MaxChain++; |
| 3880 | |
| 3881 | if (!TotalSyms) |
| 3882 | return; |
| 3883 | |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 3884 | std::vector<size_t> Count(MaxChain, 0) ; |
Hemant Kulkarni | 9b1b7f0 | 2016-04-11 17:15:30 +0000 | [diff] [blame] | 3885 | for (size_t B = 0; B < NBucket; B++) |
| 3886 | ++Count[ChainLen[B]]; |
| 3887 | // Print Number of buckets with each chain lengths and their cumulative |
| 3888 | // coverage of the symbols |
| 3889 | OS << "Histogram for `.gnu.hash' bucket list length (total of " << NBucket |
| 3890 | << " buckets)\n" |
| 3891 | << " Length Number % of total Coverage\n"; |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 3892 | for (size_t I = 0; I <MaxChain; I++) { |
Hemant Kulkarni | 9b1b7f0 | 2016-04-11 17:15:30 +0000 | [diff] [blame] | 3893 | CumulativeNonZero += Count[I] * I; |
| 3894 | OS << format("%7lu %-10lu (%5.1f%%) %5.1f%%\n", I, Count[I], |
| 3895 | (Count[I] * 100.0) / NBucket, |
| 3896 | (CumulativeNonZero * 100.0) / TotalSyms); |
| 3897 | } |
| 3898 | } |
| 3899 | } |
| 3900 | |
Michael J. Spencer | ae6eeae | 2018-06-02 16:33:01 +0000 | [diff] [blame] | 3901 | template <class ELFT> |
| 3902 | void GNUStyle<ELFT>::printCGProfile(const ELFFile<ELFT> *Obj) { |
| 3903 | OS << "GNUStyle::printCGProfile not implemented\n"; |
| 3904 | } |
| 3905 | |
Peter Collingbourne | 3e22733 | 2018-07-17 22:17:18 +0000 | [diff] [blame] | 3906 | template <class ELFT> |
| 3907 | void GNUStyle<ELFT>::printAddrsig(const ELFFile<ELFT> *Obj) { |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 3908 | OS << "GNUStyle::printAddrsig not implemented\n"; |
Peter Collingbourne | 3e22733 | 2018-07-17 22:17:18 +0000 | [diff] [blame] | 3909 | } |
| 3910 | |
Jordan Rupprecht | 871baa2 | 2019-03-29 16:48:19 +0000 | [diff] [blame] | 3911 | static StringRef getGenericNoteTypeName(const uint32_t NT) { |
| 3912 | static const struct { |
| 3913 | uint32_t ID; |
| 3914 | const char *Name; |
| 3915 | } Notes[] = { |
| 3916 | {ELF::NT_VERSION, "NT_VERSION (version)"}, |
| 3917 | {ELF::NT_ARCH, "NT_ARCH (architecture)"}, |
| 3918 | {ELF::NT_GNU_BUILD_ATTRIBUTE_OPEN, "OPEN"}, |
| 3919 | {ELF::NT_GNU_BUILD_ATTRIBUTE_FUNC, "func"}, |
| 3920 | }; |
| 3921 | |
| 3922 | for (const auto &Note : Notes) |
| 3923 | if (Note.ID == NT) |
| 3924 | return Note.Name; |
| 3925 | |
| 3926 | return ""; |
| 3927 | } |
| 3928 | |
Jordan Rupprecht | d884fbd | 2019-08-05 15:43:20 +0000 | [diff] [blame] | 3929 | static StringRef getCoreNoteTypeName(const uint32_t NT) { |
| 3930 | static const struct { |
| 3931 | uint32_t ID; |
| 3932 | const char *Name; |
| 3933 | } Notes[] = { |
| 3934 | {ELF::NT_PRSTATUS, "NT_PRSTATUS (prstatus structure)"}, |
| 3935 | {ELF::NT_FPREGSET, "NT_FPREGSET (floating point registers)"}, |
| 3936 | {ELF::NT_PRPSINFO, "NT_PRPSINFO (prpsinfo structure)"}, |
| 3937 | {ELF::NT_TASKSTRUCT, "NT_TASKSTRUCT (task structure)"}, |
| 3938 | {ELF::NT_AUXV, "NT_AUXV (auxiliary vector)"}, |
| 3939 | {ELF::NT_PSTATUS, "NT_PSTATUS (pstatus structure)"}, |
| 3940 | {ELF::NT_FPREGS, "NT_FPREGS (floating point registers)"}, |
| 3941 | {ELF::NT_PSINFO, "NT_PSINFO (psinfo structure)"}, |
| 3942 | {ELF::NT_LWPSTATUS, "NT_LWPSTATUS (lwpstatus_t structure)"}, |
| 3943 | {ELF::NT_LWPSINFO, "NT_LWPSINFO (lwpsinfo_t structure)"}, |
| 3944 | {ELF::NT_WIN32PSTATUS, "NT_WIN32PSTATUS (win32_pstatus structure)"}, |
| 3945 | |
| 3946 | {ELF::NT_PPC_VMX, "NT_PPC_VMX (ppc Altivec registers)"}, |
| 3947 | {ELF::NT_PPC_VSX, "NT_PPC_VSX (ppc VSX registers)"}, |
| 3948 | {ELF::NT_PPC_TAR, "NT_PPC_TAR (ppc TAR register)"}, |
| 3949 | {ELF::NT_PPC_PPR, "NT_PPC_PPR (ppc PPR register)"}, |
| 3950 | {ELF::NT_PPC_DSCR, "NT_PPC_DSCR (ppc DSCR register)"}, |
| 3951 | {ELF::NT_PPC_EBB, "NT_PPC_EBB (ppc EBB registers)"}, |
| 3952 | {ELF::NT_PPC_PMU, "NT_PPC_PMU (ppc PMU registers)"}, |
| 3953 | {ELF::NT_PPC_TM_CGPR, "NT_PPC_TM_CGPR (ppc checkpointed GPR registers)"}, |
| 3954 | {ELF::NT_PPC_TM_CFPR, |
| 3955 | "NT_PPC_TM_CFPR (ppc checkpointed floating point registers)"}, |
| 3956 | {ELF::NT_PPC_TM_CVMX, |
| 3957 | "NT_PPC_TM_CVMX (ppc checkpointed Altivec registers)"}, |
| 3958 | {ELF::NT_PPC_TM_CVSX, "NT_PPC_TM_CVSX (ppc checkpointed VSX registers)"}, |
| 3959 | {ELF::NT_PPC_TM_SPR, "NT_PPC_TM_SPR (ppc TM special purpose registers)"}, |
| 3960 | {ELF::NT_PPC_TM_CTAR, "NT_PPC_TM_CTAR (ppc checkpointed TAR register)"}, |
| 3961 | {ELF::NT_PPC_TM_CPPR, "NT_PPC_TM_CPPR (ppc checkpointed PPR register)"}, |
| 3962 | {ELF::NT_PPC_TM_CDSCR, |
| 3963 | "NT_PPC_TM_CDSCR (ppc checkpointed DSCR register)"}, |
| 3964 | |
| 3965 | {ELF::NT_386_TLS, "NT_386_TLS (x86 TLS information)"}, |
| 3966 | {ELF::NT_386_IOPERM, "NT_386_IOPERM (x86 I/O permissions)"}, |
| 3967 | {ELF::NT_X86_XSTATE, "NT_X86_XSTATE (x86 XSAVE extended state)"}, |
| 3968 | |
| 3969 | {ELF::NT_S390_HIGH_GPRS, |
| 3970 | "NT_S390_HIGH_GPRS (s390 upper register halves)"}, |
| 3971 | {ELF::NT_S390_TIMER, "NT_S390_TIMER (s390 timer register)"}, |
| 3972 | {ELF::NT_S390_TODCMP, "NT_S390_TODCMP (s390 TOD comparator register)"}, |
| 3973 | {ELF::NT_S390_TODPREG, |
| 3974 | "NT_S390_TODPREG (s390 TOD programmable register)"}, |
| 3975 | {ELF::NT_S390_CTRS, "NT_S390_CTRS (s390 control registers)"}, |
| 3976 | {ELF::NT_S390_PREFIX, "NT_S390_PREFIX (s390 prefix register)"}, |
| 3977 | {ELF::NT_S390_LAST_BREAK, |
| 3978 | "NT_S390_LAST_BREAK (s390 last breaking event address)"}, |
| 3979 | {ELF::NT_S390_SYSTEM_CALL, |
| 3980 | "NT_S390_SYSTEM_CALL (s390 system call restart data)"}, |
| 3981 | {ELF::NT_S390_TDB, "NT_S390_TDB (s390 transaction diagnostic block)"}, |
| 3982 | {ELF::NT_S390_VXRS_LOW, |
| 3983 | "NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)"}, |
| 3984 | {ELF::NT_S390_VXRS_HIGH, |
| 3985 | "NT_S390_VXRS_HIGH (s390 vector registers 16-31)"}, |
| 3986 | {ELF::NT_S390_GS_CB, "NT_S390_GS_CB (s390 guarded-storage registers)"}, |
| 3987 | {ELF::NT_S390_GS_BC, |
| 3988 | "NT_S390_GS_BC (s390 guarded-storage broadcast control)"}, |
| 3989 | |
| 3990 | {ELF::NT_ARM_VFP, "NT_ARM_VFP (arm VFP registers)"}, |
| 3991 | {ELF::NT_ARM_TLS, "NT_ARM_TLS (AArch TLS registers)"}, |
| 3992 | {ELF::NT_ARM_HW_BREAK, |
| 3993 | "NT_ARM_HW_BREAK (AArch hardware breakpoint registers)"}, |
| 3994 | {ELF::NT_ARM_HW_WATCH, |
| 3995 | "NT_ARM_HW_WATCH (AArch hardware watchpoint registers)"}, |
| 3996 | |
| 3997 | {ELF::NT_FILE, "NT_FILE (mapped files)"}, |
| 3998 | {ELF::NT_PRXFPREG, "NT_PRXFPREG (user_xfpregs structure)"}, |
| 3999 | {ELF::NT_SIGINFO, "NT_SIGINFO (siginfo_t data)"}, |
| 4000 | }; |
| 4001 | |
| 4002 | for (const auto &Note : Notes) |
| 4003 | if (Note.ID == NT) |
| 4004 | return Note.Name; |
| 4005 | |
| 4006 | return ""; |
| 4007 | } |
| 4008 | |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 4009 | static std::string getGNUNoteTypeName(const uint32_t NT) { |
| 4010 | static const struct { |
| 4011 | uint32_t ID; |
| 4012 | const char *Name; |
| 4013 | } Notes[] = { |
| 4014 | {ELF::NT_GNU_ABI_TAG, "NT_GNU_ABI_TAG (ABI version tag)"}, |
| 4015 | {ELF::NT_GNU_HWCAP, "NT_GNU_HWCAP (DSO-supplied software HWCAP info)"}, |
| 4016 | {ELF::NT_GNU_BUILD_ID, "NT_GNU_BUILD_ID (unique build ID bitstring)"}, |
| 4017 | {ELF::NT_GNU_GOLD_VERSION, "NT_GNU_GOLD_VERSION (gold version)"}, |
George Rimar | 6a14c02 | 2018-03-21 08:34:55 +0000 | [diff] [blame] | 4018 | {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] | 4019 | }; |
| 4020 | |
| 4021 | for (const auto &Note : Notes) |
| 4022 | if (Note.ID == NT) |
| 4023 | return std::string(Note.Name); |
| 4024 | |
| 4025 | std::string string; |
| 4026 | raw_string_ostream OS(string); |
| 4027 | OS << format("Unknown note type (0x%08x)", NT); |
Konstantin Zhuravlyov | 716af74 | 2017-10-14 16:43:46 +0000 | [diff] [blame] | 4028 | return OS.str(); |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 4029 | } |
| 4030 | |
Saleem Abdulrasool | 4b08913 | 2017-02-12 18:55:33 +0000 | [diff] [blame] | 4031 | static std::string getFreeBSDNoteTypeName(const uint32_t NT) { |
| 4032 | static const struct { |
| 4033 | uint32_t ID; |
| 4034 | const char *Name; |
| 4035 | } Notes[] = { |
| 4036 | {ELF::NT_FREEBSD_THRMISC, "NT_THRMISC (thrmisc structure)"}, |
| 4037 | {ELF::NT_FREEBSD_PROCSTAT_PROC, "NT_PROCSTAT_PROC (proc data)"}, |
| 4038 | {ELF::NT_FREEBSD_PROCSTAT_FILES, "NT_PROCSTAT_FILES (files data)"}, |
| 4039 | {ELF::NT_FREEBSD_PROCSTAT_VMMAP, "NT_PROCSTAT_VMMAP (vmmap data)"}, |
| 4040 | {ELF::NT_FREEBSD_PROCSTAT_GROUPS, "NT_PROCSTAT_GROUPS (groups data)"}, |
| 4041 | {ELF::NT_FREEBSD_PROCSTAT_UMASK, "NT_PROCSTAT_UMASK (umask data)"}, |
| 4042 | {ELF::NT_FREEBSD_PROCSTAT_RLIMIT, "NT_PROCSTAT_RLIMIT (rlimit data)"}, |
| 4043 | {ELF::NT_FREEBSD_PROCSTAT_OSREL, "NT_PROCSTAT_OSREL (osreldate data)"}, |
| 4044 | {ELF::NT_FREEBSD_PROCSTAT_PSSTRINGS, |
| 4045 | "NT_PROCSTAT_PSSTRINGS (ps_strings data)"}, |
| 4046 | {ELF::NT_FREEBSD_PROCSTAT_AUXV, "NT_PROCSTAT_AUXV (auxv data)"}, |
| 4047 | }; |
| 4048 | |
| 4049 | for (const auto &Note : Notes) |
| 4050 | if (Note.ID == NT) |
| 4051 | return std::string(Note.Name); |
| 4052 | |
| 4053 | std::string string; |
| 4054 | raw_string_ostream OS(string); |
| 4055 | OS << format("Unknown note type (0x%08x)", NT); |
Konstantin Zhuravlyov | 716af74 | 2017-10-14 16:43:46 +0000 | [diff] [blame] | 4056 | return OS.str(); |
| 4057 | } |
| 4058 | |
Scott Linder | f5b36e5 | 2018-12-12 19:39:27 +0000 | [diff] [blame] | 4059 | static std::string getAMDNoteTypeName(const uint32_t NT) { |
Konstantin Zhuravlyov | 716af74 | 2017-10-14 16:43:46 +0000 | [diff] [blame] | 4060 | static const struct { |
| 4061 | uint32_t ID; |
| 4062 | const char *Name; |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 4063 | } Notes[] = {{ELF::NT_AMD_AMDGPU_HSA_METADATA, |
| 4064 | "NT_AMD_AMDGPU_HSA_METADATA (HSA Metadata)"}, |
| 4065 | {ELF::NT_AMD_AMDGPU_ISA, "NT_AMD_AMDGPU_ISA (ISA Version)"}, |
| 4066 | {ELF::NT_AMD_AMDGPU_PAL_METADATA, |
| 4067 | "NT_AMD_AMDGPU_PAL_METADATA (PAL Metadata)"}}; |
Konstantin Zhuravlyov | 716af74 | 2017-10-14 16:43:46 +0000 | [diff] [blame] | 4068 | |
| 4069 | for (const auto &Note : Notes) |
| 4070 | if (Note.ID == NT) |
| 4071 | return std::string(Note.Name); |
| 4072 | |
| 4073 | std::string string; |
| 4074 | raw_string_ostream OS(string); |
| 4075 | OS << format("Unknown note type (0x%08x)", NT); |
| 4076 | return OS.str(); |
Saleem Abdulrasool | 4b08913 | 2017-02-12 18:55:33 +0000 | [diff] [blame] | 4077 | } |
| 4078 | |
Scott Linder | f5b36e5 | 2018-12-12 19:39:27 +0000 | [diff] [blame] | 4079 | static std::string getAMDGPUNoteTypeName(const uint32_t NT) { |
| 4080 | if (NT == ELF::NT_AMDGPU_METADATA) |
| 4081 | return std::string("NT_AMDGPU_METADATA (AMDGPU Metadata)"); |
| 4082 | |
| 4083 | std::string string; |
| 4084 | raw_string_ostream OS(string); |
| 4085 | OS << format("Unknown note type (0x%08x)", NT); |
| 4086 | return OS.str(); |
| 4087 | } |
| 4088 | |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 4089 | template <typename ELFT> |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 4090 | static std::string getGNUProperty(uint32_t Type, uint32_t DataSize, |
| 4091 | ArrayRef<uint8_t> Data) { |
| 4092 | std::string str; |
| 4093 | raw_string_ostream OS(str); |
Fangrui Song | 6a03b93 | 2019-02-13 15:58:23 +0000 | [diff] [blame] | 4094 | uint32_t PrData; |
Fangrui Song | 12d5599 | 2019-02-13 01:51:45 +0000 | [diff] [blame] | 4095 | auto DumpBit = [&](uint32_t Flag, StringRef Name) { |
Fangrui Song | 6a03b93 | 2019-02-13 15:58:23 +0000 | [diff] [blame] | 4096 | if (PrData & Flag) { |
| 4097 | PrData &= ~Flag; |
Fangrui Song | 12d5599 | 2019-02-13 01:51:45 +0000 | [diff] [blame] | 4098 | OS << Name; |
Fangrui Song | 6a03b93 | 2019-02-13 15:58:23 +0000 | [diff] [blame] | 4099 | if (PrData) |
Fangrui Song | 12d5599 | 2019-02-13 01:51:45 +0000 | [diff] [blame] | 4100 | OS << ", "; |
| 4101 | } |
| 4102 | }; |
| 4103 | |
George Rimar | 6a14c02 | 2018-03-21 08:34:55 +0000 | [diff] [blame] | 4104 | switch (Type) { |
| 4105 | default: |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 4106 | OS << format("<application-specific type 0x%x>", Type); |
| 4107 | return OS.str(); |
George Rimar | 6a14c02 | 2018-03-21 08:34:55 +0000 | [diff] [blame] | 4108 | case GNU_PROPERTY_STACK_SIZE: { |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 4109 | OS << "stack size: "; |
George Rimar | 6a14c02 | 2018-03-21 08:34:55 +0000 | [diff] [blame] | 4110 | if (DataSize == sizeof(typename ELFT::uint)) |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 4111 | OS << formatv("{0:x}", |
| 4112 | (uint64_t)(*(const typename ELFT::Addr *)Data.data())); |
George Rimar | 6a14c02 | 2018-03-21 08:34:55 +0000 | [diff] [blame] | 4113 | else |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 4114 | OS << format("<corrupt length: 0x%x>", DataSize); |
| 4115 | return OS.str(); |
George Rimar | 6a14c02 | 2018-03-21 08:34:55 +0000 | [diff] [blame] | 4116 | } |
| 4117 | case GNU_PROPERTY_NO_COPY_ON_PROTECTED: |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 4118 | OS << "no copy on protected"; |
George Rimar | 6a14c02 | 2018-03-21 08:34:55 +0000 | [diff] [blame] | 4119 | if (DataSize) |
| 4120 | OS << format(" <corrupt length: 0x%x>", DataSize); |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 4121 | return OS.str(); |
Peter Smith | 580c6d3 | 2019-06-04 11:28:22 +0000 | [diff] [blame] | 4122 | case GNU_PROPERTY_AARCH64_FEATURE_1_AND: |
Alexander Ivchenko | ab60a28 | 2018-06-04 15:14:18 +0000 | [diff] [blame] | 4123 | case GNU_PROPERTY_X86_FEATURE_1_AND: |
Peter Smith | 580c6d3 | 2019-06-04 11:28:22 +0000 | [diff] [blame] | 4124 | OS << ((Type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) ? "aarch64 feature: " |
| 4125 | : "x86 feature: "); |
Fangrui Song | 8e0d5ac | 2019-02-12 09:56:01 +0000 | [diff] [blame] | 4126 | if (DataSize != 4) { |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 4127 | OS << format("<corrupt length: 0x%x>", DataSize); |
| 4128 | return OS.str(); |
Alexander Ivchenko | ab60a28 | 2018-06-04 15:14:18 +0000 | [diff] [blame] | 4129 | } |
Fangrui Song | 6a03b93 | 2019-02-13 15:58:23 +0000 | [diff] [blame] | 4130 | PrData = support::endian::read32<ELFT::TargetEndianness>(Data.data()); |
| 4131 | if (PrData == 0) { |
Fangrui Song | 12d5599 | 2019-02-13 01:51:45 +0000 | [diff] [blame] | 4132 | OS << "<None>"; |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 4133 | return OS.str(); |
Alexander Ivchenko | ab60a28 | 2018-06-04 15:14:18 +0000 | [diff] [blame] | 4134 | } |
Peter Smith | 580c6d3 | 2019-06-04 11:28:22 +0000 | [diff] [blame] | 4135 | if (Type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) { |
| 4136 | DumpBit(GNU_PROPERTY_AARCH64_FEATURE_1_BTI, "BTI"); |
| 4137 | DumpBit(GNU_PROPERTY_AARCH64_FEATURE_1_PAC, "PAC"); |
| 4138 | } else { |
| 4139 | DumpBit(GNU_PROPERTY_X86_FEATURE_1_IBT, "IBT"); |
| 4140 | DumpBit(GNU_PROPERTY_X86_FEATURE_1_SHSTK, "SHSTK"); |
| 4141 | } |
Fangrui Song | 6a03b93 | 2019-02-13 15:58:23 +0000 | [diff] [blame] | 4142 | if (PrData) |
| 4143 | OS << format("<unknown flags: 0x%x>", PrData); |
Fangrui Song | 12d5599 | 2019-02-13 01:51:45 +0000 | [diff] [blame] | 4144 | return OS.str(); |
Fangrui Song | 91ab9bf | 2019-02-13 23:18:05 +0000 | [diff] [blame] | 4145 | case GNU_PROPERTY_X86_ISA_1_NEEDED: |
| 4146 | case GNU_PROPERTY_X86_ISA_1_USED: |
| 4147 | OS << "x86 ISA " |
| 4148 | << (Type == GNU_PROPERTY_X86_ISA_1_NEEDED ? "needed: " : "used: "); |
| 4149 | if (DataSize != 4) { |
| 4150 | OS << format("<corrupt length: 0x%x>", DataSize); |
| 4151 | return OS.str(); |
| 4152 | } |
| 4153 | PrData = support::endian::read32<ELFT::TargetEndianness>(Data.data()); |
| 4154 | if (PrData == 0) { |
| 4155 | OS << "<None>"; |
| 4156 | return OS.str(); |
| 4157 | } |
| 4158 | DumpBit(GNU_PROPERTY_X86_ISA_1_CMOV, "CMOV"); |
| 4159 | DumpBit(GNU_PROPERTY_X86_ISA_1_SSE, "SSE"); |
| 4160 | DumpBit(GNU_PROPERTY_X86_ISA_1_SSE2, "SSE2"); |
| 4161 | DumpBit(GNU_PROPERTY_X86_ISA_1_SSE3, "SSE3"); |
| 4162 | DumpBit(GNU_PROPERTY_X86_ISA_1_SSSE3, "SSSE3"); |
| 4163 | DumpBit(GNU_PROPERTY_X86_ISA_1_SSE4_1, "SSE4_1"); |
| 4164 | DumpBit(GNU_PROPERTY_X86_ISA_1_SSE4_2, "SSE4_2"); |
| 4165 | DumpBit(GNU_PROPERTY_X86_ISA_1_AVX, "AVX"); |
| 4166 | DumpBit(GNU_PROPERTY_X86_ISA_1_AVX2, "AVX2"); |
| 4167 | DumpBit(GNU_PROPERTY_X86_ISA_1_FMA, "FMA"); |
| 4168 | DumpBit(GNU_PROPERTY_X86_ISA_1_AVX512F, "AVX512F"); |
| 4169 | DumpBit(GNU_PROPERTY_X86_ISA_1_AVX512CD, "AVX512CD"); |
| 4170 | DumpBit(GNU_PROPERTY_X86_ISA_1_AVX512ER, "AVX512ER"); |
| 4171 | DumpBit(GNU_PROPERTY_X86_ISA_1_AVX512PF, "AVX512PF"); |
| 4172 | DumpBit(GNU_PROPERTY_X86_ISA_1_AVX512VL, "AVX512VL"); |
| 4173 | DumpBit(GNU_PROPERTY_X86_ISA_1_AVX512DQ, "AVX512DQ"); |
| 4174 | DumpBit(GNU_PROPERTY_X86_ISA_1_AVX512BW, "AVX512BW"); |
| 4175 | DumpBit(GNU_PROPERTY_X86_ISA_1_AVX512_4FMAPS, "AVX512_4FMAPS"); |
| 4176 | DumpBit(GNU_PROPERTY_X86_ISA_1_AVX512_4VNNIW, "AVX512_4VNNIW"); |
| 4177 | DumpBit(GNU_PROPERTY_X86_ISA_1_AVX512_BITALG, "AVX512_BITALG"); |
| 4178 | DumpBit(GNU_PROPERTY_X86_ISA_1_AVX512_IFMA, "AVX512_IFMA"); |
| 4179 | DumpBit(GNU_PROPERTY_X86_ISA_1_AVX512_VBMI, "AVX512_VBMI"); |
| 4180 | DumpBit(GNU_PROPERTY_X86_ISA_1_AVX512_VBMI2, "AVX512_VBMI2"); |
| 4181 | DumpBit(GNU_PROPERTY_X86_ISA_1_AVX512_VNNI, "AVX512_VNNI"); |
| 4182 | if (PrData) |
| 4183 | OS << format("<unknown flags: 0x%x>", PrData); |
| 4184 | return OS.str(); |
| 4185 | break; |
Fangrui Song | 12d5599 | 2019-02-13 01:51:45 +0000 | [diff] [blame] | 4186 | case GNU_PROPERTY_X86_FEATURE_2_NEEDED: |
| 4187 | case GNU_PROPERTY_X86_FEATURE_2_USED: |
| 4188 | OS << "x86 feature " |
| 4189 | << (Type == GNU_PROPERTY_X86_FEATURE_2_NEEDED ? "needed: " : "used: "); |
| 4190 | if (DataSize != 4) { |
| 4191 | OS << format("<corrupt length: 0x%x>", DataSize); |
| 4192 | return OS.str(); |
Alexander Ivchenko | ab60a28 | 2018-06-04 15:14:18 +0000 | [diff] [blame] | 4193 | } |
Fangrui Song | 6a03b93 | 2019-02-13 15:58:23 +0000 | [diff] [blame] | 4194 | PrData = support::endian::read32<ELFT::TargetEndianness>(Data.data()); |
| 4195 | if (PrData == 0) { |
Fangrui Song | 12d5599 | 2019-02-13 01:51:45 +0000 | [diff] [blame] | 4196 | OS << "<None>"; |
| 4197 | return OS.str(); |
Alexander Ivchenko | ab60a28 | 2018-06-04 15:14:18 +0000 | [diff] [blame] | 4198 | } |
Fangrui Song | 12d5599 | 2019-02-13 01:51:45 +0000 | [diff] [blame] | 4199 | DumpBit(GNU_PROPERTY_X86_FEATURE_2_X86, "x86"); |
| 4200 | DumpBit(GNU_PROPERTY_X86_FEATURE_2_X87, "x87"); |
| 4201 | DumpBit(GNU_PROPERTY_X86_FEATURE_2_MMX, "MMX"); |
| 4202 | DumpBit(GNU_PROPERTY_X86_FEATURE_2_XMM, "XMM"); |
| 4203 | DumpBit(GNU_PROPERTY_X86_FEATURE_2_YMM, "YMM"); |
| 4204 | DumpBit(GNU_PROPERTY_X86_FEATURE_2_ZMM, "ZMM"); |
| 4205 | DumpBit(GNU_PROPERTY_X86_FEATURE_2_FXSR, "FXSR"); |
| 4206 | DumpBit(GNU_PROPERTY_X86_FEATURE_2_XSAVE, "XSAVE"); |
| 4207 | DumpBit(GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT, "XSAVEOPT"); |
| 4208 | DumpBit(GNU_PROPERTY_X86_FEATURE_2_XSAVEC, "XSAVEC"); |
Fangrui Song | 6a03b93 | 2019-02-13 15:58:23 +0000 | [diff] [blame] | 4209 | if (PrData) |
| 4210 | OS << format("<unknown flags: 0x%x>", PrData); |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 4211 | return OS.str(); |
George Rimar | 6a14c02 | 2018-03-21 08:34:55 +0000 | [diff] [blame] | 4212 | } |
| 4213 | } |
| 4214 | |
| 4215 | template <typename ELFT> |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 4216 | static SmallVector<std::string, 4> getGNUPropertyList(ArrayRef<uint8_t> Arr) { |
George Rimar | 6a14c02 | 2018-03-21 08:34:55 +0000 | [diff] [blame] | 4217 | using Elf_Word = typename ELFT::Word; |
| 4218 | |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 4219 | SmallVector<std::string, 4> Properties; |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 4220 | while (Arr.size() >= 8) { |
| 4221 | uint32_t Type = *reinterpret_cast<const Elf_Word *>(Arr.data()); |
| 4222 | uint32_t DataSize = *reinterpret_cast<const Elf_Word *>(Arr.data() + 4); |
| 4223 | Arr = Arr.drop_front(8); |
| 4224 | |
| 4225 | // Take padding size into account if present. |
| 4226 | uint64_t PaddedSize = alignTo(DataSize, sizeof(typename ELFT::uint)); |
| 4227 | std::string str; |
| 4228 | raw_string_ostream OS(str); |
| 4229 | if (Arr.size() < PaddedSize) { |
| 4230 | OS << format("<corrupt type (0x%x) datasz: 0x%x>", Type, DataSize); |
| 4231 | Properties.push_back(OS.str()); |
| 4232 | break; |
| 4233 | } |
| 4234 | Properties.push_back( |
| 4235 | getGNUProperty<ELFT>(Type, DataSize, Arr.take_front(PaddedSize))); |
| 4236 | Arr = Arr.drop_front(PaddedSize); |
| 4237 | } |
| 4238 | |
| 4239 | if (!Arr.empty()) |
| 4240 | Properties.push_back("<corrupted GNU_PROPERTY_TYPE_0>"); |
| 4241 | |
| 4242 | return Properties; |
| 4243 | } |
| 4244 | |
| 4245 | struct GNUAbiTag { |
| 4246 | std::string OSName; |
| 4247 | std::string ABI; |
| 4248 | bool IsValid; |
| 4249 | }; |
| 4250 | |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 4251 | template <typename ELFT> static GNUAbiTag getGNUAbiTag(ArrayRef<uint8_t> Desc) { |
Jake Ehrlich | ee7ec6c | 2018-11-13 01:10:35 +0000 | [diff] [blame] | 4252 | typedef typename ELFT::Word Elf_Word; |
| 4253 | |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 4254 | ArrayRef<Elf_Word> Words(reinterpret_cast<const Elf_Word *>(Desc.begin()), |
| 4255 | reinterpret_cast<const Elf_Word *>(Desc.end())); |
Jake Ehrlich | ee7ec6c | 2018-11-13 01:10:35 +0000 | [diff] [blame] | 4256 | |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 4257 | if (Words.size() < 4) |
| 4258 | return {"", "", /*IsValid=*/false}; |
| 4259 | |
| 4260 | static const char *OSNames[] = { |
| 4261 | "Linux", "Hurd", "Solaris", "FreeBSD", "NetBSD", "Syllable", "NaCl", |
| 4262 | }; |
| 4263 | StringRef OSName = "Unknown"; |
| 4264 | if (Words[0] < array_lengthof(OSNames)) |
| 4265 | OSName = OSNames[Words[0]]; |
| 4266 | uint32_t Major = Words[1], Minor = Words[2], Patch = Words[3]; |
| 4267 | std::string str; |
| 4268 | raw_string_ostream ABI(str); |
| 4269 | ABI << Major << "." << Minor << "." << Patch; |
| 4270 | return {OSName, ABI.str(), /*IsValid=*/true}; |
| 4271 | } |
| 4272 | |
Jake Ehrlich | ee7ec6c | 2018-11-13 01:10:35 +0000 | [diff] [blame] | 4273 | static std::string getGNUBuildId(ArrayRef<uint8_t> Desc) { |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 4274 | std::string str; |
| 4275 | raw_string_ostream OS(str); |
Jake Ehrlich | ee7ec6c | 2018-11-13 01:10:35 +0000 | [diff] [blame] | 4276 | for (const auto &B : Desc) |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 4277 | OS << format_hex_no_prefix(B, 2); |
| 4278 | return OS.str(); |
| 4279 | } |
| 4280 | |
Jake Ehrlich | ee7ec6c | 2018-11-13 01:10:35 +0000 | [diff] [blame] | 4281 | static StringRef getGNUGoldVersion(ArrayRef<uint8_t> Desc) { |
| 4282 | return StringRef(reinterpret_cast<const char *>(Desc.data()), Desc.size()); |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 4283 | } |
| 4284 | |
| 4285 | template <typename ELFT> |
| 4286 | static void printGNUNote(raw_ostream &OS, uint32_t NoteType, |
Jake Ehrlich | ee7ec6c | 2018-11-13 01:10:35 +0000 | [diff] [blame] | 4287 | ArrayRef<uint8_t> Desc) { |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 4288 | switch (NoteType) { |
| 4289 | default: |
| 4290 | return; |
| 4291 | case ELF::NT_GNU_ABI_TAG: { |
Jake Ehrlich | ee7ec6c | 2018-11-13 01:10:35 +0000 | [diff] [blame] | 4292 | const GNUAbiTag &AbiTag = getGNUAbiTag<ELFT>(Desc); |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 4293 | if (!AbiTag.IsValid) |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 4294 | OS << " <corrupt GNU_ABI_TAG>"; |
| 4295 | else |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 4296 | OS << " OS: " << AbiTag.OSName << ", ABI: " << AbiTag.ABI; |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 4297 | break; |
| 4298 | } |
| 4299 | case ELF::NT_GNU_BUILD_ID: { |
Jake Ehrlich | ee7ec6c | 2018-11-13 01:10:35 +0000 | [diff] [blame] | 4300 | OS << " Build ID: " << getGNUBuildId(Desc); |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 4301 | break; |
| 4302 | } |
| 4303 | case ELF::NT_GNU_GOLD_VERSION: |
Jake Ehrlich | ee7ec6c | 2018-11-13 01:10:35 +0000 | [diff] [blame] | 4304 | OS << " Version: " << getGNUGoldVersion(Desc); |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 4305 | break; |
George Rimar | 6a14c02 | 2018-03-21 08:34:55 +0000 | [diff] [blame] | 4306 | case ELF::NT_GNU_PROPERTY_TYPE_0: |
| 4307 | OS << " Properties:"; |
Jake Ehrlich | ee7ec6c | 2018-11-13 01:10:35 +0000 | [diff] [blame] | 4308 | for (const auto &Property : getGNUPropertyList<ELFT>(Desc)) |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 4309 | OS << " " << Property << "\n"; |
George Rimar | 6a14c02 | 2018-03-21 08:34:55 +0000 | [diff] [blame] | 4310 | break; |
| 4311 | } |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 4312 | OS << '\n'; |
| 4313 | } |
| 4314 | |
Scott Linder | f5b36e5 | 2018-12-12 19:39:27 +0000 | [diff] [blame] | 4315 | struct AMDNote { |
| 4316 | std::string Type; |
| 4317 | std::string Value; |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 4318 | }; |
| 4319 | |
Konstantin Zhuravlyov | b3c605d | 2017-10-14 18:21:42 +0000 | [diff] [blame] | 4320 | template <typename ELFT> |
Scott Linder | f5b36e5 | 2018-12-12 19:39:27 +0000 | [diff] [blame] | 4321 | static AMDNote getAMDNote(uint32_t NoteType, ArrayRef<uint8_t> Desc) { |
Konstantin Zhuravlyov | b3c605d | 2017-10-14 18:21:42 +0000 | [diff] [blame] | 4322 | switch (NoteType) { |
| 4323 | default: |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 4324 | return {"", ""}; |
| 4325 | case ELF::NT_AMD_AMDGPU_HSA_METADATA: |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 4326 | return { |
| 4327 | "HSA Metadata", |
| 4328 | std::string(reinterpret_cast<const char *>(Desc.data()), Desc.size())}; |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 4329 | case ELF::NT_AMD_AMDGPU_ISA: |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 4330 | return { |
| 4331 | "ISA Version", |
| 4332 | std::string(reinterpret_cast<const char *>(Desc.data()), Desc.size())}; |
Konstantin Zhuravlyov | b3c605d | 2017-10-14 18:21:42 +0000 | [diff] [blame] | 4333 | } |
Konstantin Zhuravlyov | b3c605d | 2017-10-14 18:21:42 +0000 | [diff] [blame] | 4334 | } |
| 4335 | |
Scott Linder | f5b36e5 | 2018-12-12 19:39:27 +0000 | [diff] [blame] | 4336 | struct AMDGPUNote { |
| 4337 | std::string Type; |
| 4338 | std::string Value; |
| 4339 | }; |
| 4340 | |
| 4341 | template <typename ELFT> |
| 4342 | static AMDGPUNote getAMDGPUNote(uint32_t NoteType, ArrayRef<uint8_t> Desc) { |
| 4343 | switch (NoteType) { |
| 4344 | default: |
| 4345 | return {"", ""}; |
Tim Renouf | ed0b9af | 2019-03-13 18:55:50 +0000 | [diff] [blame] | 4346 | case ELF::NT_AMDGPU_METADATA: { |
Scott Linder | f5b36e5 | 2018-12-12 19:39:27 +0000 | [diff] [blame] | 4347 | auto MsgPackString = |
| 4348 | StringRef(reinterpret_cast<const char *>(Desc.data()), Desc.size()); |
Tim Renouf | ed0b9af | 2019-03-13 18:55:50 +0000 | [diff] [blame] | 4349 | msgpack::Document MsgPackDoc; |
| 4350 | if (!MsgPackDoc.readFromBlob(MsgPackString, /*Multi=*/false)) |
Scott Linder | f5b36e5 | 2018-12-12 19:39:27 +0000 | [diff] [blame] | 4351 | return {"AMDGPU Metadata", "Invalid AMDGPU Metadata"}; |
Scott Linder | f5b36e5 | 2018-12-12 19:39:27 +0000 | [diff] [blame] | 4352 | |
| 4353 | AMDGPU::HSAMD::V3::MetadataVerifier Verifier(true); |
Tim Renouf | ed0b9af | 2019-03-13 18:55:50 +0000 | [diff] [blame] | 4354 | if (!Verifier.verify(MsgPackDoc.getRoot())) |
Scott Linder | f5b36e5 | 2018-12-12 19:39:27 +0000 | [diff] [blame] | 4355 | return {"AMDGPU Metadata", "Invalid AMDGPU Metadata"}; |
| 4356 | |
| 4357 | std::string HSAMetadataString; |
| 4358 | raw_string_ostream StrOS(HSAMetadataString); |
Tim Renouf | ed0b9af | 2019-03-13 18:55:50 +0000 | [diff] [blame] | 4359 | MsgPackDoc.toYAML(StrOS); |
Scott Linder | f5b36e5 | 2018-12-12 19:39:27 +0000 | [diff] [blame] | 4360 | |
| 4361 | return {"AMDGPU Metadata", StrOS.str()}; |
| 4362 | } |
Tim Renouf | ed0b9af | 2019-03-13 18:55:50 +0000 | [diff] [blame] | 4363 | } |
Scott Linder | f5b36e5 | 2018-12-12 19:39:27 +0000 | [diff] [blame] | 4364 | } |
| 4365 | |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 4366 | template <class ELFT> |
| 4367 | void GNUStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) { |
Scott Linder | 77a5f21 | 2018-03-12 19:28:50 +0000 | [diff] [blame] | 4368 | auto PrintHeader = [&](const typename ELFT::Off Offset, |
| 4369 | const typename ELFT::Addr Size) { |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 4370 | OS << "Displaying notes found at file offset " << format_hex(Offset, 10) |
| 4371 | << " with length " << format_hex(Size, 10) << ":\n" |
Fangrui Song | c310992 | 2019-08-07 09:13:11 +0000 | [diff] [blame] | 4372 | << " Owner Data size \tDescription\n"; |
Scott Linder | 77a5f21 | 2018-03-12 19:28:50 +0000 | [diff] [blame] | 4373 | }; |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 4374 | |
Scott Linder | 77a5f21 | 2018-03-12 19:28:50 +0000 | [diff] [blame] | 4375 | auto ProcessNote = [&](const Elf_Note &Note) { |
| 4376 | StringRef Name = Note.getName(); |
Jake Ehrlich | ee7ec6c | 2018-11-13 01:10:35 +0000 | [diff] [blame] | 4377 | ArrayRef<uint8_t> Descriptor = Note.getDesc(); |
Scott Linder | 77a5f21 | 2018-03-12 19:28:50 +0000 | [diff] [blame] | 4378 | Elf_Word Type = Note.getType(); |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 4379 | |
Fangrui Song | c310992 | 2019-08-07 09:13:11 +0000 | [diff] [blame] | 4380 | OS << " " << left_justify(Name, 20) << ' ' |
Scott Linder | 77a5f21 | 2018-03-12 19:28:50 +0000 | [diff] [blame] | 4381 | << format_hex(Descriptor.size(), 10) << '\t'; |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 4382 | |
Scott Linder | 77a5f21 | 2018-03-12 19:28:50 +0000 | [diff] [blame] | 4383 | if (Name == "GNU") { |
| 4384 | OS << getGNUNoteTypeName(Type) << '\n'; |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 4385 | printGNUNote<ELFT>(OS, Type, Descriptor); |
Scott Linder | 77a5f21 | 2018-03-12 19:28:50 +0000 | [diff] [blame] | 4386 | } else if (Name == "FreeBSD") { |
| 4387 | OS << getFreeBSDNoteTypeName(Type) << '\n'; |
| 4388 | } else if (Name == "AMD") { |
Scott Linder | f5b36e5 | 2018-12-12 19:39:27 +0000 | [diff] [blame] | 4389 | OS << getAMDNoteTypeName(Type) << '\n'; |
| 4390 | const AMDNote N = getAMDNote<ELFT>(Type, Descriptor); |
| 4391 | if (!N.Type.empty()) |
| 4392 | OS << " " << N.Type << ":\n " << N.Value << '\n'; |
| 4393 | } else if (Name == "AMDGPU") { |
Scott Linder | 77a5f21 | 2018-03-12 19:28:50 +0000 | [diff] [blame] | 4394 | OS << getAMDGPUNoteTypeName(Type) << '\n'; |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 4395 | const AMDGPUNote N = getAMDGPUNote<ELFT>(Type, Descriptor); |
Scott Linder | f5b36e5 | 2018-12-12 19:39:27 +0000 | [diff] [blame] | 4396 | if (!N.Type.empty()) |
| 4397 | OS << " " << N.Type << ":\n " << N.Value << '\n'; |
Scott Linder | 77a5f21 | 2018-03-12 19:28:50 +0000 | [diff] [blame] | 4398 | } else { |
Jordan Rupprecht | d884fbd | 2019-08-05 15:43:20 +0000 | [diff] [blame] | 4399 | StringRef NoteType = Obj->getHeader()->e_type == ELF::ET_CORE |
| 4400 | ? getCoreNoteTypeName(Type) |
| 4401 | : getGenericNoteTypeName(Type); |
Jordan Rupprecht | 871baa2 | 2019-03-29 16:48:19 +0000 | [diff] [blame] | 4402 | if (!NoteType.empty()) |
| 4403 | OS << NoteType; |
| 4404 | else |
| 4405 | OS << "Unknown note type: (" << format_hex(Type, 10) << ')'; |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 4406 | } |
Scott Linder | 77a5f21 | 2018-03-12 19:28:50 +0000 | [diff] [blame] | 4407 | OS << '\n'; |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 4408 | }; |
| 4409 | |
George Rimar | 1206f5a | 2019-01-30 15:39:05 +0000 | [diff] [blame] | 4410 | if (Obj->getHeader()->e_type == ELF::ET_CORE) { |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 4411 | for (const auto &P : |
| 4412 | unwrapOrError(this->FileName, Obj->program_headers())) { |
Scott Linder | 77a5f21 | 2018-03-12 19:28:50 +0000 | [diff] [blame] | 4413 | if (P.p_type != PT_NOTE) |
| 4414 | continue; |
| 4415 | PrintHeader(P.p_offset, P.p_filesz); |
| 4416 | Error Err = Error::success(); |
| 4417 | for (const auto &Note : Obj->notes(P, Err)) |
| 4418 | ProcessNote(Note); |
| 4419 | if (Err) |
George Rimar | 36f2318 | 2019-08-13 12:07:41 +0000 | [diff] [blame^] | 4420 | reportError(std::move(Err), this->FileName); |
Scott Linder | 77a5f21 | 2018-03-12 19:28:50 +0000 | [diff] [blame] | 4421 | } |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 4422 | } else { |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 4423 | for (const auto &S : |
| 4424 | unwrapOrError(this->FileName, Obj->sections())) { |
Scott Linder | 77a5f21 | 2018-03-12 19:28:50 +0000 | [diff] [blame] | 4425 | if (S.sh_type != SHT_NOTE) |
| 4426 | continue; |
| 4427 | PrintHeader(S.sh_offset, S.sh_size); |
| 4428 | Error Err = Error::success(); |
| 4429 | for (const auto &Note : Obj->notes(S, Err)) |
| 4430 | ProcessNote(Note); |
| 4431 | if (Err) |
George Rimar | 36f2318 | 2019-08-13 12:07:41 +0000 | [diff] [blame^] | 4432 | reportError(std::move(Err), this->FileName); |
Scott Linder | 77a5f21 | 2018-03-12 19:28:50 +0000 | [diff] [blame] | 4433 | } |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 4434 | } |
| 4435 | } |
| 4436 | |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 4437 | template <class ELFT> |
Saleem Abdulrasool | b36fbbc | 2018-01-30 16:29:29 +0000 | [diff] [blame] | 4438 | void GNUStyle<ELFT>::printELFLinkerOptions(const ELFFile<ELFT> *Obj) { |
| 4439 | OS << "printELFLinkerOptions not implemented!\n"; |
| 4440 | } |
| 4441 | |
Wolfgang Pieb | c71c629 | 2019-08-05 22:47:07 +0000 | [diff] [blame] | 4442 | template <class ELFT> |
| 4443 | void DumpStyle<ELFT>::printFunctionStackSize( |
| 4444 | const ELFObjectFile<ELFT> *Obj, uint64_t SymValue, SectionRef FunctionSec, |
| 4445 | const StringRef SectionName, DataExtractor Data, uint64_t *Offset) { |
| 4446 | // This function ignores potentially erroneous input, unless it is directly |
| 4447 | // related to stack size reporting. |
| 4448 | SymbolRef FuncSym; |
| 4449 | for (const ELFSymbolRef &Symbol : Obj->symbols()) { |
| 4450 | Expected<uint64_t> SymAddrOrErr = Symbol.getAddress(); |
| 4451 | if (!SymAddrOrErr) { |
| 4452 | consumeError(SymAddrOrErr.takeError()); |
| 4453 | continue; |
| 4454 | } |
| 4455 | if (Symbol.getELFType() == ELF::STT_FUNC && *SymAddrOrErr == SymValue) { |
| 4456 | // Check if the symbol is in the right section. |
| 4457 | if (FunctionSec.containsSymbol(Symbol)) { |
| 4458 | FuncSym = Symbol; |
| 4459 | break; |
| 4460 | } |
| 4461 | } |
| 4462 | } |
| 4463 | |
| 4464 | StringRef FileStr = Obj->getFileName(); |
| 4465 | std::string FuncName = "?"; |
| 4466 | // A valid SymbolRef has a non-null object file pointer. |
| 4467 | if (FuncSym.BasicSymbolRef::getObject()) { |
| 4468 | // Extract the symbol name. |
| 4469 | Expected<StringRef> FuncNameOrErr = FuncSym.getName(); |
| 4470 | if (FuncNameOrErr) |
| 4471 | FuncName = maybeDemangle(*FuncNameOrErr); |
| 4472 | else |
| 4473 | consumeError(FuncNameOrErr.takeError()); |
| 4474 | } else |
| 4475 | reportWarning(" '" + FileStr + |
| 4476 | "': could not identify function symbol for stack size entry"); |
| 4477 | |
| 4478 | // Extract the size. The expectation is that Offset is pointing to the right |
| 4479 | // place, i.e. past the function address. |
| 4480 | uint64_t PrevOffset = *Offset; |
Igor Kudrin | 45ee933 | 2019-08-07 11:44:47 +0000 | [diff] [blame] | 4481 | uint64_t StackSize = Data.getULEB128(Offset); |
Wolfgang Pieb | c71c629 | 2019-08-05 22:47:07 +0000 | [diff] [blame] | 4482 | // getULEB128() does not advance Offset if it is not able to extract a valid |
| 4483 | // integer. |
| 4484 | if (*Offset == PrevOffset) |
| 4485 | reportError( |
Wolfgang Pieb | c71c629 | 2019-08-05 22:47:07 +0000 | [diff] [blame] | 4486 | createStringError(object_error::parse_failed, |
| 4487 | "could not extract a valid stack size in section %s", |
George Rimar | 36f2318 | 2019-08-13 12:07:41 +0000 | [diff] [blame^] | 4488 | SectionName.data()), |
| 4489 | FileStr); |
Wolfgang Pieb | c71c629 | 2019-08-05 22:47:07 +0000 | [diff] [blame] | 4490 | |
| 4491 | printStackSizeEntry(StackSize, FuncName); |
| 4492 | } |
| 4493 | |
| 4494 | template <class ELFT> |
| 4495 | void GNUStyle<ELFT>::printStackSizeEntry(uint64_t Size, StringRef FuncName) { |
| 4496 | OS.PadToColumn(2); |
| 4497 | OS << format_decimal(Size, 11); |
| 4498 | OS.PadToColumn(18); |
| 4499 | OS << FuncName << "\n"; |
| 4500 | } |
| 4501 | |
| 4502 | template <class ELFT> |
| 4503 | void DumpStyle<ELFT>::printStackSize(const ELFObjectFile<ELFT> *Obj, |
| 4504 | RelocationRef Reloc, |
| 4505 | SectionRef FunctionSec, |
| 4506 | const StringRef &StackSizeSectionName, |
| 4507 | const RelocationResolver &Resolver, |
| 4508 | DataExtractor Data) { |
| 4509 | // This function ignores potentially erroneous input, unless it is directly |
| 4510 | // related to stack size reporting. |
| 4511 | object::symbol_iterator RelocSym = Reloc.getSymbol(); |
| 4512 | uint64_t RelocSymValue = 0; |
| 4513 | StringRef FileStr = Obj->getFileName(); |
| 4514 | if (RelocSym != Obj->symbol_end()) { |
| 4515 | // Ensure that the relocation symbol is in the function section, i.e. the |
| 4516 | // section where the functions whose stack sizes we are reporting are |
| 4517 | // located. |
| 4518 | StringRef SymName = "?"; |
| 4519 | Expected<StringRef> NameOrErr = RelocSym->getName(); |
| 4520 | if (NameOrErr) |
| 4521 | SymName = *NameOrErr; |
| 4522 | else |
| 4523 | consumeError(NameOrErr.takeError()); |
| 4524 | |
| 4525 | auto SectionOrErr = RelocSym->getSection(); |
| 4526 | if (!SectionOrErr) { |
| 4527 | reportWarning(" '" + FileStr + |
| 4528 | "': cannot identify the section for relocation symbol " + |
| 4529 | SymName); |
| 4530 | consumeError(SectionOrErr.takeError()); |
| 4531 | } else if (*SectionOrErr != FunctionSec) { |
| 4532 | reportWarning(" '" + FileStr + "': relocation symbol " + SymName + |
| 4533 | " is not in the expected section"); |
| 4534 | // Pretend that the symbol is in the correct section and report its |
| 4535 | // stack size anyway. |
| 4536 | FunctionSec = **SectionOrErr; |
| 4537 | } |
| 4538 | |
| 4539 | Expected<uint64_t> RelocSymValueOrErr = RelocSym->getValue(); |
| 4540 | if (RelocSymValueOrErr) |
| 4541 | RelocSymValue = *RelocSymValueOrErr; |
| 4542 | else |
| 4543 | consumeError(RelocSymValueOrErr.takeError()); |
| 4544 | } |
| 4545 | |
| 4546 | uint64_t Offset = Reloc.getOffset(); |
| 4547 | if (!Data.isValidOffsetForDataOfSize(Offset, sizeof(Elf_Addr) + 1)) |
George Rimar | 36f2318 | 2019-08-13 12:07:41 +0000 | [diff] [blame^] | 4548 | reportError( |
| 4549 | createStringError(object_error::parse_failed, |
| 4550 | "found invalid relocation offset into section %s " |
| 4551 | "while trying to extract a stack size entry", |
| 4552 | StackSizeSectionName.data()), |
| 4553 | FileStr); |
Wolfgang Pieb | c71c629 | 2019-08-05 22:47:07 +0000 | [diff] [blame] | 4554 | |
Igor Kudrin | 45ee933 | 2019-08-07 11:44:47 +0000 | [diff] [blame] | 4555 | uint64_t Addend = Data.getAddress(&Offset); |
Wolfgang Pieb | c71c629 | 2019-08-05 22:47:07 +0000 | [diff] [blame] | 4556 | uint64_t SymValue = Resolver(Reloc, RelocSymValue, Addend); |
| 4557 | this->printFunctionStackSize(Obj, SymValue, FunctionSec, StackSizeSectionName, |
| 4558 | Data, &Offset); |
| 4559 | } |
| 4560 | |
| 4561 | template <class ELFT> |
| 4562 | SectionRef toSectionRef(const ObjectFile *Obj, const typename ELFT::Shdr *Sec) { |
| 4563 | DataRefImpl DRI; |
| 4564 | DRI.p = reinterpret_cast<uintptr_t>(Sec); |
| 4565 | return SectionRef(DRI, Obj); |
| 4566 | } |
| 4567 | |
| 4568 | template <class ELFT> |
| 4569 | void DumpStyle<ELFT>::printNonRelocatableStackSizes( |
| 4570 | const ELFObjectFile<ELFT> *Obj, std::function<void()> PrintHeader) { |
| 4571 | // This function ignores potentially erroneous input, unless it is directly |
| 4572 | // related to stack size reporting. |
| 4573 | const ELFFile<ELFT> *EF = Obj->getELFFile(); |
| 4574 | StringRef FileStr = Obj->getFileName(); |
| 4575 | for (const SectionRef &Sec : Obj->sections()) { |
| 4576 | StringRef SectionName; |
| 4577 | Sec.getName(SectionName); |
| 4578 | const Elf_Shdr *ElfSec = Obj->getSection(Sec.getRawDataRefImpl()); |
| 4579 | if (!SectionName.startswith(".stack_sizes")) |
| 4580 | continue; |
| 4581 | PrintHeader(); |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 4582 | ArrayRef<uint8_t> Contents = |
| 4583 | unwrapOrError(this->FileName, EF->getSectionContents(ElfSec)); |
Wolfgang Pieb | c71c629 | 2019-08-05 22:47:07 +0000 | [diff] [blame] | 4584 | DataExtractor Data( |
| 4585 | StringRef(reinterpret_cast<const char *>(Contents.data()), |
| 4586 | Contents.size()), |
| 4587 | Obj->isLittleEndian(), sizeof(Elf_Addr)); |
| 4588 | // A .stack_sizes section header's sh_link field is supposed to point |
| 4589 | // to the section that contains the functions whose stack sizes are |
| 4590 | // described in it. |
| 4591 | const Elf_Shdr *FunctionELFSec = |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 4592 | unwrapOrError(this->FileName, EF->getSection(ElfSec->sh_link)); |
Wolfgang Pieb | c71c629 | 2019-08-05 22:47:07 +0000 | [diff] [blame] | 4593 | uint64_t Offset = 0; |
| 4594 | while (Offset < Contents.size()) { |
| 4595 | // The function address is followed by a ULEB representing the stack |
| 4596 | // size. Check for an extra byte before we try to process the entry. |
| 4597 | if (!Data.isValidOffsetForDataOfSize(Offset, sizeof(Elf_Addr) + 1)) { |
| 4598 | reportError( |
Wolfgang Pieb | c71c629 | 2019-08-05 22:47:07 +0000 | [diff] [blame] | 4599 | createStringError( |
| 4600 | object_error::parse_failed, |
| 4601 | "section %s ended while trying to extract a stack size entry", |
George Rimar | 36f2318 | 2019-08-13 12:07:41 +0000 | [diff] [blame^] | 4602 | SectionName.data()), |
| 4603 | FileStr); |
Wolfgang Pieb | c71c629 | 2019-08-05 22:47:07 +0000 | [diff] [blame] | 4604 | } |
Igor Kudrin | 45ee933 | 2019-08-07 11:44:47 +0000 | [diff] [blame] | 4605 | uint64_t SymValue = Data.getAddress(&Offset); |
Wolfgang Pieb | c71c629 | 2019-08-05 22:47:07 +0000 | [diff] [blame] | 4606 | printFunctionStackSize(Obj, SymValue, |
| 4607 | toSectionRef<ELFT>(Obj, FunctionELFSec), |
| 4608 | SectionName, Data, &Offset); |
| 4609 | } |
| 4610 | } |
| 4611 | } |
| 4612 | |
| 4613 | template <class ELFT> |
| 4614 | void DumpStyle<ELFT>::printRelocatableStackSizes( |
| 4615 | const ELFObjectFile<ELFT> *Obj, std::function<void()> PrintHeader) { |
| 4616 | const ELFFile<ELFT> *EF = Obj->getELFFile(); |
| 4617 | StringRef FileStr = Obj->getFileName(); |
| 4618 | // Build a map between stack size sections and their corresponding relocation |
| 4619 | // sections. |
| 4620 | llvm::MapVector<SectionRef, SectionRef> StackSizeRelocMap; |
| 4621 | const SectionRef NullSection; |
| 4622 | |
| 4623 | for (const SectionRef &Sec : Obj->sections()) { |
| 4624 | StringRef SectionName; |
| 4625 | Sec.getName(SectionName); |
| 4626 | // A stack size section that we haven't encountered yet is mapped to the |
| 4627 | // null section until we find its corresponding relocation section. |
| 4628 | if (SectionName.startswith(".stack_sizes")) |
| 4629 | if (StackSizeRelocMap.count(Sec) == 0) { |
| 4630 | StackSizeRelocMap[Sec] = NullSection; |
| 4631 | continue; |
| 4632 | } |
| 4633 | |
| 4634 | // Check relocation sections if they are relocating contents of a |
| 4635 | // stack sizes section. |
| 4636 | const Elf_Shdr *ElfSec = Obj->getSection(Sec.getRawDataRefImpl()); |
| 4637 | uint32_t SectionType = ElfSec->sh_type; |
| 4638 | if (SectionType != ELF::SHT_RELA && SectionType != ELF::SHT_REL) |
| 4639 | continue; |
| 4640 | |
| 4641 | SectionRef Contents = *Sec.getRelocatedSection(); |
| 4642 | const Elf_Shdr *ContentsSec = Obj->getSection(Contents.getRawDataRefImpl()); |
| 4643 | Expected<StringRef> ContentsSectionNameOrErr = |
| 4644 | EF->getSectionName(ContentsSec); |
| 4645 | if (!ContentsSectionNameOrErr) { |
| 4646 | consumeError(ContentsSectionNameOrErr.takeError()); |
| 4647 | continue; |
| 4648 | } |
| 4649 | if (!ContentsSectionNameOrErr->startswith(".stack_sizes")) |
| 4650 | continue; |
| 4651 | // Insert a mapping from the stack sizes section to its relocation section. |
| 4652 | StackSizeRelocMap[toSectionRef<ELFT>(Obj, ContentsSec)] = Sec; |
| 4653 | } |
| 4654 | |
| 4655 | for (const auto &StackSizeMapEntry : StackSizeRelocMap) { |
| 4656 | PrintHeader(); |
| 4657 | const SectionRef &StackSizesSec = StackSizeMapEntry.first; |
| 4658 | const SectionRef &RelocSec = StackSizeMapEntry.second; |
| 4659 | |
| 4660 | // Warn about stack size sections without a relocation section. |
| 4661 | StringRef StackSizeSectionName; |
| 4662 | StackSizesSec.getName(StackSizeSectionName); |
| 4663 | if (RelocSec == NullSection) { |
| 4664 | reportWarning(" '" + FileStr + "': section " + StackSizeSectionName + |
| 4665 | " does not have a corresponding " |
| 4666 | "relocation section"); |
| 4667 | continue; |
| 4668 | } |
| 4669 | |
| 4670 | // A .stack_sizes section header's sh_link field is supposed to point |
| 4671 | // to the section that contains the functions whose stack sizes are |
| 4672 | // described in it. |
| 4673 | const Elf_Shdr *StackSizesELFSec = |
| 4674 | Obj->getSection(StackSizesSec.getRawDataRefImpl()); |
| 4675 | const SectionRef FunctionSec = toSectionRef<ELFT>( |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 4676 | Obj, unwrapOrError(this->FileName, |
| 4677 | EF->getSection(StackSizesELFSec->sh_link))); |
Wolfgang Pieb | c71c629 | 2019-08-05 22:47:07 +0000 | [diff] [blame] | 4678 | |
| 4679 | bool (*IsSupportedFn)(uint64_t); |
| 4680 | RelocationResolver Resolver; |
| 4681 | std::tie(IsSupportedFn, Resolver) = getRelocationResolver(*Obj); |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 4682 | auto Contents = unwrapOrError(this->FileName, StackSizesSec.getContents()); |
Wolfgang Pieb | c71c629 | 2019-08-05 22:47:07 +0000 | [diff] [blame] | 4683 | DataExtractor Data( |
| 4684 | StringRef(reinterpret_cast<const char *>(Contents.data()), |
| 4685 | Contents.size()), |
| 4686 | Obj->isLittleEndian(), sizeof(Elf_Addr)); |
| 4687 | for (const RelocationRef &Reloc : RelocSec.relocations()) { |
| 4688 | if (!IsSupportedFn(Reloc.getType())) { |
| 4689 | StringRef RelocSectionName; |
| 4690 | RelocSec.getName(RelocSectionName); |
| 4691 | StringRef RelocName = EF->getRelocationTypeName(Reloc.getType()); |
| 4692 | reportError( |
Wolfgang Pieb | c71c629 | 2019-08-05 22:47:07 +0000 | [diff] [blame] | 4693 | createStringError(object_error::parse_failed, |
| 4694 | "unsupported relocation type in section %s: %s", |
George Rimar | 36f2318 | 2019-08-13 12:07:41 +0000 | [diff] [blame^] | 4695 | RelocSectionName.data(), RelocName.data()), |
| 4696 | FileStr); |
Wolfgang Pieb | c71c629 | 2019-08-05 22:47:07 +0000 | [diff] [blame] | 4697 | } |
| 4698 | this->printStackSize(Obj, Reloc, FunctionSec, StackSizeSectionName, |
| 4699 | Resolver, Data); |
| 4700 | } |
| 4701 | } |
| 4702 | } |
| 4703 | |
| 4704 | template <class ELFT> |
| 4705 | void GNUStyle<ELFT>::printStackSizes(const ELFObjectFile<ELFT> *Obj) { |
| 4706 | bool HeaderHasBeenPrinted = false; |
| 4707 | auto PrintHeader = [&]() { |
| 4708 | if (HeaderHasBeenPrinted) |
| 4709 | return; |
| 4710 | OS << "\nStack Sizes:\n"; |
| 4711 | OS.PadToColumn(9); |
| 4712 | OS << "Size"; |
| 4713 | OS.PadToColumn(18); |
| 4714 | OS << "Function\n"; |
| 4715 | HeaderHasBeenPrinted = true; |
| 4716 | }; |
| 4717 | |
| 4718 | // For non-relocatable objects, look directly for sections whose name starts |
| 4719 | // with .stack_sizes and process the contents. |
| 4720 | if (Obj->isRelocatableObject()) |
| 4721 | this->printRelocatableStackSizes(Obj, PrintHeader); |
| 4722 | else |
| 4723 | this->printNonRelocatableStackSizes(Obj, PrintHeader); |
| 4724 | } |
| 4725 | |
Saleem Abdulrasool | b36fbbc | 2018-01-30 16:29:29 +0000 | [diff] [blame] | 4726 | template <class ELFT> |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 4727 | void GNUStyle<ELFT>::printMipsGOT(const MipsGOTParser<ELFT> &Parser) { |
| 4728 | size_t Bias = ELFT::Is64Bits ? 8 : 0; |
| 4729 | auto PrintEntry = [&](const Elf_Addr *E, StringRef Purpose) { |
| 4730 | OS.PadToColumn(2); |
| 4731 | OS << format_hex_no_prefix(Parser.getGotAddress(E), 8 + Bias); |
| 4732 | OS.PadToColumn(11 + Bias); |
| 4733 | OS << format_decimal(Parser.getGotOffset(E), 6) << "(gp)"; |
| 4734 | OS.PadToColumn(22 + Bias); |
| 4735 | OS << format_hex_no_prefix(*E, 8 + Bias); |
| 4736 | OS.PadToColumn(31 + 2 * Bias); |
| 4737 | OS << Purpose << "\n"; |
| 4738 | }; |
| 4739 | |
| 4740 | OS << (Parser.IsStatic ? "Static GOT:\n" : "Primary GOT:\n"); |
| 4741 | OS << " Canonical gp value: " |
| 4742 | << format_hex_no_prefix(Parser.getGp(), 8 + Bias) << "\n\n"; |
| 4743 | |
| 4744 | OS << " Reserved entries:\n"; |
Simon Atanasyan | e4f01ec | 2019-05-24 10:26:48 +0000 | [diff] [blame] | 4745 | if (ELFT::Is64Bits) |
| 4746 | OS << " Address Access Initial Purpose\n"; |
| 4747 | else |
| 4748 | OS << " Address Access Initial Purpose\n"; |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 4749 | PrintEntry(Parser.getGotLazyResolver(), "Lazy resolver"); |
| 4750 | if (Parser.getGotModulePointer()) |
| 4751 | PrintEntry(Parser.getGotModulePointer(), "Module pointer (GNU extension)"); |
| 4752 | |
| 4753 | if (!Parser.getLocalEntries().empty()) { |
| 4754 | OS << "\n"; |
| 4755 | OS << " Local entries:\n"; |
Simon Atanasyan | e4f01ec | 2019-05-24 10:26:48 +0000 | [diff] [blame] | 4756 | if (ELFT::Is64Bits) |
| 4757 | OS << " Address Access Initial\n"; |
| 4758 | else |
| 4759 | OS << " Address Access Initial\n"; |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 4760 | for (auto &E : Parser.getLocalEntries()) |
| 4761 | PrintEntry(&E, ""); |
| 4762 | } |
| 4763 | |
| 4764 | if (Parser.IsStatic) |
| 4765 | return; |
| 4766 | |
| 4767 | if (!Parser.getGlobalEntries().empty()) { |
| 4768 | OS << "\n"; |
| 4769 | OS << " Global entries:\n"; |
Simon Atanasyan | e4f01ec | 2019-05-24 10:26:48 +0000 | [diff] [blame] | 4770 | if (ELFT::Is64Bits) |
| 4771 | OS << " Address Access Initial Sym.Val." |
| 4772 | << " Type Ndx Name\n"; |
| 4773 | else |
| 4774 | OS << " Address Access Initial Sym.Val. Type Ndx Name\n"; |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 4775 | for (auto &E : Parser.getGlobalEntries()) { |
| 4776 | const Elf_Sym *Sym = Parser.getGotSym(&E); |
| 4777 | std::string SymName = this->dumper()->getFullSymbolName( |
| 4778 | Sym, this->dumper()->getDynamicStringTable(), false); |
| 4779 | |
| 4780 | OS.PadToColumn(2); |
| 4781 | OS << to_string(format_hex_no_prefix(Parser.getGotAddress(&E), 8 + Bias)); |
| 4782 | OS.PadToColumn(11 + Bias); |
| 4783 | OS << to_string(format_decimal(Parser.getGotOffset(&E), 6)) + "(gp)"; |
| 4784 | OS.PadToColumn(22 + Bias); |
| 4785 | OS << to_string(format_hex_no_prefix(E, 8 + Bias)); |
| 4786 | OS.PadToColumn(31 + 2 * Bias); |
| 4787 | OS << to_string(format_hex_no_prefix(Sym->st_value, 8 + Bias)); |
| 4788 | OS.PadToColumn(40 + 3 * Bias); |
| 4789 | OS << printEnum(Sym->getType(), makeArrayRef(ElfSymbolTypes)); |
| 4790 | OS.PadToColumn(48 + 3 * Bias); |
| 4791 | OS << getSymbolSectionNdx(Parser.Obj, Sym, |
| 4792 | this->dumper()->dynamic_symbols().begin()); |
| 4793 | OS.PadToColumn(52 + 3 * Bias); |
| 4794 | OS << SymName << "\n"; |
| 4795 | } |
| 4796 | } |
| 4797 | |
| 4798 | if (!Parser.getOtherEntries().empty()) |
| 4799 | OS << "\n Number of TLS and multi-GOT entries " |
| 4800 | << Parser.getOtherEntries().size() << "\n"; |
| 4801 | } |
| 4802 | |
| 4803 | template <class ELFT> |
| 4804 | void GNUStyle<ELFT>::printMipsPLT(const MipsGOTParser<ELFT> &Parser) { |
| 4805 | size_t Bias = ELFT::Is64Bits ? 8 : 0; |
| 4806 | auto PrintEntry = [&](const Elf_Addr *E, StringRef Purpose) { |
| 4807 | OS.PadToColumn(2); |
Hans Wennborg | 5b86163 | 2019-05-28 11:24:20 +0000 | [diff] [blame] | 4808 | OS << format_hex_no_prefix(Parser.getPltAddress(E), 8 + Bias); |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 4809 | OS.PadToColumn(11 + Bias); |
| 4810 | OS << format_hex_no_prefix(*E, 8 + Bias); |
| 4811 | OS.PadToColumn(20 + 2 * Bias); |
| 4812 | OS << Purpose << "\n"; |
| 4813 | }; |
| 4814 | |
| 4815 | OS << "PLT GOT:\n\n"; |
| 4816 | |
| 4817 | OS << " Reserved entries:\n"; |
| 4818 | OS << " Address Initial Purpose\n"; |
| 4819 | PrintEntry(Parser.getPltLazyResolver(), "PLT lazy resolver"); |
| 4820 | if (Parser.getPltModulePointer()) |
Hans Wennborg | 5b86163 | 2019-05-28 11:24:20 +0000 | [diff] [blame] | 4821 | PrintEntry(Parser.getPltModulePointer(), "Module pointer"); |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 4822 | |
| 4823 | if (!Parser.getPltEntries().empty()) { |
| 4824 | OS << "\n"; |
| 4825 | OS << " Entries:\n"; |
| 4826 | OS << " Address Initial Sym.Val. Type Ndx Name\n"; |
| 4827 | for (auto &E : Parser.getPltEntries()) { |
| 4828 | const Elf_Sym *Sym = Parser.getPltSym(&E); |
| 4829 | std::string SymName = this->dumper()->getFullSymbolName( |
| 4830 | Sym, this->dumper()->getDynamicStringTable(), false); |
| 4831 | |
| 4832 | OS.PadToColumn(2); |
Hans Wennborg | 5b86163 | 2019-05-28 11:24:20 +0000 | [diff] [blame] | 4833 | OS << to_string(format_hex_no_prefix(Parser.getPltAddress(&E), 8 + Bias)); |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 4834 | OS.PadToColumn(11 + Bias); |
| 4835 | OS << to_string(format_hex_no_prefix(E, 8 + Bias)); |
| 4836 | OS.PadToColumn(20 + 2 * Bias); |
| 4837 | OS << to_string(format_hex_no_prefix(Sym->st_value, 8 + Bias)); |
| 4838 | OS.PadToColumn(29 + 3 * Bias); |
| 4839 | OS << printEnum(Sym->getType(), makeArrayRef(ElfSymbolTypes)); |
| 4840 | OS.PadToColumn(37 + 3 * Bias); |
| 4841 | OS << getSymbolSectionNdx(Parser.Obj, Sym, |
| 4842 | this->dumper()->dynamic_symbols().begin()); |
| 4843 | OS.PadToColumn(41 + 3 * Bias); |
| 4844 | OS << SymName << "\n"; |
| 4845 | } |
| 4846 | } |
| 4847 | } |
| 4848 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 4849 | template <class ELFT> void LLVMStyle<ELFT>::printFileHeaders(const ELFO *Obj) { |
George Rimar | 1206f5a | 2019-01-30 15:39:05 +0000 | [diff] [blame] | 4850 | const Elf_Ehdr *E = Obj->getHeader(); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 4851 | { |
| 4852 | DictScope D(W, "ElfHeader"); |
| 4853 | { |
| 4854 | DictScope D(W, "Ident"); |
George Rimar | 1206f5a | 2019-01-30 15:39:05 +0000 | [diff] [blame] | 4855 | W.printBinary("Magic", makeArrayRef(E->e_ident).slice(ELF::EI_MAG0, 4)); |
| 4856 | W.printEnum("Class", E->e_ident[ELF::EI_CLASS], makeArrayRef(ElfClass)); |
| 4857 | W.printEnum("DataEncoding", E->e_ident[ELF::EI_DATA], |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 4858 | makeArrayRef(ElfDataEncoding)); |
George Rimar | 1206f5a | 2019-01-30 15:39:05 +0000 | [diff] [blame] | 4859 | W.printNumber("FileVersion", E->e_ident[ELF::EI_VERSION]); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 4860 | |
Konstantin Zhuravlyov | 121125f | 2017-10-02 20:49:58 +0000 | [diff] [blame] | 4861 | auto OSABI = makeArrayRef(ElfOSABI); |
George Rimar | 1206f5a | 2019-01-30 15:39:05 +0000 | [diff] [blame] | 4862 | if (E->e_ident[ELF::EI_OSABI] >= ELF::ELFOSABI_FIRST_ARCH && |
| 4863 | E->e_ident[ELF::EI_OSABI] <= ELF::ELFOSABI_LAST_ARCH) { |
| 4864 | switch (E->e_machine) { |
Konstantin Zhuravlyov | 121125f | 2017-10-02 20:49:58 +0000 | [diff] [blame] | 4865 | case ELF::EM_AMDGPU: |
| 4866 | OSABI = makeArrayRef(AMDGPUElfOSABI); |
| 4867 | break; |
| 4868 | case ELF::EM_ARM: |
| 4869 | OSABI = makeArrayRef(ARMElfOSABI); |
| 4870 | break; |
| 4871 | case ELF::EM_TI_C6000: |
| 4872 | OSABI = makeArrayRef(C6000ElfOSABI); |
| 4873 | break; |
| 4874 | } |
| 4875 | } |
George Rimar | 1206f5a | 2019-01-30 15:39:05 +0000 | [diff] [blame] | 4876 | W.printEnum("OS/ABI", E->e_ident[ELF::EI_OSABI], OSABI); |
| 4877 | W.printNumber("ABIVersion", E->e_ident[ELF::EI_ABIVERSION]); |
| 4878 | W.printBinary("Unused", makeArrayRef(E->e_ident).slice(ELF::EI_PAD)); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 4879 | } |
| 4880 | |
George Rimar | 1206f5a | 2019-01-30 15:39:05 +0000 | [diff] [blame] | 4881 | W.printEnum("Type", E->e_type, makeArrayRef(ElfObjectFileType)); |
| 4882 | W.printEnum("Machine", E->e_machine, makeArrayRef(ElfMachineType)); |
| 4883 | W.printNumber("Version", E->e_version); |
| 4884 | W.printHex("Entry", E->e_entry); |
| 4885 | W.printHex("ProgramHeaderOffset", E->e_phoff); |
| 4886 | W.printHex("SectionHeaderOffset", E->e_shoff); |
| 4887 | if (E->e_machine == EM_MIPS) |
| 4888 | W.printFlags("Flags", E->e_flags, makeArrayRef(ElfHeaderMipsFlags), |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 4889 | unsigned(ELF::EF_MIPS_ARCH), unsigned(ELF::EF_MIPS_ABI), |
| 4890 | unsigned(ELF::EF_MIPS_MACH)); |
George Rimar | 1206f5a | 2019-01-30 15:39:05 +0000 | [diff] [blame] | 4891 | else if (E->e_machine == EM_AMDGPU) |
| 4892 | W.printFlags("Flags", E->e_flags, makeArrayRef(ElfHeaderAMDGPUFlags), |
Konstantin Zhuravlyov | 9122a63 | 2018-02-16 22:33:59 +0000 | [diff] [blame] | 4893 | unsigned(ELF::EF_AMDGPU_MACH)); |
George Rimar | 1206f5a | 2019-01-30 15:39:05 +0000 | [diff] [blame] | 4894 | else if (E->e_machine == EM_RISCV) |
| 4895 | W.printFlags("Flags", E->e_flags, makeArrayRef(ElfHeaderRISCVFlags)); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 4896 | else |
George Rimar | 1206f5a | 2019-01-30 15:39:05 +0000 | [diff] [blame] | 4897 | W.printFlags("Flags", E->e_flags); |
| 4898 | W.printNumber("HeaderSize", E->e_ehsize); |
| 4899 | W.printNumber("ProgramHeaderEntrySize", E->e_phentsize); |
| 4900 | W.printNumber("ProgramHeaderCount", E->e_phnum); |
| 4901 | W.printNumber("SectionHeaderEntrySize", E->e_shentsize); |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 4902 | W.printString("SectionHeaderCount", |
| 4903 | getSectionHeadersNumString(Obj, this->FileName)); |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 4904 | W.printString("StringTableSectionIndex", |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 4905 | getSectionHeaderTableIndexString(Obj, this->FileName)); |
Hemant Kulkarni | d8a985e | 2016-02-10 20:40:55 +0000 | [diff] [blame] | 4906 | } |
| 4907 | } |
Hemant Kulkarni | 206ba84 | 2016-03-09 19:16:13 +0000 | [diff] [blame] | 4908 | |
| 4909 | template <class ELFT> |
| 4910 | void LLVMStyle<ELFT>::printGroupSections(const ELFO *Obj) { |
| 4911 | DictScope Lists(W, "Groups"); |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 4912 | std::vector<GroupSection> V = getGroups<ELFT>(Obj, this->FileName); |
George Rimar | 762abff6 | 2017-09-16 14:29:51 +0000 | [diff] [blame] | 4913 | DenseMap<uint64_t, const GroupSection *> Map = mapSectionsToGroups(V); |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 4914 | for (const GroupSection &G : V) { |
| 4915 | DictScope D(W, "Group"); |
| 4916 | W.printNumber("Name", G.Name, G.ShName); |
| 4917 | W.printNumber("Index", G.Index); |
Alexander Shaposhnikov | 8febe3d | 2018-03-12 22:40:09 +0000 | [diff] [blame] | 4918 | W.printNumber("Link", G.Link); |
| 4919 | W.printNumber("Info", G.Info); |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 4920 | W.printHex("Type", getGroupType(G.Type), G.Type); |
| 4921 | W.startLine() << "Signature: " << G.Signature << "\n"; |
| 4922 | |
| 4923 | ListScope L(W, "Section(s) in group"); |
George Rimar | 762abff6 | 2017-09-16 14:29:51 +0000 | [diff] [blame] | 4924 | for (const GroupMember &GM : G.Members) { |
| 4925 | const GroupSection *MainGroup = Map[GM.Index]; |
| 4926 | if (MainGroup != &G) { |
| 4927 | W.flush(); |
| 4928 | errs() << "Error: " << GM.Name << " (" << GM.Index |
| 4929 | << ") in a group " + G.Name + " (" << G.Index |
| 4930 | << ") is already in a group " + MainGroup->Name + " (" |
| 4931 | << MainGroup->Index << ")\n"; |
| 4932 | errs().flush(); |
| 4933 | continue; |
| 4934 | } |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 4935 | W.startLine() << GM.Name << " (" << GM.Index << ")\n"; |
George Rimar | 762abff6 | 2017-09-16 14:29:51 +0000 | [diff] [blame] | 4936 | } |
Hemant Kulkarni | 206ba84 | 2016-03-09 19:16:13 +0000 | [diff] [blame] | 4937 | } |
George Rimar | ea39eed | 2017-09-14 07:32:52 +0000 | [diff] [blame] | 4938 | |
| 4939 | if (V.empty()) |
Hemant Kulkarni | 206ba84 | 2016-03-09 19:16:13 +0000 | [diff] [blame] | 4940 | W.startLine() << "There are no group sections in the file.\n"; |
| 4941 | } |
George Rimar | 762abff6 | 2017-09-16 14:29:51 +0000 | [diff] [blame] | 4942 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 4943 | template <class ELFT> void LLVMStyle<ELFT>::printRelocations(const ELFO *Obj) { |
| 4944 | ListScope D(W, "Relocations"); |
| 4945 | |
| 4946 | int SectionNumber = -1; |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 4947 | for (const Elf_Shdr &Sec : unwrapOrError(this->FileName, Obj->sections())) { |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 4948 | ++SectionNumber; |
| 4949 | |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 4950 | if (Sec.sh_type != ELF::SHT_REL && Sec.sh_type != ELF::SHT_RELA && |
| 4951 | Sec.sh_type != ELF::SHT_RELR && Sec.sh_type != ELF::SHT_ANDROID_REL && |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 4952 | Sec.sh_type != ELF::SHT_ANDROID_RELA && |
| 4953 | Sec.sh_type != ELF::SHT_ANDROID_RELR) |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 4954 | continue; |
| 4955 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 4956 | StringRef Name = unwrapOrError(this->FileName, Obj->getSectionName(&Sec)); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 4957 | |
| 4958 | W.startLine() << "Section (" << SectionNumber << ") " << Name << " {\n"; |
| 4959 | W.indent(); |
| 4960 | |
| 4961 | printRelocations(&Sec, Obj); |
| 4962 | |
| 4963 | W.unindent(); |
| 4964 | W.startLine() << "}\n"; |
| 4965 | } |
| 4966 | } |
| 4967 | |
| 4968 | template <class ELFT> |
| 4969 | void LLVMStyle<ELFT>::printRelocations(const Elf_Shdr *Sec, const ELFO *Obj) { |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 4970 | const Elf_Shdr *SymTab = |
| 4971 | unwrapOrError(this->FileName, Obj->getSection(Sec->sh_link)); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 4972 | |
| 4973 | switch (Sec->sh_type) { |
| 4974 | case ELF::SHT_REL: |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 4975 | for (const Elf_Rel &R : unwrapOrError(this->FileName, Obj->rels(Sec))) { |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 4976 | Elf_Rela Rela; |
| 4977 | Rela.r_offset = R.r_offset; |
| 4978 | Rela.r_info = R.r_info; |
| 4979 | Rela.r_addend = 0; |
| 4980 | printRelocation(Obj, Rela, SymTab); |
| 4981 | } |
| 4982 | break; |
| 4983 | case ELF::SHT_RELA: |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 4984 | for (const Elf_Rela &R : unwrapOrError(this->FileName, Obj->relas(Sec))) |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 4985 | printRelocation(Obj, R, SymTab); |
| 4986 | break; |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 4987 | case ELF::SHT_RELR: |
| 4988 | case ELF::SHT_ANDROID_RELR: { |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 4989 | Elf_Relr_Range Relrs = unwrapOrError(this->FileName, Obj->relrs(Sec)); |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 4990 | if (opts::RawRelr) { |
| 4991 | for (const Elf_Relr &R : Relrs) |
| 4992 | W.startLine() << W.hex(R) << "\n"; |
| 4993 | } else { |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 4994 | std::vector<Elf_Rela> RelrRelas = |
| 4995 | unwrapOrError(this->FileName, Obj->decode_relrs(Relrs)); |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 4996 | for (const Elf_Rela &R : RelrRelas) |
| 4997 | printRelocation(Obj, R, SymTab); |
| 4998 | } |
| 4999 | break; |
| 5000 | } |
Peter Collingbourne | 689e6c05 | 2017-10-25 03:37:12 +0000 | [diff] [blame] | 5001 | case ELF::SHT_ANDROID_REL: |
| 5002 | case ELF::SHT_ANDROID_RELA: |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 5003 | for (const Elf_Rela &R : |
| 5004 | unwrapOrError(this->FileName, Obj->android_relas(Sec))) |
Peter Collingbourne | 689e6c05 | 2017-10-25 03:37:12 +0000 | [diff] [blame] | 5005 | printRelocation(Obj, R, SymTab); |
| 5006 | break; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5007 | } |
| 5008 | } |
| 5009 | |
| 5010 | template <class ELFT> |
| 5011 | void LLVMStyle<ELFT>::printRelocation(const ELFO *Obj, Elf_Rela Rel, |
| 5012 | const Elf_Shdr *SymTab) { |
| 5013 | SmallString<32> RelocName; |
| 5014 | Obj->getRelocationTypeName(Rel.getType(Obj->isMips64EL()), RelocName); |
James Henderson | e50d9cb | 2019-01-17 15:34:12 +0000 | [diff] [blame] | 5015 | std::string TargetName; |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 5016 | const Elf_Sym *Sym = |
| 5017 | unwrapOrError(this->FileName, Obj->getRelocationSymbol(&Rel, SymTab)); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5018 | if (Sym && Sym->getType() == ELF::STT_SECTION) { |
| 5019 | const Elf_Shdr *Sec = unwrapOrError( |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 5020 | this->FileName, |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5021 | Obj->getSection(Sym, SymTab, this->dumper()->getShndxTable())); |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 5022 | TargetName = unwrapOrError(this->FileName, Obj->getSectionName(Sec)); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5023 | } else if (Sym) { |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 5024 | StringRef StrTable = |
| 5025 | unwrapOrError(this->FileName, Obj->getStringTableForSymtab(*SymTab)); |
Xing GUO | eec3206 | 2019-03-12 14:30:13 +0000 | [diff] [blame] | 5026 | TargetName = this->dumper()->getFullSymbolName( |
| 5027 | Sym, StrTable, SymTab->sh_type == SHT_DYNSYM /* IsDynamic */); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5028 | } |
| 5029 | |
| 5030 | if (opts::ExpandRelocs) { |
| 5031 | DictScope Group(W, "Relocation"); |
| 5032 | W.printHex("Offset", Rel.r_offset); |
| 5033 | W.printNumber("Type", RelocName, (int)Rel.getType(Obj->isMips64EL())); |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 5034 | W.printNumber("Symbol", !TargetName.empty() ? TargetName : "-", |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5035 | Rel.getSymbol(Obj->isMips64EL())); |
| 5036 | W.printHex("Addend", Rel.r_addend); |
| 5037 | } else { |
| 5038 | raw_ostream &OS = W.startLine(); |
| 5039 | OS << W.hex(Rel.r_offset) << " " << RelocName << " " |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 5040 | << (!TargetName.empty() ? TargetName : "-") << " " << W.hex(Rel.r_addend) |
| 5041 | << "\n"; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5042 | } |
| 5043 | } |
| 5044 | |
Jordan Rupprecht | dbf552c | 2018-11-12 18:02:38 +0000 | [diff] [blame] | 5045 | template <class ELFT> |
| 5046 | void LLVMStyle<ELFT>::printSectionHeaders(const ELFO *Obj) { |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5047 | ListScope SectionsD(W, "Sections"); |
| 5048 | |
| 5049 | int SectionIndex = -1; |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 5050 | ArrayRef<Elf_Shdr> Sections = unwrapOrError(this->FileName, Obj->sections()); |
George Rimar | a137087 | 2019-07-16 11:07:30 +0000 | [diff] [blame] | 5051 | const ELFObjectFile<ELFT> *ElfObj = this->dumper()->getElfObject(); |
George Rimar | d6df7de | 2019-06-14 11:56:10 +0000 | [diff] [blame] | 5052 | for (const Elf_Shdr &Sec : Sections) { |
George Rimar | 67ea32a | 2019-08-08 07:17:35 +0000 | [diff] [blame] | 5053 | StringRef Name = unwrapOrError( |
| 5054 | ElfObj->getFileName(), Obj->getSectionName(&Sec, this->WarningHandler)); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5055 | DictScope SectionD(W, "Section"); |
George Rimar | d6df7de | 2019-06-14 11:56:10 +0000 | [diff] [blame] | 5056 | W.printNumber("Index", ++SectionIndex); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5057 | W.printNumber("Name", Name, Sec.sh_name); |
Rafael Espindola | 3ba2573 | 2017-05-02 14:04:52 +0000 | [diff] [blame] | 5058 | W.printHex( |
| 5059 | "Type", |
| 5060 | object::getELFSectionTypeName(Obj->getHeader()->e_machine, Sec.sh_type), |
| 5061 | Sec.sh_type); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5062 | std::vector<EnumEntry<unsigned>> SectionFlags(std::begin(ElfSectionFlags), |
| 5063 | std::end(ElfSectionFlags)); |
| 5064 | switch (Obj->getHeader()->e_machine) { |
Prakhar Bahuguna | 52a7dd7 | 2016-12-15 07:59:08 +0000 | [diff] [blame] | 5065 | case EM_ARM: |
| 5066 | SectionFlags.insert(SectionFlags.end(), std::begin(ElfARMSectionFlags), |
| 5067 | std::end(ElfARMSectionFlags)); |
| 5068 | break; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5069 | case EM_HEXAGON: |
| 5070 | SectionFlags.insert(SectionFlags.end(), |
| 5071 | std::begin(ElfHexagonSectionFlags), |
| 5072 | std::end(ElfHexagonSectionFlags)); |
| 5073 | break; |
| 5074 | case EM_MIPS: |
| 5075 | SectionFlags.insert(SectionFlags.end(), std::begin(ElfMipsSectionFlags), |
| 5076 | std::end(ElfMipsSectionFlags)); |
| 5077 | break; |
| 5078 | case EM_X86_64: |
| 5079 | SectionFlags.insert(SectionFlags.end(), std::begin(ElfX86_64SectionFlags), |
| 5080 | std::end(ElfX86_64SectionFlags)); |
| 5081 | break; |
George Rimar | c13c59a | 2016-05-21 10:16:58 +0000 | [diff] [blame] | 5082 | case EM_XCORE: |
| 5083 | SectionFlags.insert(SectionFlags.end(), std::begin(ElfXCoreSectionFlags), |
| 5084 | std::end(ElfXCoreSectionFlags)); |
| 5085 | break; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5086 | default: |
| 5087 | // Nothing to do. |
| 5088 | break; |
| 5089 | } |
| 5090 | W.printFlags("Flags", Sec.sh_flags, makeArrayRef(SectionFlags)); |
| 5091 | W.printHex("Address", Sec.sh_addr); |
| 5092 | W.printHex("Offset", Sec.sh_offset); |
| 5093 | W.printNumber("Size", Sec.sh_size); |
| 5094 | W.printNumber("Link", Sec.sh_link); |
| 5095 | W.printNumber("Info", Sec.sh_info); |
| 5096 | W.printNumber("AddressAlignment", Sec.sh_addralign); |
| 5097 | W.printNumber("EntrySize", Sec.sh_entsize); |
| 5098 | |
| 5099 | if (opts::SectionRelocations) { |
| 5100 | ListScope D(W, "Relocations"); |
| 5101 | printRelocations(&Sec, Obj); |
| 5102 | } |
| 5103 | |
| 5104 | if (opts::SectionSymbols) { |
| 5105 | ListScope D(W, "Symbols"); |
| 5106 | const Elf_Shdr *Symtab = this->dumper()->getDotSymtabSec(); |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 5107 | StringRef StrTable = |
| 5108 | unwrapOrError(this->FileName, Obj->getStringTableForSymtab(*Symtab)); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5109 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 5110 | for (const Elf_Sym &Sym : |
| 5111 | unwrapOrError(this->FileName, Obj->symbols(Symtab))) { |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5112 | const Elf_Shdr *SymSec = unwrapOrError( |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 5113 | this->FileName, |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5114 | Obj->getSection(&Sym, Symtab, this->dumper()->getShndxTable())); |
| 5115 | if (SymSec == &Sec) |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 5116 | printSymbol(Obj, &Sym, |
| 5117 | unwrapOrError(this->FileName, Obj->symbols(Symtab)).begin(), |
Rafael Espindola | 9ea6834 | 2016-11-03 13:43:30 +0000 | [diff] [blame] | 5118 | StrTable, false); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5119 | } |
| 5120 | } |
| 5121 | |
| 5122 | if (opts::SectionData && Sec.sh_type != ELF::SHT_NOBITS) { |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 5123 | ArrayRef<uint8_t> Data = |
| 5124 | unwrapOrError(this->FileName, Obj->getSectionContents(&Sec)); |
Xing GUO | 0df95d2 | 2019-04-08 11:48:36 +0000 | [diff] [blame] | 5125 | W.printBinaryBlock( |
| 5126 | "SectionData", |
| 5127 | StringRef(reinterpret_cast<const char *>(Data.data()), Data.size())); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5128 | } |
| 5129 | } |
| 5130 | } |
| 5131 | |
| 5132 | template <class ELFT> |
| 5133 | void LLVMStyle<ELFT>::printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, |
| 5134 | const Elf_Sym *First, StringRef StrTable, |
| 5135 | bool IsDynamic) { |
| 5136 | unsigned SectionIndex = 0; |
| 5137 | StringRef SectionName; |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 5138 | this->dumper()->getSectionNameIndex(Symbol, First, SectionName, SectionIndex); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5139 | std::string FullSymbolName = |
| 5140 | this->dumper()->getFullSymbolName(Symbol, StrTable, IsDynamic); |
| 5141 | unsigned char SymbolType = Symbol->getType(); |
| 5142 | |
| 5143 | DictScope D(W, "Symbol"); |
| 5144 | W.printNumber("Name", FullSymbolName, Symbol->st_name); |
| 5145 | W.printHex("Value", Symbol->st_value); |
| 5146 | W.printNumber("Size", Symbol->st_size); |
| 5147 | W.printEnum("Binding", Symbol->getBinding(), makeArrayRef(ElfSymbolBindings)); |
| 5148 | if (Obj->getHeader()->e_machine == ELF::EM_AMDGPU && |
| 5149 | SymbolType >= ELF::STT_LOOS && SymbolType < ELF::STT_HIOS) |
| 5150 | W.printEnum("Type", SymbolType, makeArrayRef(AMDGPUSymbolTypes)); |
| 5151 | else |
| 5152 | W.printEnum("Type", SymbolType, makeArrayRef(ElfSymbolTypes)); |
Simon Atanasyan | b7807a0 | 2016-03-24 16:10:37 +0000 | [diff] [blame] | 5153 | if (Symbol->st_other == 0) |
| 5154 | // Usually st_other flag is zero. Do not pollute the output |
| 5155 | // by flags enumeration in that case. |
| 5156 | W.printNumber("Other", 0); |
| 5157 | else { |
| 5158 | std::vector<EnumEntry<unsigned>> SymOtherFlags(std::begin(ElfSymOtherFlags), |
| 5159 | std::end(ElfSymOtherFlags)); |
| 5160 | if (Obj->getHeader()->e_machine == EM_MIPS) { |
| 5161 | // Someones in their infinite wisdom decided to make STO_MIPS_MIPS16 |
| 5162 | // flag overlapped with other ST_MIPS_xxx flags. So consider both |
| 5163 | // cases separately. |
| 5164 | if ((Symbol->st_other & STO_MIPS_MIPS16) == STO_MIPS_MIPS16) |
| 5165 | SymOtherFlags.insert(SymOtherFlags.end(), |
| 5166 | std::begin(ElfMips16SymOtherFlags), |
| 5167 | std::end(ElfMips16SymOtherFlags)); |
| 5168 | else |
| 5169 | SymOtherFlags.insert(SymOtherFlags.end(), |
| 5170 | std::begin(ElfMipsSymOtherFlags), |
| 5171 | std::end(ElfMipsSymOtherFlags)); |
| 5172 | } |
| 5173 | W.printFlags("Other", Symbol->st_other, makeArrayRef(SymOtherFlags), 0x3u); |
| 5174 | } |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5175 | W.printHex("Section", SectionName, SectionIndex); |
| 5176 | } |
| 5177 | |
James Henderson | 21ed868 | 2019-01-23 16:15:39 +0000 | [diff] [blame] | 5178 | template <class ELFT> |
| 5179 | void LLVMStyle<ELFT>::printSymbols(const ELFO *Obj, bool PrintSymbols, |
| 5180 | bool PrintDynamicSymbols) { |
| 5181 | if (PrintSymbols) |
| 5182 | printSymbols(Obj); |
| 5183 | if (PrintDynamicSymbols) |
| 5184 | printDynamicSymbols(Obj); |
| 5185 | } |
| 5186 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5187 | template <class ELFT> void LLVMStyle<ELFT>::printSymbols(const ELFO *Obj) { |
| 5188 | ListScope Group(W, "Symbols"); |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 5189 | this->dumper()->printSymbolsHelper(false); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5190 | } |
| 5191 | |
| 5192 | template <class ELFT> |
| 5193 | void LLVMStyle<ELFT>::printDynamicSymbols(const ELFO *Obj) { |
| 5194 | ListScope Group(W, "DynamicSymbols"); |
Hemant Kulkarni | a11fbe1 | 2016-03-21 17:18:23 +0000 | [diff] [blame] | 5195 | this->dumper()->printSymbolsHelper(true); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5196 | } |
| 5197 | |
Simon Atanasyan | 8362cbe | 2019-05-24 12:22:53 +0000 | [diff] [blame] | 5198 | template <class ELFT> void LLVMStyle<ELFT>::printDynamic(const ELFFile<ELFT> *Obj) { |
| 5199 | Elf_Dyn_Range Table = this->dumper()->dynamic_table(); |
| 5200 | if (Table.empty()) |
| 5201 | return; |
| 5202 | |
| 5203 | raw_ostream &OS = W.getOStream(); |
| 5204 | W.startLine() << "DynamicSection [ (" << Table.size() << " entries)\n"; |
| 5205 | |
| 5206 | bool Is64 = ELFT::Is64Bits; |
| 5207 | if (Is64) |
| 5208 | W.startLine() << " Tag Type Name/Value\n"; |
| 5209 | else |
| 5210 | W.startLine() << " Tag Type Name/Value\n"; |
| 5211 | for (auto Entry : Table) { |
| 5212 | uintX_t Tag = Entry.getTag(); |
| 5213 | W.startLine() << " " << format_hex(Tag, Is64 ? 18 : 10, true) << " " |
| 5214 | << format("%-21s", |
| 5215 | getTypeString(Obj->getHeader()->e_machine, Tag)); |
| 5216 | this->dumper()->printDynamicEntry(OS, Tag, Entry.getVal()); |
| 5217 | OS << "\n"; |
| 5218 | } |
| 5219 | |
| 5220 | W.startLine() << "]\n"; |
| 5221 | } |
| 5222 | |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5223 | template <class ELFT> |
| 5224 | void LLVMStyle<ELFT>::printDynamicRelocations(const ELFO *Obj) { |
| 5225 | const DynRegionInfo &DynRelRegion = this->dumper()->getDynRelRegion(); |
| 5226 | const DynRegionInfo &DynRelaRegion = this->dumper()->getDynRelaRegion(); |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 5227 | const DynRegionInfo &DynRelrRegion = this->dumper()->getDynRelrRegion(); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5228 | const DynRegionInfo &DynPLTRelRegion = this->dumper()->getDynPLTRelRegion(); |
| 5229 | if (DynRelRegion.Size && DynRelaRegion.Size) |
| 5230 | report_fatal_error("There are both REL and RELA dynamic relocations"); |
| 5231 | W.startLine() << "Dynamic Relocations {\n"; |
| 5232 | W.indent(); |
| 5233 | if (DynRelaRegion.Size > 0) |
| 5234 | for (const Elf_Rela &Rela : this->dumper()->dyn_relas()) |
| 5235 | printDynamicRelocation(Obj, Rela); |
| 5236 | else |
| 5237 | for (const Elf_Rel &Rel : this->dumper()->dyn_rels()) { |
| 5238 | Elf_Rela Rela; |
| 5239 | Rela.r_offset = Rel.r_offset; |
| 5240 | Rela.r_info = Rel.r_info; |
| 5241 | Rela.r_addend = 0; |
| 5242 | printDynamicRelocation(Obj, Rela); |
| 5243 | } |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 5244 | if (DynRelrRegion.Size > 0) { |
| 5245 | Elf_Relr_Range Relrs = this->dumper()->dyn_relrs(); |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 5246 | std::vector<Elf_Rela> RelrRelas = |
| 5247 | unwrapOrError(this->FileName, Obj->decode_relrs(Relrs)); |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 5248 | for (const Elf_Rela &Rela : RelrRelas) |
| 5249 | printDynamicRelocation(Obj, Rela); |
| 5250 | } |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5251 | if (DynPLTRelRegion.EntSize == sizeof(Elf_Rela)) |
Rafael Espindola | aafcf75 | 2016-04-05 14:47:22 +0000 | [diff] [blame] | 5252 | for (const Elf_Rela &Rela : DynPLTRelRegion.getAsArrayRef<Elf_Rela>()) |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5253 | printDynamicRelocation(Obj, Rela); |
| 5254 | else |
Rafael Espindola | aafcf75 | 2016-04-05 14:47:22 +0000 | [diff] [blame] | 5255 | for (const Elf_Rel &Rel : DynPLTRelRegion.getAsArrayRef<Elf_Rel>()) { |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5256 | Elf_Rela Rela; |
| 5257 | Rela.r_offset = Rel.r_offset; |
| 5258 | Rela.r_info = Rel.r_info; |
| 5259 | Rela.r_addend = 0; |
| 5260 | printDynamicRelocation(Obj, Rela); |
| 5261 | } |
| 5262 | W.unindent(); |
| 5263 | W.startLine() << "}\n"; |
| 5264 | } |
| 5265 | |
| 5266 | template <class ELFT> |
| 5267 | void LLVMStyle<ELFT>::printDynamicRelocation(const ELFO *Obj, Elf_Rela Rel) { |
| 5268 | SmallString<32> RelocName; |
| 5269 | Obj->getRelocationTypeName(Rel.getType(Obj->isMips64EL()), RelocName); |
James Henderson | e50d9cb | 2019-01-17 15:34:12 +0000 | [diff] [blame] | 5270 | std::string SymbolName; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5271 | uint32_t SymIndex = Rel.getSymbol(Obj->isMips64EL()); |
| 5272 | const Elf_Sym *Sym = this->dumper()->dynamic_symbols().begin() + SymIndex; |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 5273 | SymbolName = maybeDemangle(unwrapOrError( |
| 5274 | this->FileName, Sym->getName(this->dumper()->getDynamicStringTable()))); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5275 | if (opts::ExpandRelocs) { |
| 5276 | DictScope Group(W, "Relocation"); |
| 5277 | W.printHex("Offset", Rel.r_offset); |
| 5278 | W.printNumber("Type", RelocName, (int)Rel.getType(Obj->isMips64EL())); |
Eugene Zelenko | 416e059 | 2017-06-09 21:41:54 +0000 | [diff] [blame] | 5279 | W.printString("Symbol", !SymbolName.empty() ? SymbolName : "-"); |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5280 | W.printHex("Addend", Rel.r_addend); |
| 5281 | } else { |
| 5282 | raw_ostream &OS = W.startLine(); |
| 5283 | OS << W.hex(Rel.r_offset) << " " << RelocName << " " |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 5284 | << (!SymbolName.empty() ? SymbolName : "-") << " " << W.hex(Rel.r_addend) |
| 5285 | << "\n"; |
Hemant Kulkarni | c030f23 | 2016-03-15 17:25:31 +0000 | [diff] [blame] | 5286 | } |
| 5287 | } |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 5288 | |
| 5289 | template <class ELFT> |
Matt Davis | 50ca8ed | 2019-02-01 18:51:10 +0000 | [diff] [blame] | 5290 | void LLVMStyle<ELFT>::printProgramHeaders( |
| 5291 | const ELFO *Obj, bool PrintProgramHeaders, |
| 5292 | cl::boolOrDefault PrintSectionMapping) { |
| 5293 | if (PrintProgramHeaders) |
| 5294 | printProgramHeaders(Obj); |
| 5295 | if (PrintSectionMapping == cl::BOU_TRUE) |
| 5296 | printSectionMapping(Obj); |
| 5297 | } |
| 5298 | |
| 5299 | template <class ELFT> |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 5300 | void LLVMStyle<ELFT>::printProgramHeaders(const ELFO *Obj) { |
| 5301 | ListScope L(W, "ProgramHeaders"); |
| 5302 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 5303 | for (const Elf_Phdr &Phdr : |
| 5304 | unwrapOrError(this->FileName, Obj->program_headers())) { |
Hemant Kulkarni | 966b3ac | 2016-03-25 16:04:48 +0000 | [diff] [blame] | 5305 | DictScope P(W, "ProgramHeader"); |
| 5306 | W.printHex("Type", |
| 5307 | getElfSegmentType(Obj->getHeader()->e_machine, Phdr.p_type), |
| 5308 | Phdr.p_type); |
| 5309 | W.printHex("Offset", Phdr.p_offset); |
| 5310 | W.printHex("VirtualAddress", Phdr.p_vaddr); |
| 5311 | W.printHex("PhysicalAddress", Phdr.p_paddr); |
| 5312 | W.printNumber("FileSize", Phdr.p_filesz); |
| 5313 | W.printNumber("MemSize", Phdr.p_memsz); |
| 5314 | W.printFlags("Flags", Phdr.p_flags, makeArrayRef(ElfSegmentFlags)); |
| 5315 | W.printNumber("Alignment", Phdr.p_align); |
| 5316 | } |
| 5317 | } |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 5318 | |
Hemant Kulkarni | 9b1b7f0 | 2016-04-11 17:15:30 +0000 | [diff] [blame] | 5319 | template <class ELFT> |
Xing GUO | ea16be1 | 2019-03-25 11:02:49 +0000 | [diff] [blame] | 5320 | void LLVMStyle<ELFT>::printVersionSymbolSection(const ELFFile<ELFT> *Obj, |
| 5321 | const Elf_Shdr *Sec) { |
| 5322 | DictScope SS(W, "Version symbols"); |
| 5323 | if (!Sec) |
| 5324 | return; |
| 5325 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 5326 | StringRef SecName = unwrapOrError(this->FileName, Obj->getSectionName(Sec)); |
Xing GUO | ea16be1 | 2019-03-25 11:02:49 +0000 | [diff] [blame] | 5327 | W.printNumber("Section Name", SecName, Sec->sh_name); |
| 5328 | W.printHex("Address", Sec->sh_addr); |
| 5329 | W.printHex("Offset", Sec->sh_offset); |
| 5330 | W.printNumber("Link", Sec->sh_link); |
| 5331 | |
Xing GUO | 0df95d2 | 2019-04-08 11:48:36 +0000 | [diff] [blame] | 5332 | const uint8_t *VersymBuf = |
| 5333 | reinterpret_cast<const uint8_t *>(Obj->base() + Sec->sh_offset); |
Xing GUO | ea16be1 | 2019-03-25 11:02:49 +0000 | [diff] [blame] | 5334 | const ELFDumper<ELFT> *Dumper = this->dumper(); |
| 5335 | StringRef StrTable = Dumper->getDynamicStringTable(); |
| 5336 | |
| 5337 | // Same number of entries in the dynamic symbol table (DT_SYMTAB). |
| 5338 | ListScope Syms(W, "Symbols"); |
| 5339 | for (const Elf_Sym &Sym : Dumper->dynamic_symbols()) { |
| 5340 | DictScope S(W, "Symbol"); |
| 5341 | const Elf_Versym *Versym = reinterpret_cast<const Elf_Versym *>(VersymBuf); |
| 5342 | std::string FullSymbolName = |
| 5343 | Dumper->getFullSymbolName(&Sym, StrTable, true /* IsDynamic */); |
| 5344 | W.printNumber("Version", Versym->vs_index & VERSYM_VERSION); |
| 5345 | W.printString("Name", FullSymbolName); |
| 5346 | VersymBuf += sizeof(Elf_Versym); |
| 5347 | } |
| 5348 | } |
| 5349 | |
| 5350 | template <class ELFT> |
| 5351 | void LLVMStyle<ELFT>::printVersionDefinitionSection(const ELFFile<ELFT> *Obj, |
| 5352 | const Elf_Shdr *Sec) { |
| 5353 | DictScope SD(W, "SHT_GNU_verdef"); |
| 5354 | if (!Sec) |
| 5355 | return; |
| 5356 | |
| 5357 | const uint8_t *SecStartAddress = |
Xing GUO | 0df95d2 | 2019-04-08 11:48:36 +0000 | [diff] [blame] | 5358 | reinterpret_cast<const uint8_t *>(Obj->base() + Sec->sh_offset); |
Xing GUO | ea16be1 | 2019-03-25 11:02:49 +0000 | [diff] [blame] | 5359 | const uint8_t *SecEndAddress = SecStartAddress + Sec->sh_size; |
| 5360 | const uint8_t *VerdefBuf = SecStartAddress; |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 5361 | const Elf_Shdr *StrTab = |
| 5362 | unwrapOrError(this->FileName, Obj->getSection(Sec->sh_link)); |
Xing GUO | ea16be1 | 2019-03-25 11:02:49 +0000 | [diff] [blame] | 5363 | |
| 5364 | unsigned VerDefsNum = Sec->sh_info; |
| 5365 | while (VerDefsNum--) { |
| 5366 | if (VerdefBuf + sizeof(Elf_Verdef) > SecEndAddress) |
| 5367 | // FIXME: report_fatal_error is not a good way to report error. We should |
| 5368 | // emit a parsing error here and below. |
| 5369 | report_fatal_error("invalid offset in the section"); |
| 5370 | |
| 5371 | const Elf_Verdef *Verdef = reinterpret_cast<const Elf_Verdef *>(VerdefBuf); |
| 5372 | DictScope Def(W, "Definition"); |
| 5373 | W.printNumber("Version", Verdef->vd_version); |
| 5374 | W.printEnum("Flags", Verdef->vd_flags, makeArrayRef(SymVersionFlags)); |
| 5375 | W.printNumber("Index", Verdef->vd_ndx); |
| 5376 | W.printNumber("Hash", Verdef->vd_hash); |
Xing GUO | 0df95d2 | 2019-04-08 11:48:36 +0000 | [diff] [blame] | 5377 | W.printString("Name", StringRef(reinterpret_cast<const char *>( |
| 5378 | Obj->base() + StrTab->sh_offset + |
| 5379 | Verdef->getAux()->vda_name))); |
Xing GUO | ea16be1 | 2019-03-25 11:02:49 +0000 | [diff] [blame] | 5380 | if (!Verdef->vd_cnt) |
| 5381 | report_fatal_error("at least one definition string must exist"); |
| 5382 | if (Verdef->vd_cnt > 2) |
| 5383 | report_fatal_error("more than one predecessor is not expected"); |
| 5384 | |
| 5385 | if (Verdef->vd_cnt == 2) { |
| 5386 | const uint8_t *VerdauxBuf = |
| 5387 | VerdefBuf + Verdef->vd_aux + Verdef->getAux()->vda_next; |
| 5388 | const Elf_Verdaux *Verdaux = |
| 5389 | reinterpret_cast<const Elf_Verdaux *>(VerdauxBuf); |
| 5390 | W.printString("Predecessor", |
Xing GUO | 0df95d2 | 2019-04-08 11:48:36 +0000 | [diff] [blame] | 5391 | StringRef(reinterpret_cast<const char *>( |
| 5392 | Obj->base() + StrTab->sh_offset + Verdaux->vda_name))); |
Xing GUO | ea16be1 | 2019-03-25 11:02:49 +0000 | [diff] [blame] | 5393 | } |
| 5394 | VerdefBuf += Verdef->vd_next; |
| 5395 | } |
| 5396 | } |
| 5397 | |
| 5398 | template <class ELFT> |
| 5399 | void LLVMStyle<ELFT>::printVersionDependencySection(const ELFFile<ELFT> *Obj, |
| 5400 | const Elf_Shdr *Sec) { |
| 5401 | DictScope SD(W, "SHT_GNU_verneed"); |
| 5402 | if (!Sec) |
| 5403 | return; |
| 5404 | |
Xing GUO | 0df95d2 | 2019-04-08 11:48:36 +0000 | [diff] [blame] | 5405 | const uint8_t *SecData = |
| 5406 | reinterpret_cast<const uint8_t *>(Obj->base() + Sec->sh_offset); |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 5407 | const Elf_Shdr *StrTab = |
| 5408 | unwrapOrError(this->FileName, Obj->getSection(Sec->sh_link)); |
Xing GUO | ea16be1 | 2019-03-25 11:02:49 +0000 | [diff] [blame] | 5409 | |
| 5410 | const uint8_t *VerneedBuf = SecData; |
| 5411 | unsigned VerneedNum = Sec->sh_info; |
| 5412 | for (unsigned I = 0; I < VerneedNum; ++I) { |
| 5413 | const Elf_Verneed *Verneed = |
| 5414 | reinterpret_cast<const Elf_Verneed *>(VerneedBuf); |
| 5415 | DictScope Entry(W, "Dependency"); |
| 5416 | W.printNumber("Version", Verneed->vn_version); |
| 5417 | W.printNumber("Count", Verneed->vn_cnt); |
| 5418 | W.printString("FileName", |
Xing GUO | 0df95d2 | 2019-04-08 11:48:36 +0000 | [diff] [blame] | 5419 | StringRef(reinterpret_cast<const char *>( |
| 5420 | Obj->base() + StrTab->sh_offset + Verneed->vn_file))); |
Xing GUO | ea16be1 | 2019-03-25 11:02:49 +0000 | [diff] [blame] | 5421 | |
| 5422 | const uint8_t *VernauxBuf = VerneedBuf + Verneed->vn_aux; |
Xing GUO | 8ab7414 | 2019-04-10 12:47:21 +0000 | [diff] [blame] | 5423 | ListScope L(W, "Entries"); |
Xing GUO | ea16be1 | 2019-03-25 11:02:49 +0000 | [diff] [blame] | 5424 | for (unsigned J = 0; J < Verneed->vn_cnt; ++J) { |
| 5425 | const Elf_Vernaux *Vernaux = |
| 5426 | reinterpret_cast<const Elf_Vernaux *>(VernauxBuf); |
| 5427 | DictScope Entry(W, "Entry"); |
| 5428 | W.printNumber("Hash", Vernaux->vna_hash); |
| 5429 | W.printEnum("Flags", Vernaux->vna_flags, makeArrayRef(SymVersionFlags)); |
| 5430 | W.printNumber("Index", Vernaux->vna_other); |
| 5431 | W.printString("Name", |
Xing GUO | 0df95d2 | 2019-04-08 11:48:36 +0000 | [diff] [blame] | 5432 | StringRef(reinterpret_cast<const char *>( |
| 5433 | Obj->base() + StrTab->sh_offset + Vernaux->vna_name))); |
Xing GUO | ea16be1 | 2019-03-25 11:02:49 +0000 | [diff] [blame] | 5434 | VernauxBuf += Vernaux->vna_next; |
| 5435 | } |
| 5436 | VerneedBuf += Verneed->vn_next; |
| 5437 | } |
| 5438 | } |
| 5439 | |
| 5440 | template <class ELFT> |
Hemant Kulkarni | 9b1b7f0 | 2016-04-11 17:15:30 +0000 | [diff] [blame] | 5441 | void LLVMStyle<ELFT>::printHashHistogram(const ELFFile<ELFT> *Obj) { |
| 5442 | W.startLine() << "Hash Histogram not implemented!\n"; |
| 5443 | } |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 5444 | |
| 5445 | template <class ELFT> |
Michael J. Spencer | ae6eeae | 2018-06-02 16:33:01 +0000 | [diff] [blame] | 5446 | void LLVMStyle<ELFT>::printCGProfile(const ELFFile<ELFT> *Obj) { |
| 5447 | ListScope L(W, "CGProfile"); |
| 5448 | if (!this->dumper()->getDotCGProfileSec()) |
| 5449 | return; |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 5450 | auto CGProfile = unwrapOrError( |
| 5451 | this->FileName, Obj->template getSectionContentsAsArray<Elf_CGProfile>( |
| 5452 | this->dumper()->getDotCGProfileSec())); |
Michael J. Spencer | ae6eeae | 2018-06-02 16:33:01 +0000 | [diff] [blame] | 5453 | for (const Elf_CGProfile &CGPE : CGProfile) { |
| 5454 | DictScope D(W, "CGProfileEntry"); |
| 5455 | W.printNumber("From", this->dumper()->getStaticSymbolName(CGPE.cgp_from), |
| 5456 | CGPE.cgp_from); |
| 5457 | W.printNumber("To", this->dumper()->getStaticSymbolName(CGPE.cgp_to), |
| 5458 | CGPE.cgp_to); |
| 5459 | W.printNumber("Weight", CGPE.cgp_weight); |
| 5460 | } |
| 5461 | } |
| 5462 | |
| 5463 | template <class ELFT> |
Peter Collingbourne | 3e22733 | 2018-07-17 22:17:18 +0000 | [diff] [blame] | 5464 | void LLVMStyle<ELFT>::printAddrsig(const ELFFile<ELFT> *Obj) { |
| 5465 | ListScope L(W, "Addrsig"); |
| 5466 | if (!this->dumper()->getDotAddrsigSec()) |
| 5467 | return; |
| 5468 | ArrayRef<uint8_t> Contents = unwrapOrError( |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 5469 | this->FileName, |
Peter Collingbourne | 3e22733 | 2018-07-17 22:17:18 +0000 | [diff] [blame] | 5470 | Obj->getSectionContents(this->dumper()->getDotAddrsigSec())); |
| 5471 | const uint8_t *Cur = Contents.begin(); |
| 5472 | const uint8_t *End = Contents.end(); |
| 5473 | while (Cur != End) { |
| 5474 | unsigned Size; |
| 5475 | const char *Err; |
Peter Collingbourne | 7d17908 | 2018-08-21 17:18:18 +0000 | [diff] [blame] | 5476 | uint64_t SymIndex = decodeULEB128(Cur, &Size, End, &Err); |
Peter Collingbourne | 3e22733 | 2018-07-17 22:17:18 +0000 | [diff] [blame] | 5477 | if (Err) |
| 5478 | reportError(Err); |
| 5479 | W.printNumber("Sym", this->dumper()->getStaticSymbolName(SymIndex), |
| 5480 | SymIndex); |
| 5481 | Cur += Size; |
| 5482 | } |
| 5483 | } |
| 5484 | |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 5485 | template <typename ELFT> |
George Rimar | 9e88a26 | 2019-05-14 14:22:44 +0000 | [diff] [blame] | 5486 | static void printGNUNoteLLVMStyle(uint32_t NoteType, ArrayRef<uint8_t> Desc, |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 5487 | ScopedPrinter &W) { |
| 5488 | switch (NoteType) { |
| 5489 | default: |
| 5490 | return; |
| 5491 | case ELF::NT_GNU_ABI_TAG: { |
Jake Ehrlich | ee7ec6c | 2018-11-13 01:10:35 +0000 | [diff] [blame] | 5492 | const GNUAbiTag &AbiTag = getGNUAbiTag<ELFT>(Desc); |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 5493 | if (!AbiTag.IsValid) { |
| 5494 | W.printString("ABI", "<corrupt GNU_ABI_TAG>"); |
| 5495 | } else { |
| 5496 | W.printString("OS", AbiTag.OSName); |
| 5497 | W.printString("ABI", AbiTag.ABI); |
| 5498 | } |
| 5499 | break; |
| 5500 | } |
| 5501 | case ELF::NT_GNU_BUILD_ID: { |
Jake Ehrlich | ee7ec6c | 2018-11-13 01:10:35 +0000 | [diff] [blame] | 5502 | W.printString("Build ID", getGNUBuildId(Desc)); |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 5503 | break; |
| 5504 | } |
| 5505 | case ELF::NT_GNU_GOLD_VERSION: |
Jake Ehrlich | ee7ec6c | 2018-11-13 01:10:35 +0000 | [diff] [blame] | 5506 | W.printString("Version", getGNUGoldVersion(Desc)); |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 5507 | break; |
| 5508 | case ELF::NT_GNU_PROPERTY_TYPE_0: |
| 5509 | ListScope D(W, "Property"); |
Jake Ehrlich | ee7ec6c | 2018-11-13 01:10:35 +0000 | [diff] [blame] | 5510 | for (const auto &Property : getGNUPropertyList<ELFT>(Desc)) |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 5511 | W.printString(Property); |
| 5512 | break; |
| 5513 | } |
| 5514 | } |
| 5515 | |
Peter Collingbourne | 3e22733 | 2018-07-17 22:17:18 +0000 | [diff] [blame] | 5516 | template <class ELFT> |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 5517 | void LLVMStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) { |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 5518 | ListScope L(W, "Notes"); |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 5519 | |
| 5520 | auto PrintHeader = [&](const typename ELFT::Off Offset, |
| 5521 | const typename ELFT::Addr Size) { |
| 5522 | W.printHex("Offset", Offset); |
| 5523 | W.printHex("Size", Size); |
| 5524 | }; |
| 5525 | |
| 5526 | auto ProcessNote = [&](const Elf_Note &Note) { |
| 5527 | DictScope D2(W, "Note"); |
| 5528 | StringRef Name = Note.getName(); |
Jake Ehrlich | ee7ec6c | 2018-11-13 01:10:35 +0000 | [diff] [blame] | 5529 | ArrayRef<uint8_t> Descriptor = Note.getDesc(); |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 5530 | Elf_Word Type = Note.getType(); |
| 5531 | |
| 5532 | W.printString("Owner", Name); |
| 5533 | W.printHex("Data size", Descriptor.size()); |
| 5534 | if (Name == "GNU") { |
| 5535 | W.printString("Type", getGNUNoteTypeName(Type)); |
| 5536 | printGNUNoteLLVMStyle<ELFT>(Type, Descriptor, W); |
| 5537 | } else if (Name == "FreeBSD") { |
| 5538 | W.printString("Type", getFreeBSDNoteTypeName(Type)); |
| 5539 | } else if (Name == "AMD") { |
Scott Linder | f5b36e5 | 2018-12-12 19:39:27 +0000 | [diff] [blame] | 5540 | W.printString("Type", getAMDNoteTypeName(Type)); |
| 5541 | const AMDNote N = getAMDNote<ELFT>(Type, Descriptor); |
| 5542 | if (!N.Type.empty()) |
| 5543 | W.printString(N.Type, N.Value); |
| 5544 | } else if (Name == "AMDGPU") { |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 5545 | W.printString("Type", getAMDGPUNoteTypeName(Type)); |
| 5546 | const AMDGPUNote N = getAMDGPUNote<ELFT>(Type, Descriptor); |
Scott Linder | f5b36e5 | 2018-12-12 19:39:27 +0000 | [diff] [blame] | 5547 | if (!N.Type.empty()) |
| 5548 | W.printString(N.Type, N.Value); |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 5549 | } else { |
Jordan Rupprecht | d884fbd | 2019-08-05 15:43:20 +0000 | [diff] [blame] | 5550 | StringRef NoteType = Obj->getHeader()->e_type == ELF::ET_CORE |
| 5551 | ? getCoreNoteTypeName(Type) |
| 5552 | : getGenericNoteTypeName(Type); |
Jordan Rupprecht | 871baa2 | 2019-03-29 16:48:19 +0000 | [diff] [blame] | 5553 | if (!NoteType.empty()) |
| 5554 | W.printString("Type", NoteType); |
| 5555 | else |
| 5556 | W.printString("Type", |
| 5557 | "Unknown (" + to_string(format_hex(Type, 10)) + ")"); |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 5558 | } |
| 5559 | }; |
| 5560 | |
George Rimar | 1206f5a | 2019-01-30 15:39:05 +0000 | [diff] [blame] | 5561 | if (Obj->getHeader()->e_type == ELF::ET_CORE) { |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 5562 | for (const auto &P : |
| 5563 | unwrapOrError(this->FileName, Obj->program_headers())) { |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 5564 | if (P.p_type != PT_NOTE) |
| 5565 | continue; |
| 5566 | DictScope D(W, "NoteSection"); |
| 5567 | PrintHeader(P.p_offset, P.p_filesz); |
| 5568 | Error Err = Error::success(); |
| 5569 | for (const auto &Note : Obj->notes(P, Err)) |
| 5570 | ProcessNote(Note); |
| 5571 | if (Err) |
George Rimar | 36f2318 | 2019-08-13 12:07:41 +0000 | [diff] [blame^] | 5572 | reportError(std::move(Err), this->FileName); |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 5573 | } |
| 5574 | } else { |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 5575 | for (const auto &S : unwrapOrError(this->FileName, Obj->sections())) { |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 5576 | if (S.sh_type != SHT_NOTE) |
| 5577 | continue; |
| 5578 | DictScope D(W, "NoteSection"); |
| 5579 | PrintHeader(S.sh_offset, S.sh_size); |
| 5580 | Error Err = Error::success(); |
| 5581 | for (const auto &Note : Obj->notes(S, Err)) |
| 5582 | ProcessNote(Note); |
| 5583 | if (Err) |
George Rimar | 36f2318 | 2019-08-13 12:07:41 +0000 | [diff] [blame^] | 5584 | reportError(std::move(Err), this->FileName); |
Jordan Rupprecht | 4f36c7a | 2018-11-07 23:53:50 +0000 | [diff] [blame] | 5585 | } |
| 5586 | } |
Saleem Abdulrasool | 6a40544 | 2016-08-30 18:52:02 +0000 | [diff] [blame] | 5587 | } |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 5588 | |
| 5589 | template <class ELFT> |
Saleem Abdulrasool | b36fbbc | 2018-01-30 16:29:29 +0000 | [diff] [blame] | 5590 | void LLVMStyle<ELFT>::printELFLinkerOptions(const ELFFile<ELFT> *Obj) { |
| 5591 | ListScope L(W, "LinkerOptions"); |
| 5592 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 5593 | for (const Elf_Shdr &Shdr : unwrapOrError(this->FileName, Obj->sections())) { |
Saleem Abdulrasool | b36fbbc | 2018-01-30 16:29:29 +0000 | [diff] [blame] | 5594 | if (Shdr.sh_type != ELF::SHT_LLVM_LINKER_OPTIONS) |
| 5595 | continue; |
| 5596 | |
George Rimar | e3d81fd | 2019-08-09 10:53:12 +0000 | [diff] [blame] | 5597 | ArrayRef<uint8_t> Contents = |
| 5598 | unwrapOrError(this->FileName, Obj->getSectionContents(&Shdr)); |
George Rimar | ec895f1 | 2019-05-16 06:22:51 +0000 | [diff] [blame] | 5599 | for (const uint8_t *P = Contents.begin(), *E = Contents.end(); P < E; ) { |
Saleem Abdulrasool | b36fbbc | 2018-01-30 16:29:29 +0000 | [diff] [blame] | 5600 | StringRef Key = StringRef(reinterpret_cast<const char *>(P)); |
| 5601 | StringRef Value = |
| 5602 | StringRef(reinterpret_cast<const char *>(P) + Key.size() + 1); |
| 5603 | |
| 5604 | W.printString(Key, Value); |
| 5605 | |
| 5606 | P = P + Key.size() + Value.size() + 2; |
| 5607 | } |
| 5608 | } |
| 5609 | } |
| 5610 | |
| 5611 | template <class ELFT> |
Wolfgang Pieb | c71c629 | 2019-08-05 22:47:07 +0000 | [diff] [blame] | 5612 | void LLVMStyle<ELFT>::printStackSizes(const ELFObjectFile<ELFT> *Obj) { |
| 5613 | W.printString( |
| 5614 | "Dumping of stack sizes in LLVM style is not implemented yet\n"); |
| 5615 | } |
| 5616 | |
| 5617 | template <class ELFT> |
| 5618 | void LLVMStyle<ELFT>::printStackSizeEntry(uint64_t Size, StringRef FuncName) { |
| 5619 | // FIXME: Implement this function for LLVM-style dumping. |
| 5620 | } |
| 5621 | |
| 5622 | template <class ELFT> |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 5623 | void LLVMStyle<ELFT>::printMipsGOT(const MipsGOTParser<ELFT> &Parser) { |
| 5624 | auto PrintEntry = [&](const Elf_Addr *E) { |
| 5625 | W.printHex("Address", Parser.getGotAddress(E)); |
| 5626 | W.printNumber("Access", Parser.getGotOffset(E)); |
| 5627 | W.printHex("Initial", *E); |
| 5628 | }; |
| 5629 | |
| 5630 | DictScope GS(W, Parser.IsStatic ? "Static GOT" : "Primary GOT"); |
| 5631 | |
| 5632 | W.printHex("Canonical gp value", Parser.getGp()); |
| 5633 | { |
| 5634 | ListScope RS(W, "Reserved entries"); |
| 5635 | { |
| 5636 | DictScope D(W, "Entry"); |
| 5637 | PrintEntry(Parser.getGotLazyResolver()); |
| 5638 | W.printString("Purpose", StringRef("Lazy resolver")); |
| 5639 | } |
| 5640 | |
| 5641 | if (Parser.getGotModulePointer()) { |
| 5642 | DictScope D(W, "Entry"); |
| 5643 | PrintEntry(Parser.getGotModulePointer()); |
| 5644 | W.printString("Purpose", StringRef("Module pointer (GNU extension)")); |
| 5645 | } |
| 5646 | } |
| 5647 | { |
| 5648 | ListScope LS(W, "Local entries"); |
| 5649 | for (auto &E : Parser.getLocalEntries()) { |
| 5650 | DictScope D(W, "Entry"); |
| 5651 | PrintEntry(&E); |
| 5652 | } |
| 5653 | } |
| 5654 | |
| 5655 | if (Parser.IsStatic) |
| 5656 | return; |
| 5657 | |
| 5658 | { |
| 5659 | ListScope GS(W, "Global entries"); |
| 5660 | for (auto &E : Parser.getGlobalEntries()) { |
| 5661 | DictScope D(W, "Entry"); |
| 5662 | |
| 5663 | PrintEntry(&E); |
| 5664 | |
| 5665 | const Elf_Sym *Sym = Parser.getGotSym(&E); |
| 5666 | W.printHex("Value", Sym->st_value); |
| 5667 | W.printEnum("Type", Sym->getType(), makeArrayRef(ElfSymbolTypes)); |
| 5668 | |
| 5669 | unsigned SectionIndex = 0; |
| 5670 | StringRef SectionName; |
| 5671 | this->dumper()->getSectionNameIndex( |
| 5672 | Sym, this->dumper()->dynamic_symbols().begin(), SectionName, |
| 5673 | SectionIndex); |
| 5674 | W.printHex("Section", SectionName, SectionIndex); |
| 5675 | |
| 5676 | std::string SymName = this->dumper()->getFullSymbolName( |
| 5677 | Sym, this->dumper()->getDynamicStringTable(), true); |
| 5678 | W.printNumber("Name", SymName, Sym->st_name); |
| 5679 | } |
| 5680 | } |
| 5681 | |
| 5682 | W.printNumber("Number of TLS and multi-GOT entries", |
Simon Atanasyan | 4e945b6 | 2017-12-21 10:46:20 +0000 | [diff] [blame] | 5683 | uint64_t(Parser.getOtherEntries().size())); |
Simon Atanasyan | 62d3259 | 2017-12-21 10:26:02 +0000 | [diff] [blame] | 5684 | } |
| 5685 | |
| 5686 | template <class ELFT> |
| 5687 | void LLVMStyle<ELFT>::printMipsPLT(const MipsGOTParser<ELFT> &Parser) { |
| 5688 | auto PrintEntry = [&](const Elf_Addr *E) { |
| 5689 | W.printHex("Address", Parser.getPltAddress(E)); |
| 5690 | W.printHex("Initial", *E); |
| 5691 | }; |
| 5692 | |
| 5693 | DictScope GS(W, "PLT GOT"); |
| 5694 | |
| 5695 | { |
| 5696 | ListScope RS(W, "Reserved entries"); |
| 5697 | { |
| 5698 | DictScope D(W, "Entry"); |
| 5699 | PrintEntry(Parser.getPltLazyResolver()); |
| 5700 | W.printString("Purpose", StringRef("PLT lazy resolver")); |
| 5701 | } |
| 5702 | |
| 5703 | if (auto E = Parser.getPltModulePointer()) { |
| 5704 | DictScope D(W, "Entry"); |
| 5705 | PrintEntry(E); |
| 5706 | W.printString("Purpose", StringRef("Module pointer")); |
| 5707 | } |
| 5708 | } |
| 5709 | { |
| 5710 | ListScope LS(W, "Entries"); |
| 5711 | for (auto &E : Parser.getPltEntries()) { |
| 5712 | DictScope D(W, "Entry"); |
| 5713 | PrintEntry(&E); |
| 5714 | |
| 5715 | const Elf_Sym *Sym = Parser.getPltSym(&E); |
| 5716 | W.printHex("Value", Sym->st_value); |
| 5717 | W.printEnum("Type", Sym->getType(), makeArrayRef(ElfSymbolTypes)); |
| 5718 | |
| 5719 | unsigned SectionIndex = 0; |
| 5720 | StringRef SectionName; |
| 5721 | this->dumper()->getSectionNameIndex( |
| 5722 | Sym, this->dumper()->dynamic_symbols().begin(), SectionName, |
| 5723 | SectionIndex); |
| 5724 | W.printHex("Section", SectionName, SectionIndex); |
| 5725 | |
| 5726 | std::string SymName = |
| 5727 | this->dumper()->getFullSymbolName(Sym, Parser.getPltStrTable(), true); |
| 5728 | W.printNumber("Name", SymName, Sym->st_name); |
| 5729 | } |
| 5730 | } |
| 5731 | } |